Well, not really. Your code looks like it's examining the database to find the right ClassDescriptor, which I don't really need to do. I'm looking for a way to override readObjectFromRow, so that I can simply return an object of the correct class. All the different classes come from the same table, so I want to have only one class descriptor.
David |---------+---------------------------> | | "Jim Shingler" | | | <[EMAIL PROTECTED]| | | et> | | | | | | 06/25/2003 05:16| | | PM | | | Please respond | | | to "OJB Users | | | List" | | | | |---------+---------------------------> >--------------------------------------------------------------------------------------------------------------------------------------------------| | | | To: "'OJB Users List'" <[EMAIL PROTECTED]> | | cc: | | Subject: RE: Getting the correct class instantiated | | | >--------------------------------------------------------------------------------------------------------------------------------------------------| I do the same thing. Below you will find a segment of my row reader below. Table ContactPoint ID TypeID EmailAddress PhoneNumber ... ID TypeID EmailAddress PhoneNumber 1 1 [EMAIL PROTECTED] 2 2 NA 123-345.6789 Type Table ID classOf ID ClassOF 1 sd.loc.Email 2 sd.loc.PhoneNumber Objects ContactPoint |- sd.loc.PhoneNumber |- sd.loc.Email Obvious disclaimers, I haven't had this reviewed by the experts yet. Maybe some experts can comment. ClassDescriptor cld = getClassDescriptor(); // check if there is an attribute which tells us which concrete class is to be instantiated //FieldDescriptor concreteClassFD = cld.getFieldDescriptorByName(ClassDescriptor.OJB_CONCRETE_CLASS); FieldDescriptor concreteClassFD = cld.getFieldDescriptorByName("classOf"); FieldDescriptor concreteClassFD2 = cld.getFieldDescriptorByName("typeID"); ClassDescriptor result = null; // JLS IDEA: // IF ClassOf isnt present check for TypeID and Load the underlying TypeClass to get the "ClassOF" // TypeID should be the preferred method if (concreteClassFD == null && concreteClassFD2 == null) return cld; if (concreteClassFD2 != null) { // Load the Type and pull classof off it Type typeQuery = new Type(); typeQuery.setObjID((String) row.get(concreteClassFD2.getColumnName())); Query query = new QueryByCriteria(typeQuery); //uery. Type type = null; String concreteClass = null; PersistenceBroker broker = null; try { broker = PersistenceBrokerFactory.defaultPersistenceBroker(); //broker.beginTransaction (); Object o = broker.getObjectByQuery(query); type = (Type)ProxyHelper.getRealObject(o); //broker.commitTransaction (); concreteClass = type.getClassOf(); if (concreteClass == null || concreteClass.trim().length() == 0) { throw new PersistenceBrokerException( "type.classOf field returned null or 0-length string"); } else { concreteClass = concreteClass.trim(); } result = broker.getClassDescriptor(Class.forName(concreteClass, true, Thread.currentThread().getContextClassLoader())); //PersistenceBrokerFactory.releaseInstance(broker); //Constructor con = result.getZeroArgumentConstructor(); //Object oo = ConstructorHelper.instantiate(con); //ClassDescriptor result = cld.getRepository().getDescriptorFor(concreteClass); if (result == null) { result = cld; } return result; } catch (PBFactoryException e) { throw new PersistenceBrokerException(e); } catch (Throwable t) { //broker.abortTransaction (); t.printStackTrace(); } } else if (concreteClassFD != null) { try { String concreteClass = (String) row.get(concreteClassFD.getColumnName()); if (concreteClass == null || concreteClass.trim().length() == 0) { throw new PersistenceBrokerException( "ojbConcreteClass field returned null or 0-length string"); } else { concreteClass = concreteClass.trim(); } result = cld.getRepository().getDescriptorFor(concreteClass); if (result == null) { result = cld; } return result; } catch (PBFactoryException e) { throw new PersistenceBrokerException(e); } } return null; } -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 25, 2003 11:28 AM To: [EMAIL PROTECTED] Subject: Getting the correct class instantiated We would like to have a table that represents 3 or 4 different classes that share a common base class. When objects are created out of the table, one column in the table indicates which concrete class should be instantiated. These objects are refered to by a handful of different classes. I thought this was a perfect job for a RowReader, but the RowReader example seems to be a case of instantiating two objects out of one row, and our attempts at variations have not met with success. What is the correct approach to this? David This message contains information from Equifax Inc. which may be confidential and privileged. If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited. If you have received this transmission in error, please notify by e-mail [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]