[prev in list] [next in list] [prev in thread] [next in thread]
List: jboss-cvs-commits
Subject: [jboss-cvs] jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc JDBCStartCommand.java
From: Alexey Loubyansky <loubyansky () users ! sourceforge ! net>
Date: 2003-01-31 14:18:29
[Download RAW message or body]
User: loubyansky
Date: 03/01/31 06:18:29
Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc Tag: Branch_3_2
JDBCStartCommand.java
Log:
fix for [675932]: create only foreign key fields that are not mapped to primary key fields.
Revision Changes Path
No revision
No revision
1.29.2.3 +51 -35 jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java
Index: JDBCStartCommand.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java,v
retrieving revision 1.29.2.2
retrieving revision 1.29.2.3
diff -u -r1.29.2.2 -r1.29.2.3
--- JDBCStartCommand.java 24 Dec 2002 18:32:14 -0000 1.29.2.2
+++ JDBCStartCommand.java 31 Jan 2003 14:18:26 -0000 1.29.2.3
@@ -29,7 +29,8 @@
import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge;
import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge;
import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCFieldBridge;
-import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge;
+import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge;
+import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge;
import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData;
import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData;
import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCFunctionMappingMetaData;
@@ -45,7 +46,7 @@
* @author <a href="mailto:justin@j-m-f.demon.co.uk">Justin Forder</a>
* @author <a href="mailto:michel.anke@wolmail.nl">Michel de Groot</a>
* @author <a href="loubyansky@ua.fm">Alex Loubyansky</a>
- * @version $Revision: 1.29.2.2 $
+ * @version $Revision: 1.29.2.3 $
*/
public class JDBCStartCommand {
@@ -222,47 +223,41 @@
throws DeploymentException {
StringBuffer sql = new StringBuffer();
- sql.append("CREATE TABLE ").append(entity.getTableName());
-
- sql.append(" (");
+ sql.append("CREATE TABLE ").append(entity.getTableName()).append(" (");
+
// add fields
- // sql.append(SQLUtil.getCreateTableColumnsClause(entity.getFields()));
-
- boolean isFirstField = true;
+ int columnCount = 0; // just to decide whether to sql.append(", ")
for(Iterator iter = entity.getFields().iterator(); iter.hasNext();) {
JDBCFieldBridge field = (JDBCFieldBridge) iter.next();
JDBCType type = field.getJDBCType();
- // skip it if it is a foreign key that is a part of the primary key
- // or the side with no foreign key
- if(field instanceof JDBCCMRFieldBridge
- && ((JDBCCMRFieldBridge)field).isFkPartOfPk()
- || type == null) {
+ // the side that doesn't have a foreign key has JDBCType null
+ if(type == null)
continue;
- }
- if(!isFirstField)
- sql.append( ", " );
- else
- isFirstField = false;
-
- // apply auto-increment template
- if( type.getAutoIncrement()[0] ) {
- String columnClause = SQLUtil.getCreateTableColumnsClause( type );
-
- JDBCFunctionMappingMetaData autoIncrement =
- manager.getMetaData().getTypeMapping().getAutoIncrementTemplate();
- if(autoIncrement == null) {
- throw new IllegalStateException("auto-increment template not found");
- }
-
- String[] args = new String[] { columnClause };
- sql.append(autoIncrement.getFunctionSql(args));
- } else {
- sql.append(SQLUtil.getCreateTableColumnsClause(type));
- }
- }
+ // add foreign key fields unless they mapped to primary key fields
+ if(field instanceof JDBCCMRFieldBridge) {
+ JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)field;
+ Iterator fkFieldIter = cmrField.getForeignKeyFields().iterator();
+ while(fkFieldIter.hasNext()) {
+ JDBCCMP2xFieldBridge fkField = (JDBCCMP2xFieldBridge)fkFieldIter.next();
+ if(fkField.isFkFieldMappedToPkField())
+ continue;
+
+ if(columnCount > 0)
+ sql.append( ", " );
+
+ addField(fkField.getJDBCType(), sql);
+ ++columnCount;
+ }
+ } else {
+ if(columnCount > 0)
+ sql.append( ", " );
+ addField(type, sql);
+ ++columnCount;
+ }
+ }
// add a pk constraint
if(entityMetaData.hasPrimaryKeyConstraint()) {
@@ -285,6 +280,27 @@
return sql.toString();
}
+
+ private void addField(JDBCType type, StringBuffer sqlBuffer) {
+ // apply auto-increment template
+ if(type.getAutoIncrement()[0]) {
+ String columnClause =
+ SQLUtil.getCreateTableColumnsClause( type );
+
+ JDBCFunctionMappingMetaData autoIncrement =
+ manager.getMetaData().getTypeMapping().
+ getAutoIncrementTemplate();
+ if(autoIncrement == null) {
+ throw new IllegalStateException(
+ "auto-increment template not found");
+ }
+
+ String[] args = new String[] { columnClause };
+ sqlBuffer.append(autoIncrement.getFunctionSql(args));
+ } else {
+ sqlBuffer.append(SQLUtil.getCreateTableColumnsClause(type));
+ }
+ }
private String getRelationCreateTableSQL(
JDBCCMRFieldBridge cmrField,
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
jboss-cvs-commits mailing list
jboss-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-cvs-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic