Apache JDO Project - Patch for review: fix for JDO-81

This is Interesting: Free IT Magazines  
Home > Archive > Apache JDO Project > August 2005 > Patch for review: fix for JDO-81





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Patch for review: fix for JDO-81
Michael Bouschen

2005-08-11, 5:45 pm

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 Tech@Spree Engineering GmbH
mailto:mbo.tech@spree.de http://www.tech.spree.de/
Tel.:++49/30/235 520-33 Buelowstr. 66
Fax.:++49/30/2175 2012 D-10783 Berlin


Craig Russell

2005-08-11, 5:45 pm

Hi Michael,

Great. I didn't see any issues.

Thanks,

Craig


On Aug 11, 2005, at 8:27 AM, Michael Bouschen wrote:

> 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 Tech@Spree Engineering GmbH
> mailto:mbo.tech@spree.de 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_Nam
e;
> final String methodSig =
> JDO_PC_jdoNewObjectIdInstance_Object_Sig
;
> final int accessFlags =
> JDO_PC_jdoNewObjectIdInstance_Object_Mod
s;
> - // 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);
> }
>
> //
> ----------------------------------------------------------------------
>


Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com