it.unimi.dico.islab.idbs2.kc.session
Class KCSessionManager

java.lang.Object
  extended by it.unimi.dico.islab.idbs2.kc.session.KCSessionManager

public class KCSessionManager
extends Object

Class for Hibernate Session automatic management. This class offers only static methods, usually protected, for Hibernate session management which are used from other classes of this package.

N.B.: All the operations executed through manager classes will be exectued referring to this class's internal session

Author:
Vegeziel

Field Summary
protected static boolean AUTO_DATABASE_COHERENCE
           
static DocumentManager dm
          DocumentManager reference, used to manage Document objects.
static KCManager kcm
          KCManager reference, used to manage KnowledgeChunk objects.
static TypeManager tym
          TypeManager reference, used to manage Type objects.
 
Method Summary
static void beginTransaction()
          Start a new transaction for the internal Session.
protected static void checkActiveTransaction()
          Check if the internal session has an active transaction, otherwise creates automatically a new transaction warning the user.
static void commitTransaction()
          Commit the internal session active transaction.
static Boolean getAutoDatabaseCoherence()
           
protected static org.hibernate.Session getInternalSession()
           
static org.hibernate.SessionFactory getSessionFactory()
          Returns an Hibernate Session Factory created for this kc model.
static org.hibernate.SessionFactory getSessionFactory(File conf)
          Same as getSessionFactory().
protected static void saveOrUpdateObject(Object obj)
          Give persistence (on relational database) to an object mapped with Hibernate using the internal Session Factory of this class.
 void setAutoDatabaseCoherence(boolean active)
          Activate/deactivate the database coherence system; this system could be useful when adding new KCs to and existing and already filled database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kcm

public static KCManager kcm
KCManager reference, used to manage KnowledgeChunk objects.


dm

public static DocumentManager dm
DocumentManager reference, used to manage Document objects.


tym

public static TypeManager tym
TypeManager reference, used to manage Type objects.


AUTO_DATABASE_COHERENCE

protected static boolean AUTO_DATABASE_COHERENCE
Method Detail

saveOrUpdateObject

protected static void saveOrUpdateObject(Object obj)

Give persistence (on relational database) to an object mapped with Hibernate using the internal Session Factory of this class. This method is defined only in this class (as it is the main class of this package) and is called by every saveOrUpdate method of other classes of this package.

Parameters:
obj - The Hibernate mapped object to be persisted.

checkActiveTransaction

protected static void checkActiveTransaction()
Check if the internal session has an active transaction, otherwise creates automatically a new transaction warning the user.


beginTransaction

public static void beginTransaction()
Start a new transaction for the internal Session.


commitTransaction

public static void commitTransaction()
Commit the internal session active transaction. This method MUST be called if some KnowledgeChuks hava been saved or modified using internal session. Otherwise the saved data won't be materialized.


getSessionFactory

public static org.hibernate.SessionFactory getSessionFactory()

Returns an Hibernate Session Factory created for this kc model. This Session Factory will be different at any call of this method and is different from the internal Session Factory used by other methods (e.g. saveOrUpdate and getKnowledgeChunkById).

This session factory is created using the config/kcDatabaseConfiguration.xml file.

Returns:
Hibernate SessionFactory

getSessionFactory

public static org.hibernate.SessionFactory getSessionFactory(File conf)
Same as getSessionFactory(). Only difference is that the configuration file the SessionFactory will be built upon is passed as argument. This method can be used to obtain new SessionFactories for databases different from the standard one.

Parameters:
conf - the configuration file in a standard xml Hibernate version.
Returns:
the created SessionFactory.

setAutoDatabaseCoherence

public void setAutoDatabaseCoherence(boolean active)

Activate/deactivate the database coherence system; this system could be useful when adding new KCs to and existing and already filled database. When activated the behavior of the addType, addTerm, and addDocument methods are changed. For better understanding we present the following example based on the addType method:

  1. The method addType is called
  2. The Primary Key of the new Type is computed
  3. The database is queried looking for an already present identical value of the key
    1. If such a key already exists, the existing type is downloaded and added to the current Knowledge Chunk
    2. Else, the new Type with the given key is created.
When the database coherence system is disabled, steps 3 and 3.1 are not executed and step 3.2 is executed as default; in this situation when an inserted type is already present for this KC on the database, a Primary Kew Violation Exception is raised.


getAutoDatabaseCoherence

public static Boolean getAutoDatabaseCoherence()
Returns:
true if the autoDatabaseCoherence system is active, false otherwise.
See Also:
for better explanation.

getInternalSession

protected static org.hibernate.Session getInternalSession()