KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > pref > DBGeneratorDefaults


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     /**
10      * Updates its state to provide reasonable defaults for agiven adapter.
11      */

12     public void adjustForAdapter(DbAdapter adapter) {
13         if (!adapter.supportsFkConstraints()
14                 && booleanForBooleanProperty(CREATE_FK_PROPERTY)) {
15             setCreateFK(Boolean.FALSE);
16         }
17     }
18
19     /**
20      * Updates DbGenerator settings, consulting its own state.
21      */

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         // init defaults on insert...
35
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 JavaDoc property) {
47         Boolean JavaDoc b = (Boolean JavaDoc) readProperty(property);
48         return (b != null) ? b.booleanValue() : false;
49     }
50 }
51
52
Popular Tags