|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.db.CmsSqlManager
org.opencms.db.jpa.CmsSqlManager
public class CmsSqlManager
JPA database server implementation of the SQL manager interface.
Field Summary | |
---|---|
static int |
DEFAULT_ENTITY_MANAGER_POOL_SIZE
Default pool size for EntityManager instances. |
static java.lang.String |
JPA_PERSISTENCE_UNIT
The persistence unit name in the persistence.xml file for OpenCms'es persistence classes. |
static java.lang.String |
JPA_POOL_SIZE_PROPERTY_NAME
Property name for pool size configuration. |
static java.lang.String |
KEY_DRIVER_CLASS_NAME
The fully qualified Java class name of the JDBC driver to be used. |
static java.lang.String |
KEY_INITIAL_SIZE
The initial number of connections that are created when the pool is started. |
static java.lang.String |
KEY_MAX_ACTIVE
The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit. |
static java.lang.String |
KEY_MAX_IDLE
The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit. |
static java.lang.String |
KEY_MAX_WAIT
The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely. |
static java.lang.String |
KEY_MIN_EVICTABLE_IDLE_TIME
The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any). |
static java.lang.String |
KEY_MIN_IDLE
The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none. |
static java.lang.String |
KEY_NUM_TESTS_PER_EVICTION_RUN
The number of objects to examine during each run of the idle object evictor thread (if any). |
static java.lang.String |
KEY_PASS
The connection password to be passed to our JDBC driver to establish a connection. |
static java.lang.String |
KEY_PREP_STATEMENTS
Prepared statement pooling for this pool. |
static java.lang.String |
KEY_TEST_ON_BORROW
The indication of whether objects will be validated before being borrowed from the pool. |
static java.lang.String |
KEY_TEST_WHILE_IDLE
The indication of whether objects will be validated by the idle object evictor (if any). |
static java.lang.String |
KEY_TIME_BETWEEN_EVICTION_RUNS
The number of milliseconds to sleep between runs of the idle object evictor thread. |
static java.lang.String |
KEY_URL
The connection URL to be passed to our JDBC driver to establish a connection. |
static java.lang.String |
KEY_USER
The connection username to be passed to our JDBC driver to establish a connection. |
static java.lang.String |
KEY_VALIDATION_QUERY
The SQL query that will be used to validate connections from this pool before returning them to the caller. |
protected java.util.Hashtable<java.lang.String,java.lang.String> |
m_cachedQueries
A map to cache queries with replaced search patterns. |
protected static org.apache.commons.pool.ObjectPool |
m_openCmsEmPool
Poll of EntityManager instances for OpenCms. |
protected java.util.Hashtable<java.lang.String,java.lang.String> |
m_queries
A map holding all JPQL queries. |
protected java.util.Hashtable<java.lang.String,java.lang.String> |
m_queriesWithParameters
Queries with parameters. |
protected static java.lang.String |
OFFLINE_PROJECT
The value to be replaced with for online project. |
protected static java.lang.String |
ONLINE_PROJECT
The value to be replaced with for online project. |
protected static java.lang.String |
QUERY_PROJECT_SEARCH_PATTERN
A pattern being replaced in JPQL queries to generate JPQL queries to access online/offline tables. |
protected static java.lang.String |
QUERY_PROJECT_STRING
String which indicates project parameter in the queries. |
Constructor Summary | |
---|---|
CmsSqlManager()
The constructor. |
Method Summary | ||
---|---|---|
static javax.persistence.EntityManager |
createEntityManager(java.lang.String unitName)
Create EntityManager instance for given unit name. |
|
javax.persistence.Query |
createNativeQuery(CmsDbContext dbc,
CmsUUID projectId,
java.lang.String queryKey)
Returns a Query for a EntityManagerContext specified by the key of a SQL query and the project-ID. |
|
javax.persistence.Query |
createQuery(CmsDbContext dbc,
CmsProject project,
java.lang.String queryKey)
Returns a Query for a JDBC connection specified by the key of a JPQL query and the CmsProject. |
|
javax.persistence.Query |
createQuery(CmsDbContext dbc,
CmsUUID projectId,
java.lang.String queryKey)
Returns a Query for a EntityManagerContext specified by the key of a JPQL query and the project-ID. |
|
javax.persistence.Query |
createQuery(CmsDbContext dbc,
java.lang.String queryKey)
Returns a Query for a EntityManagerContext specified by the key of a JPQL query. |
|
javax.persistence.Query |
createQueryFromJPQL(CmsDbContext dbc,
java.lang.String query)
Returns a Query for a JDBC connection specified by the JPQL query. |
|
javax.persistence.Query |
createQueryWithParametersFromJPQL(CmsDbContext dbc,
java.lang.String query,
java.util.List<java.lang.Object> params)
Returns a Query for a JDBC connection specified by the JPQL query. |
|
static void |
destroy()
Close all instances of EntityManagerFactory. |
|
|
find(CmsDbContext dbc,
java.lang.Class<T> cls,
java.lang.Object o)
Finds an object in the db and returns it. |
|
static javax.persistence.EntityManager |
getEntityManager()
Creates EntityManager from OpenCms's factory. |
|
javax.persistence.EntityManager |
getEntityManager(CmsDbContext dbc)
Returns the entity manager from the current dbc. |
|
static javax.persistence.EntityManagerFactory |
getFactory(java.lang.String unitName)
Returns EntityManagerFactory for given unit name. |
|
static CmsSqlManager |
getInstance(java.lang.String classname)
Creates a new instance of a SQL manager. |
|
static void |
init(org.apache.commons.collections.ExtendedProperties config)
Initialize the static part of the class. |
|
protected void |
loadQueryProperties(java.lang.String propertyFilename)
Loads a Java properties hash containing JPQL queries. |
|
void |
persist(CmsDbContext dbc,
java.lang.Object o)
Persists an object. |
|
java.lang.String |
readQuery(CmsProject project,
java.lang.String queryKey)
Searches for the JPQL query with the specified key and CmsProject. |
|
java.lang.String |
readQuery(CmsUUID projectId,
java.lang.String queryKey)
Searches for the JPQL query with the specified key and project-ID. |
|
java.lang.String |
readQuery(java.lang.String queryKey)
Searches for the JPQL query with the specified key. |
|
void |
remove(CmsDbContext dbc,
java.lang.Object o)
Removes an object from the db. |
|
protected void |
replaceQuerySearchPatterns()
Replaces patterns ${XXX} by another property value, if XXX is a property key with a value. |
|
static void |
returnEntityManager(javax.persistence.EntityManager em)
Returns EntityManager instance from OpenCms, back to pool. |
|
java.lang.String |
validateEmpty(java.lang.String value)
Replaces null or empty Strings with a String with one space character " " . |
Methods inherited from class org.opencms.db.CmsSqlManager |
---|
getActiveConnections, getConnection, getConnectionByUrl, getDbPoolUrls, getDefaultDbPoolName, getIdleConnections |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_ENTITY_MANAGER_POOL_SIZE
public static final java.lang.String JPA_PERSISTENCE_UNIT
public static final java.lang.String JPA_POOL_SIZE_PROPERTY_NAME
public static final java.lang.String KEY_DRIVER_CLASS_NAME
public static final java.lang.String KEY_INITIAL_SIZE
public static final java.lang.String KEY_MAX_ACTIVE
public static final java.lang.String KEY_MAX_IDLE
public static final java.lang.String KEY_MAX_WAIT
public static final java.lang.String KEY_MIN_EVICTABLE_IDLE_TIME
public static final java.lang.String KEY_MIN_IDLE
public static final java.lang.String KEY_NUM_TESTS_PER_EVICTION_RUN
public static final java.lang.String KEY_PASS
public static final java.lang.String KEY_PREP_STATEMENTS
public static final java.lang.String KEY_TEST_ON_BORROW
public static final java.lang.String KEY_TEST_WHILE_IDLE
public static final java.lang.String KEY_TIME_BETWEEN_EVICTION_RUNS
public static final java.lang.String KEY_URL
public static final java.lang.String KEY_USER
public static final java.lang.String KEY_VALIDATION_QUERY
protected static org.apache.commons.pool.ObjectPool m_openCmsEmPool
protected static final java.lang.String OFFLINE_PROJECT
protected static final java.lang.String ONLINE_PROJECT
protected static final java.lang.String QUERY_PROJECT_SEARCH_PATTERN
protected static final java.lang.String QUERY_PROJECT_STRING
protected java.util.Hashtable<java.lang.String,java.lang.String> m_cachedQueries
protected java.util.Hashtable<java.lang.String,java.lang.String> m_queries
protected java.util.Hashtable<java.lang.String,java.lang.String> m_queriesWithParameters
Constructor Detail |
---|
public CmsSqlManager() throws CmsDbException
CmsDbException
- if the manager is not initialized yetMethod Detail |
---|
public static javax.persistence.EntityManager createEntityManager(java.lang.String unitName)
unitName
- - the unit name in the persistence.xml file
public static void destroy()
public static javax.persistence.EntityManager getEntityManager()
public static javax.persistence.EntityManagerFactory getFactory(java.lang.String unitName)
unitName
- - the unit name in the persistence.xml file
public static CmsSqlManager getInstance(java.lang.String classname)
classname
- the classname of the SQL manager
public static void init(org.apache.commons.collections.ExtendedProperties config)
config
- the combined configuration of "opencms.properties" and the "persistence.xml"public static void returnEntityManager(javax.persistence.EntityManager em)
em
- - instance which returns back to pool of OpenCmsJPAPool persistence context.public javax.persistence.Query createNativeQuery(CmsDbContext dbc, CmsUUID projectId, java.lang.String queryKey)
dbc
- the the db contextprojectId
- the ID of the specified CmsProjectqueryKey
- the key of the SQL query
public javax.persistence.Query createQuery(CmsDbContext dbc, CmsProject project, java.lang.String queryKey)
dbc
- the db contextproject
- the specified CmsProjectqueryKey
- the key of the JPQL query
public javax.persistence.Query createQuery(CmsDbContext dbc, CmsUUID projectId, java.lang.String queryKey)
dbc
- the dbc contextprojectId
- the ID of the specified CmsProjectqueryKey
- the key of the JPQL query
public javax.persistence.Query createQuery(CmsDbContext dbc, java.lang.String queryKey)
dbc
- the db contextqueryKey
- the key of the JPQL query
public javax.persistence.Query createQueryFromJPQL(CmsDbContext dbc, java.lang.String query)
dbc
- the db context objectquery
- the JPQL query
public javax.persistence.Query createQueryWithParametersFromJPQL(CmsDbContext dbc, java.lang.String query, java.util.List<java.lang.Object> params)
dbc
- the db context objectquery
- the JPQL queryparams
- the parameters to insert into the query
public <T> T find(CmsDbContext dbc, java.lang.Class<T> cls, java.lang.Object o)
T
- the class to be returneddbc
- the current dbccls
- the class information of the object to be returnedo
- the object to search for
public javax.persistence.EntityManager getEntityManager(CmsDbContext dbc)
dbc
- the current dbc
public void persist(CmsDbContext dbc, java.lang.Object o)
dbc
- the current dbco
- the object to persistpublic java.lang.String readQuery(CmsProject project, java.lang.String queryKey)
project
- the specified CmsProjectqueryKey
- the key of the JPQL query
public java.lang.String readQuery(CmsUUID projectId, java.lang.String queryKey)
For projectIds ≠ 0, the pattern QUERY_PROJECT_SEARCH_PATTERN
in table names of queries is
replaced with "Online" or "Offline" to choose the right database
tables for JPQL queries that are project dependent!
projectId
- the ID of the specified CmsProjectqueryKey
- the key of the JPQL query
public java.lang.String readQuery(java.lang.String queryKey)
queryKey
- the JPQL query key
public void remove(CmsDbContext dbc, java.lang.Object o)
dbc
- the current dbco
- the object to removepublic java.lang.String validateEmpty(java.lang.String value)
" "
.
value
- the string to validate
protected void loadQueryProperties(java.lang.String propertyFilename)
propertyFilename
- the package/filename of the properties hashprotected void replaceQuerySearchPatterns()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |