Author: rhauch
Date: 2009-09-03 16:01:08 -0400 (Thu, 03 Sep 2009)
New Revision: 1192
Modified:
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/jpa/JcrRepositoryWithJpaConfigurationTest.java
trunk/dna-integration-tests/src/test/resources/tck/jpa/configRepository.xml
trunk/docs/reference/src/main/docbook/en-US/content/connectors/jdbc_storage.xml
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorCreateWorkspacesTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorNoCreateWorkspaceTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorReadingTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorWritingTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaSourceTest.java
Log:
DNA-510 The JPA RepositorySource should provide way to specify the
'hibernate.hbm2ddl.auto' property
Applied a modified version of the patch. Note that the default
'autoGenerateSchema' property value is now 'validate', since that is the
least disruptive on an existing database (such as a production database). Therefore, note
that 'create' used to be the default, so this may affect some users.
Updated the JPA Connector chapter in the Reference Guide to include the new property.
Modified:
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/jpa/JcrRepositoryWithJpaConfigurationTest.java
===================================================================
---
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/jpa/JcrRepositoryWithJpaConfigurationTest.java 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/jpa/JcrRepositoryWithJpaConfigurationTest.java 2009-09-03
20:01:08 UTC (rev 1192)
@@ -98,7 +98,7 @@
.setProperty("largeValueSizeInBytes", 150)
.setProperty("compressData", true)
.setProperty("referentialIntegrityEnforced", true)
- .setProperty("autoDdl", "create")
+ .setProperty("autoGenerateSchema", "create")
.setProperty("showSql", false);
// Set up the JCR repository ...
Modified: trunk/dna-integration-tests/src/test/resources/tck/jpa/configRepository.xml
===================================================================
--- trunk/dna-integration-tests/src/test/resources/tck/jpa/configRepository.xml 2009-09-03
19:07:26 UTC (rev 1191)
+++ trunk/dna-integration-tests/src/test/resources/tck/jpa/configRepository.xml 2009-09-03
20:01:08 UTC (rev 1192)
@@ -47,6 +47,7 @@
dna:compressData="true"
dna:predefinedWorkspaceNames="default"
dna:showSql="false"
+ dna:autoGenerateSchema="create"
dna:defaultWorkspaceName="default"/>
</dna:sources>
<!--
Modified: trunk/docs/reference/src/main/docbook/en-US/content/connectors/jdbc_storage.xml
===================================================================
---
trunk/docs/reference/src/main/docbook/en-US/content/connectors/jdbc_storage.xml 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/docs/reference/src/main/docbook/en-US/content/connectors/jdbc_storage.xml 2009-09-03
20:01:08 UTC (rev 1192)
@@ -207,6 +207,27 @@
</entry>
</row>
<row>
+ <entry>autoGenerateSchema</entry>
+ <entry>
+ Sets the Hibernate setting dictating what it does with the database schema upon
first connection. Valid values are as
+ follows (though the value is not checked):
+ <itemizedlist>
+ <listitem><para>"<code>create</code>" - Create
the database schema objects when the &EntityManagerFactory; is created (actually
+ when Hibernate's SessionFactory is created by the entity manager factory).
If a file named "import.sql" exists in
+ the root of the class path (e.g., '/import.sql') Hibernate will read and
execute the SQL statements in this file after it
+ has created the database objects. Note that Hibernate first delete all tables,
constraints, or any other database object
+ that is going to be created in the process of building the
schema.</para></listitem>
+ <listitem><para>"<code>create-drop</code>" -
Same as "<code>create</code>", except that the schema will be
dropped after the
+ &EntityManagerFactory; is closed.</para></listitem>
+ <listitem><para>"<code>update</code>" -
Attempt to update the database structure to the current mapping (but does not read and
invoke
+ the SQL statements from "import.sql"). <emphasis>Use with
caution.</emphasis></para></listitem>
+ <listitem><para>"<code>validate</code>" -
Validates the existing schema with the current entities configuration, but does not make
any
+ changes to the schema (and does not read and invoke the SQL statements from
"import.sql"). This is often the proper setting
+ to use in production, and thus this is the default
value.</para></listitem>
+ </itemizedlist>
+ </entry>
+ </row>
+ <row>
<entry>retryLimit</entry>
<entry>Optional property that, if used, defines the number of times that any
single operation on a &RepositoryConnection; to this source should be retried
following a communication failure.
@@ -235,7 +256,8 @@
.setDescription("The database store for our content")
.setProperty("dialect", "org.hibernate.dialect.MySQLDialect")
.setProperty("dataSourceJndiName", "java:/MyDataSource")
- .setProperty("nameOfDefaultWorkspace", "My Default
Workspace");
+ .setProperty("nameOfDefaultWorkspace", "My Default Workspace")
+ .setProperty("autoGenerateSchema", "validate");
]]></programlisting>
<para>
Of course, setting other more advanced properties would entail calling
<code>setProperty(...)</code> for each. Since almost all
Modified:
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/extensions/dna-connector-store-jpa/src/main/java/org/jboss/dna/connector/store/jpa/JpaSource.java 2009-09-03
20:01:08 UTC (rev 1192)
@@ -43,6 +43,7 @@
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import net.jcip.annotations.Immutable;
+import org.hibernate.SessionFactory;
import org.hibernate.ejb.Ejb3Configuration;
import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.util.CheckArg;
@@ -123,6 +124,7 @@
protected static final String DEFAULT_WORKSPACE = "defaultWorkspace";
protected static final String PREDEFINED_WORKSPACE_NAMES =
"predefinedWorkspaceNames";
protected static final String ALLOW_CREATING_WORKSPACES =
"allowCreatingWorkspaces";
+ protected static final String AUTO_GENERATE_SCHEMA = "autoGenerateSchema";
/**
* This source supports events.
@@ -174,6 +176,12 @@
private static final boolean DEFAULT_ENFORCE_REFERENTIAL_INTEGRITY = true;
/**
+ * The initial {@link #getAutoGenerateSchema() automatic schema generation setting}
is "{@value} ", unless otherwise
+ * specified.
+ */
+ public static final String DEFAULT_AUTO_GENERATE_SCHEMA = "validate";
+
+ /**
* The first serialized version of this source.
*/
private static final long serialVersionUID = 1L;
@@ -199,6 +207,7 @@
private volatile boolean showSql = DEFAULT_SHOW_SQL;
private volatile boolean compressData = DEFAULT_COMPRESS_DATA;
private volatile boolean referentialIntegrityEnforced =
DEFAULT_ENFORCE_REFERENTIAL_INTEGRITY;
+ private volatile String autoGenerateSchema = DEFAULT_AUTO_GENERATE_SCHEMA;
private volatile String defaultWorkspace = DEFAULT_NAME_OF_DEFAULT_WORKSPACE;
private volatile String[] predefinedWorkspaces = new String[] {};
private volatile RepositorySourceCapabilities capabilities = new
RepositorySourceCapabilities(
@@ -286,6 +295,40 @@
}
/**
+ * Get the Hibernate setting dictating what it does with the database schema upon
first connection. For more information, see
+ * {@link #setAutoGenerateSchema(String)}.
+ *
+ * @return the setting; never null
+ */
+ public String getAutoGenerateSchema() {
+ return this.autoGenerateSchema;
+ }
+
+ /**
+ * Sets the Hibernate setting dictating what it does with the database schema upon
first connection. Valid values are as
+ * follows (though the value is not checked):
+ * <ul>
+ * <li>"<code>create</code>" - Create the database schema
objects when the {@link EntityManagerFactory} is created (actually
+ * when Hibernate's {@link SessionFactory} is created by the entity manager
factory). If a file named "import.sql" exists in
+ * the root of the class path (e.g., '/import.sql') Hibernate will read and
execute the SQL statements in this file after it
+ * has created the database objects. Note that Hibernate first delete all tables,
constraints, or any other database object
+ * that is going to be created in the process of building the schema.</li>
+ * <li>"<code>create-drop</code>" - Same as
"<code>create</code>", except that the schema will be dropped after
the
+ * {@link EntityManagerFactory} is closed.</li>
+ * <li>"<code>update</code>" - Attempt to update the
database structure to the current mapping (but does not read and invoke
+ * the SQL statements from "import.sql"). <i>Use with
caution.</i></li>
+ * <li>"<code>validate</code>" - Validates the existing
schema with the current entities configuration, but does not make any
+ * changes to the schema (and does not read and invoke the SQL statements from
"import.sql"). This is often the proper setting
+ * to use in production, and thus this is the default value.</li>
+ * </ul>
+ *
+ * @param autoGenerateSchema the setting for the auto-generation, or null if the
default should be used
+ */
+ public synchronized void setAutoGenerateSchema( String autoGenerateSchema ) {
+ this.autoGenerateSchema = autoGenerateSchema != null ? autoGenerateSchema.trim()
: DEFAULT_AUTO_GENERATE_SCHEMA;
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
@@ -758,6 +801,7 @@
ref.add(new StringRefAddr(ENFORCE_REFERENTIAL_INTEGRITY,
Boolean.toString(isReferentialIntegrityEnforced())));
ref.add(new StringRefAddr(DEFAULT_WORKSPACE, getDefaultWorkspaceName()));
ref.add(new StringRefAddr(ALLOW_CREATING_WORKSPACES,
Boolean.toString(isCreatingWorkspacesAllowed())));
+ ref.add(new StringRefAddr(AUTO_GENERATE_SCHEMA, getAutoGenerateSchema()));
String[] workspaceNames = getPredefinedWorkspaceNames();
if (workspaceNames != null && workspaceNames.length != 0) {
ref.add(new StringRefAddr(PREDEFINED_WORKSPACE_NAMES,
StringUtil.combineLines(workspaceNames)));
@@ -811,6 +855,7 @@
String refIntegrity = values.get(ENFORCE_REFERENTIAL_INTEGRITY);
String defaultWorkspace = values.get(DEFAULT_WORKSPACE);
String createWorkspaces = values.get(ALLOW_CREATING_WORKSPACES);
+ String autoGenerateSchema = values.get(AUTO_GENERATE_SCHEMA);
String combinedWorkspaceNames = values.get(PREDEFINED_WORKSPACE_NAMES);
String[] workspaceNames = null;
@@ -845,6 +890,7 @@
if (defaultWorkspace != null)
source.setDefaultWorkspaceName(defaultWorkspace);
if (createWorkspaces != null)
source.setCreatingWorkspacesAllowed(Boolean.parseBoolean(createWorkspaces));
if (workspaceNames != null && workspaceNames.length != 0)
source.setPredefinedWorkspaceNames(workspaceNames);
+ if (autoGenerateSchema != null)
source.setAutoGenerateSchema(autoGenerateSchema);
return source;
}
return null;
@@ -1007,7 +1053,7 @@
// setProperty(configuration, "hibernate.show_sql", "true");
// writes all SQL statements to console
setProperty(configuration, "hibernate.format_sql", "true");
setProperty(configuration, "hibernate.use_sql_comments",
"true");
- setProperty(configuration, "hibernate.hbm2ddl.auto",
"create");
+ setProperty(configuration, "hibernate.hbm2ddl.auto",
this.autoGenerateSchema);
}
protected void setProperty( Ejb3Configuration configurator,
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorCreateWorkspacesTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorCreateWorkspacesTest.java 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorCreateWorkspacesTest.java 2009-09-03
20:01:08 UTC (rev 1192)
@@ -67,6 +67,7 @@
source.setLargeValueSizeInBytes(150);
source.setCreatingWorkspacesAllowed(true);
source.setPredefinedWorkspaceNames(predefinedWorkspaces);
+ source.setAutoGenerateSchema("create");
return source;
}
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorNoCreateWorkspaceTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorNoCreateWorkspaceTest.java 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorNoCreateWorkspaceTest.java 2009-09-03
20:01:08 UTC (rev 1192)
@@ -67,6 +67,7 @@
source.setLargeValueSizeInBytes(150);
source.setCreatingWorkspacesAllowed(false);
source.setPredefinedWorkspaceNames(predefinedWorkspaces);
+ source.setAutoGenerateSchema("create");
return source;
}
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorReadingTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorReadingTest.java 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorReadingTest.java 2009-09-03
20:01:08 UTC (rev 1192)
@@ -55,6 +55,7 @@
source.setMaximumSizeOfStatementCache(100);
source.setMaximumConnectionIdleTimeInSeconds(0);
source.setLargeValueSizeInBytes(150);
+ source.setAutoGenerateSchema("create");
// Create a graph and look up the root node. We do this to initialize the
connection pool and
// force the database to be setup at this point. By doing it now, we don't
include this overhead
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorWritingTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorWritingTest.java 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaConnectorWritingTest.java 2009-09-03
20:01:08 UTC (rev 1192)
@@ -57,6 +57,7 @@
source.setMaximumConnectionIdleTimeInSeconds(0);
source.setReferentialIntegrityEnforced(true);
source.setLargeValueSizeInBytes(150);
+ source.setAutoGenerateSchema("create");
source.setCompressData(true);
return source;
@@ -93,8 +94,12 @@
graph.create("/newUuids").and();
// Copy once to get the UUID into the default workspace
-
//graph.copy("/node1").replacingExistingNodesWithSameUuids().fromWorkspace(workspaceName).to("/newUuids/node1");
-
graph.clone("/node1").fromWorkspace(workspaceName).as(name("node1")).into("/newUuids").replacingExistingNodesWithSameUuids();
+ //
graph.copy("/node1").replacingExistingNodesWithSameUuids().fromWorkspace(workspaceName).to("/newUuids/node1");
+ graph.clone("/node1")
+ .fromWorkspace(workspaceName)
+ .as(name("node1"))
+ .into("/newUuids")
+ .replacingExistingNodesWithSameUuids();
// Create a new child node that in the target workspace that has no corresponding
node in the source workspace
graph.create("/newUuids/node1/shouldBeRemoved").and();
@@ -106,7 +111,11 @@
// Copy again to test the behavior now that the UUIDs are already in the default
workspace
// This should fail because /newUuids/node1/shouldBeRemoved must be removed by
the copy, but can't be removed
// because there is a reference to it.
-
//graph.copy("/node1").replacingExistingNodesWithSameUuids().fromWorkspace(workspaceName).to("/newUuids/otherNode");
-
graph.clone("/node1").fromWorkspace(workspaceName).as(name("otherNode")).into("/newUuids").replacingExistingNodesWithSameUuids();
+ //
graph.copy("/node1").replacingExistingNodesWithSameUuids().fromWorkspace(workspaceName).to("/newUuids/otherNode");
+ graph.clone("/node1")
+ .fromWorkspace(workspaceName)
+ .as(name("otherNode"))
+ .into("/newUuids")
+ .replacingExistingNodesWithSameUuids();
}
}
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaSourceTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaSourceTest.java 2009-09-03
19:07:26 UTC (rev 1191)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/JpaSourceTest.java 2009-09-03
20:01:08 UTC (rev 1192)
@@ -60,6 +60,7 @@
this.source.setMaximumConnectionIdleTimeInSeconds(0);
this.source.setDefaultWorkspaceName("default");
this.source.setCreatingWorkspacesAllowed(true);
+ this.source.setAutoGenerateSchema("create");
}
@After