JATO Tutorial
|
Let's create a model to access the RDBMS.
__queryModel__.java.java
from the /templates/1_2/ModuleTemplates
directory to your /WEB-INF/classes/jatotutorial/module1
directory.
/JatoTutorial/WEB-INF/classes/jatotutorial/module1/__queryModel__.java.java
CustomersModel.java
Token | Replacement Text |
---|---|
__appPackage__ |
jatotutorial |
__modulePackage__ |
module1 |
__queryModel__ |
CustomersModel |
FIELD_CUSTOMERID
,
FIELD_COMPANYNAME
, FIELD_CONTACTNAME
, and FIELD_PHONE
.
Note, some parts of the template code have been omitted here. Any omitted
sections are not pertinent to this example:
package jatotutorial.module1; ... public interface CustomersModel extends SelectQueryModel { public static final String FIELD_CUSTOMERID="CustomerID"; public static final String FIELD_COMPANYNAME="CompanyName"; public static final String FIELD_CONTACTNAME="ContactName"; public static final String FIELD_PHONE="Phone"; } |
__queryModel__Impl.java.java
from the
/templates/1_2/ModuleTemplates
directory to your /WEB-INF/classes/jatotutorial/module1
directory./JatoTutorial/WEB-INF/classes/jatotutorial/module1/__queryModel__Impl.java.java
CustomersModelImpl.java
Token | Replacement Text |
---|---|
__appPackage__ |
jatotutorial |
__modulePackage__ |
module1 |
__queryModel__ |
CustomersModel |
package jatotutorial.module1; ... public class CustomersModelImpl extends QueryModelBase implements CustomersModel { public CustomersModelImpl() { super(); setDataSourceName(DATA_SOURCE_NAME); setDefaultConnectionUser("sa"); setDefaultConnectionPassword(""); setSelectSQLTemplate(SELECT_SQL_TEMPLATE); setStaticWhereCriteriaString(STATIC_WHERE_CRITERIA); setModifyingQueryTableName(MODIFYING_QUERY_TABLE_NAME); setFieldSchema(FIELD_SCHEMA); } ... //////////////////////////////////////////////////////////////////////////// // Class variables //////////////////////////////////////////////////////////////////////////// public static final String DATA_SOURCE_NAME="jdbc/NorthwindDataSource"; public static final String SELECT_SQL_TEMPLATE= "SELECT ndnwCustomers.CustomerID, ndnwCustomers.CompanyName, "+ "ndnwCustomers.ContactName, ndnwCustomers.Phone " + "FROM ndnwCustomers __WHERE__"; public static final String MODIFYING_QUERY_TABLE_NAME="ndnwCustomers"; public static final String STATIC_WHERE_CRITERIA=""; public static final QueryFieldSchema FIELD_SCHEMA=new QueryFieldSchema(); static { FIELD_SCHEMA.addFieldDescriptor( new QueryFieldDescriptor( FIELD_CUSTOMERID, "CustomerID", "ndnwCustomers.CustomerID", String.class, true)); FIELD_SCHEMA.addFieldDescriptor( new QueryFieldDescriptor( FIELD_COMPANYNAME, "CompanyName", "ndnwCustomers.CompanyName", String.class)); FIELD_SCHEMA.addFieldDescriptor( new QueryFieldDescriptor( FIELD_CONTACTNAME, "ContactName", "ndnwCustomers.ContactName", String.class)); FIELD_SCHEMA.addFieldDescriptor( new QueryFieldDescriptor( FIELD_PHONE, "Phone", "ndnwCustomers.Phone", String.class)); } } |
ModelTypeMapImpl.java
file. Add a model interface
mapping entry as indicated below. Note, some parts of the template code have
been omitted here. Any omitted sections are not pertinent to this example:
package jatotutorial.module1; ... public class ModelTypeMapImpl extends ModelTypeMapBase implements ModelTypeMap { public ModelTypeMapImpl() { super(); } static { addModelInterfaceMapping( jatotutorial.module1.CustomersModel.class, jatotutorial.module1.CustomersModelImpl.class); } } |
|