[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-28 21:48:36
|
Update of /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util In directory sc8-pr-cvs1:/tmp/cvs-serv3855/src/org/devaki/nextobjects/util Modified Files: MeriseTransform.java NOTools.java TorqueWrapper.java Log Message: Checkstyle/refactor in MeriseTransform.java +++ I get an error while refactoring causing large commit .+++ Modified Files: src/org/devaki/nextobjects/util/MeriseTransform.java Index: MeriseTransform.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/MeriseTransform.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** MeriseTransform.java 26 May 2003 17:48:51 -0000 1.18 --- MeriseTransform.java 28 May 2003 21:48:28 -0000 1.19 *************** *** 38,75 **** import org.devaki.nextobjects.workspace.models.objects.Table; public class MeriseTransform { ! // Logger ! private static Category logger ! = Logger.getInstance(MeriseTransform.class.getName()); ! ! public MeriseTransform() ! { ! } /** * Generate a PDM from the current CDM * @param aMerise */ ! 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(); --- 38,101 ---- import org.devaki.nextobjects.workspace.models.objects.Table; + /** + * The class responsible of all the CDM2PDM work. + * + * @see http://www.devaki.org/transformation.html + * @author efl...@de... + * + */ + public class MeriseTransform { ! /* ! * The logger from the log4j project ! */ ! private static Category logger ! = Logger.getInstance(MeriseTransform.class.getName()); ! /* ! * Dummy constructor ! */ ! public MeriseTransform() { } /** * Generate a PDM from the current CDM + * * @param aMerise */ ! public static PhysicalModel cdm2pdm(ConceptualModel pConceptualModel) { ! /* ! * Temporary CDM where we are going to pick all the objects. ! */ ! ConceptualModel anotherMerise=null; ! ! /* ! * The returned physical model ! */ ! PhysicalModel db=new PhysicalModel("--///--"); ! /* ! * The temp file. ! */ ! File tmpFile=null; ! ! logger.warn("Using EXPERIMENTAL merise transform"); ! ! try { ! tmpFile=File.createTempFile("erd","cdm"); ! } catch (Exception ioex) { ! logger.error("Unable to write temp-file - check space left on device:" ); ! logger.error(ioex.getLocalizedMessage()); ! } + if (CDMVerifier.verify(pConceptualModel)) + { try { ! ObjectOutputStream flux = ! new ObjectOutputStream(new FileOutputStream(tmpFile)); ! flux.writeObject(pConceptualModel); flux.flush(); flux.close(); *************** *** 77,90 **** 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) --- 103,115 ---- catch (Exception ioex) { ! logger.error("Unable to save temporary file " + tmpFile); } // then reload. try { ! ObjectInputStream flux=new ObjectInputStream(new FileInputStream(tmpFile)); anotherMerise=(ConceptualModel)flux.readObject(); flux.close(); + tmpFile.delete(); } catch (Exception ioex) *************** *** 92,102 **** 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 --- 117,131 ---- logger.error("I can't understand file : " + ioex ); } ! ! if (anotherMerise!=null) { ! ModelMan.newPhysicalDatamodel(db); ! ModelMan.setCurrentModel(db); ! MeriseTransform.initDatabase(db,anotherMerise); ! MeriseTransform.applyRule_00_(db,anotherMerise); ! ModelMan.resizeModelObjects(db); ! db.getPhysicalView().repaint(); ! } else { ! logger.error("Giving up :("); ! } } else *************** *** 105,175 **** 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); } --- 134,233 ---- logger.error("I can't continue because the model is wrong."); } + return db; } ! /* ! * Utility function to take all needed attribute of a pdm into a cdm. ! * ! * @param theDatabase context model ! * @param pMerise context model ! */ ! private static PhysicalModel initDatabase (PhysicalModel pDatabase, ConceptualModel pMerise) { //PhysicalModel theDatabase=new PhysicalModel(pMerise.getName()); ! pDatabase.setName(pMerise.getName()); ! pDatabase.setCode(pMerise.getCode()); ! pDatabase.setDefaultIdMethod(pMerise.getDefaultIdMethod()); ! pDatabase.setDefaultJavaType(pMerise.getDefaultJavaType()); ! pDatabase.setPackageName(pMerise.getPackageName()); ! pDatabase.setBaseClass(pMerise.getBaseClass()); ! pDatabase.setBasePeer(pMerise.getBasePeer()); ! pDatabase.setDefaultJavaNamingMethod(pMerise.getDefaultJavaNamingMethod()); ! pDatabase.setHeavyIndexing(pMerise.getHeavyIndexing()); ! pDatabase.setDescription(pMerise.getDescription()); ! pDatabase.setNotes(pMerise.getNotes()); ! pDatabase.setAuthor(pMerise.getAuthor()); ! pDatabase.setAuthorEmail(pMerise.getAuthorEmail()); ! pDatabase.setCompany(pMerise.getCompany()); ! pDatabase.setProjectURL(pMerise.getProjectURL()); //theDatabase.setSqlFile(pMerise.getSql); ! pDatabase.setCreateDatabaseUrl(pMerise.getCreateDatabaseUrl()); ! pDatabase.setBuildDatabaseUrl(pMerise.getBuildDatabaseUrl()); ! pDatabase.setSchema(pMerise.getSchema()); ! pDatabase.setDatabaseHost(pMerise.getDatabaseHost()); ! pDatabase.setDatabasePassword(pMerise.getDatabasePassword()); ! pDatabase.setDatabaseUser(pMerise.getDatabaseUser()); ! pDatabase.setDbType(pMerise.getDbType()); ! pDatabase.setFileForSave(pMerise.getFileForSave()); ! pDatabase.setProjectURL(pMerise.getProjectURL()); // CustomTreeNode newNode=new CustomTreeNode(theDatabase); //theDatabase.setDynamicTreeNode(newNode); + return pDatabase; + } + + /** + * Construct a new 'Table' object + * @param pObject the entity give'n as argument. + */ + private static Table initTable(PhysicalModel pDatabase,Entity pObject) + { + Table t=new Table(pDatabase); + + t.setName(pObject.getName()); + t.setJavaName(pObject.getJavaName()); + t.setCode(pObject.getCode()); + t.setIdMethod(pObject.getIdMethod()); + t.setSkipSql(pObject.getSkipSql()); + //t.AbstractClass(pObject.getAbstractClass()); //ni + t.setBaseClass(pObject.getBaseClass()); + t.setBasePeer(pObject.getBasePeer()); + t.setAlias(pObject.getAlias()); + t.setJavaNamingMethod(pObject.getJavaNamingMethod()); + t.setHeavyIndexing(pObject.getHeavyIndexing()); + t.setDescription(pObject.getDescription()); + t.setNotes(pObject.getNotes()); + return t; + } + + /* + * Rule 0: each entity become a table. + * Also act as Rules iteration starting points + * + * @param theDatabase context model + * @param pAsso context association + */ + + private static PhysicalModel applyRule_00_ (PhysicalModel pDatabase, + ConceptualModel pMerise) { ! Entity swapEntity; ! Table swapTable; for (int i=0;i<pMerise.getEntities().size();i++) { ! swapEntity=(Entity)pMerise.getEntities().elementAt(i); ! swapTable=initTable(pDatabase,swapEntity); ! swapEntity.setSubsequentTable(swapTable); ! if (swapEntity.getData()!=null) { ! swapTable.setData(new Vector(swapEntity.getData())); } ! swapTable.getObjectView().setLocation(swapEntity.getObjectView().getLocation()); ! swapTable.getObjectView().setSize(swapEntity.getObjectView().getSize()); ! ModelMan.addTable(pDatabase,swapTable); } *************** *** 179,189 **** { 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; } --- 237,247 ---- { case org.devaki.nextobjects.workspace.models.ConceptualModel._11_ : ! applyRule_11_(pDatabase, pMerise.getAssociationAt(i)); break; case org.devaki.nextobjects.workspace.models.ConceptualModel._1N_: ! applyRule_1N_(pDatabase, pMerise.getAssociationAt(i)); break; case org.devaki.nextobjects.workspace.models.ConceptualModel._NM_: ! applyRule_NN_(pDatabase, pMerise.getAssociationAt(i)); break; } *************** *** 192,196 **** for (int i=0;i<pMerise.getInheritanceLinks().size();i++) { - InheritanceLink iLnk=new InheritanceLink(pMerise, ((Entity)pMerise.getInheritanceLinkAt(i).getChildClass()) --- 250,253 ---- *************** *** 199,211 **** .getSubsequentTable() ); ! ModelMan.addInheritanceLink(theDatabase,iLnk); } ! return theDatabase; } 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(); --- 256,272 ---- .getSubsequentTable() ); ! ModelMan.addInheritanceLink(pDatabase,iLnk); } ! return pDatabase; } + /* + * Rule 2 : In case of 1:1 relation, table must share the same key. + * + * @param theDatabase context model + * @param pAsso context association + */ private static void applyRule_11_(PhysicalModel theDatabase, Association pAsso) { int card_is=((AssociationLink)pAsso.getMyAssociationLinks() .elementAt(0)).getCard(); *************** *** 224,233 **** } ! private static void applyFusion(PhysicalModel theDatabase, Association pAsso) { - // all the table of this association are going to be fusioned. - // this is most often due all _11_ relation in this association. - //For now work, on association fields, if any property in the relation. for (int i=0;i<pAsso.getData().size();i++) --- 285,298 ---- } ! /* ! * All the table of this association are going to be fusioned. ! * this is most often due all _11_ relation in this association. ! * ! * @param theDatabase context model ! * @param pAsso context association ! */ ! private static void applyFusion(PhysicalModel pDatabase, Association pAsso) { //For now work, on association fields, if any property in the relation. for (int i=0;i<pAsso.getData().size();i++) *************** *** 249,253 **** } //remove the old table. ! ModelMan.removeTable(theDatabase, pAsso.getEntityAt(j).getSubsequentTable()); --- 314,318 ---- } //remove the old table. ! ModelMan.removeTable(pDatabase, pAsso.getEntityAt(j).getSubsequentTable()); *************** *** 260,264 **** } ! private static void applyRule_11a_(PhysicalModel theDatabase, Association pAsso) { --- 325,339 ---- } ! /* ! * 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 ! * by keeping 2 different primary key. IOn that case this can cause ! * performance loss due to index multiplication. ! * ! * @param theDatabase context model ! * @param pAsso context association ! * ! */ ! private static void applyRule_11a_(PhysicalModel pDatabase, Association pAsso) { *************** *** 268,276 **** 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 - // by keeping 2 different primary key. IOn that case this can cause - // performance loss due to index multiplication. - // So we need a new column PK for right table. // At that time the left/right choice is arbitrary :( . --- 343,346 ---- *************** *** 287,291 **** // now work in adding 2 constraints ! Constraint newCst=new Constraint( theDatabase, pAsso.getEntityAt(0).getSubsequentTable(), pAsso.getEntityAt(1).getSubsequentTable()); --- 357,361 ---- // now work in adding 2 constraints ! Constraint newCst=new Constraint( pDatabase, pAsso.getEntityAt(0).getSubsequentTable(), pAsso.getEntityAt(1).getSubsequentTable()); *************** *** 295,301 **** 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()); --- 365,371 ---- newCst.setAnyField((Column)pAsso.getEntityAt(1).getSubsequentTable() .getPrimaryKeys().firstElement()); ! ModelMan.addConstraint(pDatabase,newCst); ! Constraint newCst2=new Constraint( pDatabase, pAsso.getEntityAt(1).getSubsequentTable(), pAsso.getEntityAt(0).getSubsequentTable()); *************** *** 307,311 **** .getPrimaryKeys().lastElement()); ! ModelMan.addConstraint(theDatabase,newCst2); //now work on association fields, if any property in the relation. --- 377,381 ---- .getPrimaryKeys().lastElement()); ! ModelMan.addConstraint(pDatabase,newCst2); //now work on association fields, if any property in the relation. *************** *** 330,341 **** * 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) { --- 400,409 ---- * key (secondary index). * * @param theDatabase Database context * @param theAssociation Association to be treated ! * */ ! private static void applyRule_1N_(PhysicalModel pDatabase, Association pAsso) { *************** *** 354,358 **** { // ... ! newCst=new Constraint(theDatabase, pAsso.getEntityAt(1).getSubsequentTable(), pAsso.getEntityAt(0).getSubsequentTable()); --- 422,426 ---- { // ... ! newCst=new Constraint(pDatabase, pAsso.getEntityAt(1).getSubsequentTable(), pAsso.getEntityAt(0).getSubsequentTable()); *************** *** 390,394 **** // EntityAt(0) is EntityAt(1) and vice-versa. } else { ! newCst=new Constraint(theDatabase, pAsso.getEntityAt(0).getSubsequentTable(), pAsso.getEntityAt(1).getSubsequentTable()); --- 458,462 ---- // EntityAt(0) is EntityAt(1) and vice-versa. } else { ! newCst=new Constraint(pDatabase, pAsso.getEntityAt(0).getSubsequentTable(), pAsso.getEntityAt(1).getSubsequentTable()); *************** *** 423,427 **** } ! ModelMan.addConstraint(theDatabase,newCst); } --- 491,495 ---- } ! ModelMan.addConstraint(pDatabase,newCst); } *************** *** 434,442 **** * @param theDatabase The context database * @param pAsso The association to be treated. ! * @author efl...@de... ! * @see http://www.devaki.org/transformation.html */ ! private static void applyRule_NN_(PhysicalModel theDatabase, Association pAsso) { --- 502,509 ---- * @param theDatabase The context database * @param pAsso The association to be treated. ! * */ ! private static void applyRule_NN_(PhysicalModel pDatabase, Association pAsso) { *************** *** 444,448 **** * The table to be created. */ ! Table newTable=new Table(theDatabase); newTable.setName(pAsso.getName()); --- 511,515 ---- * The table to be created. */ ! Table newTable=new Table(pDatabase); newTable.setName(pAsso.getName()); *************** *** 491,501 **** 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); } } --- 558,568 ---- newField.setAutoIncrement(false); // always in that case! newTable.getData().addElement(newField); ! newCst=new Constraint(pDatabase,pAsso.getEntityAt(i) .getSubsequentTable(),newTable); newCst.setAnyField(newField); newCst.setUniqueField(pAsso.getIdentifierAt(i)); ! ModelMan.addConstraint(pDatabase,newCst); } ! ModelMan.addTable(pDatabase,newTable); } } Index: NOTools.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/NOTools.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** NOTools.java 25 May 2003 20:21:10 -0000 1.12 --- NOTools.java 28 May 2003 21:48:28 -0000 1.13 *************** *** 173,178 **** org.devaki.nextobjects.NextObjects.class.getResource( "/org/devaki/nextobjects/icons/" + img)); ! } catch (Throwable t) { // This Should Be here since this is defined ! // in BasicLookAndFeel System.err.println("Image_Load_Error : " + img); return null; --- 173,177 ---- org.devaki.nextobjects.NextObjects.class.getResource( "/org/devaki/nextobjects/icons/" + img)); ! } catch (Throwable t) { System.err.println("Image_Load_Error : " + img); return null; Index: TorqueWrapper.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/TorqueWrapper.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** TorqueWrapper.java 6 Apr 2003 14:19:28 -0000 1.16 --- TorqueWrapper.java 28 May 2003 21:48:28 -0000 1.17 *************** *** 490,494 **** if(ModelMan.getCurrentModel()instanceof ConceptualModel) { ! MeriseTransform.genPhysical((ConceptualModel)ModelMan .getCurrentModel()); } --- 490,494 ---- if(ModelMan.getCurrentModel()instanceof ConceptualModel) { ! MeriseTransform.cdm2pdm((ConceptualModel)ModelMan .getCurrentModel()); } |