Transactional conflicts

30 views
Skip to first unread message

minimalismore

unread,
Jan 14, 2014, 7:40:10 AM1/14/14
to ont...@googlegroups.com
I am creating a service that references and open stores in this manner:


private static final String CONFIG_FILE_PATH = "/path..../tm-sources.xml";
private static final String TOPICMAP_REFERENCE_KEY = "NdlaTopicsService";

<?xml version="1.0"?>
<repository>
    <source class="net.ontopia.topicmaps.impl.rdbms.RDBMSSingleTopicMapSource">
        <param name="propertyFile"
               value="/usr/local/ontopia/rdbms/config/db.postgresql.props"/>
        <param name="topicMapId" value="M1" />
        <param name="referenceId" value="NdlaTopicsService" />
        <param name="title" value="NDLA Topics Service"/>
    </source>
</repository>


db.postgresql.props: 

net.ontopia.topicmaps.impl.rdbms.ConnectionString=jdbc:postgresql://localhost/ontopia
net.ontopia.topicmaps.impl.rdbms.DriverClass=org.postgresql.Driver
........
net.ontopia.topicmaps.impl.rdbms.ConnectionPool=true

public TopicService((final String configFile, final String topicmapReferenceKey){

      TopicMapRepositoryIF repository = XMLConfigSource.getRepository(configFile);
        TopicMapStoreIF store = null;

        _reference = repository.getReferenceByKey(topicmapReferenceKey);
        try {
            store = _reference.createStore(false);
            _topicMap = store.getTopicMap(); // Implicit opening of the topic map store.
        } catch (IOException e) {
            throw new ServiceException(e.getMessage());
        } finally {
            if ((store != null) && (store.isOpen())) {
                store.close();
            }
        }

when doing either tolog queries or interacting with the API methods we do:

TopicMapStoreIF store = _reference.createStore(false);
            if (!store.isOpen()) {
                store.open();
            }

The question is  if it is expected behaviour for getItemIdentifiers and getSubjectIdentifiers (and related) methods for objects of type TopicIF to fail if a store is not open?


Thanx, Rolf

Quintin Siebers

unread,
Feb 20, 2014, 6:56:18 AM2/20/14
to Ontopia Mailing List
Dear Rolf,

The question is  if it is expected behaviour for getItemIdentifiers and getSubjectIdentifiers (and related) methods for objects of type TopicIF to fail if a store is not open?

Without digging into the code, I'd say they might fail if the store is not open. The identifiers will have to be retrieved from the underlying database unless the store has them cached. This retrieval can only be done on an open store.

I think your problem lies more in the use of the stores. Two points on that:

1) In all my days using Ontopia, I've never manually called store.open() or even isOpen(). The general case I always use is:

TopicMapStoreIF store = null;
try {
store = reference.createStore( {readonly?} );
TopicMapIF topicmap = store.getTopicMap();
// do something with topicmap

// store.commit() if changes were made on an rw-store
} catch (IOException ioe) {
// something went wrong opening the store
} finally {
if (store != null) store.close();
}

The reference.createStore() should take care of opening the store and the store.close() should notify the store-pooling mechanism that the store is available for other use again.

2) Am I right to infer that you are caching the '_topicMap' object? If so, you shouldn't. The TopicMapStoreIF works like a transaction, and the TopicMapIF that you get from it is bound to it. Using the TopicMapIF (or any other topicmap object like TopicIF) after you closed the store will result in errors.
In most situations, caching the TopicMapReferenceIF works best. Then use the code above whenever you need to execute an action/query on the topicmap.

With regards,

Quintin Siebers

--
(+31) (0)6 - 11 06 16 27


Morpheus Kennistechnologie BV
<URL: http://www.mssm.nl >
postbus 69
3500 CD Utrecht
KVK 30 26 04 30

--
You received this message because you are subscribed to the Google Groups "ontopia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ontopia+u...@googlegroups.com.
To post to this group, send email to ont...@googlegroups.com.
Visit this group at http://groups.google.com/group/ontopia.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages