Index: entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/DefaultTableGenerator.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/DefaultTableGenerator.java,v retrieving revision 1.14 diff -c -w -r1.14 DefaultTableGenerator.java *** entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/DefaultTableGenerator.java 7 Mar 2007 02:26:57 -0000 1.14 --- entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/DefaultTableGenerator.java 12 Mar 2007 05:10:39 -0000 *************** *** 496,502 **** if (dbField.getColumnDefinition().length() > 0) { // This column definition would include the complete definition of the // column like type, size, "NULL/NOT NULL" clause, unique key clause ! fieldDef.setTypeName(dbField.getColumnDefinition()); } else { Class fieldType = dbField.getType(); --- 496,502 ---- if (dbField.getColumnDefinition().length() > 0) { // This column definition would include the complete definition of the // column like type, size, "NULL/NOT NULL" clause, unique key clause ! fieldDef.setTypeDefinition(dbField.getColumnDefinition()); } else { Class fieldType = dbField.getType(); Index: entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/FieldDefinition.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/FieldDefinition.java,v retrieving revision 1.5 diff -c -w -r1.5 FieldDefinition.java *** entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/FieldDefinition.java 4 Jan 2007 14:32:10 -0000 1.5 --- entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/FieldDefinition.java 12 Mar 2007 05:10:39 -0000 *************** *** 22,27 **** --- 22,29 ---- package oracle.toplink.essentials.tools.schemaframework; import java.io.*; + import java.util.Hashtable; + import oracle.toplink.essentials.internal.helper.*; import oracle.toplink.essentials.internal.databaseaccess.*; import oracle.toplink.essentials.exceptions.*; *************** *** 40,47 **** --- 42,62 ---- */ public class FieldDefinition implements Serializable, Cloneable { protected String name; + /** + * Java type class for the field. + * Particular database type is generated based on platform from this. + */ protected Class type; + /** + * Generic database type name for the field, which can be used instead of the Java class 'type'. + * This is translated to a particular database type based on platform. + */ protected String typeName; + /** + * Database-specific complete type definition like "VARCHAR2(50) UNIQUE NOT NULL". + * If this is given, other additional type constraint fields(size, unique, null) are meaningless. + */ + protected String typeDefinition; protected int size; protected int subSize; protected boolean shouldAllowNull; *************** *** 100,117 **** * Append the database field definition string to the table creation statement. */ public void appendDBString(Writer writer, AbstractSession session, TableDefinition table) throws ValidationException { FieldTypeDefinition fieldType; ! if (getType() != null) { fieldType = session.getPlatform().getFieldTypeDefinition(getType()); if (fieldType == null) { throw ValidationException.javaTypeIsNotAValidDatabaseType(getType()); } ! } else { fieldType = new FieldTypeDefinition(getTypeName()); } ! try { ! writer.write(getName()); ! writer.write(" "); String qualifiedName = table.getFullName() + '.' + getName(); session.getPlatform().printFieldTypeSize(writer, this, fieldType, session, qualifiedName); session.getPlatform().printFieldUnique(writer, isUnique(), session, qualifiedName); --- 115,152 ---- * Append the database field definition string to the table creation statement. */ public void appendDBString(Writer writer, AbstractSession session, TableDefinition table) throws ValidationException { + try { + writer.write(getName()); + writer.write(" "); + + if (getTypeDefinition() != null) { //apply user-defined complete type definition + writer.write(getTypeDefinition()); + + } else { + // compose type definition - type name, size, unique, identity, constraints... FieldTypeDefinition fieldType; ! ! if (getType() != null) { //translate Java 'type' fieldType = session.getPlatform().getFieldTypeDefinition(getType()); if (fieldType == null) { throw ValidationException.javaTypeIsNotAValidDatabaseType(getType()); } ! } else if (getTypeName() != null) { //translate generic type name ! Hashtable fieldTypes = session.getPlatform().getClassTypes(); ! Class type = (Class)fieldTypes.get(getTypeName()); ! if (type == null) { // if unknown type name, use as it is fieldType = new FieldTypeDefinition(getTypeName()); + } else { + fieldType = session.getPlatform().getFieldTypeDefinition(type); + if (fieldType == null) { + throw ValidationException.javaTypeIsNotAValidDatabaseType(type); } ! } ! } else { ! // both type and typeName is null ! throw ValidationException.javaTypeIsNotAValidDatabaseType(null); ! } ! String qualifiedName = table.getFullName() + '.' + getName(); session.getPlatform().printFieldTypeSize(writer, this, fieldType, session, qualifiedName); session.getPlatform().printFieldUnique(writer, isUnique(), session, qualifiedName); *************** *** 130,177 **** if (getAdditional() != null) { writer.write(" " + getAdditional()); } - } catch (IOException ioException) { - throw ValidationException.fileError(ioException); - } - } - - /** - * INTERNAL: - * Append the database field definition string to the type creation statement. - * Types do not support constraints. - */ - public void appendTypeString(Writer writer, AbstractSession session) throws ValidationException { - FieldTypeDefinition fieldType; - if (getType() != null) { - fieldType = session.getPlatform().getFieldTypeDefinition(getType()); - if (fieldType == null) { - throw ValidationException.javaTypeIsNotAValidDatabaseType(getType()); - } - } else { - fieldType = new FieldTypeDefinition(getTypeName()); - } - try { - writer.write(getName()); - writer.write(" "); - writer.write(fieldType.getName()); - if ((fieldType.isSizeAllowed()) && ((getSize() != 0) || (fieldType.isSizeRequired()))) { - writer.write("("); - if (getSize() == 0) { - writer.write(new Integer(fieldType.getDefaultSize()).toString()); - } else { - writer.write(new Integer(getSize()).toString()); - } - if (getSubSize() != 0) { - writer.write(","); - writer.write(new Integer(getSubSize()).toString()); - } else if (fieldType.getDefaultSubSize() != 0) { - writer.write(","); - writer.write(new Integer(fieldType.getDefaultSubSize()).toString()); - } - writer.write(")"); - } - if (getAdditional() != null) { - writer.write(" " + getAdditional()); } } catch (IOException ioException) { throw ValidationException.fileError(ioException); --- 165,170 ---- *************** *** 251,258 **** /** * PUBLIC: ! * Return the type of the field. ! * This is the exact DB type name, which can be used instead of the Java class. */ public String getTypeName() { return typeName; --- 244,252 ---- /** * PUBLIC: ! * Return the type name of the field. ! * This is the generic database type name, which can be used instead of the Java class 'type'. ! * This is translated to a particular database type based on platform. */ public String getTypeName() { return typeName; *************** *** 260,265 **** --- 254,269 ---- /** * PUBLIC: + * Return the type definition of the field. + * This is database-specific complete type definition like "VARCHAR2(50) UNIQUE NOT NULL". + * If this is given, other additional type constraint fields(size, unique, null) are meaningless. + */ + public String getTypeDefinition() { + return typeDefinition; + } + + /** + * PUBLIC: * Answer whether the receiver is an identity field. * Identity fields are Sybase specific, * they insure that on insert a unique sequencial value is store in the row. *************** *** 382,392 **** /** * PUBLIC: ! * Set the type of the field. ! * This is the exact DB type name, which can be used instead of the Java class. */ public void setTypeName(String typeName) { this.typeName = typeName; } /** --- 386,407 ---- /** * PUBLIC: ! * Set the type name of the field. ! * This is the generic database type name, which can be used instead of the Java class 'type'. ! * This is translated to a particular database type based on platform. */ public void setTypeName(String typeName) { this.typeName = typeName; + } + + /** + * PUBLIC: + * Set the type definition of the field. + * This is database-specific complete type definition like "VARCHAR2(50) UNIQUE NOT NULL". + * If this is given, other additional type constraint fields(size, unique, null) are meaningless. + */ + public void setTypeDefinition(String typeDefinition) { + this.typeDefinition = typeDefinition; } /** Index: entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/TableDefinition.java =================================================================== RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/TableDefinition.java,v retrieving revision 1.8 diff -c -w -r1.8 TableDefinition.java *** entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/TableDefinition.java 4 Jan 2007 14:32:11 -0000 1.8 --- entity-persistence/src/java/oracle/toplink/essentials/tools/schemaframework/TableDefinition.java 12 Mar 2007 05:10:39 -0000 *************** *** 357,371 **** /** * INTERNAL: ! * Build the field types based on the given name read in from the file. ! * Build the foriegn key constraintsas well. */ protected void buildFieldTypes(AbstractSession session) { - buildForeignFieldTypes(session); - } - - private void buildForeignFieldTypes(final AbstractSession session) { - Hashtable fieldTypes = session.getPlatform().getClassTypes(); FieldDefinition field = null; // The ForeignKeyConstraint object is the newer way of doing things. --- 357,365 ---- /** * INTERNAL: ! * Build the foriegn key constraints. */ protected void buildFieldTypes(AbstractSession session) { FieldDefinition field = null; // The ForeignKeyConstraint object is the newer way of doing things. *************** *** 376,388 **** field = (FieldDefinition)enumtr.nextElement(); if (field.getForeignKeyFieldName() != null) { addForeignKeyConstraint(buildForeignKeyConstraint(field, session.getPlatform())); - - } - if (field.getType() == null) { - field.setType((Class)fieldTypes.get(field.getTypeName())); - if (field.getType() != null) { - field.setTypeName(null); - } } } --- 370,375 ----