[jboss-svn-commits] JBoss Common SVN: r2522 - in jbossxb-builder/trunk/src/test: java/org/jboss/ejb/metadata/spec and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 31 06:00:35 EDT 2007


Author: alex.loubyansky at jboss.com
Date: 2007-08-31 06:00:35 -0400 (Fri, 31 Aug 2007)
New Revision: 2522

Added:
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRoleMetaData.java
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMappingMetaData.java
   jbossxb-builder/trunk/src/test/resources/org/jboss/test/ejb/metadata/test/JBossCMP_testRelationships.xml
Removed:
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRole.java
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMapping.java
Modified:
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationMetaData.java
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPKeyFieldMetaData.java
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPMetaData.java
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationshipsMetaData.java
   jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/spec/RelationMetaData.java
   jbossxb-builder/trunk/src/test/java/org/jboss/test/ejb/metadata/test/JBossCMPUnitTestCase.java
Log:
relationships

Modified: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationMetaData.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationMetaData.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationMetaData.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -21,8 +21,16 @@
  */
 package org.jboss.ejb.metadata.jboss.cmp;
 
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
 import org.jboss.ejb.metadata.spec.RelationMetaData;
 import org.jboss.javaee.metadata.support.NamedMetaDataWithDescriptionGroupWithOverride;
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlModelGroup;
 
 
 /**
@@ -31,55 +39,166 @@
  * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
  * @version $Revision: 1.1 $
  */
+ at JBossXmlModelGroup(
+      kind=JBossXmlConstants.MODEL_GROUP_CHOICE,
+      particles={@JBossXmlModelGroup.Particle(element=@XmlElement(name="ejb-relation"), type=JBossCMPEjbRelationMetaData.class)})
 public class JBossCMPEjbRelationMetaData
    extends NamedMetaDataWithDescriptionGroupWithOverride<RelationMetaData>
 {
-   private String ejbRelationName;
    private boolean readOnly;
    private long readTimeOut;
    private boolean foreignKeyMapping;
-   private JBossCMPRelationTableMapping relationTableMapping;
-   private JBossCMPEjbRelationshipRole leftRole;
-   private JBossCMPEjbRelationshipRole rightRole;
+   private JBossCMPRelationTableMappingMetaData relationTableMapping;
+   private JBossCMPEjbRelationshipRoleMetaData leftRole;
+   private JBossCMPEjbRelationshipRoleMetaData rightRole;
    
    public String getEjbRelationName()
    {
-      return ejbRelationName;
+      return getName();
    }
+   
    public void setEjbRelationName(String ejbRelationName)
    {
-      this.ejbRelationName = ejbRelationName;
+      setName(ejbRelationName);
    }
+   
    public boolean isForeignKeyMapping()
    {
       return foreignKeyMapping;
    }
+   
+   @XmlJavaTypeAdapter(value = EmptyElementToBooleanAdapter.class)
    public void setForeignKeyMapping(boolean foreignKeyMapping)
    {
       this.foreignKeyMapping = foreignKeyMapping;
    }
+   
    public boolean isReadOnly()
    {
       return readOnly;
    }
+   
    public void setReadOnly(boolean readOnly)
    {
       this.readOnly = readOnly;
    }
+   
    public long getReadTimeOut()
    {
       return readTimeOut;
    }
+   
    public void setReadTimeOut(long readTimeOut)
    {
       this.readTimeOut = readTimeOut;
    }
-   public JBossCMPRelationTableMapping getRelationTableMapping()
+   
+   public JBossCMPRelationTableMappingMetaData getRelationTableMapping()
    {
       return relationTableMapping;
    }
-   public void setRelationTableMapping(JBossCMPRelationTableMapping relationTableMapping)
+   
+   public void setRelationTableMapping(JBossCMPRelationTableMappingMetaData relationTableMapping)
    {
       this.relationTableMapping = relationTableMapping;
    }
+
+   /**
+    * Get the leftRole.
+    * 
+    * @return the leftRole.
+    */   
+   public JBossCMPEjbRelationshipRoleMetaData getLeftRole()
+   {
+      return leftRole;
+   }
+
+   /**
+    * Set the leftRole.
+    * 
+    * @param leftRole The leftRole to set.
+    */
+   @XmlTransient
+   public void setLeftRole(JBossCMPEjbRelationshipRoleMetaData leftRole)
+   {
+      this.leftRole = leftRole;
+   }
+
+   /**
+    * Get the rightRole.
+    * 
+    * @return the rightRole.
+    */
+   public JBossCMPEjbRelationshipRoleMetaData getRightRole()
+   {
+      return rightRole;
+   }
+
+   /**
+    * Set the rightRole.
+    * 
+    * @param rightRole The rightRole to set.
+    */
+   @XmlTransient
+   public void setRightRole(JBossCMPEjbRelationshipRoleMetaData rightRole)
+   {
+      this.rightRole = rightRole;
+   }
+
+   public List<JBossCMPEjbRelationshipRoleMetaData> getEjbRelationshipRoles()
+   {
+      return new java.util.AbstractList<JBossCMPEjbRelationshipRoleMetaData>()
+      {
+         @Override
+         public JBossCMPEjbRelationshipRoleMetaData get(int index)
+         {
+            if(index > size())
+            {
+               throw new IllegalArgumentException("Index must be less then " + size() + ": " + index);
+            }
+            return index == 0 ? leftRole : rightRole;
+         }
+
+         @Override
+         public int size()
+         {
+            return leftRole == null ? (rightRole == null ? 0 : 1) : 2;
+         }
+         
+         @Override
+         public boolean add(JBossCMPEjbRelationshipRoleMetaData o)
+         {
+            if(leftRole == null)
+            {
+               setLeftRole(o);
+            }
+            else if(rightRole == null)
+            {
+               setRightRole(o);
+            }
+            else
+            {
+               throw new IllegalStateException("Too many roles: " + o);
+            }
+            return true;
+         }
+      };
+   }
+   
+   /**
+    * Set the relation role metadata<p>
+    * 
+    * On first invocation it sets the left role,
+    * on second invocation it sets the right role,
+    * after that it throws an IllegalStateException
+    * 
+    * @param roleMetaData
+    * @throws IllegalArgumentException for a null role metadata
+    * @throws IllegalStateException for too many roles
+    */
+   @XmlElement(name="ejb-relationship-role")
+   public void setEjbRelationshipRoles(List<JBossCMPEjbRelationshipRoleMetaData> roleMetaData)
+   {
+      throw new UnsupportedOperationException("this list shouldn't be set");
+   }
 }

Deleted: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRole.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRole.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRole.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb.metadata.jboss.cmp;
-
-import java.util.List;
-
-
-/**
- * A JBossCMPEjbRelationshipRole.
- * 
- * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
- * @version $Revision: 1.1 $
- */
-public class JBossCMPEjbRelationshipRole
-{
-   private String ejbRelationshipRoleName;
-   private boolean fkConstraint;
-   private List<JBossCMPKeyFieldMetaData> keyFields;
-   private JBossCMPReadAheadMetaData readAhead;
-   private boolean batchCascadeDelete;
-}

Added: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRoleMetaData.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRoleMetaData.java	                        (rev 0)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPEjbRelationshipRoleMetaData.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb.metadata.jboss.cmp;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+
+/**
+ * A JBossCMPEjbRelationshipRoleMetaData.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossCMPEjbRelationshipRoleMetaData
+{
+   private String ejbRelationshipRoleName;
+   private boolean fkConstraint;
+   private List<JBossCMPKeyFieldMetaData> keyFields;
+   private JBossCMPReadAheadMetaData readAhead;
+   private boolean batchCascadeDelete;
+   
+   /**
+    * Get the batchCascadeDelete.
+    * 
+    * @return the batchCascadeDelete.
+    */
+   public boolean isBatchCascadeDelete()
+   {
+      return batchCascadeDelete;
+   }
+
+   /**
+    * Set the batchCascadeDelete.
+    * 
+    * @param batchCascadeDelete The batchCascadeDelete to set.
+    */
+   @XmlJavaTypeAdapter(value = EmptyElementToBooleanAdapter.class)
+   public void setBatchCascadeDelete(boolean batchCascadeDelete)
+   {
+      this.batchCascadeDelete = batchCascadeDelete;
+   }
+   /**
+    * Get the ejbRelationshipRoleName.
+    * 
+    * @return the ejbRelationshipRoleName.
+    */
+   public String getEjbRelationshipRoleName()
+   {
+      return ejbRelationshipRoleName;
+   }
+   
+   /**
+    * Set the ejbRelationshipRoleName.
+    * 
+    * @param ejbRelationshipRoleName The ejbRelationshipRoleName to set.
+    */
+   public void setEjbRelationshipRoleName(String ejbRelationshipRoleName)
+   {
+      this.ejbRelationshipRoleName = ejbRelationshipRoleName;
+   }
+
+   /**
+    * Get the fkConstraint.
+    * 
+    * @return the fkConstraint.
+    */
+   public boolean isFkConstraint()
+   {
+      return fkConstraint;
+   }
+
+   /**
+    * Set the fkConstraint.
+    * 
+    * @param fkConstraint The fkConstraint to set.
+    */
+   public void setFkConstraint(boolean fkConstraint)
+   {
+      this.fkConstraint = fkConstraint;
+   }
+
+   /**
+    * Get the keyFields.
+    * 
+    * @return the keyFields.
+    */
+   public List<JBossCMPKeyFieldMetaData> getKeyFields()
+   {
+      return keyFields;
+   }
+   
+   /**
+    * Set the keyFields.
+    * 
+    * @param keyFields The keyFields to set.
+    */
+   @XmlElementWrapper
+   @XmlElement(name="key-field")
+   public void setKeyFields(List<JBossCMPKeyFieldMetaData> keyFields)
+   {
+      this.keyFields = keyFields;
+   }
+
+   /**
+    * Get the readAhead.
+    * 
+    * @return the readAhead.
+    */
+   public JBossCMPReadAheadMetaData getReadAhead()
+   {
+      return readAhead;
+   }
+
+   /**
+    * Set the readAhead.
+    * 
+    * @param readAhead The readAhead to set.
+    */
+   public void setReadAhead(JBossCMPReadAheadMetaData readAhead)
+   {
+      this.readAhead = readAhead;
+   }
+}

Modified: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPKeyFieldMetaData.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPKeyFieldMetaData.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPKeyFieldMetaData.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -23,7 +23,10 @@
 
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
+
 /**
  * A JBossCMPKeyFieldMetaData.
  * 
@@ -37,5 +40,128 @@
    private int jdbcType;
    private String sqlType;
    private List<JBossCMPPropertyMetaData> properties;
-   private boolean dbIndex;
+   private boolean dbindex;
+   
+   /**
+    * Get the columnName.
+    * 
+    * @return the columnName.
+    */
+   public String getColumnName()
+   {
+      return columnName;
+   }
+
+   /**
+    * Set the columnName.
+    * 
+    * @param columnName The columnName to set.
+    */
+   public void setColumnName(String columnName)
+   {
+      this.columnName = columnName;
+   }
+
+   /**
+    * Get the dbindex.
+    * 
+    * @return the dbindex.
+    */
+   public boolean isDbindex()
+   {
+      return dbindex;
+   }
+
+   /**
+    * Set the dbindex.
+    * 
+    * @param dbindex The dbindex to set.
+    */
+   @XmlJavaTypeAdapter(value = EmptyElementToBooleanAdapter.class)
+   public void setDbindex(boolean dbIndex)
+   {
+      this.dbindex = dbIndex;
+   }
+   
+   /**
+    * Get the fieldName.
+    * 
+    * @return the fieldName.
+    */
+   public String getFieldName()
+   {
+      return fieldName;
+   }
+
+   /**
+    * Set the fieldName.
+    * 
+    * @param fieldName The fieldName to set.
+    */
+   public void setFieldName(String fieldName)
+   {
+      this.fieldName = fieldName;
+   }
+
+   /**
+    * Get the jdbcType.
+    * 
+    * @return the jdbcType.
+    */
+   public int getJdbcType()
+   {
+      return jdbcType;
+   }
+
+   /**
+    * Set the jdbcType.
+    * 
+    * @param jdbcType The jdbcType to set.
+    */
+   @XmlJavaTypeAdapter(value = JDBCTypeAdapter.class)
+   public void setJdbcType(int jdbcType)
+   {
+      this.jdbcType = jdbcType;
+   }
+   
+   /**
+    * Get the properties.
+    * 
+    * @return the properties.
+    */
+   public List<JBossCMPPropertyMetaData> getProperties()
+   {
+      return properties;
+   }
+   
+   /**
+    * Set the properties.
+    * 
+    * @param properties The properties to set.
+    */
+   @XmlElement(name="property")
+   public void setProperties(List<JBossCMPPropertyMetaData> properties)
+   {
+      this.properties = properties;
+   }
+
+   /**
+    * Get the sqlType.
+    * 
+    * @return the sqlType.
+    */
+   public String getSqlType()
+   {
+      return sqlType;
+   }
+
+   /**
+    * Set the sqlType.
+    * 
+    * @param sqlType The sqlType to set.
+    */
+   public void setSqlType(String sqlType)
+   {
+      this.sqlType = sqlType;
+   }
 }

Modified: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPMetaData.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPMetaData.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPMetaData.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -163,7 +163,6 @@
     * 
     * @return the relationships.
     */
-   
    public JBossCMPRelationshipsMetaData getRelationships()
    {
       return relationships;
@@ -174,7 +173,6 @@
     * 
     * @param relationships The relationships to set.
     */
-   
    public void setRelationships(JBossCMPRelationshipsMetaData relationships)
    {
       this.relationships = relationships;

Deleted: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMapping.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMapping.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMapping.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb.metadata.jboss.cmp;
-
-import java.util.List;
-
-
-/**
- * A JBossCMPRelationTableMapping.
- * 
- * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
- * @version $Revision: 1.1 $
- */
-public class JBossCMPRelationTableMapping
-{
-   private String tableName;
-   private String datasource;
-   private String datasourceMapping;
-   private boolean createTable;
-   private boolean removeTable;
-   private List<String> postTableCreate;
-   private boolean rowLocking;
-   private boolean pkConstraint;
-}

Added: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMappingMetaData.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMappingMetaData.java	                        (rev 0)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationTableMappingMetaData.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -0,0 +1,208 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb.metadata.jboss.cmp;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+
+
+/**
+ * A JBossCMPRelationTableMappingMetaData.
+ * 
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossCMPRelationTableMappingMetaData
+{
+   private String tableName;
+   private String datasource;
+   private String datasourceMapping;
+   private boolean createTable;
+   private boolean removeTable;
+   private List<String> postTableCreate;
+   private boolean rowLocking;
+   private boolean pkConstraint;
+   
+   /**
+    * Get the createTable.
+    * 
+    * @return the createTable.
+    */
+   public boolean isCreateTable()
+   {
+      return createTable;
+   }
+   
+   /**
+    * Set the createTable.
+    * 
+    * @param createTable The createTable to set.
+    */
+   public void setCreateTable(boolean createTable)
+   {
+      this.createTable = createTable;
+   }
+   
+   /**
+    * Get the datasource.
+    * 
+    * @return the datasource.
+    */
+   public String getDatasource()
+   {
+      return datasource;
+   }
+   
+   /**
+    * Set the datasource.
+    * 
+    * @param datasource The datasource to set.
+    */
+   public void setDatasource(String datasource)
+   {
+      this.datasource = datasource;
+   }
+   
+   /**
+    * Get the datasourceMapping.
+    * 
+    * @return the datasourceMapping.
+    */
+   public String getDatasourceMapping()
+   {
+      return datasourceMapping;
+   }
+   
+   /**
+    * Set the datasourceMapping.
+    * 
+    * @param datasourceMapping The datasourceMapping to set.
+    */
+   public void setDatasourceMapping(String datasourceMapping)
+   {
+      this.datasourceMapping = datasourceMapping;
+   }
+   
+   /**
+    * Get the pkConstraint.
+    * 
+    * @return the pkConstraint.
+    */
+   public boolean isPkConstraint()
+   {
+      return pkConstraint;
+   }
+   
+   /**
+    * Set the pkConstraint.
+    * 
+    * @param pkConstraint The pkConstraint to set.
+    */
+   public void setPkConstraint(boolean pkConstraint)
+   {
+      this.pkConstraint = pkConstraint;
+   }
+   
+   /**
+    * Get the postTableCreate.
+    * 
+    * @return the postTableCreate.
+    */
+   public List<String> getPostTableCreate()
+   {
+      return postTableCreate;
+   }
+   
+   /**
+    * Set the postTableCreate.
+    * 
+    * @param postTableCreate The postTableCreate to set.
+    */
+   @XmlElementWrapper
+   @XmlElement(name = "sql-statement")
+   public void setPostTableCreate(List<String> postTableCreate)
+   {
+      this.postTableCreate = postTableCreate;
+   }
+
+   /**
+    * Get the removeTable.
+    * 
+    * @return the removeTable.
+    */
+   public boolean isRemoveTable()
+   {
+      return removeTable;
+   }
+   
+   /**
+    * Set the removeTable.
+    * 
+    * @param removeTable The removeTable to set.
+    */
+   public void setRemoveTable(boolean removeTable)
+   {
+      this.removeTable = removeTable;
+   }
+   
+   /**
+    * Get the rowLocking.
+    * 
+    * @return the rowLocking.
+    */
+   public boolean isRowLocking()
+   {
+      return rowLocking;
+   }
+   
+   /**
+    * Set the rowLocking.
+    * 
+    * @param rowLocking The rowLocking to set.
+    */
+   public void setRowLocking(boolean rowLocking)
+   {
+      this.rowLocking = rowLocking;
+   }
+   
+   /**
+    * Get the tableName.
+    * 
+    * @return the tableName.
+    */
+   public String getTableName()
+   {
+      return tableName;
+   }
+   
+   /**
+    * Set the tableName.
+    * 
+    * @param tableName The tableName to set.
+    */
+   public void setTableName(String tableName)
+   {
+      this.tableName = tableName;
+   }   
+}

Modified: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationshipsMetaData.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationshipsMetaData.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/jboss/cmp/JBossCMPRelationshipsMetaData.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb.metadata.jboss.cmp;
 
+import javax.xml.bind.annotation.XmlType;
+
 import org.jboss.ejb.metadata.spec.RelationMetaData;
 import org.jboss.ejb.metadata.spec.RelationsMetaData;
 import org.jboss.javaee.metadata.support.AbstractMappedMetaDataWithOverride;
@@ -32,13 +34,14 @@
  * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
  * @version $Revision: 1.1 $
  */
+ at XmlType(name="relationshipsType")
 public class JBossCMPRelationshipsMetaData
    extends AbstractMappedMetaDataWithOverride<RelationMetaData, JBossCMPEjbRelationMetaData, RelationsMetaData>
 {
 
-   protected JBossCMPRelationshipsMetaData()
+   public JBossCMPRelationshipsMetaData()
    {
-      super("ejb name for enterprise bean");
+      super("relationships");
    }
 
    public JBossCMPEjbRelationMetaData createOverride(RelationMetaData data)

Modified: jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/spec/RelationMetaData.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/spec/RelationMetaData.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/ejb/metadata/spec/RelationMetaData.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -28,6 +28,7 @@
 import org.jboss.xb.annotations.JBossXmlModelGroup;
 
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlTransient;
 
 /**
  * RelationMetaData.
@@ -96,7 +97,7 @@
     * @param leftRole the leftRole.
     * @throws IllegalArgumentException for a null leftRole
     */
-   @XmlElement(required=false)
+   @XmlTransient
    public void setLeftRole(RelationRoleMetaData leftRole)
    {
       if (leftRole == null)
@@ -121,7 +122,7 @@
     * @param rightRole the rightRole.
     * @throws IllegalArgumentException for a null rightRole
     */
-   @XmlElement(required=false)
+   @XmlTransient
    public void setRightRole(RelationRoleMetaData rightRole)
    {
       if (rightRole == null)
@@ -137,6 +138,7 @@
     * @return the related role
     * @throws IllegalArgumentException if the role is not a role in this relationship
     */
+   @XmlTransient
    public RelationRoleMetaData getRelatedRole(RelationRoleMetaData role)
    {
       if (role == leftRole)

Modified: jbossxb-builder/trunk/src/test/java/org/jboss/test/ejb/metadata/test/JBossCMPUnitTestCase.java
===================================================================
--- jbossxb-builder/trunk/src/test/java/org/jboss/test/ejb/metadata/test/JBossCMPUnitTestCase.java	2007-08-31 08:14:10 UTC (rev 2521)
+++ jbossxb-builder/trunk/src/test/java/org/jboss/test/ejb/metadata/test/JBossCMPUnitTestCase.java	2007-08-31 10:00:35 UTC (rev 2522)
@@ -30,9 +30,12 @@
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPCMPFieldMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPDeclaredSqlMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPDefaultsMetaData;
+import org.jboss.ejb.metadata.jboss.cmp.JBossCMPEjbRelationMetaData;
+import org.jboss.ejb.metadata.jboss.cmp.JBossCMPEjbRelationshipRoleMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPEnterpriseBeansMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPEntityBeanMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPEntityCommandMetaData;
+import org.jboss.ejb.metadata.jboss.cmp.JBossCMPKeyFieldMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPLoadGroupMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPOptimisticLockingMetaData;
@@ -41,6 +44,8 @@
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPQueryMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPQueryMethodMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPReadAheadMetaData;
+import org.jboss.ejb.metadata.jboss.cmp.JBossCMPRelationTableMappingMetaData;
+import org.jboss.ejb.metadata.jboss.cmp.JBossCMPRelationshipsMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPTypeMappingMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPUnknownPkMetaData;
 import org.jboss.ejb.metadata.jboss.cmp.JBossCMPAuditMetaData.Field;
@@ -755,4 +760,197 @@
       assertEquals(0, ol.getJdbcType());
       assertNull(ol.getSqlType());
    }
+
+   public void testRelationships() throws Exception
+   {
+      //enableTrace("org.jboss.xb.builder");
+
+      JBossCMPMetaData jbossMetaData = unmarshal();    
+      assertNotNull(jbossMetaData);
+      JBossCMPRelationshipsMetaData relationships = jbossMetaData.getRelationships();
+      assertNotNull(relationships);
+      assertEquals(7, relationships.size());
+      
+      JBossCMPEjbRelationMetaData relation = relationships.get("empty");
+      assertNotNull(relation);
+      assertEquals("empty", relation.getEjbRelationName());
+      assertFalse(relation.isReadOnly());
+      assertEquals(0, relation.getReadTimeOut());
+      assertFalse(relation.isForeignKeyMapping());
+      assertNull(relation.getRelationTableMapping());
+      assertNull(relation.getLeftRole());
+      assertNull(relation.getRightRole());
+      
+      relation = relationships.get("read-only");
+      assertNotNull(relation);
+      assertEquals("read-only", relation.getEjbRelationName());
+      assertTrue(relation.isReadOnly());
+      assertEquals(111, relation.getReadTimeOut());
+      assertFalse(relation.isForeignKeyMapping());
+      assertNull(relation.getRelationTableMapping());
+      assertNull(relation.getLeftRole());
+      assertNull(relation.getRightRole());
+
+      relation = relationships.get("foreign-key-mapping");
+      assertNotNull(relation);
+      assertEquals("foreign-key-mapping", relation.getEjbRelationName());
+      assertFalse(relation.isReadOnly());
+      assertEquals(0, relation.getReadTimeOut());
+      assertTrue(relation.isForeignKeyMapping());
+      assertNull(relation.getRelationTableMapping());
+      assertNull(relation.getLeftRole());
+      assertNull(relation.getRightRole());
+      
+      relation = relationships.get("relation-table-mapping");
+      assertNotNull(relation);
+      assertEquals("relation-table-mapping", relation.getEjbRelationName());
+      assertFalse(relation.isReadOnly());
+      assertEquals(0, relation.getReadTimeOut());
+      assertFalse(relation.isForeignKeyMapping());
+      assertNull(relation.getLeftRole());
+      assertNull(relation.getRightRole());
+      JBossCMPRelationTableMappingMetaData rtm = relation.getRelationTableMapping();
+      assertNotNull(rtm);
+      assertEquals("relation_table", rtm.getTableName());
+      assertEquals("java:/DefaultDS", rtm.getDatasource());
+      assertEquals("Hypersonic SQL", rtm.getDatasourceMapping());
+      assertTrue(rtm.isCreateTable());
+      assertTrue(rtm.isRemoveTable());
+      List<String> postTableCreate = rtm.getPostTableCreate();
+      assertNotNull(postTableCreate);
+      assertEquals(3, postTableCreate.size());
+      assertEquals("sql1", postTableCreate.get(0));
+      assertEquals("sql2", postTableCreate.get(1));
+      assertEquals("sql3", postTableCreate.get(2));
+      assertTrue(rtm.isRowLocking());
+      assertTrue(rtm.isPkConstraint());
+      
+      relation = relationships.get("A-B");
+      assertNotNull(relation);
+      assertEquals("A-B", relation.getEjbRelationName());
+      assertFalse(relation.isReadOnly());
+      assertEquals(0, relation.getReadTimeOut());
+      assertFalse(relation.isForeignKeyMapping());
+      assertNull(relation.getRelationTableMapping());
+      // left
+      JBossCMPEjbRelationshipRoleMetaData role = relation.getLeftRole();
+      assertNotNull(role);
+      assertEquals("A-has-B", role.getEjbRelationshipRoleName());
+      assertFalse(role.isFkConstraint());
+      List<JBossCMPKeyFieldMetaData> keyFields = role.getKeyFields();
+      assertNotNull(keyFields);
+      assertEquals(1, keyFields.size());
+      JBossCMPKeyFieldMetaData keyField = keyFields.get(0);
+      assertNotNull(keyField);
+      assertEquals("id", keyField.getFieldName());
+      assertEquals("a_id", keyField.getColumnName());
+      assertEquals(0, keyField.getJdbcType());
+      assertNull(keyField.getSqlType());
+      assertNull(keyField.getProperties());
+      assertFalse(keyField.isDbindex());
+      assertNull(role.getReadAhead());
+      assertFalse(role.isBatchCascadeDelete());
+      // right
+      role = relation.getRightRole();
+      assertNotNull(role);
+      assertEquals("B-belongsto-A", role.getEjbRelationshipRoleName());
+      assertFalse(role.isFkConstraint());
+      assertNull(role.getKeyFields());
+      assertNull(role.getReadAhead());
+      assertFalse(role.isBatchCascadeDelete());
+
+      relation = relationships.get("A-C");
+      assertNotNull(relation);
+      assertEquals("A-C", relation.getEjbRelationName());
+      assertFalse(relation.isReadOnly());
+      assertEquals(0, relation.getReadTimeOut());
+      assertFalse(relation.isForeignKeyMapping());
+      assertNull(relation.getRelationTableMapping());
+      // left
+      role = relation.getLeftRole();
+      assertNotNull(role);
+      assertEquals("A-has-C", role.getEjbRelationshipRoleName());
+      assertFalse(role.isFkConstraint());
+      keyFields = role.getKeyFields();
+      assertNotNull(keyFields);
+      assertEquals(2, keyFields.size());
+      keyField = keyFields.get(0);
+      assertNotNull(keyField);
+      assertEquals("id1", keyField.getFieldName());
+      assertEquals("a_id1", keyField.getColumnName());
+      assertEquals(Types.INTEGER, keyField.getJdbcType());
+      assertEquals("NUMERIC", keyField.getSqlType());
+      assertNull(keyField.getProperties());
+      assertFalse(keyField.isDbindex());
+      keyField = keyFields.get(1);
+      assertNotNull(keyField);
+      assertEquals("id2", keyField.getFieldName());
+      assertEquals("a_id2", keyField.getColumnName());
+      assertEquals(0, keyField.getJdbcType());
+      assertNull(keyField.getSqlType());
+      assertNull(keyField.getProperties());
+      assertTrue(keyField.isDbindex());
+      assertNull(role.getReadAhead());
+      assertFalse(role.isBatchCascadeDelete());
+      // right
+      role = relation.getRightRole();
+      assertNotNull(role);
+      assertEquals("C-belongsto-A", role.getEjbRelationshipRoleName());
+      assertTrue(role.isFkConstraint());
+      assertNull(role.getKeyFields());
+      assertTrue(role.isBatchCascadeDelete());
+      JBossCMPReadAheadMetaData readAhead = role.getReadAhead();
+      assertNotNull(readAhead);
+      assertEquals("on-find", readAhead.getStrategy());
+      assertEquals(4, readAhead.getPageSize());
+      assertEquals("quick info", readAhead.getEagerLoadGroup());
+      assertNull(readAhead.getLeftJoins());
+
+      relation = relationships.get("A-D");
+      assertNotNull(relation);
+      assertEquals("A-D", relation.getEjbRelationName());
+      assertFalse(relation.isReadOnly());
+      assertEquals(0, relation.getReadTimeOut());
+      assertFalse(relation.isForeignKeyMapping());
+      assertNull(relation.getRelationTableMapping());
+      // left
+      role = relation.getLeftRole();
+      assertNotNull(role);
+      assertEquals("A-has-D", role.getEjbRelationshipRoleName());
+      assertFalse(role.isFkConstraint());
+      keyFields = role.getKeyFields();
+      assertNotNull(keyFields);
+      assertEquals(1, keyFields.size());
+      keyField = keyFields.get(0);
+      assertNotNull(keyField);
+      assertEquals("id", keyField.getFieldName());
+      assertNull(keyField.getColumnName());
+      assertEquals(0, keyField.getJdbcType());
+      assertNull(keyField.getSqlType());
+      assertFalse(keyField.isDbindex());
+      List<JBossCMPPropertyMetaData> properties = keyField.getProperties();
+      assertNotNull(properties);
+      assertEquals(2, properties.size());
+      JBossCMPPropertyMetaData prop = properties.get(0);
+      assertNotNull(prop);
+      assertEquals("id1", prop.getPropertyName());
+      assertNull(prop.getColumnName());
+      assertEquals(0, prop.getJdbcType());
+      prop = properties.get(1);
+      assertNotNull(prop);
+      assertEquals("id2", prop.getPropertyName());
+      assertEquals("ID2", prop.getColumnName());
+      assertEquals(Types.VARCHAR, prop.getJdbcType());
+      assertEquals("VARCHAR(11)", prop.getSqlType());
+      assertNull(role.getReadAhead());
+      assertFalse(role.isBatchCascadeDelete());
+      // right
+      role = relation.getRightRole();
+      assertNotNull(role);
+      assertEquals("D-belongsto-A", role.getEjbRelationshipRoleName());
+      assertFalse(role.isFkConstraint());
+      assertNull(role.getKeyFields());
+      assertFalse(role.isBatchCascadeDelete());
+      assertNull(role.getReadAhead());
+   }
 }

Added: jbossxb-builder/trunk/src/test/resources/org/jboss/test/ejb/metadata/test/JBossCMP_testRelationships.xml
===================================================================
--- jbossxb-builder/trunk/src/test/resources/org/jboss/test/ejb/metadata/test/JBossCMP_testRelationships.xml	                        (rev 0)
+++ jbossxb-builder/trunk/src/test/resources/org/jboss/test/ejb/metadata/test/JBossCMP_testRelationships.xml	2007-08-31 10:00:35 UTC (rev 2522)
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbosscmp-jdbc xmlns="http://www.jboss.com/xml/ns/javaee/cmp2x"
+       xmlns:jee="http://java.sun.com/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee/cmp2x http://www.jboss.org/j2ee/schema/jbosscmp-jdbc_5_0.xsd">
+
+   <relationships>
+      <ejb-relation>
+         <ejb-relation-name>empty</ejb-relation-name>
+      </ejb-relation>
+
+      <ejb-relation>
+         <ejb-relation-name>read-only</ejb-relation-name>
+         <read-only>true</read-only>
+         <read-time-out>111</read-time-out>
+      </ejb-relation>
+
+      <ejb-relation>
+         <ejb-relation-name>foreign-key-mapping</ejb-relation-name>
+         <foreign-key-mapping/>
+      </ejb-relation>
+
+      <ejb-relation>
+         <ejb-relation-name>relation-table-mapping</ejb-relation-name>
+         <relation-table-mapping>
+            <table-name>relation_table</table-name>
+            <datasource>java:/DefaultDS</datasource>
+            <datasource-mapping>Hypersonic SQL</datasource-mapping>
+            <create-table>true</create-table>
+            <remove-table>true</remove-table>
+            <post-table-create>
+               <sql-statement>sql1</sql-statement>
+               <sql-statement>sql2</sql-statement>
+               <sql-statement>sql3</sql-statement>
+            </post-table-create>
+            <row-locking>true</row-locking>
+            <pk-constraint>true</pk-constraint>
+         </relation-table-mapping>
+      </ejb-relation>
+
+      <ejb-relation>
+         <ejb-relation-name>A-B</ejb-relation-name>
+         <ejb-relationship-role>
+            <ejb-relationship-role-name>A-has-B</ejb-relationship-role-name>
+            <key-fields>
+               <key-field>
+                  <field-name>id</field-name>
+                  <column-name>a_id</column-name>
+               </key-field>
+            </key-fields>
+         </ejb-relationship-role>
+         <ejb-relationship-role>
+            <ejb-relationship-role-name>B-belongsto-A</ejb-relationship-role-name>
+            <key-fields/>
+         </ejb-relationship-role>
+      </ejb-relation>
+
+      <ejb-relation>
+         <ejb-relation-name>A-C</ejb-relation-name>
+         <ejb-relationship-role>
+            <ejb-relationship-role-name>A-has-C</ejb-relationship-role-name>
+            <key-fields>
+               <key-field>
+                  <field-name>id1</field-name>
+                  <column-name>a_id1</column-name>
+                  <jdbc-type>INTEGER</jdbc-type>
+                  <sql-type>NUMERIC</sql-type>
+               </key-field>
+               <key-field>
+                  <field-name>id2</field-name>
+                  <column-name>a_id2</column-name>
+                  <dbindex/>
+               </key-field>
+            </key-fields>
+         </ejb-relationship-role>
+         <ejb-relationship-role>
+            <ejb-relationship-role-name>C-belongsto-A</ejb-relationship-role-name>
+            <fk-constraint>true</fk-constraint>
+            <key-fields/>
+            <batch-cascade-delete/>
+            <read-ahead>
+               <strategy>on-find</strategy>
+               <page-size>4</page-size>
+               <eager-load-group>quick info</eager-load-group>
+            </read-ahead>
+         </ejb-relationship-role>
+      </ejb-relation>
+
+      <ejb-relation>
+         <ejb-relation-name>A-D</ejb-relation-name>
+         <ejb-relationship-role>
+            <ejb-relationship-role-name>A-has-D</ejb-relationship-role-name>
+            <key-fields>
+               <key-field>
+                  <field-name>id</field-name>
+                  <property>
+                     <property-name>id1</property-name>
+                  </property>
+                  <property>
+                     <property-name>id2</property-name>
+                     <column-name>ID2</column-name>
+                     <not-null>true</not-null>
+                     <jdbc-type>VARCHAR</jdbc-type>
+                     <sql-type>VARCHAR(11)</sql-type>
+                  </property>
+               </key-field>
+            </key-fields>
+         </ejb-relationship-role>
+         <ejb-relationship-role>
+            <ejb-relationship-role-name>D-belongsto-A</ejb-relationship-role-name>
+            <key-fields/>
+         </ejb-relationship-role>
+      </ejb-relation>
+   </relationships>
+
+</jbosscmp-jdbc>




More information about the jboss-svn-commits mailing list