com.endeca.portal.metadata
Class AbstractMetadataManager<T extends MetadataObject>

java.lang.Object
  extended by com.endeca.portal.metadata.AbstractMetadataManager<T>
Type Parameters:
T - class of the metadata object managed by this manager
All Implemented Interfaces:
MetadataManager<T>
Direct Known Subclasses:
FrameworkSettingManager, MDEXStateMetadataManager, MDEXStateVersionManager, SimpleMetadataManager

public abstract class AbstractMetadataManager<T extends MetadataObject>
extends java.lang.Object
implements MetadataManager<T>

Central facade for managing low-level Metadata Objects and Properties. Each extension of this class is responsible for managing objects of a class that implements MetadataObject.

Author:
Endeca Technologies, Inc.

Constructor Summary
AbstractMetadataManager()
           
 
Method Summary
 java.util.List<com.endeca.portal.liferay.ext.metadata.model.MetadataPropertyRecord> getMetadataPropertyRecords(MetadataPropertyQuery propertyQuery)
          Retrieves the properties for a given object.
 T getObject(MetadataObjectQuery query)
          Retrieves a Metadata Object from a Metadata Object Query.
 T getObjectById(long objectId)
          Retrieves a Metadata Object by its object ID
 java.util.List<T> getObjects(MetadataObjectQuery query)
          Retrieves a list of Metadata Objects from a Metadata Object Query
<S extends MetadataProperty>
java.util.List<S>
getProperties(MetadataPropertyQuery query)
          Retrieves a list of Metadata Properties from a Metadata Property Query
<S extends MetadataProperty>
S
getProperty(MetadataPropertyQuery query)
          Retrieves a Metadata Property from a Metadata Property Query.
 void handleObjectPropertyPersistence(T sourceObject, T returnObject)
          Processes a Metadata Object's list of Metadata Properties during persistence.
abstract  boolean hasProperties()
          Return true to indicate that this MetadataManager class works with MetadataObjects that have associated MetadataProperties.
abstract  T objectFromMetadataRecord(com.endeca.portal.liferay.ext.metadata.model.MetadataRecord record)
          Given a base Liferay record, return a Metadata Object; subclasses must implement this method.
 java.util.List<T> objectsFromMetadataRecords(java.util.List<com.endeca.portal.liferay.ext.metadata.model.MetadataRecord> records)
          Given a list of base Liferay records, return a list of Metadata Objects in the same order.
 java.util.List<T> persist(java.util.List<T> metadataObjectList)
          Writes a list of Metadata Objects to the database.
 T persist(T metadataObject)
          Persists a Metadata Object to the database
<S extends MetadataProperty>
java.util.List<S>
persistProperties(java.util.List<S> metadataPropertyList)
          Writes a list of Metadata Properties to the database.
<S extends MetadataProperty>
S
persistProperty(S metadataProperty)
          Persists a Metadata Property to the database
<S extends MetadataProperty>
java.util.List<S>
propertiesFromMetadataPropertyRecords(java.util.List<com.endeca.portal.liferay.ext.metadata.model.MetadataPropertyRecord> records)
          Given a list of base Liferay records, return a list of Metadata Properties in the same order.
abstract
<S extends MetadataProperty>
S
propertyFromMetadataPropertyRecord(com.endeca.portal.liferay.ext.metadata.model.MetadataPropertyRecord record)
          Given a base Liferay record, return a Metadata Property; subclasses must implement this method.
 void removeObjectById(long objectId)
          Removes an Metadata Object by it's unique identifier, the object ID.
 void removePropertyById(long propertyId)
          Removes an Metadata Property by it's unique identifier, the property ID
 MetadataPropertyQuery setupPropertyQuery(MetadataPropertyQuery propertyQuery)
          Called by getMetadataPropertyRecords and getProperties to massage the SQL query before execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMetadataManager

public AbstractMetadataManager()
Method Detail

getObjectById

public T getObjectById(long objectId)
Retrieves a Metadata Object by its object ID

Parameters:
objectId - the object ID
Returns:
the Metadata Object with the matching ID or null if none is found.

getObject

public T getObject(MetadataObjectQuery query)
Retrieves a Metadata Object from a Metadata Object Query. If the query retrieves more than one record, the first one will be returned.

Parameters:
query - the query
Returns:
the first Metadata Object retrieved by the query, or null if none is found.

getObjects

public java.util.List<T> getObjects(MetadataObjectQuery query)
Retrieves a list of Metadata Objects from a Metadata Object Query

Parameters:
query - the query
Returns:
a list of Metadata Objects

removeObjectById

public void removeObjectById(long objectId)
                      throws MetadataException
Removes an Metadata Object by it's unique identifier, the object ID. Also removes all properties associated with the object.

Parameters:
objectId - the object ID
Throws:
MetadataException

getProperty

public <S extends MetadataProperty> S getProperty(MetadataPropertyQuery query)
Retrieves a Metadata Property from a Metadata Property Query. If the query retrieves more than one record, the first one will be returned

Type Parameters:
S - class of the metadata property associated with the object managed by this manager
Parameters:
query - the query
Returns:
the first Metadata Property retrieved by the query, or null if none is found.

getProperties

public <S extends MetadataProperty> java.util.List<S> getProperties(MetadataPropertyQuery query)
Retrieves a list of Metadata Properties from a Metadata Property Query

Type Parameters:
S - class of the metadata property associated with the object managed by this manager
Parameters:
query - the query
Returns:
a list of Metadata Properties

removePropertyById

public void removePropertyById(long propertyId)
                        throws MetadataException
Removes an Metadata Property by it's unique identifier, the property ID

Parameters:
propertyId - the property ID
Throws:
MetadataException

persist

public T persist(T metadataObject)
                                 throws MetadataException
Persists a Metadata Object to the database

Parameters:
metadataObject - the Metadata Object representing the record to be persisted
Returns:
the persisted Metadata Object
Throws:
MetadataException - if there was an error persisting the data

persist

public java.util.List<T> persist(java.util.List<T> metadataObjectList)
                                                 throws MetadataException
Writes a list of Metadata Objects to the database. This method is not transactional: if some of the records in the list fail during the persistence operation, this will not keep the other records in the list from being saved. When this happens, a MetadataException will be thrown, the message of which will list the IDs of the objects that failed.

Parameters:
metadataObjectList - the list of Metadata Objects representing the records to be persisted
Returns:
the list persisted Metadata Objects
Throws:
MetadataException - if there was an error persisting the data

handleObjectPropertyPersistence

public void handleObjectPropertyPersistence(T sourceObject,
                                            T returnObject)
                                     throws MetadataException,
                                            com.liferay.portal.SystemException
Processes a Metadata Object's list of Metadata Properties during persistence. This method is called from persist(MetadataObject) and is intended to be overridden by subclasses for special handling of the Metadata Properties associated with the object being persisted. The default behavior is to iterate over each property, call persistProperty(MetadataProperty) and add the result of the property persistence to the return object.

Parameters:
sourceObject - the object being persisted
returnObject - the object that will be returned to the persistence caller
Throws:
MetadataException
com.liferay.portal.SystemException

persistProperty

public <S extends MetadataProperty> S persistProperty(S metadataProperty)
                                           throws MetadataException
Persists a Metadata Property to the database

Type Parameters:
S - an instance of a Metadata Property extension
Parameters:
metadataProperty - the Metadata Property representing the record to be persisted
Returns:
the persisted Metadata Property
Throws:
MetadataException - if there was an error persisting the data

persistProperties

public <S extends MetadataProperty> java.util.List<S> persistProperties(java.util.List<S> metadataPropertyList)
                                                             throws MetadataException
Writes a list of Metadata Properties to the database. This method is not transactional: if some of the records in the list fail during the persistence operation, this will not keep the other records in the list from being saved. When this happens, a MetadataException will be thrown, the message of which will list the IDs of the properties that failed.

Type Parameters:
S - an instance of a Metadata Property extension
Parameters:
metadataPropertyList - the list of Metadata Properties representing the records to be persisted
Returns:
the list persisted Metadata Properties
Throws:
MetadataException - if there was an error persisting the data

objectFromMetadataRecord

public abstract T objectFromMetadataRecord(com.endeca.portal.liferay.ext.metadata.model.MetadataRecord record)
Given a base Liferay record, return a Metadata Object; subclasses must implement this method.

Specified by:
objectFromMetadataRecord in interface MetadataManager<T extends MetadataObject>
Parameters:
record - the base Liferay record
Returns:
the Metadata Object
See Also:
MetadataManager.objectFromMetadataRecord(MetadataRecord)

objectsFromMetadataRecords

public java.util.List<T> objectsFromMetadataRecords(java.util.List<com.endeca.portal.liferay.ext.metadata.model.MetadataRecord> records)
Given a list of base Liferay records, return a list of Metadata Objects in the same order.

Parameters:
records - the list of base Liferay records
Returns:
the list of Metadata Objects

propertyFromMetadataPropertyRecord

public abstract <S extends MetadataProperty> S propertyFromMetadataPropertyRecord(com.endeca.portal.liferay.ext.metadata.model.MetadataPropertyRecord record)
Given a base Liferay record, return a Metadata Property; subclasses must implement this method.

Specified by:
propertyFromMetadataPropertyRecord in interface MetadataManager<T extends MetadataObject>
Type Parameters:
S - an instance of a Metadata Property extension
Parameters:
record - the base Liferay record
Returns:
the Metadata Property
See Also:
MetadataManager.propertyFromMetadataPropertyRecord(MetadataPropertyRecord)

hasProperties

public abstract boolean hasProperties()
Return true to indicate that this MetadataManager class works with MetadataObjects that have associated MetadataProperties. Return false to bypass the additional database queries required to work with associated MetadataProperties.

Returns:
true to work with associated properties; false to bypass associated property code paths

propertiesFromMetadataPropertyRecords

public <S extends MetadataProperty> java.util.List<S> propertiesFromMetadataPropertyRecords(java.util.List<com.endeca.portal.liferay.ext.metadata.model.MetadataPropertyRecord> records)
Given a list of base Liferay records, return a list of Metadata Properties in the same order.

Type Parameters:
S - an instance of a Metadata Property extension
Parameters:
records - the list of base Liferay records
Returns:
the list of Metadata Properties

getMetadataPropertyRecords

public java.util.List<com.endeca.portal.liferay.ext.metadata.model.MetadataPropertyRecord> getMetadataPropertyRecords(MetadataPropertyQuery propertyQuery)
                                                                                                               throws MetadataQueryException
Retrieves the properties for a given object. The incoming propertyQuery should be initialized with the parent metadataObjectID. This method can be overridden for custom implementations; for instance, the attribute sets metadata overrides this to order properties by their rel values.

Parameters:
propertyQuery -
Returns:
the list of base Liferay property records
Throws:
MetadataQueryException

setupPropertyQuery

public MetadataPropertyQuery setupPropertyQuery(MetadataPropertyQuery propertyQuery)
Called by getMetadataPropertyRecords and getProperties to massage the SQL query before execution. The query passed in as argument specifies the parent's metadataObjectID and nothing more; subclasses can override to control ordering, additional filtering, or other criteria.

Parameters:
propertyQuery - the base query
Returns:
the modified query