de.topicmapslab.majortom.importer
Class PostgresMapHandler

java.lang.Object
  extended by de.topicmapslab.majortom.importer.PostgresMapHandler
All Implemented Interfaces:
IHandler

public class PostgresMapHandler
extends java.lang.Object
implements IHandler

Author:
Hannes Niederhausen

Field Summary
private  Sql99QueryBuilder builder
           
private  java.sql.Connection connection
           
private static org.slf4j.Logger logger
           
private  PostGreSqlConnectionProvider provider
           
private  PostGreSqlSession session
           
private  java.util.Map<java.lang.String,java.lang.Long> topicCache
           
private  java.lang.Long topicMapId
           
 
Constructor Summary
PostgresMapHandler()
          Constructor
PostgresMapHandler(java.util.Properties properties)
          Constructor
 
Method Summary
 void addAssociation(Association assoc)
          Adds the given association to the database.
 void addIdentifier(long topicId, java.lang.String ref, int type)
          adds an identifier
 void addName(Name name)
          Adds a name to the topic map
 void addOccurrence(Occurrence occurrence)
          Adds an occurrence
private  void addReifier(long id, com.semagia.mio.IRef reifierRef)
          Adds a reifier
private  void addRole(long assocID, Role role)
          Adds a role to the association
 void addType(long currTopicId, com.semagia.mio.IRef arg0)
          Adds a type to the topic with the given id
private  void addVariant(long id, Variant variant)
           
 void commit()
          Commits the last statements
private  long createTopic(com.semagia.mio.IRef ref)
           
 void end()
          Closes the connection
private  long getScopeId(java.util.List<com.semagia.mio.IRef> themes)
           
 long getTopic(com.semagia.mio.IRef ref)
          Returns the topic id for the given identifier.
 long getTopicMapId(java.lang.String locator)
          Returns the id of the topic map for the given locator.
private  void init(java.util.Properties properties)
           
 void start()
          Handler for start event prepareing the connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.slf4j.Logger logger

provider

private PostGreSqlConnectionProvider provider

session

private PostGreSqlSession session

topicMapId

private java.lang.Long topicMapId

builder

private Sql99QueryBuilder builder

connection

private java.sql.Connection connection

topicCache

private java.util.Map<java.lang.String,java.lang.Long> topicCache
Constructor Detail

PostgresMapHandler

public PostgresMapHandler()
                   throws com.semagia.mio.MIOException
Constructor

Throws:
java.sql.SQLException
com.semagia.mio.MIOException

PostgresMapHandler

public PostgresMapHandler(java.util.Properties properties)
                   throws com.semagia.mio.MIOException
Constructor

Throws:
java.sql.SQLException
com.semagia.mio.MIOException
Method Detail

init

private void init(java.util.Properties properties)
           throws com.semagia.mio.MIOException
Throws:
com.semagia.mio.MIOException

commit

public void commit()
            throws com.semagia.mio.MIOException
Commits the last statements

Specified by:
commit in interface IHandler
Throws:
com.semagia.mio.MIOException

start

public void start()
           throws com.semagia.mio.MIOException
Handler for start event prepareing the connection

Specified by:
start in interface IHandler
Throws:
com.semagia.mio.MIOException

end

public void end()
         throws com.semagia.mio.MIOException
Closes the connection

Specified by:
end in interface IHandler
Throws:
com.semagia.mio.MIOException

getTopicMapId

public long getTopicMapId(java.lang.String locator)
                   throws com.semagia.mio.MIOException
Returns the id of the topic map for the given locator. If it does not exist it will be created.

Specified by:
getTopicMapId in interface IHandler
Parameters:
locator - locator of the tm
Returns:
the id of the tm
Throws:
com.semagia.mio.MIOException

addAssociation

public void addAssociation(Association assoc)
                    throws com.semagia.mio.MIOException
Adds the given association to the database.

Specified by:
addAssociation in interface IHandler
Parameters:
assoc -
Throws:
com.semagia.mio.MIOException

addRole

private void addRole(long assocID,
                     Role role)
              throws com.semagia.mio.MIOException
Adds a role to the association

Parameters:
assocID - the id of the parent association
role - the role helper
Throws:
com.semagia.mio.MIOException

addName

public void addName(Name name)
             throws com.semagia.mio.MIOException
Adds a name to the topic map

Specified by:
addName in interface IHandler
Parameters:
name -
Throws:
com.semagia.mio.MIOException

addOccurrence

public void addOccurrence(Occurrence occurrence)
                   throws com.semagia.mio.MIOException
Adds an occurrence

Specified by:
addOccurrence in interface IHandler
Parameters:
occurrence -
Throws:
com.semagia.mio.MIOException

getTopic

public long getTopic(com.semagia.mio.IRef ref)
              throws com.semagia.mio.MIOException
Returns the topic id for the given identifier. It it isn't in the db, it will be created.

Specified by:
getTopic in interface IHandler
Parameters:
ref - the identifier of the topic
Returns:
the id of the topic
Throws:
com.semagia.mio.MIOException

addIdentifier

public void addIdentifier(long topicId,
                          java.lang.String ref,
                          int type)
                   throws com.semagia.mio.MIOException
adds an identifier

Specified by:
addIdentifier in interface IHandler
Parameters:
topicId - id of the topic
ref - the uri
type - the type of identifier
Throws:
com.semagia.mio.MIOException

addType

public void addType(long currTopicId,
                    com.semagia.mio.IRef arg0)
             throws com.semagia.mio.MIOException
Adds a type to the topic with the given id

Specified by:
addType in interface IHandler
Parameters:
currTopicId - the current topic id
arg0 - the reference of the typing topic
Throws:
com.semagia.mio.MIOException

createTopic

private long createTopic(com.semagia.mio.IRef ref)

getScopeId

private long getScopeId(java.util.List<com.semagia.mio.IRef> themes)
                 throws com.semagia.mio.MIOException
Throws:
com.semagia.mio.MIOException

addVariant

private void addVariant(long id,
                        Variant variant)
                 throws com.semagia.mio.MIOException
Throws:
com.semagia.mio.MIOException

addReifier

private void addReifier(long id,
                        com.semagia.mio.IRef reifierRef)
                 throws com.semagia.mio.MIOException
Adds a reifier

Parameters:
id - reifiable id
reifierRef - the ref to the reifier topic
Throws:
com.semagia.mio.MIOException