Forwarding this message to include persistence_at_glassfish alias
-------- Original Message --------
Subject: Re: Code review files related to java2db in SE
Date: Wed, 14 Dec 2005 13:23:34 -0800
From: Pramod Gopinath <Pramod.Gopinath_at_Sun.COM>
To: king.wang_at_oracle.com
CC: Peter Krogh <peter.krogh_at_oracle.com>, Marina Vatkina
<Marina.Vatkina_at_Sun.COM>, "ejb3-toplink-ext_at_sun.com"
<ejb3-toplink-ext_at_Sun.COM>, Robert Campbell <ROBERT.CAMPBELL_at_oracle.com>
References: <20051206160300036.00000002188_at_pkrogh-lap>
<439F675F.30208_at_sun.com> <43A03AE6.7080300_at_oracle.com>
<43A078F5.7090207_at_sun.com>
Hi King/Peter
Based on Ur comments earlier I have made changes and here are the
final versions of the files that I have modified. Am also sending U the
diffs for the 2 files.
Once I get the ok from U, I would be checking in these changes.
Thanks
Pramod
Index: JavaSECMPInitializer.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/internal/ejb/cmp3/JavaSECMPInitializer.java,v
retrieving revision 1.3
diff -r1.3 JavaSECMPInitializer.java
358a359,362
> public Properties getPersistenceUnitProperties(String emName) {
> return emSetupPersistenceUnitInfos.get(emName).getProperties();
> }
>
Index: EntityManagerFactoryProvider.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/ejb/cmp3/EntityManagerFactoryProvider.java,v
retrieving revision 1.7
diff -r1.7 EntityManagerFactoryProvider.java
24a25
> import java.io.File;
70a72,76
>
> public static final String DEFAULT_APP_LOCATION = "." + File.separator;
> public static final String DEFAULT_CREATE_JDBC_FILE_NAME = "createDDL.jdbc";
> public static final String DEFAULT_DROP_JDBC_FILE_NAME = "dropDDL.jdbc";
> public static final String JAVASE_DB_INTERACTION = "INTERACT_WITH_DB";
99a106,107
> session.login(); //PG->
> generateDDLFiles(session, getPersistenceUnitProperties(name, m), true); //PG->
131c139
< generateDDLFiles(session, info);
---
> generateDDLFiles(session, info.getProperties(), false);
136,152c144,145
< private boolean getBooleanPersistencePropVal(PersistenceUnitInfo pi, String propertyName) {
< boolean propertyValue = false;
< String propertyValStr = pi.getProperties().getProperty(propertyName);
< if(null != propertyValStr) {
< propertyValStr = propertyValStr.toLowerCase();
< propertyValue = Boolean.valueOf(propertyValStr).booleanValue();
< }
< return propertyValue;
< }
<
< private String getPersistencePropVal(PersistenceUnitInfo pi, String propertyName) {
< String propertyValue = pi.getProperties().getProperty(propertyName);
< // If there are no properties found should we assume any defaults ??
< return propertyValue;
< }
<
< private void generateDDLFiles(ServerSession session, PersistenceUnitInfo pi) {
---
> private void generateDDLFiles(ServerSession session, Properties props,
> boolean inSEmode) {
158,160c151,152
<
< ddlGeneration = getPersistencePropVal(pi, DDL_GENERATION);
< if(null == ddlGeneration)
---
>
> if(null == props)
162,163d153
< else
< ddlGeneration = ddlGeneration.toLowerCase();
165c155,157
< if(ddlGeneration.equals(NONE))
---
> ddlGeneration = props.getProperty(DDL_GENERATION, NONE);
> ddlGeneration = ddlGeneration.toLowerCase();
> if(ddlGeneration.equals(NONE))
167c159,160
< else if(ddlGeneration.equals(CREATE_ONLY) ||
---
>
> if(ddlGeneration.equals(CREATE_ONLY) ||
176,178c169,174
< appLocation = getPersistencePropVal(pi, APP_LOCATION);
< createDDLJdbc = getPersistencePropVal(pi, CREATE_JDBC_DDL_FILE);
< dropDDLJdbc = getPersistencePropVal(pi, DROP_JDBC_DDL_FILE);
---
> appLocation = props.getProperty(
> APP_LOCATION, DEFAULT_APP_LOCATION);
> createDDLJdbc = props.getProperty(
> CREATE_JDBC_DDL_FILE, DEFAULT_CREATE_JDBC_FILE_NAME);
> dropDDLJdbc = props.getProperty(
> DROP_JDBC_DDL_FILE, DEFAULT_DROP_JDBC_FILE_NAME);
181,188c177,178
< if(null != createDDLJdbc) {
< String createJdbcFileName = appLocation + createDDLJdbc;
< mgr.outputCreateDDLToFile(createJdbcFileName);
< }
<
< if(null != dropDDLJdbc) {
< String dropJdbcFileName = appLocation + dropDDLJdbc;
< mgr.outputDropDDLToFile(dropJdbcFileName);
---
> if(inSEmode) {
> runInSEMode(mgr, shouldDropFirst);
190,195c180,181
< mgr.setCreateSQLFiles(false);
<
< if(shouldDropFirst)
< mgr.replaceDefaultTables();
< else
< mgr.createDefaultTables();
---
>
> writeDDLsToFiles(mgr, shouldDropFirst, appLocation, createDDLJdbc, dropDDLJdbc);
258a245,297
> protected Properties getPersistenceUnitProperties(String emName, Map m) {
> JavaSECMPInitializer initializer = JavaSECMPInitializer.getJavaSECMPInitializer(m);
> return initializer.getPersistenceUnitProperties(emName);
> }
>
> private void runInSEMode(SchemaManager mgr, boolean shouldDropFirst) {
> boolean interactWithDB = getJava2dbSystemProperty();
> if (!interactWithDB)
> return;
>
> createOrReplaceDefaultTables(mgr, shouldDropFirst);
> }
>
> private boolean getJava2dbSystemProperty() {
> String str = System.getProperty(JAVASE_DB_INTERACTION, "true");
> return Boolean.valueOf(str.toLowerCase()).booleanValue();
> }
>
> private void createOrReplaceDefaultTables(
> SchemaManager mgr, boolean shouldDropFirst) {
> if (shouldDropFirst)
> mgr.replaceDefaultTables();
> else
> mgr.createDefaultTables();
> }
>
> private void writeDDLsToFiles(SchemaManager mgr,
> boolean shouldDropFirst, String appLocation,
> String createDDLJdbc, String dropDDLJdbc) {
> // Ensure that the appLocation string ends with File.seperator
> appLocation = addFileSeperator(appLocation);
> if (null != createDDLJdbc) {
> String createJdbcFileName = appLocation + createDDLJdbc;
> mgr.outputCreateDDLToFile(createJdbcFileName);
> }
>
> if (null != dropDDLJdbc) {
> String dropJdbcFileName = appLocation + dropDDLJdbc;
> mgr.outputDropDDLToFile(dropJdbcFileName);
> }
>
> mgr.setCreateSQLFiles(false);
> createOrReplaceDefaultTables(mgr, shouldDropFirst);
> }
>
> private String addFileSeperator(String appLocation) {
> int strLength = appLocation.length();
> if (appLocation.substring(strLength -1, strLength).equals(File.separator))
> return appLocation;
> else
> return appLocation + File.separator;
> }
>