[Nextobjects-devel] nextobjects/nextobjects/src/org/devaki/nextobjects/util MeriseTransform.java,1.1
Status: Alpha
Brought to you by:
eflorent
From: <efl...@us...> - 2003-05-25 08:02:40
|
Update of /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util In directory sc8-pr-cvs1:/tmp/cvs-serv12214/src/org/devaki/nextobjects/util Modified Files: MeriseTransform.java NOTools.java Log Message: Fixed major bug in merise transform. Index: MeriseTransform.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/MeriseTransform.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MeriseTransform.java 6 May 2003 20:19:52 -0000 1.14 --- MeriseTransform.java 25 May 2003 08:02:36 -0000 1.15 *************** *** 42,46 **** // Logger private static Category logger ! = Logger.getInstance(MeriseTransform.class.getName()); public MeriseTransform() --- 42,46 ---- // Logger private static Category logger ! = Logger.getInstance(MeriseTransform.class.getName()); public MeriseTransform() *************** *** 55,203 **** public static void genPhysical(ConceptualModel aMerise) { ! ConceptualModel myMerise=aMerise; ! File tmp; ! tmp=new File (NOTools.TMP_DIR + "temp.erd"); ! CDMVerifier.verify(aMerise); ! if (aMerise.isVerified) ! { ! ConceptualModel anotherMerise=null; ! tmp=new File (NOTools.TMP_DIR + File.separator + "temp.erd"); ! // first I save the erd int temp. ! try ! { ! ObjectOutputStream flux = ! new ObjectOutputStream(new FileOutputStream(tmp)); ! flux.writeObject(myMerise); ! flux.flush(); ! flux.close(); ! } ! catch (Exception ioex) ! { ! logger.error("Unable to save temporary file " + tmp); ! } ! // then reload. ! try ! { ! ObjectInputStream flux=new ObjectInputStream(new FileInputStream(tmp)); ! anotherMerise=(ConceptualModel)flux.readObject(); ! flux.close(); ! } ! catch (Exception ioex) ! { ! logger.error("I can't understand file : " + ioex ); ! } ! PhysicalModel db=new PhysicalModel("--///--"); ! ModelMan.newPhysicalDatamodel(db); ! ModelMan.setCurrentModel(db); ! MeriseTransform.deduceDatabase(db,anotherMerise); ! ModelMan.resizeModelObjects(db); ! db.getPhysicalView().repaint(); ! } ! else ! { ! // the model is not verifiable. ! logger.error("I can't continue because the model is wrong."); ! } } public static PhysicalModel deduceDatabase (PhysicalModel theDatabase, ! ConceptualModel pMerise) { ! logger.warn("Using EXPERIMENTAL merise transform"); ! //PhysicalModel theDatabase=new PhysicalModel(pMerise.getName()); ! theDatabase.setName(pMerise.getName()); ! theDatabase.setCode(pMerise.getCode()); ! theDatabase.setDefaultIdMethod(pMerise.getDefaultIdMethod()); ! theDatabase.setDefaultJavaType(pMerise.getDefaultJavaType()); ! theDatabase.setPackageName(pMerise.getPackageName()); ! theDatabase.setBaseClass(pMerise.getBaseClass()); ! theDatabase.setBasePeer(pMerise.getBasePeer()); ! theDatabase.setDefaultJavaNamingMethod(pMerise.getDefaultJavaNamingMethod()); ! theDatabase.setHeavyIndexing(pMerise.getHeavyIndexing()); ! theDatabase.setDescription(pMerise.getDescription()); ! theDatabase.setNotes(pMerise.getNotes()); ! theDatabase.setAuthor(pMerise.getAuthor()); ! theDatabase.setAuthorEmail(pMerise.getAuthorEmail()); ! theDatabase.setCompany(pMerise.getCompany()); ! theDatabase.setProjectURL(pMerise.getProjectURL()); ! //theDatabase.setSqlFile(pMerise.getSql); ! theDatabase.setCreateDatabaseUrl(pMerise.getCreateDatabaseUrl()); ! theDatabase.setBuildDatabaseUrl(pMerise.getBuildDatabaseUrl()); ! theDatabase.setSchema(pMerise.getSchema()); ! theDatabase.setDatabaseHost(pMerise.getDatabaseHost()); ! theDatabase.setDatabasePassword(pMerise.getDatabasePassword()); ! theDatabase.setDatabaseUser(pMerise.getDatabaseUser()); ! theDatabase.setDbType(pMerise.getDbType()); ! theDatabase.setFileForSave(pMerise.getFileForSave()); ! theDatabase.setProjectURL(pMerise.getProjectURL()); ! // CustomTreeNode newNode=new CustomTreeNode(theDatabase); ! //theDatabase.setDynamicTreeNode(newNode); ! Entity ent; ! // rule I: each entity become a table. ! for (int i=0;i<pMerise.getEntities().size();i++) ! { ! ent=(Entity)pMerise.getEntities().elementAt(i); ! Table t=new Table(theDatabase); ! ent.setSubsequentTable(t); ! if (ent.getData()!=null) ! { ! t.setData(new Vector(ent.getData())); ! } ! t.setName(ent.getName()); ! t.setJavaName(ent.getJavaName()); ! t.setCode(ent.getCode()); ! t.setIdMethod(ent.getIdMethod()); ! t.setSkipSql(ent.getSkipSql()); ! //t.setAbstractClass(ent.getAbstractClass()); //ni ! t.setBaseClass(ent.getBaseClass()); ! t.setBasePeer(ent.getBasePeer()); ! t.setAlias(ent.getAlias()); ! t.setJavaNamingMethod(ent.getJavaNamingMethod()); ! t.setHeavyIndexing(ent.getHeavyIndexing()); ! t.setDescription(ent.getDescription()); ! t.setNotes(ent.getNotes()); ! t.getObjectView().setLocation(ent.getObjectView().getLocation()); ! t.getObjectView().setSize(ent.getObjectView().getSize()); ! ModelMan.addTable(theDatabase,t); ! } ! for (int i=0;i<pMerise.getAssociations().size();i++) ! { ! switch (NOTools.getCardType(pMerise.getAssociationAt(i))) ! { ! case org.devaki.nextobjects.workspace.models.ConceptualModel._11_ : ! applyRule_11_(theDatabase, pMerise.getAssociationAt(i)); ! break; ! case org.devaki.nextobjects.workspace.models.ConceptualModel._1N_: ! applyRule_1N_(theDatabase, pMerise.getAssociationAt(i)); ! break; ! case org.devaki.nextobjects.workspace.models.ConceptualModel._NM_: ! applyRule_NN_(theDatabase, pMerise.getAssociationAt(i)); ! break; ! } ! } ! // work on Inheritance Link ! for (int i=0;i<pMerise.getInheritanceLinks().size();i++) ! { ! InheritanceLink iLnk=new InheritanceLink(pMerise, ! ((Entity)pMerise.getInheritanceLinkAt(i).getChildClass()) ! .getSubsequentTable(), ! ((Entity)pMerise.getInheritanceLinkAt(i).getParentClass()) ! .getSubsequentTable() ! ); ! ModelMan.addInheritanceLink(theDatabase,iLnk); } return theDatabase; --- 55,203 ---- public static void genPhysical(ConceptualModel aMerise) { ! ConceptualModel myMerise=aMerise; ! File tmp; ! tmp=new File (NOTools.TMP_DIR + "temp.erd"); ! CDMVerifier.verify(aMerise); ! if (aMerise.isVerified) ! { ! ConceptualModel anotherMerise=null; ! tmp=new File (NOTools.TMP_DIR + File.separator + "temp.erd"); ! // first I save the erd int temp. ! try ! { ! ObjectOutputStream flux = ! new ObjectOutputStream(new FileOutputStream(tmp)); ! flux.writeObject(myMerise); ! flux.flush(); ! flux.close(); ! } ! catch (Exception ioex) ! { ! logger.error("Unable to save temporary file " + tmp); ! } ! // then reload. ! try ! { ! ObjectInputStream flux=new ObjectInputStream(new FileInputStream(tmp)); ! anotherMerise=(ConceptualModel)flux.readObject(); ! flux.close(); ! } ! catch (Exception ioex) ! { ! logger.error("I can't understand file : " + ioex ); ! } ! PhysicalModel db=new PhysicalModel("--///--"); ! ModelMan.newPhysicalDatamodel(db); ! ModelMan.setCurrentModel(db); ! MeriseTransform.deduceDatabase(db,anotherMerise); ! ModelMan.resizeModelObjects(db); ! db.getPhysicalView().repaint(); ! } ! else ! { ! // the model is not verifiable. ! logger.error("I can't continue because the model is wrong."); ! } } public static PhysicalModel deduceDatabase (PhysicalModel theDatabase, ! ConceptualModel pMerise) { ! logger.warn("Using EXPERIMENTAL merise transform"); ! //PhysicalModel theDatabase=new PhysicalModel(pMerise.getName()); ! theDatabase.setName(pMerise.getName()); ! theDatabase.setCode(pMerise.getCode()); ! theDatabase.setDefaultIdMethod(pMerise.getDefaultIdMethod()); ! theDatabase.setDefaultJavaType(pMerise.getDefaultJavaType()); ! theDatabase.setPackageName(pMerise.getPackageName()); ! theDatabase.setBaseClass(pMerise.getBaseClass()); ! theDatabase.setBasePeer(pMerise.getBasePeer()); ! theDatabase.setDefaultJavaNamingMethod(pMerise.getDefaultJavaNamingMethod()); ! theDatabase.setHeavyIndexing(pMerise.getHeavyIndexing()); ! theDatabase.setDescription(pMerise.getDescription()); ! theDatabase.setNotes(pMerise.getNotes()); ! theDatabase.setAuthor(pMerise.getAuthor()); ! theDatabase.setAuthorEmail(pMerise.getAuthorEmail()); ! theDatabase.setCompany(pMerise.getCompany()); ! theDatabase.setProjectURL(pMerise.getProjectURL()); ! //theDatabase.setSqlFile(pMerise.getSql); ! theDatabase.setCreateDatabaseUrl(pMerise.getCreateDatabaseUrl()); ! theDatabase.setBuildDatabaseUrl(pMerise.getBuildDatabaseUrl()); ! theDatabase.setSchema(pMerise.getSchema()); ! theDatabase.setDatabaseHost(pMerise.getDatabaseHost()); ! theDatabase.setDatabasePassword(pMerise.getDatabasePassword()); ! theDatabase.setDatabaseUser(pMerise.getDatabaseUser()); ! theDatabase.setDbType(pMerise.getDbType()); ! theDatabase.setFileForSave(pMerise.getFileForSave()); ! theDatabase.setProjectURL(pMerise.getProjectURL()); ! // CustomTreeNode newNode=new CustomTreeNode(theDatabase); ! //theDatabase.setDynamicTreeNode(newNode); ! Entity ent; ! // rule I: each entity become a table. ! for (int i=0;i<pMerise.getEntities().size();i++) ! { ! ent=(Entity)pMerise.getEntities().elementAt(i); ! Table t=new Table(theDatabase); ! ent.setSubsequentTable(t); ! if (ent.getData()!=null) ! { ! t.setData(new Vector(ent.getData())); ! } ! t.setName(ent.getName()); ! t.setJavaName(ent.getJavaName()); ! t.setCode(ent.getCode()); ! t.setIdMethod(ent.getIdMethod()); ! t.setSkipSql(ent.getSkipSql()); ! //t.setAbstractClass(ent.getAbstractClass()); //ni ! t.setBaseClass(ent.getBaseClass()); ! t.setBasePeer(ent.getBasePeer()); ! t.setAlias(ent.getAlias()); ! t.setJavaNamingMethod(ent.getJavaNamingMethod()); ! t.setHeavyIndexing(ent.getHeavyIndexing()); ! t.setDescription(ent.getDescription()); ! t.setNotes(ent.getNotes()); ! t.getObjectView().setLocation(ent.getObjectView().getLocation()); ! t.getObjectView().setSize(ent.getObjectView().getSize()); ! ModelMan.addTable(theDatabase,t); ! } ! for (int i=0;i<pMerise.getAssociations().size();i++) ! { ! switch (NOTools.getCardType(pMerise.getAssociationAt(i))) ! { ! case org.devaki.nextobjects.workspace.models.ConceptualModel._11_ : ! applyRule_11_(theDatabase, pMerise.getAssociationAt(i)); ! break; ! case org.devaki.nextobjects.workspace.models.ConceptualModel._1N_: ! applyRule_1N_(theDatabase, pMerise.getAssociationAt(i)); ! break; ! case org.devaki.nextobjects.workspace.models.ConceptualModel._NM_: ! applyRule_NN_(theDatabase, pMerise.getAssociationAt(i)); ! break; ! } ! } ! // work on Inheritance Link ! for (int i=0;i<pMerise.getInheritanceLinks().size();i++) ! { ! InheritanceLink iLnk=new InheritanceLink(pMerise, ! ((Entity)pMerise.getInheritanceLinkAt(i).getChildClass()) ! .getSubsequentTable(), ! ((Entity)pMerise.getInheritanceLinkAt(i).getParentClass()) ! .getSubsequentTable() ! ); ! ModelMan.addInheritanceLink(theDatabase,iLnk); } return theDatabase; *************** *** 205,229 **** private static void applyRule_11_(PhysicalModel theDatabase, ! Association pAsso) { // Rule 2 : In case of 1:1 relation, table must share the same key. int card_is=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(0)).getCard(); int is_card=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(1)).getCard(); // if we have 1,1 - 1,1 the table can be the same (fusion) // if we have 1,1 - 0,1 we can apply rule 2. if (card_is==ConceptualModel._11_ && is_card==ConceptualModel._11_) { ! applyFusion(theDatabase,pAsso); } else { ! applyRule_11a_(theDatabase,pAsso); } } private static void applyFusion(PhysicalModel theDatabase, ! Association pAsso) { // all the table of this association are going to be fusioned. --- 205,229 ---- private static void applyRule_11_(PhysicalModel theDatabase, ! Association pAsso) { // Rule 2 : In case of 1:1 relation, table must share the same key. int card_is=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(0)).getCard(); int is_card=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(1)).getCard(); // if we have 1,1 - 1,1 the table can be the same (fusion) // if we have 1,1 - 0,1 we can apply rule 2. if (card_is==ConceptualModel._11_ && is_card==ConceptualModel._11_) { ! applyFusion(theDatabase,pAsso); } else { ! applyRule_11a_(theDatabase,pAsso); } } private static void applyFusion(PhysicalModel theDatabase, ! Association pAsso) { // all the table of this association are going to be fusioned. *************** *** 233,238 **** for (int i=0;i<pAsso.getData().size();i++) { ! Column tmpColumn=new Column((Column)pAsso.getData().elementAt(i)); ! pAsso.getEntityAt(0).getSubsequentTable().getData().addElement(tmpColumn); } --- 233,238 ---- for (int i=0;i<pAsso.getData().size();i++) { ! Column tmpColumn=new Column((Column)pAsso.getData().elementAt(i)); ! pAsso.getEntityAt(0).getSubsequentTable().getData().addElement(tmpColumn); } *************** *** 240,271 **** for (int j=1;j<pAsso.countMyAssociationLinks();j++) { ! // j start at 1 in order to omit he first table. ! for (int i=0;i<pAsso.getEntityAt(j).getData().size();i++) ! { ! Column tmpColumn=new Column( ! (Column)pAsso.getEntityAt(j).getData().elementAt(i)); ! pAsso.getEntityAt(0).getSubsequentTable().getData() ! .addElement(tmpColumn); ! } ! //remove the old table. ! ModelMan.removeTable(theDatabase, ! pAsso.getEntityAt(j).getSubsequentTable()); ! // fix new name,code. ! String newCode=pAsso.getEntityAt(0).getSubsequentTable().getCode() + "_" ! + pAsso.getEntityAt(j).getSubsequentTable().getCode(); ! pAsso.getEntityAt(0).getSubsequentTable().setCode(newCode); ! pAsso.getEntityAt(0).getSubsequentTable().setName(newCode); } } private static void applyRule_11a_(PhysicalModel theDatabase, ! Association pAsso) { Column tmpColumn; int card_is=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(0)).getCard(); int is_card=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(1)).getCard(); // Rule 2 : In case of 1:1 relation, table must share the same key. // this could have be donne differently, by reversing right/left but also --- 240,271 ---- for (int j=1;j<pAsso.countMyAssociationLinks();j++) { ! // j start at 1 in order to omit he first table. ! for (int i=0;i<pAsso.getEntityAt(j).getData().size();i++) ! { ! Column tmpColumn=new Column( ! (Column)pAsso.getEntityAt(j).getData().elementAt(i)); ! pAsso.getEntityAt(0).getSubsequentTable().getData() ! .addElement(tmpColumn); ! } ! //remove the old table. ! ModelMan.removeTable(theDatabase, ! pAsso.getEntityAt(j).getSubsequentTable()); ! // fix new name,code. ! String newCode=pAsso.getEntityAt(0).getSubsequentTable().getCode() + "_" ! + pAsso.getEntityAt(j).getSubsequentTable().getCode(); ! pAsso.getEntityAt(0).getSubsequentTable().setCode(newCode); ! pAsso.getEntityAt(0).getSubsequentTable().setName(newCode); } } private static void applyRule_11a_(PhysicalModel theDatabase, ! Association pAsso) { Column tmpColumn; int card_is=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(0)).getCard(); int is_card=((AssociationLink)pAsso.getMyAssociationLinks() ! .elementAt(1)).getCard(); // Rule 2 : In case of 1:1 relation, table must share the same key. // this could have be donne differently, by reversing right/left but also *************** *** 281,286 **** // Tables must share the same PK. pAsso.getEntityAt(1).getSubsequentTable().getData() ! .removeElement(pAsso.getEntityAt(1).getSubsequentTable() ! .getPrimaryKeys().firstElement()); pAsso.getEntityAt(1).getSubsequentTable().getData().addElement(tmpColumn); --- 281,286 ---- // Tables must share the same PK. pAsso.getEntityAt(1).getSubsequentTable().getData() ! .removeElement(pAsso.getEntityAt(1).getSubsequentTable() ! .getPrimaryKeys().firstElement()); pAsso.getEntityAt(1).getSubsequentTable().getData().addElement(tmpColumn); *************** *** 288,309 **** // now work in adding 2 constraints Constraint newCst=new Constraint( theDatabase, ! pAsso.getEntityAt(0).getSubsequentTable(), ! pAsso.getEntityAt(1).getSubsequentTable()); newCst.setUniqueField((Column)pAsso.getEntityAt(0).getSubsequentTable() ! .getPrimaryKeys().firstElement()); newCst.setAnyField((Column)pAsso.getEntityAt(1).getSubsequentTable() ! .getPrimaryKeys().firstElement()); ModelMan.addConstraint(theDatabase,newCst); Constraint newCst2=new Constraint( theDatabase, ! pAsso.getEntityAt(1).getSubsequentTable(), ! pAsso.getEntityAt(0).getSubsequentTable()); newCst2.setUniqueField((Column)pAsso.getEntityAt(1).getSubsequentTable() ! .getPrimaryKeys().lastElement()); newCst2.setAnyField((Column)pAsso.getEntityAt(0).getSubsequentTable() ! .getPrimaryKeys().lastElement()); ModelMan.addConstraint(theDatabase,newCst2); --- 288,309 ---- // now work in adding 2 constraints Constraint newCst=new Constraint( theDatabase, ! pAsso.getEntityAt(0).getSubsequentTable(), ! pAsso.getEntityAt(1).getSubsequentTable()); newCst.setUniqueField((Column)pAsso.getEntityAt(0).getSubsequentTable() ! .getPrimaryKeys().firstElement()); newCst.setAnyField((Column)pAsso.getEntityAt(1).getSubsequentTable() ! .getPrimaryKeys().firstElement()); ModelMan.addConstraint(theDatabase,newCst); Constraint newCst2=new Constraint( theDatabase, ! pAsso.getEntityAt(1).getSubsequentTable(), ! pAsso.getEntityAt(0).getSubsequentTable()); newCst2.setUniqueField((Column)pAsso.getEntityAt(1).getSubsequentTable() ! .getPrimaryKeys().lastElement()); newCst2.setAnyField((Column)pAsso.getEntityAt(0).getSubsequentTable() ! .getPrimaryKeys().lastElement()); ModelMan.addConstraint(theDatabase,newCst2); *************** *** 311,388 **** //now work on association fields, if any property in the relation. for (int i=0;i<pAsso.getData().size();i++) { ! tmpColumn=new Column((Column)pAsso.getData().elementAt(i)); ! if (is_card==ConceptualModel._01_ || card_is==ConceptualModel._01_) ! { ! tmpColumn.setRequired(false); ! } ! pAsso.getEntityAt(0).getSubsequentTable().getData() ! .addElement(tmpColumn); } } - - /* - * This transformation rule deal with 1 --> * relation. - * - * Rule 3 : : In the case of entities connected by associations of the 1:n - * type, each table has its own key, but the key of the entity side 0,n (or - * 1,n) migrates towards the table side 0,1 (or 1,1) and becomes a foreign - * key (secondary index). - * - * Thanks to Romeo Benzoni for his submission/review. - * - * @param theDatabase Database context - * @param theAssociation Association to be treated - * @see http://www.devaki.org/transformation.html - */ - private static void applyRule_1N_(PhysicalModel theDatabase, ! Association pAsso) { ! /* Rule 3 */ Column newField; ! Constraint newCst=null; ! if (pAsso.getCardAt(1)==ConceptualModel._0N_ ! || pAsso.getCardAt(1)==ConceptualModel._1N_) { ! // ... ! newCst=new Constraint(theDatabase, ! pAsso.getEntityAt(1).getSubsequentTable(), ! pAsso.getEntityAt(0).getSubsequentTable()); ! newField=new Column(pAsso.getEntityAt(1).getIdentifier()); ! newField.setAutoIncrement(false); // always in that case! ! pAsso.getEntityAt(0).getSubsequentTable().getData().addElement(newField); ! // If the type of relation is 1:n, it is advisable to make slip the ! // attributes towards entity provided with cardinalities the 1:1. ! for (int i=0;i<pAsso.getData().size();i++) ! { ! pAsso.getEntityAt(0).getSubsequentTable().getData() ! .addElement(new Column((Column)pAsso.getData().elementAt(i))); ! } ! newCst.setUniqueField( ! pAsso.getEntityAt(1).getIdentifier()); ! newCst.setAnyField(newField); ! pAsso.getEntityAt(0).getSubsequentTable().setIdMethod("none"); } else { ! // ... ! newCst=new Constraint(theDatabase, ! pAsso.getEntityAt(0).getSubsequentTable(), ! pAsso.getEntityAt(1).getSubsequentTable()); ! newField=new Column(pAsso.getEntityAt(0).getIdentifier()); ! newField.setAutoIncrement(false); ! pAsso.getEntityAt(1).getSubsequentTable().getData().addElement(newField); ! // If the type of relation is 1:n, it is advisable to make slip the ! // attributes towards entity provided with cardinalities 1:1. ! for (int i=0;i<pAsso.getData().size();i++) { ! pAsso.getEntityAt(1).getSubsequentTable().getData() ! .addElement(new Column((Column)pAsso.getData().elementAt(i))); ! } ! newCst.setUniqueField(pAsso.getEntityAt(0).getIdentifier()); ! newCst.setAnyField(newField); ! pAsso.getEntityAt(1).getSubsequentTable().setIdMethod("none"); } ModelMan.addConstraint(theDatabase,newCst); --- 311,372 ---- //now work on association fields, if any property in the relation. for (int i=0;i<pAsso.getData().size();i++) { ! tmpColumn=new Column((Column)pAsso.getData().elementAt(i)); ! if (is_card==ConceptualModel._01_ || card_is==ConceptualModel._01_) ! { ! tmpColumn.setRequired(false); ! } ! pAsso.getEntityAt(0).getSubsequentTable().getData() ! .addElement(tmpColumn); } } private static void applyRule_1N_(PhysicalModel theDatabase, ! Association pAsso) { ! // Rule 3 : : In the case of entities connected by associations of the 1:n ! // type, each table has its own key, but the key of the entity side 0,n (or ! // 1,n) migrates towards the table side 0,1 (or 1,1) and becomes a foreign ! // key (secondary index). ! Column newField; ! Constraint newCst=new Constraint(theDatabase, ! pAsso.getEntityAt(0).getSubsequentTable(), ! pAsso.getEntityAt(1).getSubsequentTable()); ! if (pAsso.getCardAt(0)==ConceptualModel._0N_ ! && pAsso.getCardAt(0)==ConceptualModel._1N_) { ! // ... ! newField=new Column(pAsso.getEntityAt(1).getIdentifier()); ! newField.setAutoIncrement(false); // always in that case! ! pAsso.getEntityAt(0).getSubsequentTable().getData().addElement(newField); ! // If the type of relation is 1:n, it is advisable to make slip the ! // attributes towards entitY provided with cardinalities the 1:1. ! for (int i=0;i<pAsso.getData().size();i++) ! { ! pAsso.getEntityAt(0).getSubsequentTable().getData() ! .addElement(new Column((Column)pAsso.getData().elementAt(i))); ! } ! newCst.setUniqueField( ! pAsso.getEntityAt(1).getIdentifier()); ! newCst.setAnyField(newField); ! pAsso.getEntityAt(0).getSubsequentTable().setIdMethod("none"); } else { ! // ... ! newField=new Column(pAsso.getEntityAt(0).getIdentifier()); ! newField.setAutoIncrement(false); ! pAsso.getEntityAt(1).getSubsequentTable().getData().addElement(newField); ! // If the type of relation is 1:n, it is advisable to make slip the ! // attributes towards entity provided with cardinalities 1:1. ! for (int i=0;i<pAsso.getData().size();i++) { ! pAsso.getEntityAt(1).getSubsequentTable().getData() ! .addElement(new Column((Column)pAsso.getData().elementAt(i))); ! } ! newCst.setUniqueField(pAsso.getEntityAt(0).getIdentifier()); ! newCst.setAnyField(newField); ! pAsso.getEntityAt(1).getSubsequentTable().setIdMethod("none"); } ModelMan.addConstraint(theDatabase,newCst); *************** *** 390,394 **** private static void applyRule_NN_(PhysicalModel theDatabase, ! Association pAsso) { --- 374,378 ---- private static void applyRule_NN_(PhysicalModel theDatabase, ! Association pAsso) { *************** *** 422,427 **** for (int i=0;i<pAsso.getData().size();i++) { ! newTable.getData().addElement(new Column( ! (Column)pAsso.getData().elementAt(i))); } --- 406,411 ---- for (int i=0;i<pAsso.getData().size();i++) { ! newTable.getData().addElement(new Column( ! (Column)pAsso.getData().elementAt(i))); } *************** *** 430,445 **** for (int i=0;i<pAsso.getMyAssociationLinks().size();i++) { ! newField=new Column(pAsso.getIdentifierAt(i)); ! newField.setPrimaryKey(true); ! newField.setRequired(true); ! newField.setAutoIncrement(false); // always in that case! ! newTable.getData().addElement(newField); ! newCst=new Constraint(theDatabase,pAsso.getEntityAt(i) ! .getSubsequentTable(),newTable); ! newCst.setAnyField(newField); ! newCst.setUniqueField(pAsso.getIdentifierAt(i)); ! ModelMan.addConstraint(theDatabase,newCst); } ModelMan.addTable(theDatabase,newTable); } ! } --- 414,429 ---- for (int i=0;i<pAsso.getMyAssociationLinks().size();i++) { ! newField=new Column(pAsso.getIdentifierAt(i)); ! newField.setPrimaryKey(true); ! newField.setRequired(true); ! newField.setAutoIncrement(false); // always in that case! ! newTable.getData().addElement(newField); ! newCst=new Constraint(theDatabase,pAsso.getEntityAt(i) ! .getSubsequentTable(),newTable); ! newCst.setAnyField(newField); ! newCst.setUniqueField(pAsso.getIdentifierAt(i)); ! ModelMan.addConstraint(theDatabase,newCst); } ModelMan.addTable(theDatabase,newTable); } ! } \ No newline at end of file Index: NOTools.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/NOTools.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** NOTools.java 3 May 2003 20:46:28 -0000 1.10 --- NOTools.java 25 May 2003 08:02:36 -0000 1.11 *************** *** 509,545 **** } ! public static int getCardType(Association theAssociation) { int card_is=((AssociationLink)theAssociation.getMyAssociationLinks().elementAt(0)).getCard(); int is_card=((AssociationLink)theAssociation.getMyAssociationLinks().elementAt(1)).getCard(); ! int cardType; ! /* ********************************** ! CARDS RESULT MAP ! CARDIS 01 11 0N 1N ! ISCARD ! 01 11 11 1N 1N ! 11 11 11 1N 1N ! 0N 1N 1N NM NM ! 1N 1N 1N NM NM ! **************************************/ - if (card_is==ConceptualModel._01_ || card_is==ConceptualModel._11_) { - // type 1... - if (is_card==ConceptualModel._01_ || is_card==ConceptualModel._11_) { - cardType=ConceptualModel._11_; - } else { - cardType=ConceptualModel._1N_; - } - } else { // Ou 0N ou 1N - //type N... - if (is_card==ConceptualModel._01_ || is_card==ConceptualModel._11_) { - //type 1,N - cardType=ConceptualModel._1N_; - } else { - //type NM - cardType=ConceptualModel._NM_; - } - } // In any case overwrite previous switch if (theAssociation.getMyAssociationLinks().size()>2) --- 509,539 ---- } + /** + * return the type of the relation (11,1N,1N) + * so we know wich Merise rule to apply for + * a given association (cardinalities) + * + * card_is 01 11 0N 1N + * is_card --------------------------------- + * 01 | 11 11 NM NM + * 11 | 11 11 1N 1N + * 0N | NM 1N NM NM + * 1N | NM 1N NM NM + * + * @param theAssociation + * @return + */ ! public static int getCardType(Association theAssociation) { int card_is=((AssociationLink)theAssociation.getMyAssociationLinks().elementAt(0)).getCard(); int is_card=((AssociationLink)theAssociation.getMyAssociationLinks().elementAt(1)).getCard(); ! ! int [][] results= { {ConceptualModel._11_ ,ConceptualModel._11_ ,ConceptualModel._NM_ ,ConceptualModel._NM_ }, ! {ConceptualModel._11_,ConceptualModel._11_ ,ConceptualModel._1N_ ,ConceptualModel._1N_ }, ! {ConceptualModel._NM_ ,ConceptualModel._1N_ ,ConceptualModel._NM_ ,ConceptualModel._NM_ }, ! {ConceptualModel._NM_,ConceptualModel._1N_ ,ConceptualModel._NM_ ,ConceptualModel._NM_ }} ; ! int cardType=results[card_is][is_card]; // In any case overwrite previous switch if (theAssociation.getMyAssociationLinks().size()>2) |