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

4/16/09 4:40 AM # Posted By 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 # Posted By 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 # Posted By James

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


9/22/09 10:51 AM # Posted By 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 # Posted By 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