Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] closing down a database
[CDO] closing down a database [message #429421] Wed, 22 April 2009 20:55 Go to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Hi,

I have a simple application in which I am storing large models into individual
databases. I am using HSQLDB for this purpose. The target application is an
Eclipse plugin, and because each model has its own (smallish) database (rather
than storing everything in one large database), I'm starting up the databases
using the JVM acceptor.

My problem is basically the following: there are times when I would like to
delete the databases that have been created. So, I basically want to close down
all connections, and delete the database files. But, I'm not able to do this. No
matter what I do, the log file for the database stays locked, and I can't delete
it. I'm using CDO version 1.0.8, and here are some code snippets for how the
databases are set up:

Any help would be greatly appreciated.

----------------

private void init() throws CoreException {
IManagedContainer container = IPluginContainer.INSTANCE;
if (acceptor == null) {
acceptor = JVMUtil.getAcceptor(container, "default");
}
if (repository == null) {
repository = createRepository();
CDOServerUtil.addRepository(container, repository);
}
if (connector == null) {
connector = JVMUtil.getConnector(container, "default");
}
if (session == null) {
CDOSessionConfiguration config = CDOUtil.createSessionConfiguration();
config.setConnector(connector);
config.setRepositoryName(databasePath.toPortableString());
config.setLegacySupportEnabled(false);
config.setDemandPopulatingPackageRegistry();
session = config.openSession();
}
}

private IRepository createRepository() throws CoreException {
Map<String, String> props = new HashMap<String, String>();
props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
IRepository repository =
CDOServerUtil.createRepository(databasePath.toPortableString (),
createStore(databasePath), props);
return repository;
}

private IStore createStore(IPath databaseAlias) throws CoreException {
HSQLDBDataSource dataSource = new HSQLDBDataSource();
dataSource.setUser("sa");
dataSource.setPassword("");
dataSource.setDatabase(getDBName());
IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy();
IDBStore store = CDODBUtil.createStore(
mappingStrategy,
DBUtil.getDBAdapter("hsqldb"),
DBUtil.createConnectionProvider(dataSource));
mappingStrategy.setStore(store);
this.dataSource = dataSource;
return store;
}

public void close() {
if (view != null) {
view.close();
}
if (session != null) {
CDOView[] views = session.getViews();
for (CDOView view : views) {
view.close();
}
session.close();
}
if (connector != null) {
connector.disconnect();
}
if (dataSource != null) {
try {
if (!dataSource.getConnection().isClosed()) {
dataSource.getConnection().close();
}
} catch (SQLException e) {
DBPlugin.getDefault().log(e);
}
}


}
Re: [CDO] closing down a database [message #429433 is a reply to message #429421] Thu, 23 April 2009 13:40 Go to previous messageGo to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 307
Registered: July 2009
Location: Germany
Senior Member
Hi,

comments below ...
> public void close() {
> if (view != null) {
> view.close();
> }
> if (session != null) {
> CDOView[] views = session.getViews();
> for (CDOView view : views) {
> view.close();
> }
> session.close();
> }
> if (connector != null) {
> connector.disconnect();
> }
> if (dataSource != null) {
> try {
> if (!dataSource.getConnection().isClosed()) {
> dataSource.getConnection().close();
> }
I think dataSource.getConnection() opens a new connection, so what you
do here is opening and closing a dummy connection.
Not that I had tried it, but
if(repository != null) {
LifecycleUtil.deactivate(repository)
}
would help. However I don't know if there's an inverse of
CDOServerUtil.addRepository -- there is, at least, no
CDOServerUtil.removeRepository
and I don't know what implications a deactivated repository has on the
PluginContainer :-(

Maybe Eike can jump in here ...

Cheers,
Stefan
Re: [CDO] closing down a database [message #429443 is a reply to message #429433] Thu, 23 April 2009 17:57 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
I didn't think that closing down the connection would do anything, but I was
just trying anything I could. I'll try the LifeCycleUtils, though. thanks.

Stefan Winkler wrote:
> Hi,
>
> comments below ...
>> public void close() {
>> if (view != null) {
>> view.close();
>> }
>> if (session != null) {
>> CDOView[] views = session.getViews();
>> for (CDOView view : views) {
>> view.close();
>> }
>> session.close();
>> }
>> if (connector != null) {
>> connector.disconnect();
>> }
>> if (dataSource != null) {
>> try {
>> if (!dataSource.getConnection().isClosed()) {
>> dataSource.getConnection().close();
>> }
> I think dataSource.getConnection() opens a new connection, so what you
> do here is opening and closing a dummy connection.
> Not that I had tried it, but
> if(repository != null) {
> LifecycleUtil.deactivate(repository)
> }
> would help. However I don't know if there's an inverse of
> CDOServerUtil.addRepository -- there is, at least, no
> CDOServerUtil.removeRepository
> and I don't know what implications a deactivated repository has on the
> PluginContainer :-(
>
> Maybe Eike can jump in here ...
>
> Cheers,
> Stefan
Re: [CDO] closing down a database [message #429493 is a reply to message #429433] Thu, 23 April 2009 18:04 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Tried it, and it didn't work. I don't know, something is still running and has a
lock on the log file. I don't know what it is.

Del
Stefan Winkler wrote:
> Hi,
>
> comments below ...
>> public void close() {
>> if (view != null) {
>> view.close();
>> }
>> if (session != null) {
>> CDOView[] views = session.getViews();
>> for (CDOView view : views) {
>> view.close();
>> }
>> session.close();
>> }
>> if (connector != null) {
>> connector.disconnect();
>> }
>> if (dataSource != null) {
>> try {
>> if (!dataSource.getConnection().isClosed()) {
>> dataSource.getConnection().close();
>> }
> I think dataSource.getConnection() opens a new connection, so what you
> do here is opening and closing a dummy connection.
> Not that I had tried it, but
> if(repository != null) {
> LifecycleUtil.deactivate(repository)
> }
> would help. However I don't know if there's an inverse of
> CDOServerUtil.addRepository -- there is, at least, no
> CDOServerUtil.removeRepository
> and I don't know what implications a deactivated repository has on the
> PluginContainer :-(
>
> Maybe Eike can jump in here ...
>
> Cheers,
> Stefan
Re: [CDO] closing down a database [message #429525 is a reply to message #429421] Fri, 24 April 2009 09:55 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Del,

Like Stefan, I would have recommended to deactivate the repository with:

LifecycleUtil.deactivate(repository);

If anything inside stays active after this, I guess we'd need a running
code example to reproduce it...

Cheers
/Eike

----
http://thegordian.blogspot.com



Del Myers schrieb:
> Hi,
>
> I have a simple application in which I am storing large models into
> individual databases. I am using HSQLDB for this purpose. The target
> application is an Eclipse plugin, and because each model has its own
> (smallish) database (rather than storing everything in one large
> database), I'm starting up the databases using the JVM acceptor.
>
> My problem is basically the following: there are times when I would
> like to delete the databases that have been created. So, I basically
> want to close down all connections, and delete the database files.
> But, I'm not able to do this. No matter what I do, the log file for
> the database stays locked, and I can't delete it. I'm using CDO
> version 1.0.8, and here are some code snippets for how the databases
> are set up:
>
> Any help would be greatly appreciated.
>
> ----------------
>
> private void init() throws CoreException {
> IManagedContainer container = IPluginContainer.INSTANCE;
> if (acceptor == null) {
> acceptor = JVMUtil.getAcceptor(container, "default");
> }
> if (repository == null) {
> repository = createRepository();
> CDOServerUtil.addRepository(container, repository);
> }
> if (connector == null) {
> connector = JVMUtil.getConnector(container, "default");
> }
> if (session == null) {
> CDOSessionConfiguration config =
> CDOUtil.createSessionConfiguration();
> config.setConnector(connector);
> config.setRepositoryName(databasePath.toPortableString());
> config.setLegacySupportEnabled(false);
> config.setDemandPopulatingPackageRegistry();
> session = config.openSession();
> }
> }
>
> private IRepository createRepository() throws CoreException {
> Map<String, String> props = new HashMap<String, String>();
> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
> IRepository repository =
> CDOServerUtil.createRepository(databasePath.toPortableString (),
> createStore(databasePath), props);
> return repository;
> }
>
> private IStore createStore(IPath databaseAlias) throws CoreException {
> HSQLDBDataSource dataSource = new HSQLDBDataSource();
> dataSource.setUser("sa");
> dataSource.setPassword("");
> dataSource.setDatabase(getDBName());
> IMappingStrategy mappingStrategy =
> CDODBUtil.createHorizontalMappingStrategy();
> IDBStore store = CDODBUtil.createStore(
> mappingStrategy,
> DBUtil.getDBAdapter("hsqldb"),
> DBUtil.createConnectionProvider(dataSource));
> mappingStrategy.setStore(store);
> this.dataSource = dataSource;
> return store;
> }
>
> public void close() {
> if (view != null) {
> view.close();
> }
> if (session != null) {
> CDOView[] views = session.getViews();
> for (CDOView view : views) {
> view.close();
> }
> session.close();
> }
> if (connector != null) {
> connector.disconnect();
> }
> if (dataSource != null) {
> try {
> if (!dataSource.getConnection().isClosed()) {
> dataSource.getConnection().close();
> }
> } catch (SQLException e) {
> DBPlugin.getDefault().log(e);
> }
> }
>
>
> }


Re: [CDO] closing down a database [message #429526 is a reply to message #429421] Fri, 24 April 2009 10:02 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Forgot to mention that cdoSession.close() automatically closes all views
and their possible queries ;-)

Cheers
/Eike

----
http://thegordian.blogspot.com



Del Myers schrieb:
> Hi,
>
> I have a simple application in which I am storing large models into
> individual databases. I am using HSQLDB for this purpose. The target
> application is an Eclipse plugin, and because each model has its own
> (smallish) database (rather than storing everything in one large
> database), I'm starting up the databases using the JVM acceptor.
>
> My problem is basically the following: there are times when I would
> like to delete the databases that have been created. So, I basically
> want to close down all connections, and delete the database files.
> But, I'm not able to do this. No matter what I do, the log file for
> the database stays locked, and I can't delete it. I'm using CDO
> version 1.0.8, and here are some code snippets for how the databases
> are set up:
>
> Any help would be greatly appreciated.
>
> ----------------
>
> private void init() throws CoreException {
> IManagedContainer container = IPluginContainer.INSTANCE;
> if (acceptor == null) {
> acceptor = JVMUtil.getAcceptor(container, "default");
> }
> if (repository == null) {
> repository = createRepository();
> CDOServerUtil.addRepository(container, repository);
> }
> if (connector == null) {
> connector = JVMUtil.getConnector(container, "default");
> }
> if (session == null) {
> CDOSessionConfiguration config =
> CDOUtil.createSessionConfiguration();
> config.setConnector(connector);
> config.setRepositoryName(databasePath.toPortableString());
> config.setLegacySupportEnabled(false);
> config.setDemandPopulatingPackageRegistry();
> session = config.openSession();
> }
> }
>
> private IRepository createRepository() throws CoreException {
> Map<String, String> props = new HashMap<String, String>();
> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
> IRepository repository =
> CDOServerUtil.createRepository(databasePath.toPortableString (),
> createStore(databasePath), props);
> return repository;
> }
>
> private IStore createStore(IPath databaseAlias) throws CoreException {
> HSQLDBDataSource dataSource = new HSQLDBDataSource();
> dataSource.setUser("sa");
> dataSource.setPassword("");
> dataSource.setDatabase(getDBName());
> IMappingStrategy mappingStrategy =
> CDODBUtil.createHorizontalMappingStrategy();
> IDBStore store = CDODBUtil.createStore(
> mappingStrategy,
> DBUtil.getDBAdapter("hsqldb"),
> DBUtil.createConnectionProvider(dataSource));
> mappingStrategy.setStore(store);
> this.dataSource = dataSource;
> return store;
> }
>
> public void close() {
> if (view != null) {
> view.close();
> }
> if (session != null) {
> CDOView[] views = session.getViews();
> for (CDOView view : views) {
> view.close();
> }
> session.close();
> }
> if (connector != null) {
> connector.disconnect();
> }
> if (dataSource != null) {
> try {
> if (!dataSource.getConnection().isClosed()) {
> dataSource.getConnection().close();
> }
> } catch (SQLException e) {
> DBPlugin.getDefault().log(e);
> }
> }
>
>
> }


Re: [CDO] closing down a database [message #429538 is a reply to message #429526] Fri, 24 April 2009 11:09 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
IIRC hsql needs a special sql-command send at the end to release all
locks immediately on the files. Closing the db-connection is not enough!

I'm going to look up some old old project code.

Tom

Eike Stepper schrieb:
> Forgot to mention that cdoSession.close() automatically closes all views
> and their possible queries ;-)
>
> Cheers
> /Eike
>
> ----
> http://thegordian.blogspot.com
>
>
>
> Del Myers schrieb:
>> Hi,
>>
>> I have a simple application in which I am storing large models into
>> individual databases. I am using HSQLDB for this purpose. The target
>> application is an Eclipse plugin, and because each model has its own
>> (smallish) database (rather than storing everything in one large
>> database), I'm starting up the databases using the JVM acceptor.
>>
>> My problem is basically the following: there are times when I would
>> like to delete the databases that have been created. So, I basically
>> want to close down all connections, and delete the database files.
>> But, I'm not able to do this. No matter what I do, the log file for
>> the database stays locked, and I can't delete it. I'm using CDO
>> version 1.0.8, and here are some code snippets for how the databases
>> are set up:
>>
>> Any help would be greatly appreciated.
>>
>> ----------------
>>
>> private void init() throws CoreException {
>> IManagedContainer container = IPluginContainer.INSTANCE;
>> if (acceptor == null) {
>> acceptor = JVMUtil.getAcceptor(container, "default");
>> }
>> if (repository == null) {
>> repository = createRepository();
>> CDOServerUtil.addRepository(container, repository);
>> }
>> if (connector == null) {
>> connector = JVMUtil.getConnector(container, "default");
>> }
>> if (session == null) {
>> CDOSessionConfiguration config =
>> CDOUtil.createSessionConfiguration();
>> config.setConnector(connector);
>> config.setRepositoryName(databasePath.toPortableString());
>> config.setLegacySupportEnabled(false);
>> config.setDemandPopulatingPackageRegistry();
>> session = config.openSession();
>> }
>> }
>>
>> private IRepository createRepository() throws CoreException {
>> Map<String, String> props = new HashMap<String, String>();
>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>> IRepository repository =
>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>> createStore(databasePath), props);
>> return repository;
>> }
>>
>> private IStore createStore(IPath databaseAlias) throws CoreException {
>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>> dataSource.setUser("sa");
>> dataSource.setPassword("");
>> dataSource.setDatabase(getDBName());
>> IMappingStrategy mappingStrategy =
>> CDODBUtil.createHorizontalMappingStrategy();
>> IDBStore store = CDODBUtil.createStore(
>> mappingStrategy,
>> DBUtil.getDBAdapter("hsqldb"),
>> DBUtil.createConnectionProvider(dataSource));
>> mappingStrategy.setStore(store);
>> this.dataSource = dataSource;
>> return store;
>> }
>>
>> public void close() {
>> if (view != null) {
>> view.close();
>> }
>> if (session != null) {
>> CDOView[] views = session.getViews();
>> for (CDOView view : views) {
>> view.close();
>> }
>> session.close();
>> }
>> if (connector != null) {
>> connector.disconnect();
>> }
>> if (dataSource != null) {
>> try {
>> if (!dataSource.getConnection().isClosed()) {
>> dataSource.getConnection().close();
>> }
>> } catch (SQLException e) {
>> DBPlugin.getDefault().log(e);
>> }
>> }
>>
>>
>> }
Re: [CDO] closing down a database [message #429542 is a reply to message #429538] Fri, 24 April 2009 11:26 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Tom,

Thanks for the hint!

In this case I suggest to file a Bugzilla against CDO so that we can fix
this (Del!).

Cheers
/Eike

----
http://thegordian.blogspot.com


Tom Schindl schrieb:
> IIRC hsql needs a special sql-command send at the end to release all
> locks immediately on the files. Closing the db-connection is not enough!
>
> I'm going to look up some old old project code.
>
> Tom
>
> Eike Stepper schrieb:
>
>> Forgot to mention that cdoSession.close() automatically closes all views
>> and their possible queries ;-)
>>
>> Cheers
>> /Eike
>>
>> ----
>> http://thegordian.blogspot.com
>>
>>
>>
>> Del Myers schrieb:
>>
>>> Hi,
>>>
>>> I have a simple application in which I am storing large models into
>>> individual databases. I am using HSQLDB for this purpose. The target
>>> application is an Eclipse plugin, and because each model has its own
>>> (smallish) database (rather than storing everything in one large
>>> database), I'm starting up the databases using the JVM acceptor.
>>>
>>> My problem is basically the following: there are times when I would
>>> like to delete the databases that have been created. So, I basically
>>> want to close down all connections, and delete the database files.
>>> But, I'm not able to do this. No matter what I do, the log file for
>>> the database stays locked, and I can't delete it. I'm using CDO
>>> version 1.0.8, and here are some code snippets for how the databases
>>> are set up:
>>>
>>> Any help would be greatly appreciated.
>>>
>>> ----------------
>>>
>>> private void init() throws CoreException {
>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>> if (acceptor == null) {
>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>> }
>>> if (repository == null) {
>>> repository = createRepository();
>>> CDOServerUtil.addRepository(container, repository);
>>> }
>>> if (connector == null) {
>>> connector = JVMUtil.getConnector(container, "default");
>>> }
>>> if (session == null) {
>>> CDOSessionConfiguration config =
>>> CDOUtil.createSessionConfiguration();
>>> config.setConnector(connector);
>>> config.setRepositoryName(databasePath.toPortableString());
>>> config.setLegacySupportEnabled(false);
>>> config.setDemandPopulatingPackageRegistry();
>>> session = config.openSession();
>>> }
>>> }
>>>
>>> private IRepository createRepository() throws CoreException {
>>> Map<String, String> props = new HashMap<String, String>();
>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>> IRepository repository =
>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>> createStore(databasePath), props);
>>> return repository;
>>> }
>>>
>>> private IStore createStore(IPath databaseAlias) throws CoreException {
>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>> dataSource.setUser("sa");
>>> dataSource.setPassword("");
>>> dataSource.setDatabase(getDBName());
>>> IMappingStrategy mappingStrategy =
>>> CDODBUtil.createHorizontalMappingStrategy();
>>> IDBStore store = CDODBUtil.createStore(
>>> mappingStrategy,
>>> DBUtil.getDBAdapter("hsqldb"),
>>> DBUtil.createConnectionProvider(dataSource));
>>> mappingStrategy.setStore(store);
>>> this.dataSource = dataSource;
>>> return store;
>>> }
>>>
>>> public void close() {
>>> if (view != null) {
>>> view.close();
>>> }
>>> if (session != null) {
>>> CDOView[] views = session.getViews();
>>> for (CDOView view : views) {
>>> view.close();
>>> }
>>> session.close();
>>> }
>>> if (connector != null) {
>>> connector.disconnect();
>>> }
>>> if (dataSource != null) {
>>> try {
>>> if (!dataSource.getConnection().isClosed()) {
>>> dataSource.getConnection().close();
>>> }
>>> } catch (SQLException e) {
>>> DBPlugin.getDefault().log(e);
>>> }
>>> }
>>>
>>>
>>> }
>>>


Re: [CDO] closing down a database [message #429545 is a reply to message #429538] Fri, 24 April 2009 11:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
[Disclaimer] Maybe this is not true any more because I haven't used HSQL
since about 2 years.

Hi,

When disconnecting from HSQL you need to execute.

---------8<---------
connection.executeQuery("SHUTDOWN");
---------8<---------

=> Looks this can be controled in 1.8 with a connection property [1]

Another special thing is that HSQL while running collects all executed
statements in a log-File and to write it back to the final condensed
format you need to execute

---------8<---------
connection.executeQuery("CHECKPOINT");
---------8<---------

at a given point or setting the size of the hsqldb.log_size-property a
SHUTDOWN will automatically execute a CHECKPOINT.

Tom

[1]http://hsqldb.org/doc/guide/ch01.html#N101DB

Tom Schindl schrieb:
> IIRC hsql needs a special sql-command send at the end to release all
> locks immediately on the files. Closing the db-connection is not enough!
>
> I'm going to look up some old old project code.
>
> Tom
>
> Eike Stepper schrieb:
>> Forgot to mention that cdoSession.close() automatically closes all views
>> and their possible queries ;-)
>>
>> Cheers
>> /Eike
>>
>> ----
>> http://thegordian.blogspot.com
>>
>>
>>
>> Del Myers schrieb:
>>> Hi,
>>>
>>> I have a simple application in which I am storing large models into
>>> individual databases. I am using HSQLDB for this purpose. The target
>>> application is an Eclipse plugin, and because each model has its own
>>> (smallish) database (rather than storing everything in one large
>>> database), I'm starting up the databases using the JVM acceptor.
>>>
>>> My problem is basically the following: there are times when I would
>>> like to delete the databases that have been created. So, I basically
>>> want to close down all connections, and delete the database files.
>>> But, I'm not able to do this. No matter what I do, the log file for
>>> the database stays locked, and I can't delete it. I'm using CDO
>>> version 1.0.8, and here are some code snippets for how the databases
>>> are set up:
>>>
>>> Any help would be greatly appreciated.
>>>
>>> ----------------
>>>
>>> private void init() throws CoreException {
>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>> if (acceptor == null) {
>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>> }
>>> if (repository == null) {
>>> repository = createRepository();
>>> CDOServerUtil.addRepository(container, repository);
>>> }
>>> if (connector == null) {
>>> connector = JVMUtil.getConnector(container, "default");
>>> }
>>> if (session == null) {
>>> CDOSessionConfiguration config =
>>> CDOUtil.createSessionConfiguration();
>>> config.setConnector(connector);
>>> config.setRepositoryName(databasePath.toPortableString());
>>> config.setLegacySupportEnabled(false);
>>> config.setDemandPopulatingPackageRegistry();
>>> session = config.openSession();
>>> }
>>> }
>>>
>>> private IRepository createRepository() throws CoreException {
>>> Map<String, String> props = new HashMap<String, String>();
>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>> IRepository repository =
>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>> createStore(databasePath), props);
>>> return repository;
>>> }
>>>
>>> private IStore createStore(IPath databaseAlias) throws CoreException {
>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>> dataSource.setUser("sa");
>>> dataSource.setPassword("");
>>> dataSource.setDatabase(getDBName());
>>> IMappingStrategy mappingStrategy =
>>> CDODBUtil.createHorizontalMappingStrategy();
>>> IDBStore store = CDODBUtil.createStore(
>>> mappingStrategy,
>>> DBUtil.getDBAdapter("hsqldb"),
>>> DBUtil.createConnectionProvider(dataSource));
>>> mappingStrategy.setStore(store);
>>> this.dataSource = dataSource;
>>> return store;
>>> }
>>>
>>> public void close() {
>>> if (view != null) {
>>> view.close();
>>> }
>>> if (session != null) {
>>> CDOView[] views = session.getViews();
>>> for (CDOView view : views) {
>>> view.close();
>>> }
>>> session.close();
>>> }
>>> if (connector != null) {
>>> connector.disconnect();
>>> }
>>> if (dataSource != null) {
>>> try {
>>> if (!dataSource.getConnection().isClosed()) {
>>> dataSource.getConnection().close();
>>> }
>>> } catch (SQLException e) {
>>> DBPlugin.getDefault().log(e);
>>> }
>>> }
>>>
>>>
>>> }
Re: [CDO] closing down a database [message #429548 is a reply to message #429545] Fri, 24 April 2009 11:48 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Tom Schindl schrieb:
> [Disclaimer] Maybe this is not true any more because I haven't used HSQL
> since about 2 years.
>
> Hi,
>
> When disconnecting from HSQL you need to execute.
>
> ---------8<---------
> connection.executeQuery("SHUTDOWN");
> ---------8<---------
>
Darn, I can remember that I added this line to our test framework:
org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.DB.Hs qldb.shutDownHsqldb()

But doesn't this shutdown *all* connections, or worse: the server itself?
This could be something that wedon't want to trigger from inside CDO,
i.e. the repository or store...

> => Looks this can be controled in 1.8 with a connection property [1]
>
> Another special thing is that HSQL while running collects all executed
> statements in a log-File and to write it back to the final condensed
> format you need to execute
>
> ---------8<---------
> connection.executeQuery("CHECKPOINT");
> ---------8<---------
>
You mean, in addition to the commit?
Should we have a problem here and no test uncovered it so far.
I never herad complaints about lost data after restarts...

Cheers
/Eike

----
http://thegordian.blogspot.com


> at a given point or setting the size of the hsqldb.log_size-property a
> SHUTDOWN will automatically execute a CHECKPOINT.
>
> Tom
>
> [1]http://hsqldb.org/doc/guide/ch01.html#N101DB
>
> Tom Schindl schrieb:
>
>> IIRC hsql needs a special sql-command send at the end to release all
>> locks immediately on the files. Closing the db-connection is not enough!
>>
>> I'm going to look up some old old project code.
>>
>> Tom
>>
>> Eike Stepper schrieb:
>>
>>> Forgot to mention that cdoSession.close() automatically closes all views
>>> and their possible queries ;-)
>>>
>>> Cheers
>>> /Eike
>>>
>>> ----
>>> http://thegordian.blogspot.com
>>>
>>>
>>>
>>> Del Myers schrieb:
>>>
>>>> Hi,
>>>>
>>>> I have a simple application in which I am storing large models into
>>>> individual databases. I am using HSQLDB for this purpose. The target
>>>> application is an Eclipse plugin, and because each model has its own
>>>> (smallish) database (rather than storing everything in one large
>>>> database), I'm starting up the databases using the JVM acceptor.
>>>>
>>>> My problem is basically the following: there are times when I would
>>>> like to delete the databases that have been created. So, I basically
>>>> want to close down all connections, and delete the database files.
>>>> But, I'm not able to do this. No matter what I do, the log file for
>>>> the database stays locked, and I can't delete it. I'm using CDO
>>>> version 1.0.8, and here are some code snippets for how the databases
>>>> are set up:
>>>>
>>>> Any help would be greatly appreciated.
>>>>
>>>> ----------------
>>>>
>>>> private void init() throws CoreException {
>>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>>> if (acceptor == null) {
>>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>>> }
>>>> if (repository == null) {
>>>> repository = createRepository();
>>>> CDOServerUtil.addRepository(container, repository);
>>>> }
>>>> if (connector == null) {
>>>> connector = JVMUtil.getConnector(container, "default");
>>>> }
>>>> if (session == null) {
>>>> CDOSessionConfiguration config =
>>>> CDOUtil.createSessionConfiguration();
>>>> config.setConnector(connector);
>>>> config.setRepositoryName(databasePath.toPortableString());
>>>> config.setLegacySupportEnabled(false);
>>>> config.setDemandPopulatingPackageRegistry();
>>>> session = config.openSession();
>>>> }
>>>> }
>>>>
>>>> private IRepository createRepository() throws CoreException {
>>>> Map<String, String> props = new HashMap<String, String>();
>>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>>> IRepository repository =
>>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>>> createStore(databasePath), props);
>>>> return repository;
>>>> }
>>>>
>>>> private IStore createStore(IPath databaseAlias) throws CoreException {
>>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>>> dataSource.setUser("sa");
>>>> dataSource.setPassword("");
>>>> dataSource.setDatabase(getDBName());
>>>> IMappingStrategy mappingStrategy =
>>>> CDODBUtil.createHorizontalMappingStrategy();
>>>> IDBStore store = CDODBUtil.createStore(
>>>> mappingStrategy,
>>>> DBUtil.getDBAdapter("hsqldb"),
>>>> DBUtil.createConnectionProvider(dataSource));
>>>> mappingStrategy.setStore(store);
>>>> this.dataSource = dataSource;
>>>> return store;
>>>> }
>>>>
>>>> public void close() {
>>>> if (view != null) {
>>>> view.close();
>>>> }
>>>> if (session != null) {
>>>> CDOView[] views = session.getViews();
>>>> for (CDOView view : views) {
>>>> view.close();
>>>> }
>>>> session.close();
>>>> }
>>>> if (connector != null) {
>>>> connector.disconnect();
>>>> }
>>>> if (dataSource != null) {
>>>> try {
>>>> if (!dataSource.getConnection().isClosed()) {
>>>> dataSource.getConnection().close();
>>>> }
>>>> } catch (SQLException e) {
>>>> DBPlugin.getDefault().log(e);
>>>> }
>>>> }
>>>>
>>>>
>>>> }
>>>>


Re: [CDO] closing down a database [message #429551 is a reply to message #429548] Fri, 24 April 2009 12:10 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Eike Stepper schrieb:
> Tom Schindl schrieb:
>> [Disclaimer] Maybe this is not true any more because I haven't used HSQL
>> since about 2 years.
>>
>> Hi,
>>
>> When disconnecting from HSQL you need to execute.
>>
>> ---------8<---------
>> connection.executeQuery("SHUTDOWN");
>> ---------8<---------
>>
> Darn, I can remember that I added this line to our test framework:
> org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.DB.Hs qldb.shutDownHsqldb()
>
> But doesn't this shutdown *all* connections, or worse: the server itself?
> This could be something that wedon't want to trigger from inside CDO,
> i.e. the repository or store...
>
>> => Looks this can be controled in 1.8 with a connection property [1]

I think this property is the correct one not?

>>
>> Another special thing is that HSQL while running collects all executed
>> statements in a log-File and to write it back to the final condensed
>> format you need to execute
>>
>> ---------8<---------
>> connection.executeQuery("CHECKPOINT");
>> ---------8<---------
>>
> You mean, in addition to the commit?
> Should we have a problem here and no test uncovered it so far.
> I never herad complaints about lost data after restarts...
>

Well this checkpoint is something different than what you might think it
is. It's not like a checkpoint you know from JDBC and has nothing to do
with transactions, ... .

Let's start with an empty database:

..script like this:
------------------
CREATE TABLE a ( .... )

..log like this:
---------------
<Empty>

When you execute a SEQUENCE of SQL-Statement in a transaction on an
HSQL-Database they are at first stored inside a log-File.

Say you execute the following statements:

INSERT IGNORE INTO a (a,b) VALUES (1,1);
UPDATE a SET b = 2 WHERE a = 1;

..script like this:
------------------
CREATE TABLE a ( .... )

..log like this:
---------------
START TRANSACTION;
INSERT IGNORE INTO a (a,b) VALUES (1,1);
UPDATE a SET b = 2 WHERE a = 1;
COMMIT;


now when you stop the database with out a shutdown the next time the
HSQL-DB first reads the .script and then in sequence execute the
SQL-Statements found in .log.

If you called CHECKPOINT after the above the situation is different and
when shutting down it looks like this:

..script like this:
------------------
CREATE TABLE a ( .... )
INSERT IGNORE INTO a (a,b) VALUES (1,2);

..log like this:
---------------
<Empty>

So it's not necessarily needed to execute CHECKPOINT but normally ones
better when its acceptable to execute such a condense command instead of
relying on the log_size. IIRC we also had corruption problems with the
..log-File and so we called CHECKPOINT at some given points in the
application.

Tom
Re: [CDO] closing down a database [message #429553 is a reply to message #429551] Fri, 24 April 2009 13:00 Go to previous messageGo to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 307
Registered: July 2009
Location: Germany
Senior Member
Hi,

some comments below ...

>>> When disconnecting from HSQL you need to execute.
>>>
>>> ---------8<---------
>>> connection.executeQuery("SHUTDOWN");
>>> ---------8<---------
>>>
>>>
>> Darn, I can remember that I added this line to our test framework:
>> org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.DB.Hs qldb.shutDownHsqldb()
>>
>> But doesn't this shutdown *all* connections, or worse: the server itself?
>> This could be something that wedon't want to trigger from inside CDO,
>> i.e. the repository or store...
>>
Yes it does. It is something a client might want to do.
Also the client might add ";shutdown=true" to the JDBC URL in order to
shut down the DB automatically at the end of the application.

[Checkpoint description deleted ...]
> So it's not necessarily needed to execute CHECKPOINT but normally ones
> better when its acceptable to execute such a condense command instead of
> relying on the log_size. IIRC we also had corruption problems with the
> .log-File and so we called CHECKPOINT at some given points in the
> application.
>
I think this is nothing we would like to handle in CDO as this can be
configured externally (using the log_size property which automatically
writes the log to the script of the log extends a given size).

Cheers,
Stefan
Re: [CDO] closing down a database [message #429561 is a reply to message #429545] Fri, 24 April 2009 18:14 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Thanks, executing SHUTDOWN does work after I close the session.

It works for my purposes because each of my models is stored in a separate
database, and I want to delete all of the database files. I'm not sure that I
want to file a bug about this because I imagine that, in most cases, client's
aren't going to want to shut down the database after closing their sessions.
Most of the time, I would expect, users would just want to clear their resource
and commit the transaction.

Del

Tom Schindl wrote:
> [Disclaimer] Maybe this is not true any more because I haven't used HSQL
> since about 2 years.
>
> Hi,
>
> When disconnecting from HSQL you need to execute.
>
> ---------8<---------
> connection.executeQuery("SHUTDOWN");
> ---------8<---------
>
> => Looks this can be controled in 1.8 with a connection property [1]
>
> Another special thing is that HSQL while running collects all executed
> statements in a log-File and to write it back to the final condensed
> format you need to execute
>
> ---------8<---------
> connection.executeQuery("CHECKPOINT");
> ---------8<---------
>
> at a given point or setting the size of the hsqldb.log_size-property a
> SHUTDOWN will automatically execute a CHECKPOINT.
>
> Tom
>
> [1]http://hsqldb.org/doc/guide/ch01.html#N101DB
>
> Tom Schindl schrieb:
>> IIRC hsql needs a special sql-command send at the end to release all
>> locks immediately on the files. Closing the db-connection is not enough!
>>
>> I'm going to look up some old old project code.
>>
>> Tom
>>
>> Eike Stepper schrieb:
>>> Forgot to mention that cdoSession.close() automatically closes all views
>>> and their possible queries ;-)
>>>
>>> Cheers
>>> /Eike
>>>
>>> ----
>>> http://thegordian.blogspot.com
>>>
>>>
>>>
>>> Del Myers schrieb:
>>>> Hi,
>>>>
>>>> I have a simple application in which I am storing large models into
>>>> individual databases. I am using HSQLDB for this purpose. The target
>>>> application is an Eclipse plugin, and because each model has its own
>>>> (smallish) database (rather than storing everything in one large
>>>> database), I'm starting up the databases using the JVM acceptor.
>>>>
>>>> My problem is basically the following: there are times when I would
>>>> like to delete the databases that have been created. So, I basically
>>>> want to close down all connections, and delete the database files.
>>>> But, I'm not able to do this. No matter what I do, the log file for
>>>> the database stays locked, and I can't delete it. I'm using CDO
>>>> version 1.0.8, and here are some code snippets for how the databases
>>>> are set up:
>>>>
>>>> Any help would be greatly appreciated.
>>>>
>>>> ----------------
>>>>
>>>> private void init() throws CoreException {
>>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>>> if (acceptor == null) {
>>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>>> }
>>>> if (repository == null) {
>>>> repository = createRepository();
>>>> CDOServerUtil.addRepository(container, repository);
>>>> }
>>>> if (connector == null) {
>>>> connector = JVMUtil.getConnector(container, "default");
>>>> }
>>>> if (session == null) {
>>>> CDOSessionConfiguration config =
>>>> CDOUtil.createSessionConfiguration();
>>>> config.setConnector(connector);
>>>> config.setRepositoryName(databasePath.toPortableString());
>>>> config.setLegacySupportEnabled(false);
>>>> config.setDemandPopulatingPackageRegistry();
>>>> session = config.openSession();
>>>> }
>>>> }
>>>>
>>>> private IRepository createRepository() throws CoreException {
>>>> Map<String, String> props = new HashMap<String, String>();
>>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>>> IRepository repository =
>>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>>> createStore(databasePath), props);
>>>> return repository;
>>>> }
>>>>
>>>> private IStore createStore(IPath databaseAlias) throws CoreException {
>>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>>> dataSource.setUser("sa");
>>>> dataSource.setPassword("");
>>>> dataSource.setDatabase(getDBName());
>>>> IMappingStrategy mappingStrategy =
>>>> CDODBUtil.createHorizontalMappingStrategy();
>>>> IDBStore store = CDODBUtil.createStore(
>>>> mappingStrategy,
>>>> DBUtil.getDBAdapter("hsqldb"),
>>>> DBUtil.createConnectionProvider(dataSource));
>>>> mappingStrategy.setStore(store);
>>>> this.dataSource = dataSource;
>>>> return store;
>>>> }
>>>>
>>>> public void close() {
>>>> if (view != null) {
>>>> view.close();
>>>> }
>>>> if (session != null) {
>>>> CDOView[] views = session.getViews();
>>>> for (CDOView view : views) {
>>>> view.close();
>>>> }
>>>> session.close();
>>>> }
>>>> if (connector != null) {
>>>> connector.disconnect();
>>>> }
>>>> if (dataSource != null) {
>>>> try {
>>>> if (!dataSource.getConnection().isClosed()) {
>>>> dataSource.getConnection().close();
>>>> }
>>>> } catch (SQLException e) {
>>>> DBPlugin.getDefault().log(e);
>>>> }
>>>> }
>>>>
>>>>
>>>> }
Re: [CDO] closing down a database [message #429567 is a reply to message #429561] Fri, 24 April 2009 19:49 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Del,

Good that it works!

Would you like to add a short explanation to
http://wiki.eclipse.org/FAQ_for_CDO_and_Net4j ?

Cheers
/Eike

----
http://thegordian.blogspot.com



Del Myers schrieb:
> Thanks, executing SHUTDOWN does work after I close the session.
>
> It works for my purposes because each of my models is stored in a
> separate database, and I want to delete all of the database files. I'm
> not sure that I want to file a bug about this because I imagine that,
> in most cases, client's aren't going to want to shut down the database
> after closing their sessions. Most of the time, I would expect, users
> would just want to clear their resource and commit the transaction.
>
> Del
>
> Tom Schindl wrote:
>> [Disclaimer] Maybe this is not true any more because I haven't used HSQL
>> since about 2 years.
>>
>> Hi,
>>
>> When disconnecting from HSQL you need to execute.
>>
>> ---------8<---------
>> connection.executeQuery("SHUTDOWN");
>> ---------8<---------
>>
>> => Looks this can be controled in 1.8 with a connection property [1]
>>
>> Another special thing is that HSQL while running collects all executed
>> statements in a log-File and to write it back to the final condensed
>> format you need to execute
>>
>> ---------8<---------
>> connection.executeQuery("CHECKPOINT");
>> ---------8<---------
>>
>> at a given point or setting the size of the hsqldb.log_size-property a
>> SHUTDOWN will automatically execute a CHECKPOINT.
>>
>> Tom
>>
>> [1]http://hsqldb.org/doc/guide/ch01.html#N101DB
>>
>> Tom Schindl schrieb:
>>> IIRC hsql needs a special sql-command send at the end to release all
>>> locks immediately on the files. Closing the db-connection is not
>>> enough!
>>>
>>> I'm going to look up some old old project code.
>>>
>>> Tom
>>>
>>> Eike Stepper schrieb:
>>>> Forgot to mention that cdoSession.close() automatically closes all
>>>> views
>>>> and their possible queries ;-)
>>>>
>>>> Cheers
>>>> /Eike
>>>>
>>>> ----
>>>> http://thegordian.blogspot.com
>>>>
>>>>
>>>>
>>>> Del Myers schrieb:
>>>>> Hi,
>>>>>
>>>>> I have a simple application in which I am storing large models into
>>>>> individual databases. I am using HSQLDB for this purpose. The target
>>>>> application is an Eclipse plugin, and because each model has its own
>>>>> (smallish) database (rather than storing everything in one large
>>>>> database), I'm starting up the databases using the JVM acceptor.
>>>>>
>>>>> My problem is basically the following: there are times when I would
>>>>> like to delete the databases that have been created. So, I basically
>>>>> want to close down all connections, and delete the database files.
>>>>> But, I'm not able to do this. No matter what I do, the log file for
>>>>> the database stays locked, and I can't delete it. I'm using CDO
>>>>> version 1.0.8, and here are some code snippets for how the databases
>>>>> are set up:
>>>>>
>>>>> Any help would be greatly appreciated.
>>>>>
>>>>> ----------------
>>>>>
>>>>> private void init() throws CoreException {
>>>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>>>> if (acceptor == null) {
>>>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>>>> }
>>>>> if (repository == null) {
>>>>> repository = createRepository();
>>>>> CDOServerUtil.addRepository(container, repository);
>>>>> }
>>>>> if (connector == null) {
>>>>> connector = JVMUtil.getConnector(container, "default");
>>>>> }
>>>>> if (session == null) {
>>>>> CDOSessionConfiguration config =
>>>>> CDOUtil.createSessionConfiguration();
>>>>> config.setConnector(connector);
>>>>>
>>>>> config.setRepositoryName(databasePath.toPortableString());
>>>>> config.setLegacySupportEnabled(false);
>>>>> config.setDemandPopulatingPackageRegistry();
>>>>> session = config.openSession();
>>>>> }
>>>>> }
>>>>>
>>>>> private IRepository createRepository() throws CoreException {
>>>>> Map<String, String> props = new HashMap<String, String>();
>>>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>>>> IRepository repository =
>>>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>>>> createStore(databasePath), props);
>>>>> return repository;
>>>>> }
>>>>>
>>>>> private IStore createStore(IPath databaseAlias) throws
>>>>> CoreException {
>>>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>>>> dataSource.setUser("sa");
>>>>> dataSource.setPassword("");
>>>>> dataSource.setDatabase(getDBName());
>>>>> IMappingStrategy mappingStrategy =
>>>>> CDODBUtil.createHorizontalMappingStrategy();
>>>>> IDBStore store = CDODBUtil.createStore(
>>>>> mappingStrategy,
>>>>> DBUtil.getDBAdapter("hsqldb"),
>>>>> DBUtil.createConnectionProvider(dataSource));
>>>>> mappingStrategy.setStore(store);
>>>>> this.dataSource = dataSource;
>>>>> return store; }
>>>>>
>>>>> public void close() {
>>>>> if (view != null) {
>>>>> view.close();
>>>>> }
>>>>> if (session != null) {
>>>>> CDOView[] views = session.getViews();
>>>>> for (CDOView view : views) {
>>>>> view.close();
>>>>> }
>>>>> session.close();
>>>>> }
>>>>> if (connector != null) {
>>>>> connector.disconnect();
>>>>> }
>>>>> if (dataSource != null) {
>>>>> try {
>>>>> if (!dataSource.getConnection().isClosed()) {
>>>>> dataSource.getConnection().close();
>>>>> }
>>>>> } catch (SQLException e) {
>>>>> DBPlugin.getDefault().log(e);
>>>>> }
>>>>> }
>>>>> }


Re: [CDO] closing down a database [message #429648 is a reply to message #429567] Tue, 28 April 2009 18:21 Go to previous messageGo to next message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Done!

Eike Stepper wrote:
> Del,
>
> Good that it works!
>
> Would you like to add a short explanation to
> http://wiki.eclipse.org/FAQ_for_CDO_and_Net4j ?
>
> Cheers
> /Eike
>
> ----
> http://thegordian.blogspot.com
>
>
>
> Del Myers schrieb:
>> Thanks, executing SHUTDOWN does work after I close the session.
>>
>> It works for my purposes because each of my models is stored in a
>> separate database, and I want to delete all of the database files. I'm
>> not sure that I want to file a bug about this because I imagine that,
>> in most cases, client's aren't going to want to shut down the database
>> after closing their sessions. Most of the time, I would expect, users
>> would just want to clear their resource and commit the transaction.
>>
>> Del
>>
>> Tom Schindl wrote:
>>> [Disclaimer] Maybe this is not true any more because I haven't used HSQL
>>> since about 2 years.
>>>
>>> Hi,
>>>
>>> When disconnecting from HSQL you need to execute.
>>>
>>> ---------8<---------
>>> connection.executeQuery("SHUTDOWN");
>>> ---------8<---------
>>>
>>> => Looks this can be controled in 1.8 with a connection property [1]
>>>
>>> Another special thing is that HSQL while running collects all executed
>>> statements in a log-File and to write it back to the final condensed
>>> format you need to execute
>>>
>>> ---------8<---------
>>> connection.executeQuery("CHECKPOINT");
>>> ---------8<---------
>>>
>>> at a given point or setting the size of the hsqldb.log_size-property a
>>> SHUTDOWN will automatically execute a CHECKPOINT.
>>>
>>> Tom
>>>
>>> [1]http://hsqldb.org/doc/guide/ch01.html#N101DB
>>>
>>> Tom Schindl schrieb:
>>>> IIRC hsql needs a special sql-command send at the end to release all
>>>> locks immediately on the files. Closing the db-connection is not
>>>> enough!
>>>>
>>>> I'm going to look up some old old project code.
>>>>
>>>> Tom
>>>>
>>>> Eike Stepper schrieb:
>>>>> Forgot to mention that cdoSession.close() automatically closes all
>>>>> views
>>>>> and their possible queries ;-)
>>>>>
>>>>> Cheers
>>>>> /Eike
>>>>>
>>>>> ----
>>>>> http://thegordian.blogspot.com
>>>>>
>>>>>
>>>>>
>>>>> Del Myers schrieb:
>>>>>> Hi,
>>>>>>
>>>>>> I have a simple application in which I am storing large models into
>>>>>> individual databases. I am using HSQLDB for this purpose. The target
>>>>>> application is an Eclipse plugin, and because each model has its own
>>>>>> (smallish) database (rather than storing everything in one large
>>>>>> database), I'm starting up the databases using the JVM acceptor.
>>>>>>
>>>>>> My problem is basically the following: there are times when I would
>>>>>> like to delete the databases that have been created. So, I basically
>>>>>> want to close down all connections, and delete the database files.
>>>>>> But, I'm not able to do this. No matter what I do, the log file for
>>>>>> the database stays locked, and I can't delete it. I'm using CDO
>>>>>> version 1.0.8, and here are some code snippets for how the databases
>>>>>> are set up:
>>>>>>
>>>>>> Any help would be greatly appreciated.
>>>>>>
>>>>>> ----------------
>>>>>>
>>>>>> private void init() throws CoreException {
>>>>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>>>>> if (acceptor == null) {
>>>>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>>>>> }
>>>>>> if (repository == null) {
>>>>>> repository = createRepository();
>>>>>> CDOServerUtil.addRepository(container, repository);
>>>>>> }
>>>>>> if (connector == null) {
>>>>>> connector = JVMUtil.getConnector(container, "default");
>>>>>> }
>>>>>> if (session == null) {
>>>>>> CDOSessionConfiguration config =
>>>>>> CDOUtil.createSessionConfiguration();
>>>>>> config.setConnector(connector);
>>>>>>
>>>>>> config.setRepositoryName(databasePath.toPortableString());
>>>>>> config.setLegacySupportEnabled(false);
>>>>>> config.setDemandPopulatingPackageRegistry();
>>>>>> session = config.openSession();
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> private IRepository createRepository() throws CoreException {
>>>>>> Map<String, String> props = new HashMap<String, String>();
>>>>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>>>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>>>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>>>>> IRepository repository =
>>>>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>>>>> createStore(databasePath), props);
>>>>>> return repository;
>>>>>> }
>>>>>>
>>>>>> private IStore createStore(IPath databaseAlias) throws
>>>>>> CoreException {
>>>>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>>>>> dataSource.setUser("sa");
>>>>>> dataSource.setPassword("");
>>>>>> dataSource.setDatabase(getDBName());
>>>>>> IMappingStrategy mappingStrategy =
>>>>>> CDODBUtil.createHorizontalMappingStrategy();
>>>>>> IDBStore store = CDODBUtil.createStore(
>>>>>> mappingStrategy,
>>>>>> DBUtil.getDBAdapter("hsqldb"),
>>>>>> DBUtil.createConnectionProvider(dataSource));
>>>>>> mappingStrategy.setStore(store);
>>>>>> this.dataSource = dataSource;
>>>>>> return store; }
>>>>>>
>>>>>> public void close() {
>>>>>> if (view != null) {
>>>>>> view.close();
>>>>>> }
>>>>>> if (session != null) {
>>>>>> CDOView[] views = session.getViews();
>>>>>> for (CDOView view : views) {
>>>>>> view.close();
>>>>>> }
>>>>>> session.close();
>>>>>> }
>>>>>> if (connector != null) {
>>>>>> connector.disconnect();
>>>>>> }
>>>>>> if (dataSource != null) {
>>>>>> try {
>>>>>> if (!dataSource.getConnection().isClosed()) {
>>>>>> dataSource.getConnection().close();
>>>>>> }
>>>>>> } catch (SQLException e) {
>>>>>> DBPlugin.getDefault().log(e);
>>>>>> }
>>>>>> }
>>>>>> }
Re: [CDO] closing down a database [message #429652 is a reply to message #429648] Tue, 28 April 2009 19:04 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Del Myers schrieb:
> Done!
Excellent!
Thanks a lot ;-)

One question though:
Do you think the connection that is *opened* on
store.getDBConnectionProvider().getConnection() should be closed to free
local resources?

Cheers
/Eike

----
http://thegordian.blogspot.com


>
> Eike Stepper wrote:
>> Del,
>>
>> Good that it works!
>>
>> Would you like to add a short explanation to
>> http://wiki.eclipse.org/FAQ_for_CDO_and_Net4j ?
>>
>> Cheers
>> /Eike
>>
>> ----
>> http://thegordian.blogspot.com
>>
>>
>>
>> Del Myers schrieb:
>>> Thanks, executing SHUTDOWN does work after I close the session.
>>>
>>> It works for my purposes because each of my models is stored in a
>>> separate database, and I want to delete all of the database files. I'm
>>> not sure that I want to file a bug about this because I imagine that,
>>> in most cases, client's aren't going to want to shut down the database
>>> after closing their sessions. Most of the time, I would expect, users
>>> would just want to clear their resource and commit the transaction.
>>>
>>> Del
>>>
>>> Tom Schindl wrote:
>>>> [Disclaimer] Maybe this is not true any more because I haven't used
>>>> HSQL
>>>> since about 2 years.
>>>>
>>>> Hi,
>>>>
>>>> When disconnecting from HSQL you need to execute.
>>>>
>>>> ---------8<---------
>>>> connection.executeQuery("SHUTDOWN");
>>>> ---------8<---------
>>>>
>>>> => Looks this can be controled in 1.8 with a connection property [1]
>>>>
>>>> Another special thing is that HSQL while running collects all executed
>>>> statements in a log-File and to write it back to the final condensed
>>>> format you need to execute
>>>>
>>>> ---------8<---------
>>>> connection.executeQuery("CHECKPOINT");
>>>> ---------8<---------
>>>>
>>>> at a given point or setting the size of the hsqldb.log_size-property a
>>>> SHUTDOWN will automatically execute a CHECKPOINT.
>>>>
>>>> Tom
>>>>
>>>> [1]http://hsqldb.org/doc/guide/ch01.html#N101DB
>>>>
>>>> Tom Schindl schrieb:
>>>>> IIRC hsql needs a special sql-command send at the end to release all
>>>>> locks immediately on the files. Closing the db-connection is not
>>>>> enough!
>>>>>
>>>>> I'm going to look up some old old project code.
>>>>>
>>>>> Tom
>>>>>
>>>>> Eike Stepper schrieb:
>>>>>> Forgot to mention that cdoSession.close() automatically closes all
>>>>>> views
>>>>>> and their possible queries ;-)
>>>>>>
>>>>>> Cheers
>>>>>> /Eike
>>>>>>
>>>>>> ----
>>>>>> http://thegordian.blogspot.com
>>>>>>
>>>>>>
>>>>>>
>>>>>> Del Myers schrieb:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have a simple application in which I am storing large models into
>>>>>>> individual databases. I am using HSQLDB for this purpose. The
>>>>>>> target
>>>>>>> application is an Eclipse plugin, and because each model has its
>>>>>>> own
>>>>>>> (smallish) database (rather than storing everything in one large
>>>>>>> database), I'm starting up the databases using the JVM acceptor.
>>>>>>>
>>>>>>> My problem is basically the following: there are times when I would
>>>>>>> like to delete the databases that have been created. So, I
>>>>>>> basically
>>>>>>> want to close down all connections, and delete the database files.
>>>>>>> But, I'm not able to do this. No matter what I do, the log file for
>>>>>>> the database stays locked, and I can't delete it. I'm using CDO
>>>>>>> version 1.0.8, and here are some code snippets for how the
>>>>>>> databases
>>>>>>> are set up:
>>>>>>>
>>>>>>> Any help would be greatly appreciated.
>>>>>>>
>>>>>>> ----------------
>>>>>>>
>>>>>>> private void init() throws CoreException {
>>>>>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>>>>>> if (acceptor == null) {
>>>>>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>>>>>> }
>>>>>>> if (repository == null) {
>>>>>>> repository = createRepository();
>>>>>>> CDOServerUtil.addRepository(container, repository);
>>>>>>> }
>>>>>>> if (connector == null) {
>>>>>>> connector = JVMUtil.getConnector(container, "default");
>>>>>>> }
>>>>>>> if (session == null) {
>>>>>>> CDOSessionConfiguration config =
>>>>>>> CDOUtil.createSessionConfiguration();
>>>>>>> config.setConnector(connector);
>>>>>>>
>>>>>>> config.setRepositoryName(databasePath.toPortableString());
>>>>>>> config.setLegacySupportEnabled(false);
>>>>>>> config.setDemandPopulatingPackageRegistry();
>>>>>>> session = config.openSession();
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> private IRepository createRepository() throws CoreException {
>>>>>>> Map<String, String> props = new HashMap<String, String>();
>>>>>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>>>>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>>>>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>>>>>> IRepository repository =
>>>>>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>>>>>> createStore(databasePath), props);
>>>>>>> return repository;
>>>>>>> }
>>>>>>>
>>>>>>> private IStore createStore(IPath databaseAlias) throws
>>>>>>> CoreException {
>>>>>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>>>>>> dataSource.setUser("sa");
>>>>>>> dataSource.setPassword("");
>>>>>>> dataSource.setDatabase(getDBName());
>>>>>>> IMappingStrategy mappingStrategy =
>>>>>>> CDODBUtil.createHorizontalMappingStrategy();
>>>>>>> IDBStore store = CDODBUtil.createStore(
>>>>>>> mappingStrategy,
>>>>>>> DBUtil.getDBAdapter("hsqldb"),
>>>>>>> DBUtil.createConnectionProvider(dataSource));
>>>>>>> mappingStrategy.setStore(store);
>>>>>>> this.dataSource = dataSource;
>>>>>>> return store; }
>>>>>>>
>>>>>>> public void close() {
>>>>>>> if (view != null) {
>>>>>>> view.close();
>>>>>>> }
>>>>>>> if (session != null) {
>>>>>>> CDOView[] views = session.getViews();
>>>>>>> for (CDOView view : views) {
>>>>>>> view.close();
>>>>>>> }
>>>>>>> session.close();
>>>>>>> }
>>>>>>> if (connector != null) {
>>>>>>> connector.disconnect();
>>>>>>> }
>>>>>>> if (dataSource != null) {
>>>>>>> try {
>>>>>>> if (!dataSource.getConnection().isClosed()) {
>>>>>>> dataSource.getConnection().close();
>>>>>>> }
>>>>>>> } catch (SQLException e) {
>>>>>>> DBPlugin.getDefault().log(e);
>>>>>>> }
>>>>>>> }
>>>>>>> }


Re: [CDO] closing down a database [message #429658 is a reply to message #429652] Tue, 28 April 2009 20:49 Go to previous message
Del Myers is currently offline Del MyersFriend
Messages: 82
Registered: July 2009
Member
Hmm... You are probably right that it should be closed, though I haven't needed
to. I'm guessing the HSQLDB frees everything up because it is shut down. The
connection is probably invalid from then on? I don't know though.

Del

Eike Stepper wrote:
> Del Myers schrieb:
>> Done!
> Excellent!
> Thanks a lot ;-)
>
> One question though:
> Do you think the connection that is *opened* on
> store.getDBConnectionProvider().getConnection() should be closed to free
> local resources?
>
> Cheers
> /Eike
>
> ----
> http://thegordian.blogspot.com
>
>
>> Eike Stepper wrote:
>>> Del,
>>>
>>> Good that it works!
>>>
>>> Would you like to add a short explanation to
>>> http://wiki.eclipse.org/FAQ_for_CDO_and_Net4j ?
>>>
>>> Cheers
>>> /Eike
>>>
>>> ----
>>> http://thegordian.blogspot.com
>>>
>>>
>>>
>>> Del Myers schrieb:
>>>> Thanks, executing SHUTDOWN does work after I close the session.
>>>>
>>>> It works for my purposes because each of my models is stored in a
>>>> separate database, and I want to delete all of the database files. I'm
>>>> not sure that I want to file a bug about this because I imagine that,
>>>> in most cases, client's aren't going to want to shut down the database
>>>> after closing their sessions. Most of the time, I would expect, users
>>>> would just want to clear their resource and commit the transaction.
>>>>
>>>> Del
>>>>
>>>> Tom Schindl wrote:
>>>>> [Disclaimer] Maybe this is not true any more because I haven't used
>>>>> HSQL
>>>>> since about 2 years.
>>>>>
>>>>> Hi,
>>>>>
>>>>> When disconnecting from HSQL you need to execute.
>>>>>
>>>>> ---------8<---------
>>>>> connection.executeQuery("SHUTDOWN");
>>>>> ---------8<---------
>>>>>
>>>>> => Looks this can be controled in 1.8 with a connection property [1]
>>>>>
>>>>> Another special thing is that HSQL while running collects all executed
>>>>> statements in a log-File and to write it back to the final condensed
>>>>> format you need to execute
>>>>>
>>>>> ---------8<---------
>>>>> connection.executeQuery("CHECKPOINT");
>>>>> ---------8<---------
>>>>>
>>>>> at a given point or setting the size of the hsqldb.log_size-property a
>>>>> SHUTDOWN will automatically execute a CHECKPOINT.
>>>>>
>>>>> Tom
>>>>>
>>>>> [1]http://hsqldb.org/doc/guide/ch01.html#N101DB
>>>>>
>>>>> Tom Schindl schrieb:
>>>>>> IIRC hsql needs a special sql-command send at the end to release all
>>>>>> locks immediately on the files. Closing the db-connection is not
>>>>>> enough!
>>>>>>
>>>>>> I'm going to look up some old old project code.
>>>>>>
>>>>>> Tom
>>>>>>
>>>>>> Eike Stepper schrieb:
>>>>>>> Forgot to mention that cdoSession.close() automatically closes all
>>>>>>> views
>>>>>>> and their possible queries ;-)
>>>>>>>
>>>>>>> Cheers
>>>>>>> /Eike
>>>>>>>
>>>>>>> ----
>>>>>>> http://thegordian.blogspot.com
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Del Myers schrieb:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have a simple application in which I am storing large models into
>>>>>>>> individual databases. I am using HSQLDB for this purpose. The
>>>>>>>> target
>>>>>>>> application is an Eclipse plugin, and because each model has its
>>>>>>>> own
>>>>>>>> (smallish) database (rather than storing everything in one large
>>>>>>>> database), I'm starting up the databases using the JVM acceptor.
>>>>>>>>
>>>>>>>> My problem is basically the following: there are times when I would
>>>>>>>> like to delete the databases that have been created. So, I
>>>>>>>> basically
>>>>>>>> want to close down all connections, and delete the database files.
>>>>>>>> But, I'm not able to do this. No matter what I do, the log file for
>>>>>>>> the database stays locked, and I can't delete it. I'm using CDO
>>>>>>>> version 1.0.8, and here are some code snippets for how the
>>>>>>>> databases
>>>>>>>> are set up:
>>>>>>>>
>>>>>>>> Any help would be greatly appreciated.
>>>>>>>>
>>>>>>>> ----------------
>>>>>>>>
>>>>>>>> private void init() throws CoreException {
>>>>>>>> IManagedContainer container = IPluginContainer.INSTANCE;
>>>>>>>> if (acceptor == null) {
>>>>>>>> acceptor = JVMUtil.getAcceptor(container, "default");
>>>>>>>> }
>>>>>>>> if (repository == null) {
>>>>>>>> repository = createRepository();
>>>>>>>> CDOServerUtil.addRepository(container, repository);
>>>>>>>> }
>>>>>>>> if (connector == null) {
>>>>>>>> connector = JVMUtil.getConnector(container, "default");
>>>>>>>> }
>>>>>>>> if (session == null) {
>>>>>>>> CDOSessionConfiguration config =
>>>>>>>> CDOUtil.createSessionConfiguration();
>>>>>>>> config.setConnector(connector);
>>>>>>>>
>>>>>>>> config.setRepositoryName(databasePath.toPortableString());
>>>>>>>> config.setLegacySupportEnabled(false);
>>>>>>>> config.setDemandPopulatingPackageRegistry();
>>>>>>>> session = config.openSession();
>>>>>>>> }
>>>>>>>> }
>>>>>>>>
>>>>>>>> private IRepository createRepository() throws CoreException {
>>>>>>>> Map<String, String> props = new HashMap<String, String>();
>>>>>>>> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");
>>>>>>>> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
>>>>>>>> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>>>>>>>> IRepository repository =
>>>>>>>> CDOServerUtil.createRepository(databasePath.toPortableString (),
>>>>>>>> createStore(databasePath), props);
>>>>>>>> return repository;
>>>>>>>> }
>>>>>>>>
>>>>>>>> private IStore createStore(IPath databaseAlias) throws
>>>>>>>> CoreException {
>>>>>>>> HSQLDBDataSource dataSource = new HSQLDBDataSource();
>>>>>>>> dataSource.setUser("sa");
>>>>>>>> dataSource.setPassword("");
>>>>>>>> dataSource.setDatabase(getDBName());
>>>>>>>> IMappingStrategy mappingStrategy =
>>>>>>>> CDODBUtil.createHorizontalMappingStrategy();
>>>>>>>> IDBStore store = CDODBUtil.createStore(
>>>>>>>> mappingStrategy,
>>>>>>>> DBUtil.getDBAdapter("hsqldb"),
>>>>>>>> DBUtil.createConnectionProvider(dataSource));
>>>>>>>> mappingStrategy.setStore(store);
>>>>>>>> this.dataSource = dataSource;
>>>>>>>> return store; }
>>>>>>>>
>>>>>>>> public void close() {
>>>>>>>> if (view != null) {
>>>>>>>> view.close();
>>>>>>>> }
>>>>>>>> if (session != null) {
>>>>>>>> CDOView[] views = session.getViews();
>>>>>>>> for (CDOView view : views) {
>>>>>>>> view.close();
>>>>>>>> }
>>>>>>>> session.close();
>>>>>>>> }
>>>>>>>> if (connector != null) {
>>>>>>>> connector.disconnect();
>>>>>>>> }
>>>>>>>> if (dataSource != null) {
>>>>>>>> try {
>>>>>>>> if (!dataSource.getConnection().isClosed()) {
>>>>>>>> dataSource.getConnection().close();
>>>>>>>> }
>>>>>>>> } catch (SQLException e) {
>>>>>>>> DBPlugin.getDefault().log(e);
>>>>>>>> }
>>>>>>>> }
>>>>>>>> }
Previous Topic:Re: Cannot find EMF sources (was Re: Debugging EMF in Eclipse)
Next Topic:ItemProviderAdapter implements Interfaces but doesn't declare them
Goto Forum:
  


Current Time: Tue Apr 23 11:18:24 GMT 2024

Powered by FUDForum. Page generated in 0.05102 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top