Re: AbstractPersistentField Question
Thomas: Thanks for your reply. I am already at version 1.17 of AbstractPersistentField . I have already tried overriding computeField(), and in it calling AbstractPersistentField.computeField(); I catch the MetadateException and then try to replace the interface Class with an actual implementer Class. The problem is that the interface Class I need to replace is not the one I pass in to computeField(), but the one that is the next level down (in the recursion chain). This is done in the private methods, and so I have no way to modify that behavior. Am I explaining this in such a way as to make the problem clear? If methods getFieldRecursive() and getNestedFieldRecursive() were protected, I could modify them and substitute my implementer Class for the interface Class when needed... The actual exception thrown is originally a NoSuchFieldException thrown from getFieldRecursive(). Gary --- Thomas Dudziak [EMAIL PROTECTED] wrote: On Tue, 30 Mar 2004, Gary wrote: I am wondering why the methods getFieldRecursive() and getNestedFieldRecursive() in class AbstractPersistentField are private. I would like to have the ability to override them in a custom persistent field implementation. Here is my dilemma: I have the following classes: package ojb; public interface IParent { IChild getChild(); void setChild(IChild child); } package ojb; public interface IChild { String getDescription(); void setDescription(String description); } package ojb; public class Parent implements IParent { private IChild child = null; public Parent() { super(); } public IChild getChild() { return child; } public void setChild(IChild child) { this.child = child; } } package ojb; public class Child implements IChild { private String description = null; public Child() { super(); } public String getDescription() { return description; } public void setDescription(String string) { description = string; } } I have the following OJB metadata. field-descriptor name=child::description column=childDescription jdbc-type=VARCHAR / I am using a subclass of PersistentFieldIntrospectorImpl. The problem is that when it tries to resolve child::description, it ends up going through the IChild getChild() method signature. This causes it to analyze the fields of IChild; of course there arent any, so it fails with a MetadataException. If I could override methods getFieldRecursive() and getNestedFieldRecursive(), I could substitute at run time a class that implements IChild. Any ideas? I really need to return a reference to an interface here, rather than to a concrete class, as our design is heavily interface based. Have you tried the CVS version ? I made some changed that may be of interest to you: * methods getFieldRecursive and getNestedRecursiveField are static and, though still private, you can use them via the protected static method computeField in AbstractPersistentField * I fixed getFieldRecursive such that it no longer throws an exception when given an interface * support for interfaces in the repository descriptor is now much better; specifically using PersistentFieldIntrospectorImpl (bean-access) or PersistentFieldAutoProxyImpl (detects access method automatically - best for mixing concrete classes and interfaces) should work much better now Perhaps you could try the CVS version with the unmodified PersistentFieldIntrospectorImpl, and if you still have problems, then please post the stacktrace ? Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: AbstractPersistentField Question
I've tried your classes and descriptor, and I've found one problem which is concerned with the initialization of the nested field. To be more precise, when reading an object from the database, OJB must create the nested field (child in your case, e.g. setChild/getChild when using IProduct). In order to do so, it creates an instance (line 293 in AbstractPersistentField) using newInstance(). This of course won't work with IChild. I've extracted the newInstance line into a new protected method createNestedFieldValue which you could override in your PersistentField subtype like this: public class MyPersistentFieldImpl extends PersistentFieldIntrospectorImpl { public MyPersistentFieldImpl() { super(); } public MyPersistentFieldImpl(Class aClass, String aPropertyName) { super(aClass, aPropertyName); } protected Object createNestedFieldValue(PersistentField nestedField) throws InstantiationException, IllegalAccessException { Class type = nestedField.getType(); // this of course should be more generic if (type == IChild.class) { return new Child(); } else { return super.createNestedFieldValue(nestedField); } } } Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
AbstractPersistentField Question
I am wondering why the methods getFieldRecursive() and getNestedFieldRecursive() in class AbstractPersistentField are private. I would like to have the ability to override them in a custom persistent field implementation. Here is my dilemma: I have the following classes: package ojb; public interface IParent { IChild getChild(); void setChild(IChild child); } package ojb; public interface IChild { String getDescription(); void setDescription(String description); } package ojb; public class Parent implements IParent { private IChild child = null; public Parent() { super(); } public IChild getChild() { return child; } public void setChild(IChild child) { this.child = child; } } package ojb; public class Child implements IChild { private String description = null; public Child() { super(); } public String getDescription() { return description; } public void setDescription(String string) { description = string; } } I have the following OJB metadata. field-descriptor name=child::description column=childDescription jdbc-type=VARCHAR / I am using a subclass of PersistentFieldIntrospectorImpl. The problem is that when it tries to resolve child::description, it ends up going through the IChild getChild() method signature. This causes it to analyze the fields of IChild; of course there arent any, so it fails with a MetadataException. If I could override methods getFieldRecursive() and getNestedFieldRecursive(), I could substitute at run time a class that implements IChild. Any ideas? I really need to return a reference to an interface here, rather than to a concrete class, as our design is heavily interface based. Thanks again, Gary __ Do you Yahoo!? Yahoo! Finance Tax Center - File online. File on time. http://taxes.yahoo.com/filing.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: AbstractPersistentField Question
On Tue, 30 Mar 2004, Gary wrote: I am wondering why the methods getFieldRecursive() and getNestedFieldRecursive() in class AbstractPersistentField are private. I would like to have the ability to override them in a custom persistent field implementation. Here is my dilemma: I have the following classes: package ojb; public interface IParent { IChild getChild(); void setChild(IChild child); } package ojb; public interface IChild { String getDescription(); void setDescription(String description); } package ojb; public class Parent implements IParent { private IChild child = null; public Parent() { super(); } public IChild getChild() { return child; } public void setChild(IChild child) { this.child = child; } } package ojb; public class Child implements IChild { private String description = null; public Child() { super(); } public String getDescription() { return description; } public void setDescription(String string) { description = string; } } I have the following OJB metadata. field-descriptor name=child::description column=childDescription jdbc-type=VARCHAR / I am using a subclass of PersistentFieldIntrospectorImpl. The problem is that when it tries to resolve child::description, it ends up going through the IChild getChild() method signature. This causes it to analyze the fields of IChild; of course there arent any, so it fails with a MetadataException. If I could override methods getFieldRecursive() and getNestedFieldRecursive(), I could substitute at run time a class that implements IChild. Any ideas? I really need to return a reference to an interface here, rather than to a concrete class, as our design is heavily interface based. Have you tried the CVS version ? I made some changed that may be of interest to you: * methods getFieldRecursive and getNestedRecursiveField are static and, though still private, you can use them via the protected static method computeField in AbstractPersistentField * I fixed getFieldRecursive such that it no longer throws an exception when given an interface * support for interfaces in the repository descriptor is now much better; specifically using PersistentFieldIntrospectorImpl (bean-access) or PersistentFieldAutoProxyImpl (detects access method automatically - best for mixing concrete classes and interfaces) should work much better now Perhaps you could try the CVS version with the unmodified PersistentFieldIntrospectorImpl, and if you still have problems, then please post the stacktrace ? Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]