User: dsundstrom Date: 02/02/11 22:17:15 Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc JDBCType.java JDBCTypeComplex.java JDBCTypeComplexProperty.java JDBCTypeFactory.java JDBCTypeSimple.java SQLUtil.java Log: Added optional not-null element to cmp-fields. Not null is on by by default for primitive types and primary key fields. Revision Changes Path 1.4 +2 -1 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCType.java Index: JDBCType.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCType.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JDBCType.java 1 Sep 2001 22:03:15 -0000 1.3 +++ JDBCType.java 12 Feb 2002 06:17:15 -0000 1.4 @@ -12,13 +12,14 @@ * mapping of java classes to multipul columns. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ public interface JDBCType { public String[] getColumnNames(); public Class[] getJavaTypes(); public int[] getJDBCTypes(); public String[] getSQLTypes(); + public boolean[] getNotNull(); public Object getColumnValue(int index, Object value); public Object setColumnValue(int index, Object value, Object columnValue); 1.8 +11 -1 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplex.java Index: JDBCTypeComplex.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplex.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- JDBCTypeComplex.java 15 Jan 2002 21:38:37 -0000 1.7 +++ JDBCTypeComplex.java 12 Feb 2002 06:17:15 -0000 1.8 @@ -24,7 +24,7 @@ * details on how this is done. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ */ public class JDBCTypeComplex implements JDBCType { private JDBCTypeComplexProperty[] properties; @@ -32,6 +32,7 @@ private Class[] javaTypes; private int[] jdbcTypes; private String[] sqlTypes; + private boolean[] notNull; private Class fieldType; private HashMap propertiesByName = new HashMap(); @@ -62,6 +63,11 @@ sqlTypes[i] = properties[i].getSQLType(); } + notNull = new boolean[properties.length]; + for(int i=0; i<notNull.length; i++) { + notNull[i] = properties[i].isNotNull(); + } + for(int i=0; i<properties.length; i++) { propertiesByName.put(properties[i].getPropertyName(), properties[i]); } @@ -82,6 +88,10 @@ public String[] getSQLTypes() { return sqlTypes; + } + + public boolean[] getNotNull() { + return notNull; } public JDBCTypeComplexProperty[] getProperties() { 1.7 +10 -2 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplexProperty.java Index: JDBCTypeComplexProperty.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplexProperty.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JDBCTypeComplexProperty.java 24 Nov 2001 22:31:09 -0000 1.6 +++ JDBCTypeComplexProperty.java 12 Feb 2002 06:17:15 -0000 1.7 @@ -20,7 +20,7 @@ * the Java Bean. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ public class JDBCTypeComplexProperty { private final String propertyName; @@ -28,6 +28,7 @@ private final Class javaType; private final int jdbcType; private final String sqlType; + private final boolean notNull; private final Method[] getters; private final Method[] setters; @@ -46,6 +47,7 @@ this.javaType = javaType; this.jdbcType = jdbcType; this.sqlType = sqlType; + this.notNull = false; this.getters = getters; this.setters = setters; } @@ -54,13 +56,15 @@ JDBCTypeComplexProperty defaultProperty, String columnName, int jdbcType, - String sqlType) { + String sqlType, + boolean notNull) { this.propertyName = defaultProperty.propertyName; this.columnName = columnName; this.javaType = defaultProperty.javaType; this.jdbcType = jdbcType; this.sqlType = sqlType; + this.notNull = notNull; this.getters = defaultProperty.getters; this.setters = defaultProperty.setters; } @@ -83,6 +87,10 @@ public String getSQLType() { return sqlType; + } + + public boolean isNotNull() { + return notNull; } public Object getColumnValue(Object value) throws Exception { 1.9 +17 -5 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeFactory.java Index: JDBCTypeFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeFactory.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- JDBCTypeFactory.java 24 Nov 2001 22:31:09 -0000 1.8 +++ JDBCTypeFactory.java 12 Feb 2002 06:17:15 -0000 1.9 @@ -27,7 +27,7 @@ * this class is to flatten the JDBCValueClassMetaData into columns. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ */ public class JDBCTypeFactory { // the type mapping to use with the specified database @@ -63,7 +63,8 @@ } else { String sqlType = typeMapping.getSqlTypeForJavaType(javaType); int jdbcType = typeMapping.getJdbcTypeForJavaType(javaType); - return new JDBCTypeSimple(null, javaType, jdbcType, sqlType); + boolean notNull = javaType.isPrimitive(); + return new JDBCTypeSimple(null, javaType, jdbcType, sqlType, notNull); } } @@ -108,7 +109,15 @@ sqlType = typeMapping.getSqlTypeForJavaType(javaType); jdbcType = typeMapping.getJdbcTypeForJavaType(javaType); } - return new JDBCTypeSimple(columnName, javaType, jdbcType, sqlType); + + boolean notNull = cmpField.isNotNull(); + + return new JDBCTypeSimple( + columnName, + javaType, + jdbcType, + sqlType, + notNull); } private JDBCTypeComplex createTypeComplex(JDBCCMPFieldMetaData cmpField) { @@ -158,11 +167,14 @@ jdbcType = defaultProperties[i].getJDBCType(); } + boolean notNull = cmpField.isNotNull(); + finalProperties[i] = new JDBCTypeComplexProperty( defaultProperties[i], columnName, jdbcType, - sqlType); + sqlType, + notNull); } } @@ -223,7 +235,7 @@ sqlType = typeMapping.getSqlTypeForJavaType(javaType); jdbcType = typeMapping.getJdbcTypeForJavaType(javaType); } - + Method[] getters = propertyStack.getGetters(); Method[] setters = propertyStack.getSetters(); 1.4 +18 -4 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeSimple.java Index: JDBCTypeSimple.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeSimple.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- JDBCTypeSimple.java 1 Sep 2001 22:03:15 -0000 1.3 +++ JDBCTypeSimple.java 12 Feb 2002 06:17:15 -0000 1.4 @@ -12,19 +12,27 @@ * This class provides a simple mapping of a Java type type to a single column. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ public class JDBCTypeSimple implements JDBCType { private String[] columnNames; private Class[] javaTypes; private int[] jdbcTypes; private String[] sqlTypes; + private boolean[] notNull; - public JDBCTypeSimple(String columnName, Class javaType, int jdbcType, String sqlType) { + public JDBCTypeSimple( + String columnName, + Class javaType, + int jdbcType, + String sqlType, + boolean notNull) { + columnNames = new String[] { columnName }; javaTypes = new Class[] { javaType }; jdbcTypes = new int[] { jdbcType }; sqlTypes = new String[] { sqlType }; + this.notNull = new boolean[] { notNull }; } public String[] getColumnNames() { @@ -43,16 +51,22 @@ return sqlTypes; } + public boolean[] getNotNull() { + return notNull; + } + public Object getColumnValue(int index, Object value) { if(index != 0) { - throw new IndexOutOfBoundsException("JDBCSimpleType does not support an index>0."); + throw new IndexOutOfBoundsException("JDBCSimpleType does not " + + "support an index>0."); } return value; } public Object setColumnValue(int index, Object value, Object columnValue) { if(index != 0) { - throw new IndexOutOfBoundsException("JDBCSimpleType does not support an index>0."); + throw new IndexOutOfBoundsException("JDBCSimpleType does not " + + "support an index>0."); } return columnValue; } 1.6 +5 -1 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/SQLUtil.java Index: SQLUtil.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/SQLUtil.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SQLUtil.java 15 Jan 2002 21:29:50 -0000 1.5 +++ SQLUtil.java 12 Feb 2002 06:17:15 -0000 1.6 @@ -18,7 +18,7 @@ * SQLUtil helps with building sql statements. * * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public class SQLUtil { // ======================================================================= @@ -58,6 +58,7 @@ public static String getCreateTableColumnsClause(JDBCType type) { String[] columnNames = type.getColumnNames(); String[] sqlTypes = type.getSQLTypes(); + boolean[] notNull = type.getNotNull(); StringBuffer buf = new StringBuffer(); for(int i=0; i<columnNames.length; i++) { @@ -65,6 +66,9 @@ buf.append(", "); } buf.append(columnNames[i]).append(" ").append(sqlTypes[i]); + if(notNull[i]) { + buf.append(" NOT NULL"); + } } return buf.toString(); }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development