public class BasePersistenceImpl<T extends BaseModel<T>> extends Object implements BasePersistence<T>, SessionFactory
Caching information and settings can be found in
portal.properties
Modifier and Type | Field and Description |
---|---|
protected static String |
CAST_CLOB_TEXT_OPEN |
static String |
COUNT_COLUMN_NAME |
protected int |
databaseInMaxParameters |
protected static Object[] |
FINDER_ARGS_EMPTY |
protected ModelListener<T>[] |
listeners
Deprecated.
As of Wilberforce (7.0.x), with no direct replacement
|
protected static Comparator<String> |
NULL_SAFE_STRING_COMPARATOR |
protected static com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl.NullModel |
nullModel |
protected static String |
ORDER_BY_ASC |
protected static String |
ORDER_BY_ASC_HAS_NEXT |
protected static String |
ORDER_BY_CLAUSE |
protected static String |
ORDER_BY_DESC |
protected static String |
ORDER_BY_DESC_HAS_NEXT |
protected static String |
WHERE_AND |
protected static String |
WHERE_GREATER_THAN |
protected static String |
WHERE_GREATER_THAN_HAS_NEXT |
protected static String |
WHERE_LESSER_THAN |
protected static String |
WHERE_LESSER_THAN_HAS_NEXT |
protected static String |
WHERE_OR |
Constructor and Description |
---|
BasePersistenceImpl() |
Modifier and Type | Method and Description |
---|---|
protected void |
appendOrderByComparator(StringBundler sb,
String entityAlias,
OrderByComparator<T> orderByComparator) |
protected void |
appendOrderByComparator(StringBundler sb,
String entityAlias,
OrderByComparator<T> orderByComparator,
boolean sqlQuery) |
void |
clearCache()
Clears the cache for all instances of this model.
|
void |
clearCache(List<T> model)
Clears the cache for a List instances of this model.
|
void |
clearCache(T model)
Clears the cache for one instance of this model.
|
void |
closeSession(Session session) |
long |
countWithDynamicQuery(DynamicQuery dynamicQuery)
Returns the number of rows that match the dynamic query.
|
long |
countWithDynamicQuery(DynamicQuery dynamicQuery,
Projection projection)
Returns the number of rows that match the dynamic query.
|
T |
fetchByPrimaryKey(Serializable primaryKey)
Returns the model instance with the primary key or returns
null if it could not be found. |
Map<Serializable,T> |
fetchByPrimaryKeys(Set<Serializable> primaryKeys) |
T |
findByPrimaryKey(Serializable primaryKey)
Returns the model instance with the primary key or throws a
NoSuchModelException if it could not be found. |
<V> List<V> |
findWithDynamicQuery(DynamicQuery dynamicQuery)
Performs a dynamic query on the database and returns the matching rows.
|
<V> List<V> |
findWithDynamicQuery(DynamicQuery dynamicQuery,
int start,
int end)
Performs a dynamic query on the database and returns a range of the
matching rows.
|
<V> List<V> |
findWithDynamicQuery(DynamicQuery dynamicQuery,
int start,
int end,
OrderByComparator<V> orderByComparator)
Performs a dynamic query on the database and returns an ordered range of
the matching rows.
|
void |
flush() |
Set<String> |
getBadColumnNames() |
protected ClassLoader |
getClassLoader() |
protected String |
getColumnName(String entityAlias,
String fieldName,
boolean sqlQuery) |
Set<String> |
getCompoundPKColumnNames() |
Session |
getCurrentSession() |
javax.sql.DataSource |
getDataSource()
Returns the data source for this model.
|
DB |
getDB() |
Dialect |
getDialect() |
ModelListener<T>[] |
getListeners()
Returns the listeners registered for this model.
|
Class<T> |
getModelClass() |
protected Map<String,Integer> |
getTableColumnsMap() |
Session |
openNewSession(Connection connection) |
Session |
openSession() |
SystemException |
processException(Exception e) |
void |
registerListener(ModelListener<T> listener)
Registers a new listener for this model.
|
T |
remove(Serializable primaryKey)
Removes the model instance with the primary key from the database.
|
T |
remove(T model)
Removes the model instance from the database.
|
protected static String |
removeConjunction(String sql) |
protected T |
removeImpl(T model)
Removes the model instance from the database.
|
void |
setDataSource(javax.sql.DataSource dataSource)
Sets the data source for this model.
|
protected void |
setModelClass(Class<T> modelClass) |
void |
setSessionFactory(SessionFactory sessionFactory) |
void |
unregisterListener(ModelListener<T> listener)
Unregisters the model listener.
|
T |
update(T model)
Updates the model instance in the database or adds it if it does not yet
exist.
|
T |
update(T model,
ServiceContext serviceContext)
Updates the model instance in the database or adds it if it does not yet
exist, within a different service context.
|
protected T |
updateImpl(T model)
Updates the model instance in the database or adds it if it does not yet
exist.
|
public static final String COUNT_COLUMN_NAME
protected static final String CAST_CLOB_TEXT_OPEN
protected static final Object[] FINDER_ARGS_EMPTY
protected static final Comparator<String> NULL_SAFE_STRING_COMPARATOR
protected static final String ORDER_BY_ASC
protected static final String ORDER_BY_ASC_HAS_NEXT
protected static final String ORDER_BY_CLAUSE
protected static final String ORDER_BY_DESC
protected static final String ORDER_BY_DESC_HAS_NEXT
protected static final String WHERE_AND
protected static final String WHERE_GREATER_THAN
protected static final String WHERE_GREATER_THAN_HAS_NEXT
protected static final String WHERE_LESSER_THAN
protected static final String WHERE_LESSER_THAN_HAS_NEXT
protected static final String WHERE_OR
protected static final com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl.NullModel nullModel
protected int databaseInMaxParameters
@Deprecated protected ModelListener<T extends BaseModel<T>>[] listeners
public void clearCache()
BasePersistence
The EntityCache
and FinderCache
are both cleared by this
method.
clearCache
in interface BasePersistence<T extends BaseModel<T>>
public void clearCache(List<T> model)
BasePersistence
The EntityCache
and FinderCache
are both cleared by this
method.
clearCache
in interface BasePersistence<T extends BaseModel<T>>
model
- the List instances of this model to clear the cache forpublic void clearCache(T model)
BasePersistence
The EntityCache
and FinderCache
are both cleared by this
method.
clearCache
in interface BasePersistence<T extends BaseModel<T>>
model
- the instance of this model to clear the cache forpublic void closeSession(Session session)
closeSession
in interface SessionFactory
closeSession
in interface BasePersistence<T extends BaseModel<T>>
public long countWithDynamicQuery(DynamicQuery dynamicQuery)
BasePersistence
countWithDynamicQuery
in interface BasePersistence<T extends BaseModel<T>>
dynamicQuery
- the dynamic querypublic long countWithDynamicQuery(DynamicQuery dynamicQuery, Projection projection)
BasePersistence
countWithDynamicQuery
in interface BasePersistence<T extends BaseModel<T>>
dynamicQuery
- the dynamic queryprojection
- the projection to apply to the querypublic T fetchByPrimaryKey(Serializable primaryKey)
BasePersistence
null
if it could not be found.fetchByPrimaryKey
in interface BasePersistence<T extends BaseModel<T>>
primaryKey
- the primary key of the model instancenull
if an instance of this
model with the primary key could not be foundpublic Map<Serializable,T> fetchByPrimaryKeys(Set<Serializable> primaryKeys)
fetchByPrimaryKeys
in interface BasePersistence<T extends BaseModel<T>>
public T findByPrimaryKey(Serializable primaryKey) throws NoSuchModelException
BasePersistence
NoSuchModelException
if it could not be found.findByPrimaryKey
in interface BasePersistence<T extends BaseModel<T>>
primaryKey
- the primary key of the model instanceNoSuchModelException
public <V> List<V> findWithDynamicQuery(DynamicQuery dynamicQuery)
BasePersistence
findWithDynamicQuery
in interface BasePersistence<T extends BaseModel<T>>
dynamicQuery
- the dynamic querypublic <V> List<V> findWithDynamicQuery(DynamicQuery dynamicQuery, int start, int end)
BasePersistence
Useful when paginating results. Returns a maximum of end -
start
instances. start
and end
are not
primary keys, they are indexes in the result set. Thus, 0
refers to the first result in the set. Setting both start
and end
to QueryUtil.ALL_POS
will return the full
result set.
findWithDynamicQuery
in interface BasePersistence<T extends BaseModel<T>>
dynamicQuery
- the dynamic querystart
- the lower bound of the range of matching rowsend
- the upper bound of the range of matching rows (not inclusive)QueryUtil.list(
com.liferay.portal.kernel.dao.orm.Query,
com.liferay.portal.kernel.dao.orm.Dialect, int, int)
public <V> List<V> findWithDynamicQuery(DynamicQuery dynamicQuery, int start, int end, OrderByComparator<V> orderByComparator)
BasePersistence
Useful when paginating results. Returns a maximum of end -
start
instances. start
and end
are not
primary keys, they are indexes in the result set. Thus, 0
refers to the first result in the set. Setting both start
and end
to QueryUtil.ALL_POS
will return the full
result set.
findWithDynamicQuery
in interface BasePersistence<T extends BaseModel<T>>
dynamicQuery
- the dynamic querystart
- the lower bound of the range of matching rowsend
- the upper bound of the range of matching rows (not inclusive)orderByComparator
- the comparator to order the results by
(optionally null
)public void flush()
flush
in interface BasePersistence<T extends BaseModel<T>>
public Set<String> getBadColumnNames()
getBadColumnNames
in interface BasePersistence<T extends BaseModel<T>>
public Set<String> getCompoundPKColumnNames()
public Session getCurrentSession() throws ORMException
getCurrentSession
in interface SessionFactory
getCurrentSession
in interface BasePersistence<T extends BaseModel<T>>
ORMException
public javax.sql.DataSource getDataSource()
BasePersistence
getDataSource
in interface BasePersistence<T extends BaseModel<T>>
BasePersistence.setDataSource(DataSource)
public DB getDB()
public Dialect getDialect()
getDialect
in interface SessionFactory
public ModelListener<T>[] getListeners()
BasePersistence
getListeners
in interface BasePersistence<T extends BaseModel<T>>
BasePersistence.registerListener(ModelListener)
public Class<T> getModelClass()
getModelClass
in interface BasePersistence<T extends BaseModel<T>>
public Session openNewSession(Connection connection) throws ORMException
openNewSession
in interface SessionFactory
ORMException
public Session openSession() throws ORMException
openSession
in interface SessionFactory
openSession
in interface BasePersistence<T extends BaseModel<T>>
ORMException
public SystemException processException(Exception e)
processException
in interface BasePersistence<T extends BaseModel<T>>
public void registerListener(ModelListener<T> listener)
BasePersistence
A model listener is notified whenever a change is made to an instance of this model, such as when one is added, updated, or removed.
registerListener
in interface BasePersistence<T extends BaseModel<T>>
listener
- the model listener to registerpublic T remove(Serializable primaryKey) throws NoSuchModelException
BasePersistence
remove
in interface BasePersistence<T extends BaseModel<T>>
primaryKey
- the primary key of the model instance to removeNoSuchModelException
public T remove(T model)
BasePersistence
remove
in interface BasePersistence<T extends BaseModel<T>>
model
- the model instance to removepublic void setDataSource(javax.sql.DataSource dataSource)
BasePersistence
setDataSource
in interface BasePersistence<T extends BaseModel<T>>
dataSource
- the data source to use for this modelpublic void setSessionFactory(SessionFactory sessionFactory)
public void unregisterListener(ModelListener<T> listener)
BasePersistence
unregisterListener
in interface BasePersistence<T extends BaseModel<T>>
listener
- the model listener to unregisterBasePersistence.registerListener(ModelListener)
public T update(T model)
BasePersistence
Typically not called directly, use local service update model methods
instead. For example, UserLocalServiceUtil.updateUser(
com.liferay.portal.kernel.model.User)
.
update
in interface BasePersistence<T extends BaseModel<T>>
model
- the model instance to updatepublic T update(T model, ServiceContext serviceContext)
BasePersistence
update
in interface BasePersistence<T extends BaseModel<T>>
model
- the model instance to updateserviceContext
- the service context to be appliedprotected static String removeConjunction(String sql)
protected void appendOrderByComparator(StringBundler sb, String entityAlias, OrderByComparator<T> orderByComparator)
protected void appendOrderByComparator(StringBundler sb, String entityAlias, OrderByComparator<T> orderByComparator, boolean sqlQuery)
protected ClassLoader getClassLoader()
protected String getColumnName(String entityAlias, String fieldName, boolean sqlQuery)
protected Map<String,Integer> getTableColumnsMap()
protected T removeImpl(T model)
#update(BaseModel,
boolean)
depends on this method to implement the remove operation; it
only notifies the model listeners.model
- the model instance to removeprotected void setModelClass(Class<T> modelClass)
protected T updateImpl(T model)
remove(BaseModel)
depends on this method to implement the
update operation; it only notifies the model listeners.model
- the model instance to update