Re: Cayenne 3.0M4 ignoring extended data types

From: Michael Gentry (blacknex..mail.com)
Date: Thu Jul 31 2008 - 14:34:14 EDT

  • Next message: Francois Eyl: "Re: Unique persistent object and caching issue"

    It is a lot to dig through ... :-)

    Some more questions:

    You show regsitering PostgresUniqueIdentifier and PostgresMoney in the
    code, but they are not in the XML. Is this a red herring or an
    omission? Do you have the full class name, including package name, in
    the XML for your types?

    Also, are you registering your ExtendedTypes in ALL DataNodes? You
    mentioned having having multiple cayenne.xml files and the
    ExtendedTypes need to be registered in ALL DataNodes because each
    DataNode is responsible for doing type translation processing.

    And, do your ExtendedTypes implement ExtendedType? Or subclass
    something which does?

    Thanks.

    On Thu, Jul 31, 2008 at 1:13 PM, Chris Gamache <cgamach..mail.com> wrote:
    > On Thu, Jul 31, 2008 at 12:38 PM, Michael Gentry <blacknex..mail.com>wrote:
    >
    >> Could you give an example of how you are using and declaring the
    >> extended types? A lot of work has been done in that department since
    >> 2.x, including adding enumeration support.
    >
    >
    > Sure!
    >
    > public DataContext makeContext(final String configuration, final String
    > classPath, final String nodeName ) {
    >
    > if (!initialized) {
    > DefaultConfiguration dc = new DefaultConfiguration(configuration);
    > dc.addClassPath(classPath);
    > boolean cayenneNotInitialized = false;
    > try {
    > Configuration conf = Configuration.getSharedConfiguration();
    > } catch (Exception e) {
    > cayenneNotInitialized = true;
    > }
    >
    > if (cayenneNotInitialized) {
    > dc.initializeSharedConfiguration(dc);
    > } else {
    > try{
    > dc.initialize();
    > }catch(Exception e){
    > throw new ConfigurationException();
    > }
    > }
    >
    > for (Object d : dc.getDomain().getDataMaps().toArray()) {
    > DataMap dm = (DataMap)d;
    > }
    > for (Object d : dc.getDomain().getDataNodes().toArray()) {
    > DataNode dn = (DataNode)d;
    > }
    > * //Heres where I'm registering the types...*
    >
    > dc.getDomain().getNode(nodeName).getAdapter().getExtendedTypes().registerType(new
    > PostgresUniqueIdentifier());
    > dc.getDomain().getNode(nodeName).getAdapter().getExtendedTypes().registerType(new
    > PostgresMoney());
    > Configuration sharedConfig = null;
    > try {
    > sharedConfig = Configuration.getSharedConfiguration();
    > Iterator<DataMap> dcDataMapItr =
    > dc.getDomain().getDataMaps().iterator();
    > while (dcDataMapItr.hasNext()) {
    > sharedConfig.getDomain().addMap(dcDataMapItr.next());
    > }
    > Iterator<DataNode> dcDataNodeItr =
    > dc.getDomain().getDataNodes().iterator();
    > while(dcDataNodeItr.hasNext()) {
    > sharedConfig.getDomain().addNode(dcDataNodeItr.next());
    > }
    > } catch (Exception e) {
    > Configuration.initializeSharedConfiguration(dc);
    > }
    >
    > initialized = true;
    > }
    > for (Object d :
    > Configuration.getSharedConfiguration().getDomain().getDataMaps().toArray())
    > {
    > DataMap dm = (DataMap)d;
    > }
    > for (Object d :
    > Configuration.getSharedConfiguration().getDomain().getDataNodes().toArray())
    > {
    > DataNode dn = (DataNode)d;
    > }
    >
    > return DataContext.createDataContext();
    > }
    >
    > And here's some XML for declaring the fields...
    > <obj-entity name="CompanyTable" className="com.user.rdbms.CompanyTable"
    > dbEntityName="company_table">
    > <obj-attribute name="code" type="java.lang.Integer"
    > db-attribute-path="code"/>
    > <obj-attribute name="comment" type="java.lang.String"
    > db-attribute-path="comment"/>
    > <obj-attribute name="companyName" type="java.lang.String"
    > db-attribute-path="company_name"/>
    > <obj-attribute name="companyUuid" type="java.util.UUID"
    > db-attribute-path="company_uuid"/>
    > ....and so on
    >
    > <db-entity name="company_table">
    > <db-attribute name="code" type="INTEGER" length="10"/>
    > <db-attribute name="comment" type="CLOB" length="2147483647"/>
    > <db-attribute name="company_name" type="VARCHAR" length="50"/>
    > <db-attribute name="company_uuid" type="OTHER" length="2147483647"/>
    > ....and so on
    >
    > <db-relationship name="toCompanyTable" source="user_table"
    > target="company_table" toMany="false">
    > <db-attribute-pair source="company_name" target="company_name"/>
    > </db-relationship>
    >
    > and user_table has a company_name which is used as the unqiue key to
    > retrieve the relevant company from the user.
    >
    > So then....
    >
    > protected UserTable getUser() {
    > if(context == null){
    > this.context = ContextCreator.makeContext(..., ..., ...); //with
    > real values for "..."
    > }
    > if(user == null){
    > Expression exp = ExpressionFactory.matchExp(UserTable.USER_UUID_PROPERTY,
    > userUUID);
    > SelectQuery select = new SelectQuery(UserTable.class, exp);
    > user = (UserTable) DataObjectUtils.objectForQuery(context, select);
    > if(user == null) throw new IllegalStateException("user " + userUUID + "
    > not found);
    > }
    > return user;
    > }
    >
    > And then...
    >
    > protected CompanyTable getCompany() {
    > if(company == null){
    > company = getUser().getToCompanyTable();
    > if(company == null) throw new IllegalStateException("Company not found
    > for user " + getUser().getUserUuid());
    > }
    > return company;
    > }
    >
    >
    > And I can use user.getUserUuid() with no problems, but if I try to do
    > company.getCompanyUuid() where company was retrieved using
    > user.getToCompanyTable() it bombs as though the ExtendedTypes aren't there.
    >
    > I hope this isn't too much to dig through....
    >
    > Thanks again for taking a peek...
    >



    This archive was generated by hypermail 2.0.0 : Thu Jul 31 2008 - 14:35:05 EDT