I'm working with mysql and sql-server database, I' ve found bugs in the last
cvs turbine (15-02-2001)


1.- To generate tables with 1 to 3 primary keys, not autoncremente
neccesarily, it could compose by date - int - string

2.- Generate schema.xml from schema.sql generated by PowerDesigner ( mysql,
msl-server, oracle and other database.)

I had modified torque to solve that problems.


- Java file /Torque/model/Column.java

- Method  

    public String toString()
    { 

         ...

        if (isPrimaryKey)
        {
            result.append(" primaryKey=\""+isPrimaryKey+"\"");
        }

        //Start Line Added
        if (isAutoIncrement)
        {
            result.append(" autoIncrement=\""+isAutoIncrement+"\"");
        }
        //End Line Added

        if (isNotNull)
        {
            result.append(" required=\"true\"");
        }
        else
        {
            result.append(" required=\"false\"");
        }
        ...

    }



- Method 

    public void setTypeFromString (String typeName, String size)
    {
        ....

        else if (tn.indexOf ("FLOAT") != -1)
        {
            torqueType = "FLOAT";
            columnType = new Float (0);
        }
        
        // Start lines added
        else  if (tn.indexOf ("DATE") != -1 )
        {
            torqueType = "DATE"; 
            columnType = new java.util.Date();
        }
        else  if (tn.indexOf ("TIMESTAMP") != -1 || tn.indexOf ("TIME") !=
-1)
        {
            torqueType = "TIMESTAMP";
            columnType = new java.util.Date();
        }
        else  if (tn.indexOf ("BINARY") != -1 )
        {
            torqueType = "LONGVARBINARY";
            columnType = new java.util.Hashtable();
        }
        // End lines added

        
        /* Comment 
        else if (tn.indexOf ("DATE") != -1 || tn.indexOf ("TIME") != -1)
        {
            torqueType = "TIMESTAMP";
            columnType = new java.util.Date();
        }
        */
        else
        {
            torqueType = "VARCHAR";
            columnType = "";
        }
}

- Java file  /Torque/model/Table.java

-Method
    public String toString()
    {
        StringBuffer result = new StringBuffer();

        result.append ("<table name=\"").append(name);
        
        // Line added
        result.append("\"");
        
        if (javaName != null)
        {
            result.append(" javaname=\""+javaName+"\"");
        }

        if (idMethod != null)
        {
            result.append(" idMethod=\""+idMethod+"\"");
        }

        // Commented line
        // result.append("\">\n");
        // Line added
        result.append(">\n");

        if (columnVector != null)
        {
            for (Enumeration e = columnVector.elements() ;
e.hasMoreElements() ;)
            {
                result.append (e.nextElement());
            }
        }
        
      ...

}



-Java file Torque/transform/SQLToAppData.java

-Method

    private void Create_Table() throws ParseException
    {
        next();
        String tableName = token.getStr(); // name of the table
        next();
        if (!token.getStr().equals("(")) err ("( expected");
        next();

        Table tbl = new Table (tableName);

        /*
        Don´t always wanted IDBroker into PrimaryKey,
        because primaryKeys is composed ie, date-int-string
        */
        //Line added, 
        tbl.setIdMethod("none");

        while (!token.getStr().equals(";"))
        {
            Create_Table_Column(tbl);
        }
        appDataDB.addTable (tbl);
    }

- Java File  Torque/transform/DTDResolver.java

-Method 

    public DTDResolver()
    {
        try
        {
           // Work fine into jdk1.3 and NT
            File file = new File("./dtd/database.dtd");
            URL url = file.toURL();
            databaseDTD = new InputSource(url.openStream());
            /* Comment 
            URL url = getClass().getResource("database.dtd");
            if (url != null)  // jdk1.3 on linux allways returns null!!
                databaseDTD = new InputSource(url.openStream());
            */    
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    } // DTDResolver()



- Template file object.vm 

- method

    public void setPrimaryKey(Object id) throws Exception
    {
        StringTokenizer st = new StringTokenizer(id.toString(), ":");
     #foreach ($col in $table.Columns)
      #set ( $cjtype = $col.JavaNative )
      #if($col.isPrimaryKey())        
        #if ($cjtype == "int")
        set${col.JavaName}( Integer.parseInt(st.nextToken()) );
        #elseif ($cjtype == "long")
        set${col.JavaName}( Long.parseLong(st.nextToken()) );
        #elseif ($cjtype == "BigDecimal")
        set${col.JavaName}( BigDecimal(st.nextToken()) );
        #elseif ($cjtype == "String")
        set${col.JavaName}( st.nextToken() );

 ##  Start  line added
        #else
        set${col.JavaName}( new ${cjtype}(st.nextToken()) );
 ##  End  line added

        #end
      #end
      #end
    }

- Template file Peer.vm

-method 

    public static $table.JavaName retrieveById(Object pkid) 
        throws Exception
    {
        StringTokenizer stok = new StringTokenizer((String)pkid, ":");
        if ( stok.countTokens() < $table.PrimaryKeys.size() )
        {   
            throw new TurbineException(
                "id tokens did not match number of primary keys" );
        }
#foreach ($col in $table.PrimaryKeys)
  #set ( $clo = $col.Name.toLowerCase() )
  #set ( $cjtype = $col.JavaNative )
  #if ( $cjtype == "int" )
    #set ( $convert = "Integer.parseInt(stok.nextToken())" )    ## semicolon
Removed ; 
  #elseif  ( $cjtype == "long" )
    #set ( $convert = "Long.parseLong(stok.nextToken())" )   ## semicolon
Removed ; 
  #elseif ( $cjtype == "String" )
    #set ( $convert = "stok.nextToken()" )  ## Removed ; 
  #else 
    #set ( $convert = "new ${cjtype}(stok.nextToken())" )       ## semicolon
Removed ; 
  #end
       $cjtype $clo = $convert;
#end







------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to