User: danch   
  Date: 01/06/21 22:04:23

  Modified:    src/main/org/jboss/ejb/plugins/jaws/jdbc JDBCCommand.java
                        JDBCInitCommand.java
  Log:
  merged patch 424409 - not null constraint for columns (thanks to David Jencks) also 
fixed a bug where remapping the name of a primary key field caused the primary key 
constraint to be wrong
  
  Revision  Changes    Path
  1.35      +36 -35    jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.java
  
  Index: JDBCCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- JDBCCommand.java  2001/06/22 03:24:49     1.34
  +++ JDBCCommand.java  2001/06/22 05:04:23     1.35
  @@ -58,10 +58,11 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dirk Zimmermann</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>danch (Dan Christopherson</a>
  - * @version $Revision: 1.34 $ 
  + * @version $Revision: 1.35 $ 
    * 
    * Revision:
    * 20010621 danch: add getter for name
  + * 20010621 (ref 1.25) danch: improve logging: an exception execing SQL is an error!
    */
   public abstract class JDBCCommand
   {
  @@ -164,11 +165,11 @@
            {
               log.debug(name + " command executing: " + theSQL);
            }
  -                              stmt = con.prepareStatement(theSQL);
  -                              setParameters(stmt, argOrArgs);
  -                              result = executeStatementAndHandleResult(stmt, 
argOrArgs);
  +             stmt = con.prepareStatement(theSQL);
  +             setParameters(stmt, argOrArgs);
  +             result = executeStatementAndHandleResult(stmt, argOrArgs);
         } catch(SQLException e) {
  -          log.debug(e);
  +          log.error("Exception caught executing SQL: "+e);
             throw e;
         } finally
         {
  @@ -458,12 +459,12 @@
              // Use the class loader to deserialize
   
               try {
  -                             ObjectInputStream ois = new ObjectInputStream(bais);
  +            ObjectInputStream ois = new ObjectInputStream(bais);
   
  -                             result = ((MarshalledObject) ois.readObject()).get();
  +            result = ((MarshalledObject) ois.readObject()).get();
   
  -                             // ejb-reference: get the object back from the handle
  -                             if (result instanceof Handle) result = 
((Handle)result).getEJBObject();
  +            // ejb-reference: get the object back from the handle
  +            if (result instanceof Handle) result = ((Handle)result).getEJBObject();
   
               // is this a marshalled object that we stuck in earlier?
               if (result instanceof MarshalledObject && 
!destination.equals(MarshalledObject.class)) 
  @@ -491,8 +492,8 @@
                }
   
                ois.close();
  -                     } catch (RemoteException e) {
  -                             throw new SQLException("Unable to load EJBObject back 
from Handle: " +e);
  +         } catch (RemoteException e) {
  +            throw new SQLException("Unable to load EJBObject back from Handle: " 
+e);
               } catch (IOException e) {
                   throw new SQLException("Unable to load a ResultSet column "+idx+" 
into a variable of type '"+destination.getName()+"': "+e);
               } catch (ClassNotFoundException e) {
  @@ -503,20 +504,20 @@
           return result;
       }
   
  -     /**
  -      * Wrapper around getResultObject(ResultSet rs, int idx, Class destination).
  -      */
  -     protected Object getResultObject(ResultSet rs, int idx, CMPFieldMetaData 
cmpField)
  -             throws SQLException {
  -             if (!cmpField.isNested()) {
  -                     // do it as before
  -                     return getResultObject(rs, idx, cmpField.getField().getType());
  -             }
  -             
  -             // Assuming no one will ever use BLOPS in composite objects.
  -             // TODO Should be tested for BLOPability
  -             return rs.getObject(idx);
  -     }
  +   /**
  +    * Wrapper around getResultObject(ResultSet rs, int idx, Class destination).
  +    */
  +   protected Object getResultObject(ResultSet rs, int idx, CMPFieldMetaData 
cmpField)
  +      throws SQLException {
  +      if (!cmpField.isNested()) {
  +         // do it as before
  +         return getResultObject(rs, idx, cmpField.getField().getType());
  +      }
  +      
  +      // Assuming no one will ever use BLOPS in composite objects.
  +      // TODO Should be tested for BLOPability
  +      return rs.getObject(idx);
  +   }
   
   
      /**
  @@ -646,7 +647,7 @@
      protected Object getCMPFieldValue(Object instance, CMPFieldMetaData 
fieldMetaData)
         throws IllegalAccessException
      {
  -              return fieldMetaData.getValue(instance);
  +       return fieldMetaData.getValue(instance);
      }
   
      protected void setCMPFieldValue(Object instance,
  @@ -654,15 +655,15 @@
                                      Object value)
         throws IllegalAccessException
      {
  -              if (fieldMetaData.isNested()) {
  -                      // we have a nested field
  -                      fieldMetaData.set(instance, value);
  -              }
  -              else {
  -                      // the usual way
  -                      Field field = fieldMetaData.getField();
  -                      field.set(instance, value);
  -              }
  +       if (fieldMetaData.isNested()) {
  +          // we have a nested field
  +          fieldMetaData.set(instance, value);
  +       }
  +       else {
  +          // the usual way
  +          Field field = fieldMetaData.getField();
  +          field.set(instance, value);
  +       }
      }
   
      protected Object getPkFieldValue(Object pk, PkFieldMetaData pkFieldMetaData)
  
  
  
  1.13      +29 -19    
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java
  
  Index: JDBCInitCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JDBCInitCommand.java      2001/01/24 20:36:24     1.12
  +++ JDBCInitCommand.java      2001/06/22 05:04:23     1.13
  @@ -30,7 +30,15 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
  - * @version $Revision: 1.12 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>danch (Dan Christopherson</a>
  + * 
  + * @version $Revision: 1.13 $
  + * 
  + * Revison:
  + * 20010621 danch: merged patch from David Jenks - null constraint on columns.
  + *    Also fixed bug where remapping column name of key field caused an invalid
  + *    PK constraint to be build.
    */
   public class JDBCInitCommand
      extends JDBCUpdateCommand
  @@ -53,23 +61,26 @@
            
            sql += (first ? "" : ",") +
                   cmpField.getColumnName() + " " +
  -                cmpField.getSQLType();
  +                cmpField.getSQLType() +
  +                cmpField.getNullable();
                   
            
            first = false;
         }
   
  -     // If there is a primary key field,
  -     // and the bean has explicitly <pk-constraint>true</pk-constraint> in jaws.xml
  -     // add primary key constraint.
  -       if (jawsEntity.getPrimKeyField() != null && jawsEntity.hasPkConstraint())  {
  -             sql += ",CONSTRAINT pk"+jawsEntity.getTableName()+" PRIMARY KEY (";
  -             for (Iterator i = jawsEntity.getPkFields();i.hasNext();) {
  -                     sql += ((PkFieldMetaData)i.next()).getName();
  -                     sql += i.hasNext()?",":"";
  -             }
  -             sql +=")";
  +      // If there is a primary key field,
  +      // and the bean has explicitly <pk-constraint>true</pk-constraint> in jaws.xml
  +      // add primary key constraint.
  +      if (jawsEntity.getPrimKeyField() != null && jawsEntity.hasPkConstraint())  
  +      {
  +         sql += ",CONSTRAINT pk"+jawsEntity.getTableName()+" PRIMARY KEY (";
  +         for (Iterator i = jawsEntity.getPkFields();i.hasNext();) {
  +            String keyCol = ((PkFieldMetaData)i.next()).getColumnName();
  +            sql += keyCol;
  +            sql += i.hasNext()?",":"";
            }
  +         sql +=")";
  +      }
   
         sql += ")";
   
  @@ -115,17 +126,16 @@
                log.log("Table '"+jawsEntity.getTableName()+"' already exists");
            } else {
                try
  -             {
  -             
  -                 // since we use the pools, we have to do this within a transaction
  +             {          
  +                // since we use the pools, we have to do this within a transaction
                   factory.getContainer().getTransactionManager().begin ();
                   jdbcExecute(null);
                   factory.getContainer().getTransactionManager().commit ();
   
  -                  // Create successful, log this
  -                  log.log("Created table '"+jawsEntity.getTableName()+"' 
successfully.");
  -                  log.debug("Primary key of table '"+jawsEntity.getTableName()+"' 
is '"
  -                     +jawsEntity.getPrimKeyField()+"'.");
  +                // Create successful, log this
  +                log.log("Created table '"+jawsEntity.getTableName()+"' 
successfully.");
  +                log.debug("Primary key of table '"+jawsEntity.getTableName()+"' is 
'"
  +                  +jawsEntity.getPrimKeyField()+"'.");
                } catch (Exception e)
                {
                   log.debug("Could not create table " +
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to