ObjectDB ObjectDB

How force always recreate database on redeployment.

#1

Is there some easy way to force recreation/deletion of the current database on deployment of a web application (to Glassfish).

My web application uses a @Singleton @Startup bean to create and persist a test model each run. I keep getting models on top of each other on rerunning my web application.

Currently, to avoid multiple models in the database, I have to undeploy from Glassfish, stop the server, delete the database file, re-start the objectdb server, re-run the web app, which is tedious.

Is there a system property, persistence.xml property, or config file property I can use to set to force ObjectDB to always delete or empty the database file on startup ?

edit
delete
#2

You should be able to drop the entire database if its file is not locked by Glassfish.

See the connection url section in the manual and relevant configuration. See also this forum thread.

ObjectDB Support
edit
delete
#3

Thanks for feedback, I have read the provided links.

From EntityManagerFactory: Connection URL Parameters

To obtain a connection to an empty database (discarding existing content if any) the drop parameter has to be specified:

  EntityManagerFactory emf =
      Persistence.createEntityManagerFactory("objectdb:myDbFile.tmp;drop");

But I am obtaining an EntityManager from the container using @PersistenceContext. I can then obtain the related EntityManagerFactory from EntityManager.getEntityManagerFactory, but by then it is constructed and I can't see how to set the drop parameter before the database file is opened. Setting parameters on the Properties map of an EntityManagerFactory does not work:

'http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManagerFactory.html#getProperties()
java.util.Map<java.lang.String,java.lang.Object> getProperties()

Get the properties and associated values that are in effect for the entity manager factory. Changing the contents of the map does not change the configuration in effect.'

Q: How can I set 'drop' when using a web application container and persistence.xml in client-server mode ?

edit
delete
#4

Also at http://www.objectdb.com/database/forum/235 support says:

'In client-server mode this configuration should be set on the server side.'

How is that done ?

edit
delete
#5

Q: How can I set 'drop' when using a web application container and persistence.xml in client-server mode ?

You may add the drop parameter to the url that you specify in the persistence.xml file.

Q: 'In client-server mode this configuration should be set on the server side.' How is that done ?

If you are using ObjectDB in client-server mode you probably have 2 objectdb.jar in use, one on the client side (as part of the web application) and the other on the server side (possibly in the ObjectDB installation directory). Configuration is loaded relatively to the path of the objectdb.jar file (see the manual), so make sure you edit the correct objectdb.conf file.

ObjectDB Support
edit
delete
#6

Thanks for prompt reply. I am sorry, I am not getting it to work.

My connection URL in persistence.xml is:

<property name="javax.persistence.jdbc.url" value="objectdb://localhost/greensoftObjectdbTest/greensoftObjectdbTest.tmp;drop"/>

I run the server from /usr/local/objectdb/bin as:

java  -cp ./objectdb.jar com.objectdb.Server start

The objectdb.conf above the bin I run the server from definitely has:

<extensions drop="temp,tmp" />

The database file is created as:

.../objectdb/db/greensoftObjectdbTest/greensoftObjectdbTest.tmp

On running the web application a project/model is created in the @PostConstruct method of a @Singleton @Startup.

On rerunning the web application a 2nd project/model is created, the 1st is not deleted from the database file.

edit
delete
#7

See this forum thread that also discusses drop in C/S mode.

It includes a simple test case (F330) that demonstrates a successful drop in C/S mode.

But if the database file is in use, including if it is open in the Explorer, drop will not work.

ObjectDB Support
edit
delete
#8

Thanks for your reply.

I am now working in embedded mode, and am not having problems with drop anymore.

In client-server mode, sometimes drop works for me, sometimes it does not, and I don't know why or under what circumstances, perhaps something gets locked up, I know that is not a very useful diagnostic. 

Anyway, I can currently work ok.

thanks

Webel

edit
delete

Reply

To post on this website please sign in.