Hi Martin, hi Craig,
today one test in fostore20 fails: Test_EmpDeptAppId. The enhancer from
the enhancer20 project generates a method jdoNewObjectIdInstance(Object)
throwing an UnsupportedOperationException. I changed the enhancer to
generate the old code as it was generated for the JDO1 method
jdoNewObjectIdInstance(String). I just added a cast expression for the
Object argument before it is passed to the ObjectId constructor.
This change is a workaround allowing the test to pass. It is not a full
implementation of jdoNewObjectIdInstance, because it lacks support for
single field identity. Attached you find a patch.
Regards Michael
--
Michael Bouschen [EMAIL PROTECTED] Engineering GmbH
mailto:[EMAIL PROTECTED] http://www.tech.spree.de/
Tel.:++49/30/235 520-33 Buelowstr. 66
Fax.:++49/30/2175 2012 D-10783 Berlin
Index: src/java/org/apache/jdo/impl/enhancer/generator/ImplHelper.java
===================================================================
--- src/java/org/apache/jdo/impl/enhancer/generator/ImplHelper.java
(revision 231450)
+++ src/java/org/apache/jdo/impl/enhancer/generator/ImplHelper.java
(working copy)
@@ -392,9 +392,12 @@
String o)
{
final List impl = new ArrayList(5);
- // TODO: generate real method body
- String msg = "Method jdoNewObjectIdInstance not yet supported";
- impl.add("throw new UnsupportedOperationException(\"" + msg + "\");");
+ if (oidclassname == null) {
+ impl.add("return null;");
+ } else {
+ // TODO: support for single field identity
+ impl.add("return new " + oidclassname + "((String)" + o + ");");
+ }
return impl;
}
Index: src/java/org/apache/jdo/impl/enhancer/core/Builder.java
===================================================================
--- src/java/org/apache/jdo/impl/enhancer/core/Builder.java (revision
231450)
+++ src/java/org/apache/jdo/impl/enhancer/core/Builder.java (working copy)
@@ -3040,8 +3040,61 @@
final String methodName = JDO_PC_jdoNewObjectIdInstance_Object_Name;
final String methodSig = JDO_PC_jdoNewObjectIdInstance_Object_Sig;
final int accessFlags = JDO_PC_jdoNewObjectIdInstance_Object_Mods;
- // TODO: generate real method body
- addNotYetImplementedMethod(methodName, methodSig, accessFlags);
+ final ExceptionsAttribute exceptAttr = null;
+
+ // begin of method body
+ final InsnTarget begin = new InsnTarget();
+ Insn insn = begin;
+
+ // generate empty method in case of datastore identity
+ final String keyClassName = analyzer.getKeyClassName();
+ if (keyClassName == null){
+ // end of method body
+ insn = insn.append(Insn.create(opc_aconst_null));
+ insn = insn.append(Insn.create(opc_areturn));
+
+ final CodeAttribute codeAttr
+ = new CodeAttribute(getCodeAttributeUtf8(),
+ 1, // maxStack
+ 2, // maxLocals
+ begin,
+ new ExceptionTable(),
+ new AttributeVector());
+ augmenter.addMethod(methodName, methodSig, accessFlags,
+ codeAttr, exceptAttr);
+ return;
+ }
+ affirm(keyClassName != null);
+
+ // TODO: support for single field identity
+
+ // push a newly created an instance of this class
+ insn = insn.append(
+ Insn.create(opc_new,
+ pool.addClass(keyClassName)));
+ insn = insn.append(Insn.create(opc_dup));
+ insn = insn.append(Insn.create(opc_aload_1));
+ insn = insn.append(Insn.create(opc_checkcast,
+ pool.addClass(JAVA_String_Path)));
+ insn = insn.append(
+ Insn.create(opc_invokespecial,
+ pool.addMethodRef(
+ keyClassName,
+ NameHelper.constructorName(),
+ NameHelper.constructorSig(JAVA_String_Sig))));
+
+ // end of method body
+ insn = insn.append(Insn.create(opc_areturn));
+
+ final CodeAttribute codeAttr
+ = new CodeAttribute(getCodeAttributeUtf8(),
+ 3, // maxStack
+ 2, // maxLocals
+ begin,
+ new ExceptionTable(),
+ new AttributeVector());
+ augmenter.addMethod(methodName, methodSig, accessFlags,
+ codeAttr, exceptAttr);
}
// ----------------------------------------------------------------------