org.ujorm.orm
Class OrmHandler

java.lang.Object
  extended by org.ujorm.orm.OrmHandler
All Implemented Interfaces:
OrmHandlerProvider

public class OrmHandler
extends Object
implements OrmHandlerProvider

The basic class for an ORM support.


Constructor Summary
OrmHandler()
          The constructor
OrmHandler(Class<UJO>... databaseModels)
          The constructor with a database metamodel initialization.
OrmHandler(Class<UJO> databaseModel)
          The constructor with a database metamodel initialization.
 
Method Summary
 void addColumnModel(MetaRelation2Many column)
          Map a key to the table
 void addProcedureModel(MetaProcedure metaProcedure)
          Map a key to the table
 void addTableModel(MetaTable metaTable)
          Map a key to the table
<UJO extends OrmUjo>
AliasTable<UJO>
alias(Class<UJO> entity, String alias)
          Deprecated. 
 void config(MetaParams params)
          Save the ORM parameters.
 void config(MetaRoot config)
          Save the alternative ORM configuration including parameters (if the parameters are not null).
 boolean config(String url)
          Load parameters from an external XML file.
 boolean config(URL url, boolean throwsException)
          Load parameters from an external XML file.
 Session createSession()
          Create new session
<T extends Annotation>
T
findAnnotation(Key<?,?> key, Class<T> annotation)
          Find a key annotation by the required type.
<T extends MetaRelation2Many>
T
findColumnModel(Key pathProperty)
          Find a Relation/Column model of the paramemeter key.
<T extends MetaRelation2Many>
T
findColumnModel(Key pathProperty, boolean throwException)
          Find a Relation/Column model of the paramemeter key.
 MetaProcedure findProcedureModel(Class<? extends DbProcedure> procedureClass)
          Find a procedure model by the procedureClass.
 List<Key> findPropertiesByType(Class type)
          Find all persistent keys with the required type or subtype.
 MetaTable findTableModel(Class<? extends OrmUjo> dbClass)
          Find a tableOf model by the dbClass.
 String getConfig()
          Returns a final meta-model in the XML format
 List<MetaDatabase> getDatabases()
          Returns all database
 Session getDefaultSession()
          Get a default Session of the OrmHandler.
 OrmHandler getOrmHandler()
          Returns the same instance
 MetaParams getParameters()
          Returns parameters
 Session getSession()
          Deprecated. Method was replaced by the name getDefaultSession()
 boolean isDatabaseLoaded()
          Returns true, if a database meta-model is loaded.
 boolean isPersistent(Key key)
          Is the parameter a persistent key?
 boolean isReadOnly()
          Do the handler have a read-only state?
<UJO extends OrmUjo>
void
loadDatabase(Class<UJO>... databaseModel)
          Load a meta-data, lock it and create database tables.
<UJO extends OrmUjo>
void
loadDatabase(Class<UJO> databaseModel)
          Load a meta-data, lock it and create database tables.
<UJO extends OrmUjo>
AliasTable<UJO>
tableOf(Class<UJO> entity)
          Create a new instance of the class AliasTable
<UJO extends OrmUjo>
AliasTable<UJO>
tableOf(Class<UJO> entity, String alias)
          Create a new instance of the class AliasTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OrmHandler

public OrmHandler()
The constructor


OrmHandler

public OrmHandler(Class<UJO> databaseModel)
The constructor with a database metamodel initialization.


OrmHandler

public OrmHandler(Class<UJO>... databaseModels)
The constructor with a database metamodel initialization.

Method Detail

getDefaultSession

public Session getDefaultSession()
Get a default Session of the OrmHandler. On a multi-thread application use a method createSession() rather.

See Also:
createSession()

getSession

public Session getSession()
Deprecated. Method was replaced by the name getDefaultSession()

Get a default Session of the OrmHandler. On a multi-thread application use a method createSession() rather.

See Also:
createSession()

createSession

public Session createSession()
Create new session


config

public boolean config(String url)
               throws IllegalArgumentException
Load parameters from an external XML file. The initialization must be finished before an ORM definition loading.
Note: in case the parameter starts by the character tilde '~' than the symbol is replaced by a local home directory. See some valid parameter examples:

Throws:
IllegalArgumentException

config

public void config(MetaParams params)
            throws IllegalArgumentException
Save the ORM parameters. The assigning must be finished before an ORM definition loading.

Throws:
IllegalArgumentException

config

public void config(MetaRoot config)
            throws IllegalArgumentException
Save the alternative ORM configuration including parameters (if the parameters are not null). The assigning must be finished before an ORM definition loading.

Throws:
IllegalArgumentException

config

public boolean config(URL url,
                      boolean throwsException)
               throws IllegalArgumentException
Load parameters from an external XML file. The initialization must be finished before an ORM definition loading.

Throws:
IllegalArgumentException

isPersistent

public boolean isPersistent(Key key)
Is the parameter a persistent key?


loadDatabase

public final <UJO extends OrmUjo> void loadDatabase(Class<UJO> databaseModel)
Load a meta-data, lock it and create database tables. There is not allowed to make any change to the created meta-model.


loadDatabase

public final <UJO extends OrmUjo> void loadDatabase(Class<UJO>... databaseModel)
Load a meta-data, lock it and create database tables. There is not allowed to make any change to the created meta-model.


isReadOnly

public boolean isReadOnly()
Do the handler have a read-only state?


addProcedureModel

public void addProcedureModel(MetaProcedure metaProcedure)
Map a key to the table


addTableModel

public void addTableModel(MetaTable metaTable)
Map a key to the table


addColumnModel

public void addColumnModel(MetaRelation2Many column)
Map a key to the table


findAnnotation

public <T extends Annotation> T findAnnotation(Key<?,?> key,
                                               Class<T> annotation)
Find a key annotation by the required type.

Parameters:
key - The key must be a public static final field of the related Ujo class.
annotation - Annotation type
Returns:
An annotation instance or the null value

findColumnModel

public final <T extends MetaRelation2Many> T findColumnModel(Key pathProperty)
Find a Relation/Column model of the paramemeter key. The column result is type of MetaColumn.

Parameters:
pathProperty - Parameter can be type of Key of CompositeKey (direct or indirect);
Returns:
Returns an object type of MetaColumn for database column or a related model type of MetaRelation2Many or the NULL if no model was found.

findColumnModel

public <T extends MetaRelation2Many> T findColumnModel(Key pathProperty,
                                                       boolean throwException)
                                            throws IllegalArgumentException
Find a Relation/Column model of the paramemeter key. The column result is type of MetaColumn.

Parameters:
pathProperty - Parameter can be type of Property of CompositeKey (direct or indirect);
throwException - Throw the IllegalArgument exception of no Model was not found
Returns:
Returns an object type of MetaColumn for database column or a related model type of MetaRelation2Many or the NULL if no model was found.
Throws:
IllegalArgumentException

findTableModel

public MetaTable findTableModel(Class<? extends OrmUjo> dbClass)
                         throws IllegalStateException
Find a tableOf model by the dbClass. If the tableOf model is not found then the IllegalStateException is throwed.

Throws:
IllegalStateException

findProcedureModel

public MetaProcedure findProcedureModel(Class<? extends DbProcedure> procedureClass)
                                 throws IllegalStateException
Find a procedure model by the procedureClass. If the procedure model is not found then the IllegalStateException is throwed.

Throws:
IllegalStateException

getParameters

public MetaParams getParameters()
Returns parameters


isDatabaseLoaded

public boolean isDatabaseLoaded()
Returns true, if a database meta-model is loaded.


getDatabases

public List<MetaDatabase> getDatabases()
Returns all database


findPropertiesByType

public List<Key> findPropertiesByType(Class type)
Find all persistent keys with the required type or subtype.

Parameters:
type - The parameter value Object.clas returns all persistent keys.

getConfig

public String getConfig()
Returns a final meta-model in the XML format


getOrmHandler

public OrmHandler getOrmHandler()
Returns the same instance

Specified by:
getOrmHandler in interface OrmHandlerProvider

tableOf

public <UJO extends OrmUjo> AliasTable<UJO> tableOf(Class<UJO> entity,
                                                    String alias)
Create a new instance of the class AliasTable


tableOf

public <UJO extends OrmUjo> AliasTable<UJO> tableOf(Class<UJO> entity)
Create a new instance of the class AliasTable


alias

@Deprecated
public <UJO extends OrmUjo> AliasTable<UJO> alias(Class<UJO> entity,
                                                             String alias)
Deprecated. 

Create a new instance of the class AliasTable. Use the new method tableOf(java.lang.Class, java.lang.String) rather



Copyright 2013, Pavel Ponec