Photo from Chile

Getting Started with VT and Transfer - Part I - What You Need

Update: The information in this post is no longer correct due to changes to the framework. A new series is available via the Getting Started with VT category of my blog.

Original content of the article follows:

In this initial post in my series about getting started with Transfer and ValidateThis!, my validation framework for ColdFusion objects, we're going to look at the setup for a simple demo application.

First off, we'll need the following ColdFusion frameworks:

  • Transfer ORM, at least version 1, the latest of which can be found here.
  • Coldspring, version 1.2, which can be found here.
  • ValidateThis!, the latest of which can be found here.

The sample application that we're going to work through is a scaled down version of the demo that can be found at www.validatethis.org. We're going to start with a simple, one screen app that doesn't include any validations, and then integrate VT into the model and define a few validation business rules. The example will not be using an MVC framework, but will be using Coldspring to wire the dependencies together.

In addition to the above mentioned frameworks, we're going to need a database table. Here's a script to generate the User table (MS SQL Server):

view plain print about
1CREATE TABLE dbo.tblUser (
2    [UserId] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
3    [UserName] [varchar](100) NOT NULL,
4    [UserPass] [varchar](50) NOT NULL,
5    [Nickname] [varchar](50) NULL
6)

And, of course, we'll need a transfer.xml file to define our User Business Object:

view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<transfer xsi:noNamespaceSchemaLocation="transfer.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3    <objectDefinitions>
4        <package name="user">
5            <object name="User" table="tblUser">
6                <id name="UserId" type="numeric" />
7                <property name="UserName" type="string" />
8                <property name="UserPass" type="string" />
9                <property name="Nickname" type="string" nullable="true" />
10            </object>
11        </package>
12    </objectDefinitions>
13</transfer>

To allow Transfer to find our database table, we're going to need a datasource.xml file as well:

view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<datasource xsi:noNamespaceSchemaLocation="datasource.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3    <name>VTAndTransfer</name>
4    <username></username>
5    <password></password>
6</datasource>

That means that to run this sample app you'll need a DSN defined to ColdFusion called VTAndTransfer that points to the database containing the tblUser table.

Finally, we need a coldspring.xml config file in which we'll include the setup for Transfer, as well as defining the bean for our Service Object:

view plain print about
1<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
2<beans default-autowire="byName">
3    
4    <!-- Transfer beans-->
5
6    <bean id="transferFactory" class="transfer.TransferFactory">
7        <constructor-arg name="datasourcePath">
8            <value>/model/config/datasource.xml.cfm</value>
9        </constructor-arg>
10        <constructor-arg name="configPath">
11            <value>/model/config/transfer.xml.cfm</value>
12        </constructor-arg>
13        <constructor-arg name="definitionPath">
14            <value>/TransferTemp</value>
15        </constructor-arg>
16    </bean>
17
18    <bean id="transfer"
19        factory-bean="transferFactory" factory-method="getTransfer" />

20    
21    <!-- Service beans -->
22    
23    <bean id="UserService" class="model.service.UserService" />
24
25</beans>

For anyone already using Transfer the above configuration files should be straightforward. In the interest of keeping these posts short I'm going to stop here for now.

I really want to keep this series focused on simply integrating VT into an existing Transfer application, so the sample app that we'll be working with is not reflective of the way that I actually use Transfer. My goal is to create the simplest possible app that uses Transfer and demonstrate how to integrate ValidateThis into that app.

If you are interested in how I structure and code my real world applications with Transfer, I've written extensively about it in the past. You can find those posts here.

In my next post I will go over the code that comprises the initial sample app, which will give us a starting point for integration.

TweetBacks
Comments