Re: Cayenne 3.0M4 ignoring extended data types

From: Chris Gamache (cgamach..mail.com)
Date: Thu Jul 31 2008 - 13:13:48 EDT

  • Next message: Andrus Adamchik: "Re: Can't extract a master key"

    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 - 13:14:41 EDT