Installing Transfer in ModelGlue:Unity

Today we will install the Transfer ORM inside our Contact-O-Matic application. To complete this tutorial, you should have the Contact-O-Matic installed and running. If you have not completed this step, please create the database described at the bottom of Series 6 and install the files at Series 10 download link. Test the application by manually adding several ContactTypes to the ContactType table in your database (I chose Co-Worker, Enemy, Friend). Then use the Contact Form in the ContactOMatic application to enter a few contacts.

Once you confirm the application works as intended, open your /ContactOMatic/config/ColdSpring.xml file and make the following edits to the ModelGlueConfiguration bean:

  • Set reload = true
  • Set rescaffold = true
  • Set debug = true
Reload your application and scroll below the footer to the ModelGlue Debug output. You should see the following message:
Not using an ORM adapter. You will not be able to do automatic database functions.
All good? Now we begin the integration.

The Transfer Integration in ModelGlue:Unity depends on the alias functionality in ColdSpring which is currently found in the BER release. If you do not have the BER release, or are not sure, you should Checkout the /Head/Coldspring directory into your webroot as 'coldspring'.

Note: If you complete this series and do not have a version of ColdSpring with alias support, you will not get an obvious error. Here are the CVS configuration details for checking out ColdSpring. If you use (cf)eclipse, you already have a CVS client. If not, I suggest you download one.

Below is a screenshot of the CVS parameters for Eclipse:

Download the latest Transfer ORM framework at RIA Forge/ Transfer ORM, then extract it to your webroot.

Now open the ContactManagerMG directory and create a 'transfer' directory in /ContactManagerMG/Config and also a 'transfer' directory inside /ContactManagerMG/Model.

Following that, create two new .xml files named Datasource.xml and Transfer.xml inside /ContactManagerMG/Config/transfer. Datasource.xml file contains the datasource used by your application. Fill it out like so:

<?xml version="1.0" encoding="UTF-8"?>
<datasource xsi:noNamespaceSchemaLocation="../../transfer/resources/xsd/datasource.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>ContactOMatic</name>
<username></username>
<password></password>
</datasource>
The contents of the Transfer.xml file define the objects Transfer will manage for us. To begin, we define a Contact Object and a ContactType Object. Note:The Contact Object is composed of a ContactType Object through a manytoone relationship. This is because several Contacts can have the same Contact Type, makes sense, no?
<?xml version="1.0" encoding="UTF-8"?>
<transfer xsi:noNamespaceSchemaLocation="../../../transfer/resources/xsd/transfer.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<objectDefintions>
       <!-- Contact details -->
      <object name="Contact" table="Contact">
         <id name="ContactID" type="numeric"/>
         <property name="ContactName" type="string" column="ContactName"/>
         <manytoone name="ContactType">
            <!--
            The column on the Post table that links
            to the primary key on the User
             -->

            <link to="ContactType" column="ContactTypeID"/>
         </manytoone>       
      </object>
   
      <object name="ContactType" table="ContactType">
         <id name="ContactTypeID" type="numeric"/>
         <property name="ContactType" type="string" column="ContactType"/>
      </object>
</objectDefintions>
</transfer>

Lastly, connect Transfer to ModelGlue:Unity through ColdSpring. Open /ContactManagerMG/config/ColdSpring.xml and paste the following definitions:

<!-- This tells ModelGlue to use the Transfer Adapter. Used for Integrated ORM functions in MG:U. This is why we needed the BER of ColdSpring-->
   <alias alias="ormAdapter" name="ormAdapter.Transfer" />
   <alias alias="ormService" name="ormService.Transfer" />
   <!-- This sets the definitions for the ModelGlue -->
   <bean id="ormAdapter.Transfer" class="ModelGlue.unity.orm.transfer.TransferAdapter">
      <constructor-arg name="framework">
         <ref bean="ModelGlue" />
      </constructor-arg>
   </bean>
   <!-- This sets the definitions for Transfer -->
   <bean id="ormService.Transfer" class="transfer.TransferFactory">
      <constructor-arg name="configuration">
         <ref bean="transferConfiguration" />
      </constructor-arg>
   </bean>
   <!-- This is your application specific Transfer Configuration. Paths are from the webroot or mapping -->
   <bean id="transferConfiguration" class="transfer.com.config.Configuration">
      <constructor-arg name="datasourcePath">
         <value>/ContactManagerMG/config/transfer/datasource.xml</value>
      </constructor-arg>
      <constructor-arg name="configPath">
         <value>/ContactManagerMG/config/transfer/transfer.xml</value>
      </constructor-arg>
      <constructor-arg name="definitionPath">
         <value>/ContactManagerMG/model/transfer</value>
      </constructor-arg>
   </bean>

Note: If you are using MG:3 Gesture, you do not need the definitions for the ormAdapter and the ormService.

Why? Because these are provided for you already in the Gesture framework. If you use the above definitions, you will get the following error:

 Bean creation exception during init() of ModelGlue.unity.orm.transfer.TransferAdapter
The TRANSFER parameter to the init function is required but was not passed in.:

The fix is easy. Remove the following XML from the above configuration:

<!-- This sets the definitions for the ModelGlue -->
   <bean id="ormAdapter.Transfer" class="ModelGlue.unity.orm.transfer.TransferAdapter">
      <constructor-arg name="framework">
         <ref bean="ModelGlue" />
      </constructor-arg>
   </bean>
   <!-- This sets the definitions for Transfer -->
   <bean id="ormService.Transfer" class="transfer.TransferFactory">
      <constructor-arg name="configuration">
         <ref bean="transferConfiguration" />
      </constructor-arg>
   </bean>

Test the integration by running your ContactOMatic application again. Scroll to the ModelGlue Debug output and look for the Happy Message:

0ms    Core    Using ORM Adapter: com.adobe.hs.common.orm.TransferAdapter

If you did not get the Happy Message, something is borked. You may see one of the below messages:

Missing Datasource file:
   Not using an ORM adapter. You will not be able to do automatic database functions.

Cause: Transfer failed to load: coldspring.beanCreationException : Bean creation exception during init() of transfer.TransferFactory : An error occurred when performing a file operation read on file C:\Webroot\ContactManagerMG\config\transfer\datasource.xml.:The cause of this exception was: java.io.FileNotFoundException: C:\Webroot\ContactManagerMG\config\transfer\datasource.xml (The system cannot find the file specified).
Missing Transfer File
   Not using an ORM adapter. You will not be able to do automatic database functions.

Cause: Transfer failed to load: coldspring.beanCreationException : Bean creation exception during init() of transfer.TransferFactory : An error occurred when performing a file operation read on file C:\Webroot\ContactManagerMG\config\transfer\transfer.xml.:The cause of this exception was: java.io.FileNotFoundException: C:\Webroot\ContactManagerMG\config\transfer\transfer.xml (The system cannot find the file specified).

To resolve this, examine the name and path of each of the configuration files above.

Remember: the file path referenced in the ColdSpring.xml / transferConfiguration bean is the path from your webroot or ColdFusion Mapping.

If you still get this message:

Not using an ORM adapter. You will not be able to do automatic database functions.

One of three things is wrong:

  • You did not reload your application
  • You did not install the ColdSpring BER properly
  • You did not install Transfer Properly

For reference, below is the proper directory/file structure for the completed installation:

Comments
Hey Dan, thanks for sharing your knowledge. I can't express enough gratitude to you for the time you have taken to put these tutorials together, you are the man! Although I've only had the time to go through the first few, I am excited to continue working with them. You make learning a framework easy and enjoyable. You should write a book.
# Posted By TJ Downes | 7/24/07 7:42 PM
Dan, nice work. I'm just getting up to speed with MG/CS/Transfer. I would love to see how Transfer changes your Controller and ContactService. I'm getting stuck right now with finding a standard method to go from FORM data to Controller to Service object to Bean to transfer.save().
# Posted By Brian | 7/26/07 1:15 PM
@TJ Thank you for the kind words!

@Brian,

We will certainly be getting to that. I am juggling project work, but I have begun the process. I was thinking of leaving the original architecture intact. then creating some additional features using different architecture.

I felt this would give people the chance to compare between the two.

Thoughts?

DW
# Posted By Dan Wilson | 7/30/07 10:50 AM
That could work... I think the main thing is that as you go to a more automated infrastructure (leveraging the stuff that CS/TR do for you), you need to make changes in how you pass data around. For example; when you receive a form submission, do you create the bean in the controller and pass it to the service layer or do you individually pass each parameter along to the service layer and IT creates the bean, validates, and throws it back if it's not OK? I don't know why you would choose one or the other exactly so that kind of stuff would be good to know.
# Posted By Brian | 7/30/07 9:42 PM
Dan, your efforts are really appreciated. You are the man helped me to pick up Coldspring Frameworks and you will be the person who will teach me the Transfer ORM. BTW, using CVS I cant able to download BER version of Transfer ORM. Can you please explain how u downloaded it?
# Posted By Shimju | 8/16/07 8:05 AM
Shimju,

Thank you for your kind words. You can download the latest transfer release from http://transfer.riaforge.org/ by clicking the download link. The zip file will appear and simply extract the contents into your webroot.


ColdSpring is the only framework used in the tutorials that must be downloaded by CVS. If, by chance, you were referring to that, simply open eclipse, choose Window->Perspective->CVS Repository. Next right-click in the CVS Repositories pane and create a New repository location. Use the data shown in the image above.


Let me know if I haven't answered your question correctly...

DW
# Posted By Dan Wilson | 8/16/07 2:11 PM
Hi Dan, Sorry I mentioned about Coldspring, not Transfer.
Last time I attempted to checkout Coldspring-BER from the CVS Server and this time I checkout the Coldspring directory and once installed , Transfer ORM integration worked. Thanks again. Iam eagerly awaiting
# Posted By Shimju | 8/17/07 3:03 AM
Iam eagerly waiting for your Transfer ORM series.
# Posted By Shimju | 8/17/07 3:18 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001. Contact Blog Owner