Author: scottbw
Date: Thu Jun 17 13:51:08 2010
New Revision: 955596
URL: http://svn.apache.org/viewvc?rev=955596&view=rev
Log:
Applied patch adding support for SQL scripts for initialization (Thanks to
Randy Watler for the patch)
Modified:
incubator/wookie/branches/pluggablepersistence/readme.txt
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/util/PersistenceManagerFactory.java
Modified: incubator/wookie/branches/pluggablepersistence/readme.txt
URL:
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/readme.txt?rev=955596&r1=955595&r2=955596&view=diff
==============================================================================
--- incubator/wookie/branches/pluggablepersistence/readme.txt (original)
+++ incubator/wookie/branches/pluggablepersistence/readme.txt Thu Jun 17
13:51:08 2010
@@ -111,7 +111,21 @@ To shutdown the Wookie Tomcat server and
> CATALINA_HOME/bin/shutdown.sh
> export CATALINA_OPTS=
-There are also SQL scripts for all of the valid database configurations built
as part of Wookie that can be used to initialize the database schema manually
if desired.
+There are also SQL scripts for all of the valid database configurations built
as part of Wookie that can be used to initialize the database schema manually
if desired. These are located here:
+
+build/classes/org/apache/wookie/beans/jpa/db2-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/derby-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/hsqldb-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/mssql-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/mysql5-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/mysql-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/oracle10-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/oracle9-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/oracle-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/postgresql-wookie-schema.sql
+build/classes/org/apache/wookie/beans/jpa/sybase-wookie-schema.sql
+
+The Wookie server will populate the newly initialized database with seed data
to complete the process when started.
Running Wookie using embedded Jackrabbit JCR
============================================
Modified:
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/util/PersistenceManagerFactory.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/util/PersistenceManagerFactory.java?rev=955596&r1=955595&r2=955596&view=diff
==============================================================================
---
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/util/PersistenceManagerFactory.java
(original)
+++
incubator/wookie/branches/pluggablepersistence/src/org/apache/wookie/beans/util/PersistenceManagerFactory.java
Thu Jun 17 13:51:08 2010
@@ -76,17 +76,20 @@ public class PersistenceManagerFactory
initialized = true;
- // initialize persistence store using persistence manager
- if (initializeStore)
+ // initialize/verify/validate persistence store using persistence
manager
+ try
{
- try
- {
- // allocate and begin persistence manager transaction
- IPersistenceManager persistenceManager =
getPersistenceManager();
- persistenceManager.begin();
+ // allocate and begin persistence manager transaction
+ IPersistenceManager persistenceManager =
getPersistenceManager();
+ persistenceManager.begin();
- // Widget
- IWidget widget =
persistenceManager.newInstance(IWidget.class);
+ // Widget
+ boolean initializing = true;
+ IWidget widget =
persistenceManager.findWidgetByGuid("http://notsupported");
+ if (widget == null)
+ {
+ // required: always create if not found
+ widget = persistenceManager.newInstance(IWidget.class);
widget.setHeight(350);
widget.setWidth(500);
widget.setGuid("http://notsupported");
@@ -126,17 +129,30 @@ public class PersistenceManagerFactory
widgetIcon.setLang("en");
widget.getWidgetIcons().add(widgetIcon);
persistenceManager.save(widget);
+ }
+ else
+ {
+ initializing = false;
+ }
- // WidgetDefault
+ // WidgetDefault
+ if (persistenceManager.findWidgetDefaultByType("unsupported")
== null)
+ {
+ // required: always create if not found
IWidgetDefault widgetDefault =
persistenceManager.newInstance(IWidgetDefault.class);
widgetDefault.setWidget(widget);
widgetDefault.setWidgetContext("unsupported");
persistenceManager.save(widgetDefault);
+ }
+ else
+ {
+ initializing = false;
+ }
- // WidgetService
- IWidgetService unsupportedWidgetService =
persistenceManager.newInstance(IWidgetService.class);
- unsupportedWidgetService.setServiceName("unsupported");
- persistenceManager.save(unsupportedWidgetService);
+ // WidgetService
+ if (initializing &&
(persistenceManager.findAll(IWidgetService.class).length == 0))
+ {
+ // optional: create only if initializing
IWidgetService chatWidgetService =
persistenceManager.newInstance(IWidgetService.class);
chatWidgetService.setServiceName("chat");
persistenceManager.save(chatWidgetService);
@@ -149,33 +165,89 @@ public class PersistenceManagerFactory
IWidgetService weatherWidgetService =
persistenceManager.newInstance(IWidgetService.class);
weatherWidgetService.setServiceName("weather");
persistenceManager.save(weatherWidgetService);
+ }
+ else
+ {
+ initializing = false;
+ }
+ if (persistenceManager.findByValue(IWidgetService.class,
"serviceName", "unsupported").length == 0)
+ {
+ // required: always create if not found
+ IWidgetService unsupportedWidgetService =
persistenceManager.newInstance(IWidgetService.class);
+ unsupportedWidgetService.setServiceName("unsupported");
+ persistenceManager.save(unsupportedWidgetService);
+ }
+ else
+ {
+ initializing = false;
+ }
- // Whitelist
+ // Whitelist
+ if (initializing &&
(persistenceManager.findAll(IWhitelist.class).length == 0))
+ {
+ // optional: create only if initializing
+ IWhitelist wookieServerWhitelist =
persistenceManager.newInstance(IWhitelist.class);
+
wookieServerWhitelist.setfUrl("http://incubator.apache.org/wookie");
+ persistenceManager.save(wookieServerWhitelist);
+ }
+ else
+ {
+ initializing = false;
+ }
+ if (persistenceManager.findByValue(IWhitelist.class, "fUrl",
"http://127.0.0.1").length == 0)
+ {
+ // required: always create if not found
IWhitelist localhostIPAddrWhitelist =
persistenceManager.newInstance(IWhitelist.class);
localhostIPAddrWhitelist.setfUrl("http://127.0.0.1");
persistenceManager.save(localhostIPAddrWhitelist);
+ }
+ else
+ {
+ initializing = false;
+ }
+ if (persistenceManager.findByValue(IWhitelist.class, "fUrl",
"http://localhost").length == 0)
+ {
+ // required: always create if not found
IWhitelist localhostWhitelist =
persistenceManager.newInstance(IWhitelist.class);
localhostWhitelist.setfUrl("http://localhost");
persistenceManager.save(localhostWhitelist);
- IWhitelist wookieServerWhitelist =
persistenceManager.newInstance(IWhitelist.class);
-
wookieServerWhitelist.setfUrl("http://incubator.apache.org/wookie");
- persistenceManager.save(wookieServerWhitelist);
+ }
+ else
+ {
+ initializing = false;
+ }
- // ApiKey
+ // ApiKey
+ if (initializing &&
(persistenceManager.findAll(IApiKey.class).length == 0))
+ {
+ // optional: create only if initializing
IApiKey apiKey =
persistenceManager.newInstance(IApiKey.class);
apiKey.setValue("TEST");
apiKey.setEmail("[email protected]");
persistenceManager.save(apiKey);
+ }
+ else
+ {
+ initializing = false;
+ }
+
+ // commit persistence manager transaction
+ persistenceManager.commit();
- // commit persistence manager transaction
- persistenceManager.commit();
+ if (initializing)
+ {
+ logger.info("Initialized persistent store with seed data");
}
- finally
+ else
{
- // close persistence manager transaction
- closePersistenceManager();
+ logger.info("Validated persistent store seed data");
}
}
+ finally
+ {
+ // close persistence manager transaction
+ closePersistenceManager();
+ }
logger.info("Initialized with "+className);
}