mpoeschl 2002/07/02 18:08:44
Modified: src/templates/ojb/model Object.vm
src/templates/ojb/repository MainRepository.vm Repository.vm
Log:
patch by Perolo Silantico <[EMAIL PROTECTED]>
I added some features to the OJB templates. They are far from complete and
far from being ready for production but may be it is of some help :)
Revision Changes Path
1.4 +2 -1 jakarta-turbine-torque/src/templates/ojb/model/Object.vm
Index: Object.vm
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/templates/ojb/model/Object.vm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Object.vm 18 Apr 2002 17:38:18 -0000 1.3
+++ Object.vm 3 Jul 2002 01:08:44 -0000 1.4
@@ -30,11 +30,12 @@
{
#foreach ($col in $table.Columns)
- private $col.JavaPrimitive $col.Name.toLowerCase() = null;
+ protected $col.JavaPrimitive $col.Name.toLowerCase() = null;
#end
#foreach ($col in $table.Columns)
#set ( $cfc=$col.JavaName )
+ #set ( $cfc=$cfc.replaceFirst(".", $cfc.substring(0,1).toUpperCase()) )
#set ( $clo=$col.Name.toLowerCase() )
#set ( $cjtype = $col.JavaPrimitive )
1.3 +25 -14
jakarta-turbine-torque/src/templates/ojb/repository/MainRepository.vm
Index: MainRepository.vm
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/templates/ojb/repository/MainRepository.vm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MainRepository.vm 16 Apr 2002 07:51:18 -0000 1.2
+++ MainRepository.vm 3 Jul 2002 01:08:44 -0000 1.3
@@ -3,29 +3,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- defining entities for include-files -->
-<!DOCTYPE MappingRepository SYSTEM "repository.dtd" [
+<!DOCTYPE descriptor-repository SYSTEM "repository.dtd" [
+<!ENTITY internal SYSTEM "repository_internal.xml">
#foreach ($dataModel in $dataModels)
<!ENTITY $dataModel.shortName SYSTEM "repository_${dataModel.shortName}.xml">
#end
]>
-<MappingRepository>
+<descriptor-repository isolation-level="read-uncommitted">
<!-- The Default JDBC Connection. If a Class does not specify its own JDBC
Connection,
the Connection specified here will be used. -->
- <JdbcConnectionDescriptor id="default">
- <dbms.name>Hsqldb</dbms.name>
- <driver.name>${databaseDriver}</driver.name>
- <url.protocol>jdbc</url.protocol>
- <url.subprotocol>hsqldb</url.subprotocol>
- <url.dbalias>../OJB</url.dbalias>
- <!--url.dbalias>ojb-1-0/build/test/OJB</url.dbalias-->
- <user.name>${databaseUser}</user.name>
- <user.passwd>$!{databasePassword}</user.passwd>
- </JdbcConnectionDescriptor>
+ <jdbc-connection-descriptor id="default"
+ platform="${ojb.platform}"
+ jdbc-level="${jdbcLevel}"
+ #if (${ojb.useJNDI} == "true")
+ jndi-datasource-name="${ojb.JNDISource}"
+ #else
+ driver="${databaseDriver}"
+ protocol="jdbc"
+ subprotocol="${database}"
+ dbalias="${databaseName}"
+ #end
+ username="${databaseUser}"
+ password="$!{databasePassword}"
+ >
+
<!-- include mappings here -->
#foreach ($dataModel in $dataModels)
- ${dataModel.shortName};
+ &${dataModel.shortName};
#end
-</MappingRepository>
+
+ <!-- include internal mappings here -->
+ &internal;
+</descriptor-repository>
+
+
1.4 +87 -18
jakarta-turbine-torque/src/templates/ojb/repository/Repository.vm
Index: Repository.vm
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/templates/ojb/repository/Repository.vm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Repository.vm 15 Apr 2002 22:18:54 -0000 1.3
+++ Repository.vm 3 Jul 2002 01:08:44 -0000 1.4
@@ -1,32 +1,101 @@
#set ( $database = $dataModel.database )
-
+#set ( $unkownTorqueTypes = [ 'NULL', 'OTHER', 'JAVA_OBJECT', 'DISTINCT',
'STRUCT', 'ARRAY', 'REF', 'BOOLEANINT', 'BOOLEANCHAR' ] )
+#set ( $mappedJdbcTypes = ['INTEGER', 'BLOB', 'BLOB', 'BLOB', 'BLOB', 'BLOB',
'BLOB', 'INTEGER', 'CHAR' ] )
+#set ( $fieldsWithNoSize = ['INTEGER', 'BLOB', 'CLOB', 'DATE', 'TIME', 'TIMESTAMP',
'BINARY', 'BIGINT', 'SMALLINT', 'TINYINT' ] )
+#set ( $space = " " )
#if ($database.Package)
#set ($package = $database.Package)
#else
#set ($package = $targetPackage)
#end
-#set ( $baseId = $modelCount * 1000 )
#foreach ($table in $database.tables)
- #set ( $id = $baseId + $velocityCount )
- <ClassDescriptor id="$id">
- <class.name>${package}.${table.JavaName}</class.name>
- <class.proxy>dynamic</class.proxy>
- <class.extent>test.ojb.broker.BookArticle</class.extent>
- <class.extent>test.ojb.broker.CdArticle</class.extent>
- <table.name>$table.Name</table.name>
-
<conversionStrategy>test.ojb.broker.ArticleConversionStrategy</conversionStrategy>
+
+
+<!--
+==============================================================
+ TABLE $table.Name
+==============================================================
+$!table.getDescription()
+-->
+ <class-descriptor proxy="dynamic"
+ class="${package}.${table.JavaName}"
+ table="$table.Name"
+ >
+ #set ( $indices = [ "" ] )
+ #foreach ($index in $table.getIndices())
+ #set ( $indexColumnListString = $index.getColumnList() )
+ #set ( $indexColumnList = $indexColumnListString.split(",") )
+ #foreach ( $indexedColumn in $indexColumnList )
+ #set ( $result = $indices.add($indexedColumn) )
+ #end
+ #end
#foreach ($col in $table.Columns)
- <FieldDescriptor id="$velocityCount">
- <field.name>$col.JavaName</field.name>
- <column.name>$col.Name</column.name>
- <jdbc_type>INTEGER</jdbc_type>
- <PrimaryKey>$col.isPrimaryKey()</PrimaryKey>
- <autoincrement>true</autoincrement>
- </FieldDescriptor>
+
+
+<!--
+ COLUMN $col.Name
+..............................................
+$!col.getDescription()
+-->
+ #set ( $mappingPos = $unkownTorqueTypes.indexOf($col.TorqueType) )
+ #set ( $size = ${col.size} )
+ #set ( $precision = "" )
+ #set ( $colType = $col.getType() )
+ #set ( $colTypeClass = $colType.getClass() )
+ #set ( $colTypeClassName = $colTypeClass.getName() )
+ ## === determin the type of the field. OJB recognizes less types than Torque,
thus unkown types must be mapped
+ #if ($mappingPos != -1)
+ #set ( $jdbcFieldType = $mappedJdbcTypes.get($mappingPos) )
+ #if ( $mappedJdbcTypes.get($mappingPos) == "CHAR" )
+ #set ( $size = "1" )
+ #else
+ #set ( $size = "" )
+ #end
+ #else ## == no mapping is required
+ #set ( $jdbcFieldType = $col.TorqueType )
+ ## === split the size field into length and precision
+ #if ($col.size != "")
+ #set ( $sizeList = $size.split(",") )
+ #set ( $foundPart = 0 )
+ ## == unfortunatedly $sizeList.get(0) dows not work so I did this hack
+ #foreach ( $part in $sizeList)
+ #if ($foundPart == 0)
+ #set ( $size = $part )
+ #set ( $foundPart = 1 )
+ #elseif ($foundPart == 1)
+ #set ( $precision = $part )
+ #set ( $foundPart = 2 )
+ #end
+ #end
+ #end
+ #end
+
+ <field-descriptor id="$velocityCount"
+ name="$col.JavaName"
+ column="$col.Name"
+ jdbc-type="$jdbcFieldType"
+#if ($col.isNotNull()) ${space}nullable="false"
+#end
+#if ($indices.indexOf($col.Name) != -1) ${space}indexed="true"
+#end
+#if ($col.isPrimaryKey()) ${space}primarykey="true"
+#end
+#if ($col.isAutoIncrement()) ${space}autoincrement="true"
+#end
+#if ($size != "") ${space}length="${size}"
+#end
+#if ($precision != "") ${space}precision="${precision}"
+#end
+ >
+
+
#end
- </ClassDescriptor>
+
+ </class-descriptor>
+
+
#end
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>