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:
view plain print about
1Not 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:

view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<datasource xsi:noNamespaceSchemaLocation="../../transfer/resources/xsd/datasource.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3 <name>ContactOMatic</name>
4 <username></username>
5 <password></password>
6</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?
view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<transfer xsi:noNamespaceSchemaLocation="../../../transfer/resources/xsd/transfer.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3 <objectDefintions>
4         <!-- Contact details -->
5         <object name="Contact" table="Contact">
6             <id name="ContactID" type="numeric"/>
7             <property name="ContactName" type="string" column="ContactName"/>
8             <manytoone name="ContactType">
9                 <!--
10                 The column on the Post table that links
11                 to the primary key on the User
12                  -->

13                 <link to="ContactType" column="ContactTypeID"/>
14             </manytoone>         
15         </object>
16     
17         <object name="ContactType" table="ContactType">
18             <id name="ContactTypeID" type="numeric"/>
19             <property name="ContactType" type="string" column="ContactType"/>
20         </object>
21 </objectDefintions>
22</transfer>

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

view plain print about
1<!-- 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-->
2    <alias alias="ormAdapter" name="ormAdapter.Transfer" />
3    <alias alias="ormService" name="ormService.Transfer" />
4     <!-- This sets the definitions for the ModelGlue -->
5    <bean id="ormAdapter.Transfer" class="ModelGlue.unity.orm.transfer.TransferAdapter">
6        <constructor-arg name="framework">
7            <ref bean="ModelGlue" />
8        </constructor-arg>
9    </bean>
10    <!-- This sets the definitions for Transfer -->
11    <bean id="ormService.Transfer" class="transfer.TransferFactory">
12        <constructor-arg name="configuration">
13            <ref bean="transferConfiguration" />
14        </constructor-arg>
15    </bean>
16    <!-- This is your application specific Transfer Configuration. Paths are from the webroot or mapping -->
17    <bean id="transferConfiguration" class="transfer.com.config.Configuration">
18        <constructor-arg name="datasourcePath">
19            <value>/ContactManagerMG/config/transfer/datasource.xml</value>
20        </constructor-arg>
21        <constructor-arg name="configPath">
22            <value>/ContactManagerMG/config/transfer/transfer.xml</value>
23        </constructor-arg>
24        <constructor-arg name="definitionPath">
25            <value>/ContactManagerMG/model/transfer</value>
26        </constructor-arg>
27    </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:

view plain print about
1<!-- This sets the definitions for the ModelGlue -->
2    <bean id="ormAdapter.Transfer" class="ModelGlue.unity.orm.transfer.TransferAdapter">
3        <constructor-arg name="framework">
4            <ref bean="ModelGlue" />
5        </constructor-arg>
6    </bean>
7    <!-- This sets the definitions for Transfer -->
8    <bean id="ormService.Transfer" class="transfer.TransferFactory">
9        <constructor-arg name="configuration">
10            <ref bean="transferConfiguration" />
11        </constructor-arg>
12    </bean>

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

view plain print about
10ms     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:

view plain print about
1Missing Datasource file:
2     Not using an ORM adapter. You will not be able to do automatic database functions.
3
4Cause: 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).
view plain print about
1Missing Transfer File
2     Not using an ORM adapter. You will not be able to do automatic database functions.
3
4Cause: 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:

view plain print about
1Not 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:

There are no comments for this entry.

Add Comment Subscribe to Comments

7/24/07 7:42 PM # Sez TJ Downes

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.


7/26/07 1:15 PM # Sez Brian

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().


7/30/07 10:50 AM # Sez Dan Wilson

@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


7/30/07 9:42 PM # Sez Brian

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.


8/16/07 8:05 AM # Sez Shimju

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?


8/16/07 2:11 PM # Sez Dan Wilson

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


8/17/07 3:03 AM # Sez Shimju

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


8/17/07 3:18 AM # Sez Shimju

Iam eagerly waiting for your Transfer ORM series.


4/16/09 4:40 AM # Sez Joe

Hello,

I just downloaded the most recent version of the Transfer ORM and am having all sorts of difficulty with your transfer.xml

   Not using an ORM adapter. You will not be able to do automatic database functions. I did a copy and paste. I see no other problems reported so I might assume the xsd changed since the time of this post?

Cause: Transfer failed to load: coldspring.beanCreationException : Bean creation exception during init() of transfer.TransferFactory : The XML Provided in 'C:\Inetpub\wwwroot\ContactManagerMG\config\transfer\Transfer.xml' is not valid against its XML Schema:[Error] :32:19: cvc-complex-type.2.4.a: Invalid content was found starting with element 'objectDefintions'. One of '{"":nullValues, "":objectDefinitions}' is expected.


4/16/09 4:45 AM # Sez Joe

Can I retract my post?

The problem was simply that the <objectDefinitions> tag was missing one of the "i"s


7/1/09 11:46 AM # Sez James

Thanks to Joe for picking out the missing "i" in the <objectDefinitions>. Fixed my problem.


9/22/09 10:51 AM # Sez Philip Bedi

Hi Dan,

I am getting following error and when I check the xml there isn't any ModelGlue bean:

There is no bean registered with the factory with the id ModelGlue

The error occurred in C:\inetpub\wwwroot\coldspring\beans\AbstractBeanFactory.cfc: line 146
Called from C:\inetpub\wwwroot\coldspring\beans\AbstractBeanFactory.cfc: line 215
Called from C:\inetpub\wwwroot\coldspring\beans\BeanDefinition.cfc: line 534


9/22/09 10:56 AM # Sez Philip Bedi

Actally I am using - MG:3 Gesture, and I need to comment the definition, and now it worked.

cheers

philip


Add Comment Subscribe to Comments