Liferay 7.0-ce-b4

com.liferay.portal.service.persistence.impl
Class BasePersistenceImpl<T extends BaseModel<T>>

java.lang.Object
  extended by com.liferay.portal.service.persistence.impl.BasePersistenceImpl<T>
All Implemented Interfaces:
SessionFactory, BasePersistence<T>
Direct Known Subclasses:
AccountPersistenceImpl, AddressPersistenceImpl, AnnouncementsDeliveryPersistenceImpl, AnnouncementsEntryFinderBaseImpl, AnnouncementsEntryPersistenceImpl, AnnouncementsFlagPersistenceImpl, AssetCategoryFinderBaseImpl, AssetCategoryPersistenceImpl, AssetCategoryPropertyFinderBaseImpl, AssetCategoryPropertyPersistenceImpl, AssetEntryFinderBaseImpl, AssetEntryPersistenceImpl, AssetLinkPersistenceImpl, AssetTagFinderBaseImpl, AssetTagPersistenceImpl, AssetTagStatsPersistenceImpl, AssetVocabularyFinderBaseImpl, AssetVocabularyPersistenceImpl, BlogsEntryFinderBaseImpl, BlogsEntryPersistenceImpl, BlogsStatsUserFinderBaseImpl, BlogsStatsUserPersistenceImpl, BrowserTrackerPersistenceImpl, CalEventFinderBaseImpl, CalEventPersistenceImpl, ClassNamePersistenceImpl, ClusterGroupPersistenceImpl, CompanyPersistenceImpl, ContactPersistenceImpl, CounterFinderImpl, CounterPersistenceImpl, CountryPersistenceImpl, DLContentPersistenceImpl, DLFileEntryFinderBaseImpl, DLFileEntryMetadataFinderBaseImpl, DLFileEntryMetadataPersistenceImpl, DLFileEntryPersistenceImpl, DLFileEntryTypeFinderBaseImpl, DLFileEntryTypePersistenceImpl, DLFileRankFinderBaseImpl, DLFileRankPersistenceImpl, DLFileShortcutPersistenceImpl, DLFileVersionPersistenceImpl, DLFolderFinderBaseImpl, DLFolderPersistenceImpl, DLSyncEventPersistenceImpl, EmailAddressPersistenceImpl, ExpandoColumnPersistenceImpl, ExpandoRowPersistenceImpl, ExpandoTablePersistenceImpl, ExpandoValuePersistenceImpl, ExportImportConfigurationPersistenceImpl, GroupFinderBaseImpl, GroupPersistenceImpl, ImagePersistenceImpl, LayoutBranchPersistenceImpl, LayoutFinderBaseImpl, LayoutFriendlyURLPersistenceImpl, LayoutPersistenceImpl, LayoutPrototypePersistenceImpl, LayoutRevisionPersistenceImpl, LayoutSetBranchPersistenceImpl, LayoutSetPersistenceImpl, LayoutSetPrototypePersistenceImpl, ListTypePersistenceImpl, MBBanPersistenceImpl, MBCategoryFinderBaseImpl, MBCategoryPersistenceImpl, MBDiscussionPersistenceImpl, MBMailingListPersistenceImpl, MBMessageFinderBaseImpl, MBMessagePersistenceImpl, MBStatsUserPersistenceImpl, MBThreadFinderBaseImpl, MBThreadFlagPersistenceImpl, MBThreadPersistenceImpl, MembershipRequestPersistenceImpl, OrganizationFinderBaseImpl, OrganizationPersistenceImpl, OrgGroupRolePersistenceImpl, OrgLaborPersistenceImpl, PasswordPolicyFinderBaseImpl, PasswordPolicyPersistenceImpl, PasswordPolicyRelPersistenceImpl, PasswordTrackerPersistenceImpl, PhonePersistenceImpl, PluginSettingPersistenceImpl, PortalPreferencesPersistenceImpl, PortletItemPersistenceImpl, PortletPersistenceImpl, PortletPreferencesFinderBaseImpl, PortletPreferencesPersistenceImpl, RatingsEntryFinderBaseImpl, RatingsEntryPersistenceImpl, RatingsStatsFinderBaseImpl, RatingsStatsPersistenceImpl, RecentLayoutBranchPersistenceImpl, RecentLayoutRevisionPersistenceImpl, RecentLayoutSetBranchPersistenceImpl, RegionPersistenceImpl, ReleasePersistenceImpl, RepositoryEntryPersistenceImpl, RepositoryPersistenceImpl, ResourceActionPersistenceImpl, ResourceBlockFinderBaseImpl, ResourceBlockPermissionPersistenceImpl, ResourceBlockPersistenceImpl, ResourcePermissionFinderBaseImpl, ResourcePermissionPersistenceImpl, ResourceTypePermissionFinderBaseImpl, ResourceTypePermissionPersistenceImpl, RoleFinderBaseImpl, RolePersistenceImpl, ServiceComponentFinderBaseImpl, ServiceComponentPersistenceImpl, SocialActivityAchievementPersistenceImpl, SocialActivityCounterFinderBaseImpl, SocialActivityCounterPersistenceImpl, SocialActivityFinderBaseImpl, SocialActivityLimitPersistenceImpl, SocialActivityPersistenceImpl, SocialActivitySetFinderBaseImpl, SocialActivitySetPersistenceImpl, SocialActivitySettingPersistenceImpl, SocialRelationPersistenceImpl, SocialRequestPersistenceImpl, SubscriptionPersistenceImpl, SystemEventPersistenceImpl, TeamFinderBaseImpl, TeamPersistenceImpl, TicketPersistenceImpl, TrashEntryPersistenceImpl, TrashVersionPersistenceImpl, UserFinderBaseImpl, UserGroupFinderBaseImpl, UserGroupGroupRoleFinderBaseImpl, UserGroupGroupRolePersistenceImpl, UserGroupPersistenceImpl, UserGroupRoleFinderBaseImpl, UserGroupRolePersistenceImpl, UserIdMapperPersistenceImpl, UserNotificationDeliveryPersistenceImpl, UserNotificationEventPersistenceImpl, UserPersistenceImpl, UserTrackerPathPersistenceImpl, UserTrackerPersistenceImpl, VirtualHostPersistenceImpl, WebDAVPropsPersistenceImpl, WebsitePersistenceImpl, WorkflowDefinitionLinkPersistenceImpl, WorkflowInstanceLinkPersistenceImpl

public class BasePersistenceImpl<T extends BaseModel<T>>
extends Object
implements BasePersistence<T>, SessionFactory

The base implementation for all persistence classes. This class should never need to be used directly.

Caching information and settings can be found in portal.properties


Field Summary
protected static String CAST_CLOB_TEXT_OPEN
           
static String COUNT_COLUMN_NAME
           
protected static Object[] FINDER_ARGS_EMPTY
           
protected  ModelListener<T>[] listeners
          Deprecated. As of 7.0.0, with no direct replacement
protected static Comparator<String> NULL_SAFE_STRING_COMPARATOR
           
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 Summary
BasePersistenceImpl()
           
 
Method Summary
protected  void appendOrderByComparator(StringBundler query, String entityAlias, OrderByComparator<T> orderByComparator)
           
protected  void appendOrderByComparator(StringBundler query, 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)
           
 Session getCurrentSession()
           
 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(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, boolean merge)
          Deprecated. As of 6.2.0, replaced by update(BaseModel)}
 T update(T model, boolean merge, ServiceContext serviceContext)
          Deprecated. As of 6.2.0, replaced by update(BaseModel, ServiceContext)}
 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.
protected  T updateImpl(T model, boolean merge)
          Deprecated. As of 6.2.0, replaced by updateImpl(BaseModel)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COUNT_COLUMN_NAME

public static final String COUNT_COLUMN_NAME
See Also:
Constant Field Values

CAST_CLOB_TEXT_OPEN

protected static final String CAST_CLOB_TEXT_OPEN
See Also:
Constant Field Values

FINDER_ARGS_EMPTY

protected static final Object[] FINDER_ARGS_EMPTY

NULL_SAFE_STRING_COMPARATOR

protected static final Comparator<String> NULL_SAFE_STRING_COMPARATOR

ORDER_BY_ASC

protected static final String ORDER_BY_ASC
See Also:
Constant Field Values

ORDER_BY_ASC_HAS_NEXT

protected static final String ORDER_BY_ASC_HAS_NEXT
See Also:
Constant Field Values

ORDER_BY_CLAUSE

protected static final String ORDER_BY_CLAUSE
See Also:
Constant Field Values

ORDER_BY_DESC

protected static final String ORDER_BY_DESC
See Also:
Constant Field Values

ORDER_BY_DESC_HAS_NEXT

protected static final String ORDER_BY_DESC_HAS_NEXT
See Also:
Constant Field Values

WHERE_AND

protected static final String WHERE_AND
See Also:
Constant Field Values

WHERE_GREATER_THAN

protected static final String WHERE_GREATER_THAN
See Also:
Constant Field Values

WHERE_GREATER_THAN_HAS_NEXT

protected static final String WHERE_GREATER_THAN_HAS_NEXT
See Also:
Constant Field Values

WHERE_LESSER_THAN

protected static final String WHERE_LESSER_THAN
See Also:
Constant Field Values

WHERE_LESSER_THAN_HAS_NEXT

protected static final String WHERE_LESSER_THAN_HAS_NEXT
See Also:
Constant Field Values

WHERE_OR

protected static final String WHERE_OR
See Also:
Constant Field Values

listeners

@Deprecated
protected ModelListener<T extends BaseModel<T>>[] listeners
Deprecated. As of 7.0.0, with no direct replacement
Constructor Detail

BasePersistenceImpl

public BasePersistenceImpl()
Method Detail

clearCache

public void clearCache()
Description copied from interface: BasePersistence
Clears the cache for all instances of this model.

The EntityCache and FinderCache are both cleared by this method.

Specified by:
clearCache in interface BasePersistence<T extends BaseModel<T>>

clearCache

public void clearCache(List<T> model)
Description copied from interface: BasePersistence
Clears the cache for a List instances of this model.

The EntityCache and FinderCache are both cleared by this method.

Specified by:
clearCache in interface BasePersistence<T extends BaseModel<T>>
Parameters:
model - the List instances of this model to clear the cache for

clearCache

public void clearCache(T model)
Description copied from interface: BasePersistence
Clears the cache for one instance of this model.

The EntityCache and FinderCache are both cleared by this method.

Specified by:
clearCache in interface BasePersistence<T extends BaseModel<T>>
Parameters:
model - the instance of this model to clear the cache for

closeSession

public void closeSession(Session session)
Specified by:
closeSession in interface SessionFactory
Specified by:
closeSession in interface BasePersistence<T extends BaseModel<T>>

countWithDynamicQuery

public long countWithDynamicQuery(DynamicQuery dynamicQuery)
Description copied from interface: BasePersistence
Returns the number of rows that match the dynamic query.

Specified by:
countWithDynamicQuery in interface BasePersistence<T extends BaseModel<T>>
Parameters:
dynamicQuery - the dynamic query
Returns:
the number of rows that match the dynamic query

countWithDynamicQuery

public long countWithDynamicQuery(DynamicQuery dynamicQuery,
                                  Projection projection)
Description copied from interface: BasePersistence
Returns the number of rows that match the dynamic query.

Specified by:
countWithDynamicQuery in interface BasePersistence<T extends BaseModel<T>>
Parameters:
dynamicQuery - the dynamic query
projection - the projection to apply to the query
Returns:
the number of rows that match the dynamic query

fetchByPrimaryKey

public T fetchByPrimaryKey(Serializable primaryKey)
Description copied from interface: BasePersistence
Returns the model instance with the primary key or returns null if it could not be found.

Specified by:
fetchByPrimaryKey in interface BasePersistence<T extends BaseModel<T>>
Parameters:
primaryKey - the primary key of the model instance
Returns:
the model instance, or null if an instance of this model with the primary key could not be found

fetchByPrimaryKeys

public Map<Serializable,T> fetchByPrimaryKeys(Set<Serializable> primaryKeys)
Specified by:
fetchByPrimaryKeys in interface BasePersistence<T extends BaseModel<T>>

findByPrimaryKey

public T findByPrimaryKey(Serializable primaryKey)
                                        throws NoSuchModelException
Description copied from interface: BasePersistence
Returns the model instance with the primary key or throws a NoSuchModelException if it could not be found.

Specified by:
findByPrimaryKey in interface BasePersistence<T extends BaseModel<T>>
Parameters:
primaryKey - the primary key of the model instance
Returns:
the model instance
Throws:
NoSuchModelException

findWithDynamicQuery

public <V> List<V> findWithDynamicQuery(DynamicQuery dynamicQuery)
Description copied from interface: BasePersistence
Performs a dynamic query on the database and returns the matching rows.

Specified by:
findWithDynamicQuery in interface BasePersistence<T extends BaseModel<T>>
Parameters:
dynamicQuery - the dynamic query
Returns:
the matching rows

findWithDynamicQuery

public <V> List<V> findWithDynamicQuery(DynamicQuery dynamicQuery,
                                        int start,
                                        int end)
Description copied from interface: BasePersistence
Performs a dynamic query on the database and returns a range of the matching rows.

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.

Specified by:
findWithDynamicQuery in interface BasePersistence<T extends BaseModel<T>>
Parameters:
dynamicQuery - the dynamic query
start - the lower bound of the range of matching rows
end - the upper bound of the range of matching rows (not inclusive)
Returns:
the range of matching rows
See Also:
QueryUtil.list( com.liferay.portal.kernel.dao.orm.Query, com.liferay.portal.kernel.dao.orm.Dialect, int, int)

findWithDynamicQuery

public <V> List<V> findWithDynamicQuery(DynamicQuery dynamicQuery,
                                        int start,
                                        int end,
                                        OrderByComparator<V> orderByComparator)
Description copied from interface: BasePersistence
Performs a dynamic query on the database and returns an ordered range of the matching rows.

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.

Specified by:
findWithDynamicQuery in interface BasePersistence<T extends BaseModel<T>>
Parameters:
dynamicQuery - the dynamic query
start - the lower bound of the range of matching rows
end - the upper bound of the range of matching rows (not inclusive)
orderByComparator - the comparator to order the results by (optionally null)
Returns:
the ordered range of matching rows

flush

public void flush()
Specified by:
flush in interface BasePersistence<T extends BaseModel<T>>

getBadColumnNames

public Set<String> getBadColumnNames()
Specified by:
getBadColumnNames in interface BasePersistence<T extends BaseModel<T>>

getCurrentSession

public Session getCurrentSession()
                          throws ORMException
Specified by:
getCurrentSession in interface SessionFactory
Specified by:
getCurrentSession in interface BasePersistence<T extends BaseModel<T>>
Throws:
ORMException

getDataSource

public DataSource getDataSource()
Description copied from interface: BasePersistence
Returns the data source for this model.

Specified by:
getDataSource in interface BasePersistence<T extends BaseModel<T>>
Returns:
the data source for this model
See Also:
BasePersistence.setDataSource(DataSource)

getDB

public DB getDB()

getDialect

public Dialect getDialect()
Specified by:
getDialect in interface SessionFactory

getListeners

public ModelListener<T>[] getListeners()
Description copied from interface: BasePersistence
Returns the listeners registered for this model.

Specified by:
getListeners in interface BasePersistence<T extends BaseModel<T>>
Returns:
the listeners registered for this model
See Also:
BasePersistence.registerListener(ModelListener)

getModelClass

public Class<T> getModelClass()
Specified by:
getModelClass in interface BasePersistence<T extends BaseModel<T>>

openNewSession

public Session openNewSession(Connection connection)
                       throws ORMException
Specified by:
openNewSession in interface SessionFactory
Throws:
ORMException

openSession

public Session openSession()
                    throws ORMException
Specified by:
openSession in interface SessionFactory
Specified by:
openSession in interface BasePersistence<T extends BaseModel<T>>
Throws:
ORMException

processException

public SystemException processException(Exception e)
Specified by:
processException in interface BasePersistence<T extends BaseModel<T>>

registerListener

public void registerListener(ModelListener<T> listener)
Description copied from interface: BasePersistence
Registers a new listener for this model.

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.

Specified by:
registerListener in interface BasePersistence<T extends BaseModel<T>>
Parameters:
listener - the model listener to register

remove

public T remove(Serializable primaryKey)
                              throws NoSuchModelException
Description copied from interface: BasePersistence
Removes the model instance with the primary key from the database. Also notifies the appropriate model listeners.

Specified by:
remove in interface BasePersistence<T extends BaseModel<T>>
Parameters:
primaryKey - the primary key of the model instance to remove
Returns:
the model instance that was removed
Throws:
NoSuchModelException

remove

public T remove(T model)
Description copied from interface: BasePersistence
Removes the model instance from the database. Also notifies the appropriate model listeners.

Specified by:
remove in interface BasePersistence<T extends BaseModel<T>>
Parameters:
model - the model instance to remove
Returns:
the model instance that was removed

setDataSource

public void setDataSource(DataSource dataSource)
Description copied from interface: BasePersistence
Sets the data source for this model.

Specified by:
setDataSource in interface BasePersistence<T extends BaseModel<T>>
Parameters:
dataSource - the data source to use for this model

setSessionFactory

public void setSessionFactory(SessionFactory sessionFactory)

unregisterListener

public void unregisterListener(ModelListener<T> listener)
Description copied from interface: BasePersistence
Unregisters the model listener.

Specified by:
unregisterListener in interface BasePersistence<T extends BaseModel<T>>
Parameters:
listener - the model listener to unregister
See Also:
BasePersistence.registerListener(ModelListener)

update

public T update(T model)
Description copied from interface: BasePersistence
Updates the model instance in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.

Typically not called directly, use local service update model methods instead. For example, UserLocalServiceUtil.updateUser( com.liferay.portal.model.User).

Specified by:
update in interface BasePersistence<T extends BaseModel<T>>
Parameters:
model - the model instance to update
Returns:
the model instance that was updated

update

@Deprecated
public T update(T model,
                           boolean merge)
Deprecated. As of 6.2.0, replaced by update(BaseModel)}

Specified by:
update in interface BasePersistence<T extends BaseModel<T>>

update

@Deprecated
public T update(T model,
                           boolean merge,
                           ServiceContext serviceContext)
Deprecated. As of 6.2.0, replaced by update(BaseModel, ServiceContext)}

Specified by:
update in interface BasePersistence<T extends BaseModel<T>>

update

public T update(T model,
                ServiceContext serviceContext)
Description copied from interface: BasePersistence
Updates the model instance in the database or adds it if it does not yet exist, within a different service context. Also notifies the appropriate model listeners.

Specified by:
update in interface BasePersistence<T extends BaseModel<T>>
Parameters:
model - the model instance to update
serviceContext - the service context to be applied
Returns:
the model instance that was updated

removeConjunction

protected static String removeConjunction(String sql)

appendOrderByComparator

protected void appendOrderByComparator(StringBundler query,
                                       String entityAlias,
                                       OrderByComparator<T> orderByComparator)

appendOrderByComparator

protected void appendOrderByComparator(StringBundler query,
                                       String entityAlias,
                                       OrderByComparator<T> orderByComparator,
                                       boolean sqlQuery)

getClassLoader

protected ClassLoader getClassLoader()

getColumnName

protected String getColumnName(String entityAlias,
                               String fieldName,
                               boolean sqlQuery)

getTableColumnsMap

protected Map<String,Integer> getTableColumnsMap()

removeImpl

protected T removeImpl(T model)
Removes the model instance from the database. update(BaseModel, boolean) depends on this method to implement the remove operation; it only notifies the model listeners.

Parameters:
model - the model instance to remove
Returns:
the model instance that was removed

setModelClass

protected void setModelClass(Class<T> modelClass)

updateImpl

protected T updateImpl(T model)
Updates the model instance in the database or adds it if it does not yet exist. remove(BaseModel) depends on this method to implement the update operation; it only notifies the model listeners.

Parameters:
model - the model instance to update
Returns:
the model instance that was updated

updateImpl

@Deprecated
protected T updateImpl(T model,
                                  boolean merge)
Deprecated. As of 6.2.0, replaced by updateImpl(BaseModel)


Liferay 7.0-ce-b4