|
||||||||
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 String |
JPA_PERSISTENCE_UNIT
The persistence unit name in the persistence.xml file for OpenCms'es persistence classes. |
static String |
JPA_POOL_SIZE_PROPERTY_NAME
Property name for pool size configuration. |
static String |
KEY_DRIVER_CLASS_NAME
The fully qualified Java class name of the JDBC driver to be used. |
static String |
KEY_INITIAL_SIZE
The initial number of connections that are created when the pool is started. |
static 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 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 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 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 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 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 String |
KEY_PASS
The connection password to be passed to our JDBC driver to establish a connection. |
static String |
KEY_PREP_STATEMENTS
Prepared statement pooling for this pool. |
static String |
KEY_TEST_ON_BORROW
The indication of whether objects will be validated before being borrowed from the pool. |
static String |
KEY_TEST_WHILE_IDLE
The indication of whether objects will be validated by the idle object evictor (if any). |
static String |
KEY_TIME_BETWEEN_EVICTION_RUNS
The number of milliseconds to sleep between runs of the idle object evictor thread. |
static String |
KEY_URL
The connection URL to be passed to our JDBC driver to establish a connection. |
static String |
KEY_USER
The connection username to be passed to our JDBC driver to establish a connection. |
static String |
KEY_VALIDATION_QUERY
The SQL query that will be used to validate connections from this pool before returning them to the caller. |
protected Hashtable<String,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 Hashtable<String,String> |
m_queries
A map holding all JPQL queries. |
protected Hashtable<String,String> |
m_queriesWithParameters
Queries with parameters. |
protected static String |
OFFLINE_PROJECT
The value to be replaced with for online project. |
protected static String |
ONLINE_PROJECT
The value to be replaced with for online project. |
protected static String |
QUERY_PROJECT_SEARCH_PATTERN
A pattern being replaced in JPQL queries to generate JPQL queries to access online/offline tables. |
protected static String |
QUERY_PROJECT_STRING
String which indicates project parameter in the queries. |
Constructor Summary | |
---|---|
CmsSqlManager()
The constructor. |
Method Summary | ||
---|---|---|
static javax.persistence.EntityManager |
createEntityManager(String unitName)
Create EntityManager instance for given unit name. |
|
javax.persistence.Query |
createNativeQuery(CmsDbContext dbc,
CmsUUID projectId,
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,
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,
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,
String queryKey)
Returns a Query for a EntityManagerContext specified by the key of a JPQL query. |
|
javax.persistence.Query |
createQueryFromJPQL(CmsDbContext dbc,
String query)
Returns a Query for a JDBC connection specified by the JPQL query. |
|
javax.persistence.Query |
createQueryWithParametersFromJPQL(CmsDbContext dbc,
String query,
List<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,
Class<T> cls,
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(String unitName)
Returns EntityManagerFactory for given unit name. |
|
static CmsSqlManager |
getInstance(String classname)
Creates a new instance of a SQL manager. |
|
static void |
init(CmsParameterConfiguration config)
Initialize the static part of the class. |
|
protected void |
loadQueryProperties(String propertyFilename)
Loads a Java properties hash containing JPQL queries. |
|
void |
persist(CmsDbContext dbc,
Object o)
Persists an object. |
|
String |
readQuery(CmsProject project,
String queryKey)
Searches for the JPQL query with the specified key and CmsProject. |
|
String |
readQuery(CmsUUID projectId,
String queryKey)
Searches for the JPQL query with the specified key and project-ID. |
|
String |
readQuery(String queryKey)
Searches for the JPQL query with the specified key. |
|
void |
remove(CmsDbContext dbc,
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. |
|
String |
validateEmpty(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 String JPA_PERSISTENCE_UNIT
public static final String JPA_POOL_SIZE_PROPERTY_NAME
public static final String KEY_DRIVER_CLASS_NAME
public static final String KEY_INITIAL_SIZE
public static final String KEY_MAX_ACTIVE
public static final String KEY_MAX_IDLE
public static final String KEY_MAX_WAIT
public static final String KEY_MIN_EVICTABLE_IDLE_TIME
public static final String KEY_MIN_IDLE
public static final String KEY_NUM_TESTS_PER_EVICTION_RUN
public static final String KEY_PASS
public static final String KEY_PREP_STATEMENTS
public static final String KEY_TEST_ON_BORROW
public static final String KEY_TEST_WHILE_IDLE
public static final String KEY_TIME_BETWEEN_EVICTION_RUNS
public static final String KEY_URL
public static final String KEY_USER
public static final String KEY_VALIDATION_QUERY
protected static org.apache.commons.pool.ObjectPool m_openCmsEmPool
protected static final String OFFLINE_PROJECT
protected static final String ONLINE_PROJECT
protected static final String QUERY_PROJECT_SEARCH_PATTERN
protected static final String QUERY_PROJECT_STRING
protected Hashtable<String,String> m_cachedQueries
protected Hashtable<String,String> m_queries
protected Hashtable<String,String> m_queriesWithParameters
Constructor Detail |
---|
public CmsSqlManager() throws CmsDbException
CmsDbException
- if the manager is not initialized yetMethod Detail |
---|
public static javax.persistence.EntityManager createEntityManager(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(String unitName)
unitName
- - the unit name in the persistence.xml file
public static CmsSqlManager getInstance(String classname)
classname
- the classname of the SQL manager
public static void init(CmsParameterConfiguration 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, 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, String queryKey)
dbc
- the db contextproject
- the specified CmsProjectqueryKey
- the key of the JPQL query
public javax.persistence.Query createQuery(CmsDbContext dbc, CmsUUID projectId, 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, String queryKey)
dbc
- the db contextqueryKey
- the key of the JPQL query
public javax.persistence.Query createQueryFromJPQL(CmsDbContext dbc, String query)
dbc
- the db context objectquery
- the JPQL query
public javax.persistence.Query createQueryWithParametersFromJPQL(CmsDbContext dbc, String query, List<Object> params)
dbc
- the db context objectquery
- the JPQL queryparams
- the parameters to insert into the query
public <T> T find(CmsDbContext dbc, Class<T> cls, 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, Object o)
dbc
- the current dbco
- the object to persistpublic String readQuery(CmsProject project, String queryKey)
project
- the specified CmsProjectqueryKey
- the key of the JPQL query
public String readQuery(CmsUUID projectId, 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 String readQuery(String queryKey)
queryKey
- the JPQL query key
public void remove(CmsDbContext dbc, Object o)
dbc
- the current dbco
- the object to removepublic String validateEmpty(String value)
" "
.
value
- the string to validate
protected void loadQueryProperties(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 |