User: kvvinaymenon
  Date: 01/07/11 08:03:26

  Modified:    src/main/org/jboss/ejb/plugins/jaws/metadata Tag: Branch_2_4
                        JawsEntityMetaData.java
  Log:
  Modified for support for stable row id based updates in databases like Oracle. The 
jaws.xml file needs to include a <stable-rowid-column> field for the entity and its 
value
  should correspond to the name of the stable row id column e.g. rowid in Oracle.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.4.2   +214 -206  
jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsEntityMetaData.java
  
  Index: JawsEntityMetaData.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/metadata/JawsEntityMetaData.java,v
  retrieving revision 1.9.4.1
  retrieving revision 1.9.4.2
  diff -u -r1.9.4.1 -r1.9.4.2
  --- JawsEntityMetaData.java   2001/07/03 16:40:13     1.9.4.1
  +++ JawsEntityMetaData.java   2001/07/11 15:03:26     1.9.4.2
  @@ -36,58 +36,61 @@
    *   @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Dirk Zimmermann</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Vinay Menon</a>
  - *   @version $Revision: 1.9.4.1 $
  + *   @version $Revision: 1.9.4.2 $
    */
   public class JawsEntityMetaData extends MetaData implements XmlLoadable {
  -     // Constants -----------------------------------------------------
  +   // Constants -----------------------------------------------------
   
  -     // Attributes ----------------------------------------------------
  +   // Attributes ----------------------------------------------------
   
  -     // parent metadata structures
  -     private JawsApplicationMetaData jawsApplication;
  -     private EntityMetaData entity;
  +   // parent metadata structures
  +   private JawsApplicationMetaData jawsApplication;
  +   private EntityMetaData entity;
   
  -     // the name of the bean (same as entity.getEjbName())
  -     private String ejbName = null;
  +   // the name of the bean (same as entity.getEjbName())
  +   private String ejbName = null;
   
  -     // the name of the table to use for this bean
  -     private String tableName = null;
  +   // the name of the table to use for this bean
  +   private String tableName = null;
   
  -     // do we have to try and create the table on deployment?
  -     private boolean createTable;
  +   // do we have to try and create the table on deployment?
  +   private boolean createTable;
   
  -     // do we have to drop the table on undeployment?
  -     private boolean removeTable;
  +   // do we have to drop the table on undeployment?
  +   private boolean removeTable;
   
  -     // do we use tuned updates?
  -     private boolean tunedUpdates;
  +   // do we use tuned updates?
  +   private boolean tunedUpdates;
   
  +   //Enable fast updates based on stable row id column
  +   private String stableRowIdColumn;
  +
      // do we use 'SELECT ... FOR UPDATE' syntax?
      private boolean selectForUpdate;
   
  -     // is the bean read-only?
  -     private boolean readOnly;
  -     private int timeOut;
  +   // is the bean read-only?
  +   private boolean readOnly;
  +   private int timeOut;
   
  -     // should the table have a primary key constraint?
  -     private boolean pkConstraint;
  +   // should the table have a primary key constraint?
  +   private boolean pkConstraint;
   
  -     // is the bean's primary key a composite object
  -     private boolean compositeKey;
  +   // is the bean's primary key a composite object
  +   private boolean compositeKey;
   
  -     // the class of the primary key
  -     private Class primaryKeyClass;
  +   // the class of the primary key
  +   private Class primaryKeyClass;
   
  -     // the fields we must persist for this bean
  -     private Hashtable cmpFields = new Hashtable();
  +   // the fields we must persist for this bean
  +   private Hashtable cmpFields = new Hashtable();
   
  -     // the fields that belong to the primary key (if composite)
  -     private ArrayList pkFields = new ArrayList();
  +   // the fields that belong to the primary key (if composite)
  +   private ArrayList pkFields = new ArrayList();
   
  -     // finders for this bean
  -     private ArrayList finders = new ArrayList();
  +   // finders for this bean
  +   private ArrayList finders = new ArrayList();
   
  -     // the bean level datasource
  +   // the bean level datasource
       /**
        * This will now support datasources at the bean level. If no datasource
        * has been specified at the bean level then the global datasource is used
  @@ -96,104 +99,106 @@
        * different datasources for different beans.
        *
        */
  -     private DataSource dataSource=null;
  +   private DataSource dataSource=null;
   
  -     /**
  -      * Here we store the basename of all detailed fields in jaws.xml
  -      * (e.g., "data" for "data.categoryPK").
  -      */
  -     private HashMap detailedFieldDescriptions = new HashMap();
  +   /**
  +    * Here we store the basename of all detailed fields in jaws.xml
  +    * (e.g., "data" for "data.categoryPK").
  +    */
  +   private HashMap detailedFieldDescriptions = new HashMap();
   
  -     /**
  -      * This is the Boolean we store as value in detailedFieldDescriptions.
  -      */
  -     private static final Boolean detailedBoolean = new Boolean(true);
  +   /**
  +    * This is the Boolean we store as value in detailedFieldDescriptions.
  +    */
  +   private static final Boolean detailedBoolean = new Boolean(true);
   
   
  -     // Static --------------------------------------------------------
  +   // Static --------------------------------------------------------
   
  -     // Constructors --------------------------------------------------
  +   // Constructors --------------------------------------------------
   
  -     public JawsEntityMetaData(JawsApplicationMetaData app, EntityMetaData ent) 
throws DeploymentException {
  -             // initialisation of this object goes as follows:
  -             //  - constructor
  -             //  - importXml() for standardjaws.xml and jaws.xml
  +   public JawsEntityMetaData(JawsApplicationMetaData app, EntityMetaData ent) 
throws DeploymentException {
  +      // initialisation of this object goes as follows:
  +      //  - constructor
  +      //  - importXml() for standardjaws.xml and jaws.xml
   
  -             jawsApplication = app;
  -             entity = ent;
  -             ejbName = entity.getEjbName();
  -             compositeKey = entity.getPrimKeyField() == null;
  +      jawsApplication = app;
  +      entity = ent;
  +      ejbName = entity.getEjbName();
  +      compositeKey = entity.getPrimKeyField() == null;
   
  -             try {
  -                     primaryKeyClass = 
jawsApplication.getClassLoader().loadClass(entity.getPrimaryKeyClass());
  -             } catch (ClassNotFoundException e) {
  -                     throw new DeploymentException("could not load primary key 
class: " + entity.getPrimaryKeyClass());
  -             }
  +      try {
  +         primaryKeyClass = 
jawsApplication.getClassLoader().loadClass(entity.getPrimaryKeyClass());
  +      } catch (ClassNotFoundException e) {
  +         throw new DeploymentException("could not load primary key class: " + 
entity.getPrimaryKeyClass());
  +      }
   
  -             // we replace the . by _ because some dbs die on it...
  -             // the table name may be overridden in importXml(jaws.xml)
  -             tableName = ejbName.replace('.', '_');
  +      // we replace the . by _ because some dbs die on it...
  +      // the table name may be overridden in importXml(jaws.xml)
  +      tableName = ejbName.replace('.', '_');
   
  -             // build the metadata for the cmp fields now in case there is no 
jaws.xml
  -             Iterator cmpFieldNames = entity.getCMPFields();
  +      // build the metadata for the cmp fields now in case there is no jaws.xml
  +      Iterator cmpFieldNames = entity.getCMPFields();
   
  -             while (cmpFieldNames.hasNext()) {
  -                     String cmpFieldName = (String)cmpFieldNames.next();
  -                     CMPFieldMetaData cmpField = new CMPFieldMetaData(cmpFieldName, 
this);
  +      while (cmpFieldNames.hasNext()) {
  +         String cmpFieldName = (String)cmpFieldNames.next();
  +         CMPFieldMetaData cmpField = new CMPFieldMetaData(cmpFieldName, this);
   
  -                     cmpFields.put(cmpFieldName, cmpField);
  -             }
  +         cmpFields.put(cmpFieldName, cmpField);
  +      }
   
  -             // build the pkfields metadatas
  -             if (compositeKey) {
  -                     Field[] pkClassFields = primaryKeyClass.getFields();
  +      // build the pkfields metadatas
  +      if (compositeKey) {
  +         Field[] pkClassFields = primaryKeyClass.getFields();
   
  -                     for (int i = 0; i < pkClassFields.length; i++) {
  -                             Field pkField = pkClassFields[i];
  -                             CMPFieldMetaData cmpField = 
(CMPFieldMetaData)cmpFields.get(pkField.getName());
  +         for (int i = 0; i < pkClassFields.length; i++) {
  +            Field pkField = pkClassFields[i];
  +            CMPFieldMetaData cmpField = 
(CMPFieldMetaData)cmpFields.get(pkField.getName());
   
  -                             if (cmpField == null) throw new 
DeploymentException("Bean " + ejbName + " has PK of type " + primaryKeyClass.getName() 
+ ", so it should have a cmp-field named " + pkField.getName());
  +            if (cmpField == null) throw new DeploymentException("Bean " + ejbName + 
" has PK of type " + primaryKeyClass.getName() + ", so it should have a cmp-field 
named " + pkField.getName());
   
  -                             pkFields.add(new PkFieldMetaData(pkField, cmpField, 
this));
  -                     }
  +            pkFields.add(new PkFieldMetaData(pkField, cmpField, this));
  +         }
   
  -             } else {
  -                     String pkFieldName = entity.getPrimKeyField();
  -             CMPFieldMetaData cmpField = 
(CMPFieldMetaData)cmpFields.get(pkFieldName);
  +      } else {
  +         String pkFieldName = entity.getPrimKeyField();
  +            CMPFieldMetaData cmpField = 
(CMPFieldMetaData)cmpFields.get(pkFieldName);
   
  -                     pkFields.add(new PkFieldMetaData(cmpField, this));
  -             }
  -     }
  +         pkFields.add(new PkFieldMetaData(cmpField, this));
  +      }
  +   }
   
  -     // Public --------------------------------------------------------
  +   // Public --------------------------------------------------------
   
       public JawsApplicationMetaData getJawsApplication() { return jawsApplication; }
   
  -     public EntityMetaData getEntity() { return entity; }
  +   public EntityMetaData getEntity() { return entity; }
   
  -     public Iterator getCMPFields() { return cmpFields.values().iterator(); }
  +   public Iterator getCMPFields() { return cmpFields.values().iterator(); }
   
  -     public CMPFieldMetaData getCMPFieldByName(String name) {
  -             return (CMPFieldMetaData)cmpFields.get(name);
  -     }
  +   public CMPFieldMetaData getCMPFieldByName(String name) {
  +      return (CMPFieldMetaData)cmpFields.get(name);
  +   }
   
  -     public Iterator getPkFields() { return pkFields.iterator(); }
  +   public Iterator getPkFields() { return pkFields.iterator(); }
   
      public int getNumberOfPkFields() { return pkFields.size(); }
  +
  +   public String getTableName() { return tableName; }
   
  -     public String getTableName() { return tableName; }
  +   public boolean getCreateTable() { return createTable; }
   
  -     public boolean getCreateTable() { return createTable; }
  +   public boolean getRemoveTable() { return removeTable; }
   
  -     public boolean getRemoveTable() { return removeTable; }
  +   public boolean hasTunedUpdates() { return tunedUpdates; }
   
  -     public boolean hasTunedUpdates() { return tunedUpdates; }
  +   public String getStableRowIdColumn() { return stableRowIdColumn; }
   
  -     public boolean hasPkConstraint() { return pkConstraint; }
  +   public boolean hasPkConstraint() { return pkConstraint; }
   
  -     public int getReadOnlyTimeOut() { return timeOut; }
  +   public int getReadOnlyTimeOut() { return timeOut; }
   
  -     public boolean hasCompositeKey() { return compositeKey; }
  +   public boolean hasCompositeKey() { return compositeKey; }
   
       //Return appropriate datasource
       public DataSource getDataSource()
  @@ -210,37 +215,37 @@
           }
       }
   
  -     public String getDbURL() { return jawsApplication.getDbURL(); }
  +   public String getDbURL() { return jawsApplication.getDbURL(); }
   
  -     public Iterator getFinders() { return finders.iterator(); }
  +   public Iterator getFinders() { return finders.iterator(); }
   
  -     public String getName() { return ejbName; }
  +   public String getName() { return ejbName; }
   
  -     public int getNumberOfCMPFields() { return cmpFields.size(); }
  +   public int getNumberOfCMPFields() { return cmpFields.size(); }
   
  -     public Class getPrimaryKeyClass() { return primaryKeyClass; }
  +   public Class getPrimaryKeyClass() { return primaryKeyClass; }
   
  -     public boolean isReadOnly() { return readOnly; }
  +   public boolean isReadOnly() { return readOnly; }
   
  -     public Iterator getEjbReferences() { return entity.getEjbReferences(); }
  +   public Iterator getEjbReferences() { return entity.getEjbReferences(); }
   
  -     public String getPrimKeyField() { return entity.getPrimKeyField(); }
  +   public String getPrimKeyField() { return entity.getPrimKeyField(); }
   
  -     public boolean hasSelectForUpdate() { return selectForUpdate; }
  +   public boolean hasSelectForUpdate() { return selectForUpdate; }
   
  -     // XmlLoadable implementation ------------------------------------
  +   // XmlLoadable implementation ------------------------------------
   
  -     public void importXml(Element element) throws DeploymentException {
  -             // This method will be called:
  -             //  - with element = <default-entity> from standardjaws.xml (always)
  -             //  - with element = <default-entity> from jaws.xml (if provided)
  -             //  - with element = <entity> from jaws.xml (if provided)
  +   public void importXml(Element element) throws DeploymentException {
  +      // This method will be called:
  +      //  - with element = <default-entity> from standardjaws.xml (always)
  +      //  - with element = <default-entity> from jaws.xml (if provided)
  +      //  - with element = <entity> from jaws.xml (if provided)
   
  -             // All defaults are set during the first call. The following calls 
override them.
  +      // All defaults are set during the first call. The following calls override 
them.
   
  -             // get table name
  -             String tableStr = getElementContent(getOptionalChild(element, 
"table-name"));
  -             if (tableStr != null) tableName = tableStr;
  +      // get table name
  +      String tableStr = getElementContent(getOptionalChild(element, "table-name"));
  +      if (tableStr != null) tableName = tableStr;
   
           //get the bean level datasouce name
         String dataSourceName = getElementContent(getOptionalChild(element, 
"datasource"));
  @@ -261,101 +266,104 @@
                   }
               }
           }
  +
  +      // create table?  If not provided, keep default.
  +      String createStr = getElementContent(getOptionalChild(element, 
"create-table"));
  +      if (createStr != null) createTable = 
Boolean.valueOf(createStr).booleanValue();
  +
  +      // remove table?  If not provided, keep default.
  +      String removeStr = getElementContent(getOptionalChild(element, 
"remove-table"));
  +      if (removeStr != null) removeTable = 
Boolean.valueOf(removeStr).booleanValue();
  +
  +      // tuned updates?  If not provided, keep default.
  +      String tunedStr = getElementContent(getOptionalChild(element, 
"tuned-updates"));
  +      if (tunedStr != null) tunedUpdates = Boolean.valueOf(tunedStr).booleanValue();
  +
  +      //Get row id for fast stable row id based updates/deletes and inserts
  +      stableRowIdColumn = getElementContent(getOptionalChild(element, 
"stable-rowid-column"));
  +
  +      // read only?  If not provided, keep default.
  +      String roStr = getElementContent(getOptionalChild(element, "read-only"));
  +       if (roStr != null) readOnly = Boolean.valueOf(roStr).booleanValue();
  +
  +      String sForUpStr = getElementContent(getOptionalChild(element, 
"select-for-update"));
  +      if (sForUpStr != null) selectForUpdate = 
(Boolean.valueOf(sForUpStr).booleanValue());
  +      selectForUpdate = selectForUpdate && !readOnly;
  +
  +      // read only timeout?
  +      String toStr = getElementContent(getOptionalChild(element, "time-out"));
  +      if (toStr != null) timeOut = Integer.valueOf(toStr).intValue();
  +
  +      // primary key constraint?  If not provided, keep default.
  +      String pkStr = getElementContent(getOptionalChild(element, "pk-constraint"));
  +       if (pkStr != null) pkConstraint = Boolean.valueOf(pkStr).booleanValue();
  +
  +      // cmp fields
  +      Iterator iterator = getChildrenByTagName(element, "cmp-field");
  +
  +      while (iterator.hasNext()) {
  +         Element cmpField = (Element)iterator.next();
  +         String fieldName = getElementContent(getUniqueChild(cmpField, 
"field-name"));
  +
  +         CMPFieldMetaData cmpFieldMetaData = getCMPFieldByName(fieldName);
  +         if (cmpFieldMetaData == null) {
  +            // Before we throw an exception, we have to check for nested cmp-fields.
  +            // We just add a new CMPFieldMetaData.
  +            if (isDetailedFieldDescription(fieldName)) {
  +               // We obviously have a cmp-field like "data.categoryPK" in jaws.xml
  +               // and a cmp-field "data" in ejb-jar.xml.
  +               // In this case, we assume the "data.categoryPK" as a detailed 
description for "data".
  +               cmpFieldMetaData = new CMPFieldMetaData(fieldName, this);
  +               cmpFields.put(fieldName, cmpFieldMetaData);
  +            }
  +            else {
  +               throw new DeploymentException("cmp-field '"+fieldName+"' found in 
jaws.xml but not in ejb-jar.xml");
  +            }
  +         }
  +         cmpFieldMetaData.importXml(cmpField);
  +      }
  +
  +      // finders
  +      iterator = getChildrenByTagName(element, "finder");
  +
  +      while (iterator.hasNext()) {
  +         Element finder = (Element)iterator.next();
  +         FinderMetaData finderMetaData = new FinderMetaData();
  +         finderMetaData.importXml(finder);
  +
  +         finders.add(finderMetaData);
  +      }
  +
  +   }
  +
  +   /**
  +    * @return true For a fieldname declared in jaws.xml like "data.categoryPK" if
  +    * there was a fieldname declared in ejb-jar.xml like "data".
  +    */
  +   private boolean isDetailedFieldDescription(String fieldName) {
  +      String fieldBaseName = CMPFieldMetaData.getFirstComponent(fieldName);
  +
  +      if (detailedFieldDescriptions.containsKey(fieldBaseName)) {
  +         return true;
  +      }
   
  -             // create table?  If not provided, keep default.
  -             String createStr = getElementContent(getOptionalChild(element, 
"create-table"));
  -             if (createStr != null) createTable = 
Boolean.valueOf(createStr).booleanValue();
  -
  -     // remove table?  If not provided, keep default.
  -             String removeStr = getElementContent(getOptionalChild(element, 
"remove-table"));
  -             if (removeStr != null) removeTable = 
Boolean.valueOf(removeStr).booleanValue();
  -
  -             // tuned updates?  If not provided, keep default.
  -             String tunedStr = getElementContent(getOptionalChild(element, 
"tuned-updates"));
  -             if (tunedStr != null) tunedUpdates = 
Boolean.valueOf(tunedStr).booleanValue();
  -
  -             // read only?  If not provided, keep default.
  -             String roStr = getElementContent(getOptionalChild(element, 
"read-only"));
  -         if (roStr != null) readOnly = Boolean.valueOf(roStr).booleanValue();
  -
  -             String sForUpStr = getElementContent(getOptionalChild(element, 
"select-for-update"));
  -             if (sForUpStr != null) selectForUpdate = 
(Boolean.valueOf(sForUpStr).booleanValue());
  -             selectForUpdate = selectForUpdate && !readOnly;
  -
  -             // read only timeout?
  -             String toStr = getElementContent(getOptionalChild(element, 
"time-out"));
  -             if (toStr != null) timeOut = Integer.valueOf(toStr).intValue();
  -
  -             // primary key constraint?  If not provided, keep default.
  -             String pkStr = getElementContent(getOptionalChild(element, 
"pk-constraint"));
  -         if (pkStr != null) pkConstraint = Boolean.valueOf(pkStr).booleanValue();
  -
  -             // cmp fields
  -             Iterator iterator = getChildrenByTagName(element, "cmp-field");
  -
  -             while (iterator.hasNext()) {
  -                     Element cmpField = (Element)iterator.next();
  -                     String fieldName = getElementContent(getUniqueChild(cmpField, 
"field-name"));
  -
  -                     CMPFieldMetaData cmpFieldMetaData = 
getCMPFieldByName(fieldName);
  -                     if (cmpFieldMetaData == null) {
  -                             // Before we throw an exception, we have to check for 
nested cmp-fields.
  -                             // We just add a new CMPFieldMetaData.
  -                             if (isDetailedFieldDescription(fieldName)) {
  -                                     // We obviously have a cmp-field like 
"data.categoryPK" in jaws.xml
  -                                     // and a cmp-field "data" in ejb-jar.xml.
  -                                     // In this case, we assume the 
"data.categoryPK" as a detailed description for "data".
  -                                     cmpFieldMetaData = new 
CMPFieldMetaData(fieldName, this);
  -                                     cmpFields.put(fieldName, cmpFieldMetaData);
  -                             }
  -                             else {
  -                                     throw new DeploymentException("cmp-field 
'"+fieldName+"' found in jaws.xml but not in ejb-jar.xml");
  -                             }
  -                     }
  -                     cmpFieldMetaData.importXml(cmpField);
  -             }
  -
  -             // finders
  -             iterator = getChildrenByTagName(element, "finder");
  -
  -             while (iterator.hasNext()) {
  -                     Element finder = (Element)iterator.next();
  -                     FinderMetaData finderMetaData = new FinderMetaData();
  -                     finderMetaData.importXml(finder);
  -
  -                     finders.add(finderMetaData);
  -             }
  -
  -     }
  -
  -     /**
  -      * @return true For a fieldname declared in jaws.xml like "data.categoryPK" if
  -      * there was a fieldname declared in ejb-jar.xml like "data".
  -      */
  -     private boolean isDetailedFieldDescription(String fieldName) {
  -             String fieldBaseName = CMPFieldMetaData.getFirstComponent(fieldName);
  -
  -             if (detailedFieldDescriptions.containsKey(fieldBaseName)) {
  -                     return true;
  -             }
  -
  -             CMPFieldMetaData cmpFieldMetaData = getCMPFieldByName(fieldBaseName);
  -             if (cmpFieldMetaData == null) {
  -                     return false;
  -             }
  -             else {
  -                     detailedFieldDescriptions.put(fieldBaseName, detailedBoolean);
  -                     cmpFields.remove(fieldBaseName);
  -                     return true;
  -             }
  -     }
  +      CMPFieldMetaData cmpFieldMetaData = getCMPFieldByName(fieldBaseName);
  +      if (cmpFieldMetaData == null) {
  +         return false;
  +      }
  +      else {
  +         detailedFieldDescriptions.put(fieldBaseName, detailedBoolean);
  +         cmpFields.remove(fieldBaseName);
  +         return true;
  +      }
  +   }
   
   
  -     // Package protected ---------------------------------------------
  +   // Package protected ---------------------------------------------
   
  -     // Protected -----------------------------------------------------
  +   // Protected -----------------------------------------------------
   
  -     // Private -------------------------------------------------------
  +   // Private -------------------------------------------------------
   
  -     // Inner classes -------------------------------------------------
  +   // Inner classes -------------------------------------------------
   }
  
  
  

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

Reply via email to