You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/11/04 12:33:32 UTC

cvs commit: jakarta-commons-sandbox/sql/src/test-input datamodel.xml

jstrachan    2002/11/04 03:33:32

  Modified:    sql      project.xml
               sql/src/java/org/apache/commons/sql/builder SqlBuilder.java
                        AxionBuilder.java
               sql/src/test/org/apache/commons/sql/io
                        AbstractTestJdbcModelReader.java
                        TestHsqlDbJdbcModelReader.java
               sql/src/test-input datamodel.xml
  Log:
  Applied Russell Smyth's patches...
  
  A few patches for some small problems reported by Ralph Schaer, plus
  some other things I found along the way:
  
  src/test/org/apache/commons/sql/io/AbstractTestJdbcModelReader.java
  
  added check to make sure author table and column are found (not
  necessary now, but I needed them to debug another problem, so it makes
  sense to leave them here should a similar problem re-occur)
  
  src/java/org/apache/commons/sql/builder/SqlBuilder.java
  (SqlBuilder.java.patch)
  =======================================================
  correct genration of columns of decimal type with size and 
  scale
  add getNativeType to allow db specific translation of type 
  strings - used in AxionBuilder.java change
  
  src/java/org/apache/commons/sql/builder/AxionBuilder.java
  (AxionBuilder.java.patch)
  ====================================================================
  minor change to get axion tables built correctly when they contain
  "DECIMAL" columns. This type of change may be needed for other types 
  as well, and possibly in other databases - this is what the new table
  in datamodel.xml is for!
  
  src/test-data/datamodel.xml
  (datamodel.xml.patch)
  ===============================
  Added a new table for testing correct generation of each type of 
  column (work in progress, much commented out waiting for time to 
  work on the code that creates table columns)
  
  src/test/org/apache/commons/sql/io/TestHsqlDbJdbcModelReader.java
  (TestHsqlDbJdbcModelREader.java)
  =================================================================
  added code to check version of hssqldb and correctly check foreign
  key import if version >=1.7.1 (this function is corrected in 1.7.1)
  
  Revision  Changes    Path
  1.7       +3 -2      jakarta-commons-sandbox/sql/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/project.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- project.xml	13 Sep 2002 12:14:16 -0000	1.6
  +++ project.xml	4 Nov 2002 11:33:31 -0000	1.7
  @@ -149,7 +149,7 @@
       </dependency>
       <dependency>
         <id>hsqldb</id>
  -      <version>1.7.0</version>
  +      <version>1.7.1</version>
       </dependency>
   
   	  <!-- no longer requird -->    
  @@ -206,7 +206,8 @@
       <!-- Resources that are packaged up inside the JAR file -->
       <resources>
         <includes>
  -        <include>**/*.properties, **/*.betwixt</include>
  +        <include>**/*.properties</include>
  +	<include>src/java/**/*.betwixt</include>
         </includes>
       </resources>
     </build>
  
  
  
  1.11      +9 -6      jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/SqlBuilder.java
  
  Index: SqlBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/SqlBuilder.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SqlBuilder.java	28 Oct 2002 16:15:29 -0000	1.10
  +++ SqlBuilder.java	4 Nov 2002 11:33:31 -0000	1.11
  @@ -393,15 +393,14 @@
        * @return the full SQL type string including the size
        */
       protected String getSqlType(Column column) {
  -        StringBuffer sqlType = new StringBuffer(column.getType());
  +        StringBuffer sqlType = new StringBuffer(getNativeType(column));
           if ( column.getSize() > 0 ) {
               sqlType.append(" (");
               sqlType.append(column.getSize());
  -            sqlType.append(")");
  -        }
  -        if ( TypeMap.isDecimalType(column.getType()) ){
  -            sqlType.append(",");
  -            sqlType.append(column.getScale());
  +            if ( TypeMap.isDecimalType(column.getType()) ){
  +                sqlType.append(",");
  +                sqlType.append(column.getScale());
  +            }
               sqlType.append(")");
           }
           return sqlType.toString();
  @@ -704,6 +703,10 @@
        */ 
       protected void printAutoIncrementColumn() throws IOException {
           print( "IDENTITY" );
  +    }
  +
  +    protected String getNativeType(Column column){
  +        return column.getType();
       }
   
   }
  
  
  
  1.6       +9 -1      jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/AxionBuilder.java
  
  Index: AxionBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/AxionBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AxionBuilder.java	28 Oct 2002 19:37:19 -0000	1.5
  +++ AxionBuilder.java	4 Nov 2002 11:33:31 -0000	1.6
  @@ -87,7 +87,7 @@
   
       protected String getSqlType(Column column) {
           // Axion doesn't support text width specification 
  -        return column.getType();
  +        return getNativeType(column);
       }
       
       protected void writePrimaryKeys(Table table) throws IOException {
  @@ -108,6 +108,14 @@
   
       protected void printNullable() throws IOException {
           //print("NULL");
  +    }
  +
  +    protected String getNativeType(Column column){
  +        if(column.getTypeCode() == java.sql.Types.DECIMAL){
  +            return "FLOAT";
  +	}else{
  +            return super.getNativeType(column);
  +	}
       }
   
       /** 
  
  
  
  1.3       +2 -0      jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/io/AbstractTestJdbcModelReader.java
  
  Index: AbstractTestJdbcModelReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/io/AbstractTestJdbcModelReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractTestJdbcModelReader.java	28 Oct 2002 19:42:31 -0000	1.2
  +++ AbstractTestJdbcModelReader.java	4 Nov 2002 11:33:31 -0000	1.3
  @@ -192,7 +192,9 @@
           }
   
           Table authorTable = testDatabase.findTable("author");
  +        assertTrue("found author table",authorTable!=null);
           Column authorColumn = authorTable.findColumn("organisation");
  +        assertTrue("found organisation column", authorColumn!=null);
           
           assertTrue("organisation column is not a primary key", !authorColumn.isPrimaryKey());
           assertTrue("organisation column is not auto inc", !authorColumn.isAutoIncrement());
  
  
  
  1.2       +44 -6     jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/io/TestHsqlDbJdbcModelReader.java
  
  Index: TestHsqlDbJdbcModelReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/io/TestHsqlDbJdbcModelReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestHsqlDbJdbcModelReader.java	28 Oct 2002 18:40:19 -0000	1.1
  +++ TestHsqlDbJdbcModelReader.java	4 Nov 2002 11:33:31 -0000	1.2
  @@ -81,6 +81,9 @@
    */
   public class TestHsqlDbJdbcModelReader extends AbstractTestJdbcModelReader {
   
  +    private float driverMajor = -1;
  +    private int driverMinor = -1;
  +    
       /** The Log to which logging calls will be made. */
       private static final Log log =
           LogFactory.getLog(TestHsqlDbJdbcModelReader.class);
  @@ -88,6 +91,35 @@
       public static void main(String[] args) {
           TestRunner.run(suite());
       }
  +    public void setUp() throws Exception{
  +        super.setUp();
  +        
  +        // Get driver version
  +        // cant use DatabaseMetaData.getDatabaseMajorVersion() - it dosnt work
  +        // for hsqldb
  +        String driverVersion = null;
  +        try{
  +            java.sql.Connection conn = getConnection();
  +            java.sql.DatabaseMetaData dbmd = conn.getMetaData();
  +            driverVersion = dbmd.getDriverVersion();
  +        }catch(Exception e){
  +        }
  +        int dotpos = driverVersion.lastIndexOf(".");
  +        String strMajor = null;
  +        String strMinor = null;
  +        if(dotpos>=0){
  +            strMajor = driverVersion.substring(0,dotpos);
  +            strMinor = driverVersion.substring(dotpos+1,driverVersion.length());
  +        }
  +        try{
  +            driverMajor = Float.parseFloat(strMajor);
  +        }catch(NumberFormatException nfe){
  +        }
  +        try{
  +            driverMinor = Integer.parseInt(strMinor);
  +        }catch(NumberFormatException nfe){
  +        }
  +    }
   
       /**
        * A unit test suite for JUnit
  @@ -97,17 +129,23 @@
       }
   
       public void doImportForeignKeys(Table srcTable, Table testTable) {
  -        // HsqlDb doesn't support importing forign keys
  -        assertTrue(
  -            "No FK imported from HSQLDB",
  -            testTable.getForeignKeys().size() == 0);
  +        if(driverMajor>=1.7 && driverMinor>0){
  +            assertTrue(
  +                "Foreign Keys Imported", 
  +                testTable.getForeignKeys().size() ==
  +                    testTable.getForeignKeys().size());
  +        }else{
  +            // HsqlDb < 1.7.1 doesn't support importing forign keys
  +            assertTrue(
  +                "No FK imported from HSQLDB",
  +                testTable.getForeignKeys().size() == 0);
  +        }
   
       }
   
       public void doImportPrimaryKeyColumns(Table srcTable, Table testTable) {
  -        // HsqlDb does support importing primary keys
           assertTrue(
  -            "Table OK's match",
  +            "Table PK's match",
               testTable.getPrimaryKeyColumns().size()
                   == srcTable.getPrimaryKeyColumns().size());
       }
  
  
  
  1.7       +38 -1     jakarta-commons-sandbox/sql/src/test-input/datamodel.xml
  
  Index: datamodel.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test-input/datamodel.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- datamodel.xml	28 Oct 2002 19:42:31 -0000	1.6
  +++ datamodel.xml	4 Nov 2002 11:33:32 -0000	1.7
  @@ -10,7 +10,7 @@
       <column name="author_id" type="INTEGER" primaryKey="true" required="true"/>
       <column name="name" type="VARCHAR" size="50" required="true"/>
       <column name="organisation" type="VARCHAR" size="50" required="false"/>
  -	</table>
  +  </table>
   
     <!-- =================================================== -->
     <!-- B O O K  T A B L E                                  -->
  @@ -30,6 +30,43 @@
        <index-column name="isbn"/>
       </index>
                 
  +  </table>
  +
  +  <!-- =================================================== -->
  +  <!-- COLUMN TYPE TEST TABLE                              -->
  +  <!-- =================================================== -->
  +  <table name="coltype">
  +    <!--column name="COL_BIT" primaryKey="false" required="false" type="BIT"/-->
  +    <!--column name="COL_TINYINT" primaryKey="false" required="false" type="TINYINT"/-->
  +    <!--column name="COL_SMALLINT" primaryKey="false" required="false" type="SMALLINT"/-->
  +    <column name="COL_INTEGER" primaryKey="false" required="false" type="INTEGER"/>
  +    <!--column name="COL_BIGINT" primaryKey="false" required="false" type="BIGINT"/-->
  +    <column name="COL_FLOAT" primaryKey="false" required="false" type="FLOAT"/>
  +    <!--column name="COL_REAL" primaryKey="false" required="false" type="REAL"/-->
  +    <!--column name="COL_NUMERIC" primaryKey="false" required="false" size="15" type="NUMERIC"/-->
  +    <column name="COL_DECIMAL" primaryKey="false" required="false" scale="3" size="15" type="DECIMAL"/>
  +    <column name="COL_DEC_NOSCALE" primaryKey="false" required="false" size="15" type="DECIMAL"/>
  +    <column name="COL_CHAR" primaryKey="false" required="false" size="15" type="CHAR"/>
  +    <column name="COL_VARCHAR" primaryKey="false" required="false" size="15" type="VARCHAR"/>
  +    <!--column name="COL_LONGVARCHAR" primaryKey="false" required="false" type="LONGVARCHAR"/-->
  +    <column name="COL_DATE" primaryKey="false" required="false" type="DATE"/>
  +    <column name="COL_TIME" primaryKey="false" required="false" type="TIME"/>
  +    <column name="COL_TIMESTAMP" primaryKey="false" required="false" type="TIMESTAMP"/>
  +    <!--column name="COL_BINARY" primaryKey="false" required="false" type="BINARY"/-->
  +    <!--column name="COL_VARBINARY" primaryKey="false" required="false" size="15" type="VARBINARY"/-->
  +    <!--column name="COL_LONGVARBINARY" primaryKey="false" required="false" type="LONGVARBINARY"/-->
  +    <!--column name="COL_NULL" primaryKey="false" required="false" type="NULL"/-->
  +    <!--column name="COL_OTHER" primaryKey="false" required="false" size="15" type="OTHER"/-->
  +    <!--column name="COL_JAVA_OBJECT" primaryKey="false" required="false" size="15" type="JAVA_OBJECT"/-->
  +    <!--column name="COL_DISTINCT" primaryKey="false" required="false" size="15" type="DISTINCT"/-->
  +    <!--column name="COL_STRUCT" primaryKey="false" required="false" size="15" type="STRUCT"/-->
  +    <!--column name="COL_ARRAY" primaryKey="false" required="false" size="15" type="ARRAY"/-->
  +    <!--column name="COL_BLOB" primaryKey="false" required="false" type="BLOB"/-->
  +    <!--column name="COL_CLOB" primaryKey="false" required="false" type="CLOB"/-->
  +    <!--column name="COL_REF" primaryKey="false" required="false" size="15" type="REF"/-->
  +    <!--column name="COL_DOUBLE" primaryKey="false" required="false" type="DOUBLE"/-->
  +    <!--column name="COL_BOOLEAN" primaryKey="false" required="false" type="BOOLEAN"/-->
  +    <!--column name="COL_DATALINK" primaryKey="false" required="false" size="15" type="DECIMAL"/-->
     </table>
   
   </database>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>