1 package org.objectstyle.cayenne.modeler.pref; 2 3 import org.objectstyle.cayenne.PersistenceState; 4 import org.objectstyle.cayenne.access.DbGenerator; 5 import org.objectstyle.cayenne.dba.DbAdapter; 6 7 public class DBGeneratorDefaults extends _DBGeneratorDefaults { 8 9 12 public void adjustForAdapter(DbAdapter adapter) { 13 if (!adapter.supportsFkConstraints() 14 && booleanForBooleanProperty(CREATE_FK_PROPERTY)) { 15 setCreateFK(Boolean.FALSE); 16 } 17 } 18 19 22 public void configureGenerator(DbGenerator generator) { 23 generator 24 .setShouldCreateFKConstraints(booleanForBooleanProperty(CREATE_FK_PROPERTY)); 25 generator.setShouldCreatePKSupport(booleanForBooleanProperty(CREATE_PK_PROPERTY)); 26 generator 27 .setShouldCreateTables(booleanForBooleanProperty(CREATE_TABLES_PROPERTY)); 28 generator.setShouldDropPKSupport(booleanForBooleanProperty(DROP_PK_PROPERTY)); 29 generator.setShouldDropTables(booleanForBooleanProperty(DROP_TABLES_PROPERTY)); 30 } 31 32 public void setPersistenceState(int persistenceState) { 33 34 if (this.persistenceState == PersistenceState.TRANSIENT 36 && persistenceState == PersistenceState.NEW) { 37 setCreateFK(Boolean.TRUE); 38 setCreatePK(Boolean.TRUE); 39 setCreateTables(Boolean.TRUE); 40 setDropPK(Boolean.FALSE); 41 setDropTables(Boolean.FALSE); 42 } 43 super.setPersistenceState(persistenceState); 44 } 45 46 protected boolean booleanForBooleanProperty(String property) { 47 Boolean b = (Boolean ) readProperty(property); 48 return (b != null) ? b.booleanValue() : false; 49 } 50 } 51 52 | Popular Tags |