db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From proph...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/metadata/auto AutoCreatorDb.java
Date Thu, 28 Nov 2002 19:05:06 GMT
prophecy    2002/11/28 11:05:06

  Modified:    src/java/org/apache/ojb/broker/metadata/auto
                        AutoCreatorDb.java
  Log:
  fixed some bugs
  
  Revision  Changes    Path
  1.5       +17 -10    jakarta-ojb/src/java/org/apache/ojb/broker/metadata/auto/AutoCreatorDb.java
  
  Index: AutoCreatorDb.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/auto/AutoCreatorDb.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AutoCreatorDb.java	27 Nov 2002 05:48:15 -0000	1.4
  +++ AutoCreatorDb.java	28 Nov 2002 19:05:06 -0000	1.5
  @@ -33,6 +33,7 @@
   	/**
   	 * TODO: Don't know why the Pbroker is needed for the newConnection() method, but since
it is
   	 * i've passed it in here.
  +     * @deprecated
   	 */
   	public static void autoCreate(DescriptorRepository repos, PersistenceBrokerImpl pb) {
   
  @@ -181,6 +182,7 @@
               while(enum.hasMoreElements()){
                   ClassDescriptor cld = (ClassDescriptor) enum.nextElement();
                   // check if table exists in db
  +                // todo: should this be getFullTableName or just getTableName()
                   String tname = cld.getFullTableName();
                   //System.out.println(tname);
                   if(exists(tableNames, tname)){
  @@ -204,12 +206,12 @@
                       for (int i = 0; i < fld.length; i++)
                       {
                           FieldDescriptor fieldDescriptor = fld[i];
  -                        String colname = fieldDescriptor.getFullColumnName();
  -                        if(exists(colsInDb, colname)){
  +                        String colname = fieldDescriptor.getColumnName();
  +                        if(!exists(colsInDb, colname)){
                               // alter table to add column
                               logger.info("Altering table [" + tname + "] - adding column
[" + colname + "]");
                               AlterTableQuery altq = factory.getAlterTableQuery();
  -                            altq.setTable("tname");
  +                            altq.setTable(tname);
   
                               altq.addColumn(new Column(colname, fieldDescriptor.getColumnJdbcType()));
                               altq.execute(st);
  @@ -222,13 +224,17 @@
                       CreateTableQuery ctq = factory.getCreateTableQuery();
                       ctq.setName(tname);
                       FieldDescriptor fld[] = cld.getFieldDescriptions();
  -                    for (int i = 0; i < fld.length; i++)
  -                    {
  -                        FieldDescriptor fieldDescriptor = fld[i];
  -                        String colname = fieldDescriptor.getFullColumnName();
  -                        ctq.addColumn(new Column(colname, fieldDescriptor.getColumnJdbcType()));
  +                    if(fld != null){
  +                        for (int i = 0; i < fld.length; i++)
  +                        {
  +                            FieldDescriptor fieldDescriptor = fld[i];
  +                            String colname = fieldDescriptor.getColumnName();
  +                            ctq.addColumn(new Column(colname, fieldDescriptor.getColumnJdbcType()));
  +                        }
  +                        ctq.execute(st);
  +                        //System.out.println(ctq);
  +                        tableNames.add(tname);
                       }
  -                    ctq.execute(st);
                   }
   
               }
  @@ -257,6 +263,7 @@
           {
               String s = (String) tableNames.get(i);
               if(s.equalsIgnoreCase(tname)){
  +                //System.out.println("table exists: " + tname + " - " + s);
                   return true;
               }
   
  
  
  

Mime
View raw message