1
1
package javaxt .orm ;
2
2
import javaxt .json .*;
3
+ import java .util .HashMap ;
3
4
4
5
//******************************************************************************
5
6
//** Model Class
@@ -19,20 +20,21 @@ public class Model {
19
20
private String packageName ;
20
21
private String schemaName ;
21
22
private String escapedSchemaName ;
23
+ private HashMap <String , String > options ;
22
24
23
25
24
26
//**************************************************************************
25
27
//** Constructor
26
28
//**************************************************************************
27
29
/** Creates a new instance of this class.
28
30
*/
29
- protected Model (String modelName , String packageName , String schemaName , JSONObject modelInfo ){
31
+ protected Model (String modelName , JSONObject modelInfo , String packageName , HashMap < String , String > options ){
30
32
this .name = modelName ;
31
33
this .fields = new java .util .ArrayList <Field >();
32
-
34
+ this . options = options ;
33
35
this .packageName = packageName ;
34
36
this .tableName = Utils .camelCaseToUnderScore (name ).toLowerCase ();
35
- this .schemaName = schemaName ;
37
+ this .schemaName = options . get ( "schema" ) ;
36
38
37
39
38
40
if (schemaName ==null ){
@@ -83,13 +85,14 @@ protected Model(String modelName, String packageName, String schemaName, JSONObj
83
85
Boolean isUnique = constraint .get ("unique" ).toBoolean ();
84
86
Integer length = constraint .get ("length" ).toInteger ();
85
87
if (length ==null ) length = constraint .get ("size" ).toInteger ();
88
+ Integer srid = constraint .get ("srid" ).toInteger ();
86
89
87
90
for (Field field : fields ){
88
91
if (field .getName ().equals (fieldName )){
89
92
if (isRequired !=null ) field .isRequired (isRequired );
90
93
if (isUnique !=null ) field .isUnique (isUnique );
91
94
if (length !=null ) field .setLength (length );
92
-
95
+ if ( srid != null ) field . setSRID ( srid );
93
96
94
97
ForeignKey foreignKey = field .getForeignKey ();
95
98
if (foreignKey !=null ){
@@ -207,8 +210,10 @@ public String getJavaCode(){
207
210
if (fieldType .equals ("Date" )) includes .add ("javaxt.utils.Date" );
208
211
if (fieldType .equals ("BigDecimal" )) includes .add ("java.math.BigDecimal" );
209
212
if (fieldType .equals ("Geometry" )){
210
- includes .add ("com.vividsolutions.jts.geom.Geometry" );
211
- includes .add ("com.vividsolutions.jts.io.WKTReader" );
213
+ String jts = options .get ("jts" );
214
+ if (jts ==null ) jts = "com.vividsolutions.jts" ;
215
+ includes .add (jts +".geom.Geometry" );
216
+ includes .add (jts +".io.WKTReader" );
212
217
}
213
218
214
219
@@ -348,11 +353,11 @@ else if (fieldType.equals("byte[]")){
348
353
getValues .append ("\" ).toByteArray();\r \n " );
349
354
}
350
355
else if (fieldType .equals ("Geometry" )){
351
- getValues .append (" this." );
356
+ getValues .append (" try{ this." );
352
357
getValues .append (fieldName );
353
358
getValues .append (" = new WKTReader().read(getValue(rs, \" " );
354
359
getValues .append (columnName );
355
- getValues .append ("\" ).toString());\r \n " );
360
+ getValues .append ("\" ).toString());}catch(Exception e){} \r \n " );
356
361
}
357
362
else {
358
363
getValues .append (" this." );
@@ -773,8 +778,8 @@ public String getDiamondTableSQL(){
773
778
if (leftTable .equals (rightTable )) rightColumn = rightTable + "_ID2" ;
774
779
775
780
776
- // String tableName = leftTable + "_" + rightTable;
777
- String tableName = leftTable + "_" + field .getColumnName ().toUpperCase ();
781
+ String tableName = leftTable + "_" + rightTable ;
782
+ // String tableName = leftTable + "_" + field.getColumnName().toUpperCase();
778
783
779
784
780
785
String foreignKey = "FK_" + tableName ;
0 commit comments