org.usergrid.persistence.EntityManager Maven / Gradle / Ivy
Show all versions of usergrid-core Show documentation
/*******************************************************************************
* Copyright 2012 Apigee Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.usergrid.persistence;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.usergrid.persistence.cassandra.GeoIndexManager;
import org.usergrid.persistence.entities.Application;
import org.usergrid.persistence.entities.Role;
/**
* The interface class for the data access object for Applications. Each
* application contains a set of users as well as a hierarchy of groups. A
* application also includes a set of message inboxes and a set of assets.
*/
public interface EntityManager {
public void setApplicationId(UUID applicationId);
public GeoIndexManager getGeoIndexManager();
public EntityRef getApplicationRef();
public Application getApplication() throws Exception;
public void updateApplication(Application app) throws Exception;
public void updateApplication(Map properties)
throws Exception;
public RelationManager getRelationManager(EntityRef entityRef);
/**
* Get all collections for the application. Includes both user defined
* collections and schema collections
*
* @return
* @throws Exception
*/
public Set getApplicationCollections() throws Exception;
public Map getApplicationCollectionMetadata()
throws Exception;
public long getApplicationCollectionSize(String collectionName)
throws Exception;
/**
* Creates an entity of the specified type attached to the specified
* application.
*
* @param type
* the type of the entity to create.
* @param properties
* property values to create in the new entity or null.
* @return the newly created entity object.
*
* @throws Exception
*/
public Entity create(String entityType, Map properties)
throws Exception;
public A create(String entityType, Class entityClass,
Map properties) throws Exception;
public A create(A entity) throws Exception;
/**
* Creates an entity of the specified type attached to the specified
* application.
*
* @param importId
* the UUID to assign to the imported entity
* @param type
* the type of the entity to create.
* @param properties
* property values to create in the new entity or null.
* @return the newly created entity object.
* @throws Exception
* the exception
*/
public Entity create(UUID importId, String entityType,
Map properties) throws Exception;
public void createApplicationCollection(String entityType) throws Exception;
// public UUID createAlias(UUID id, String aliasType, String alias)
// throws Exception;
//
// public UUID createAlias(EntityRef ref, String aliasType, String alias)
// throws Exception;
// public UUID createAlias(UUID ownerId, EntityRef ref, String aliasType,
// String alias) throws Exception;
public void deleteAlias(String aliasType, String alias) throws Exception;
public void deleteAlias(UUID ownerId, String aliasType, String alias)
throws Exception;
public EntityRef getAlias(String aliasType, String alias) throws Exception;
public EntityRef getAlias(UUID ownerId, String aliasType, String alias)
throws Exception;
public Map getAlias(String aliasType,
List aliases) throws Exception;
public Map getAlias(UUID ownerId, String aliasType,
List aliases) throws Exception;
/**
* Validates that the entity exists in the datastore meaning that it exists
* and the type has been loaded if not already provided.
*
* @param EntityRef
*
* @return an validated EntityRef or null.
*
* @throws Exception
*/
public EntityRef validate(EntityRef entityRef) throws Exception;
public String getType(UUID entityId) throws Exception;
public EntityRef getRef(UUID entityId) throws Exception;
public Entity get(UUID entityId) throws Exception;
/**
* Retrieves the entity for the specified entity reference.
*
* @param entity
* an Entity reference
*
* @return an Entity object for the specified entity reference.
*
* @throws Exception
*/
public Entity get(EntityRef entityRef) throws Exception;
public A get(UUID entityId, Class entityClass)
throws Exception;
/**
* Retrieves a set of Entities. Will return an Entity object containing all
* of the entity's name/value properties and properties. For large numbers
* of entities, retrieving the properties can have additional overhead,
* passing false for includeProperties can result in better performance.
*
* This method will be deprecated in future releases in favor of a version
* that supports paging.
*
* @param entityIds
* a list of entity UUIDs.
* @param includeProperties
* whether to retrieve properties for the specified entities.
* @return a list of entity objects.
*
* @throws Exception
*/
public Results get(List entityIds, Results.Level resultsLevel)
throws Exception;
/**
* Retrieves a set of Entitues cast to the specified class type.
*
* @param
* @param entityIds
* @param includeProperties
* @param entityClass
* @return a list of entity objects.
* @throws Exception
*/
public Results get(List entityIds,
Class entityClass, Results.Level resultsLevel)
throws Exception;
/**
* Retrieves a set of Entities cast to the specified class type.
*
* @param
* @param entityIds
* @param includeProperties
* @param entityType
* @param entityClass
* @return a list of entity objects.
* @throws Exception
*/
public Results get(List entityIds, String entityType,
Class entityClass, Results.Level resultsLevel)
throws Exception;
/**
* Updates the entity with the properties and values in the Entity Object.
*
* @param entity
* an Entity object.
*
* @throws Exception
*/
public void update(Entity entity) throws Exception;
/**
* Gets the value for a named entity property. Entity properties must be
* defined in the schema
*
* @param entity
* an entity reference
* @param propertyName
* the property name to retrieve.
* @return the value of the named property or null.
* @throws Exception
* the exception
*/
public Object getProperty(EntityRef entityRef, String propertyName)
throws Exception;
/**
* Gets the properties for the specified entity property.
*
* @param entity
* an entity reference
* @return the property values.
* @throws Exception
* the exception
*/
public Map getProperties(EntityRef entityRef)
throws Exception;
/**
* Sets the value for a named entity property. If the property is being
* index, the index is updated to remove the old value and add the new
* value.
*
* @param entity
* an entity reference
* @param propertyName
* the property to set.
* @param propertyValue
* new value for property.
* @throws Exception
* the exception
*/
public void setProperty(EntityRef entityRef, String propertyName,
Object propertyValue) throws Exception;
/**
* You should only use this method if you are absolutely sure what you're
* doing. Use setProperty without the override param in most cases. With
* great power comes great responsibility....
*
* @param entityRef
* @param propertyName
* @param propertyValue
* @param override
* set to true to force this value to persist. This will ignore
* all mutable attributes as well as validation. Use with care
* @throws Exception
*/
void setProperty(EntityRef entityRef, String propertyName,
Object propertyValue, boolean override) throws Exception;
/**
* Updates the properties for the specified entity.
*
* @param entity
* an entity reference
* @param properties
* the properties
* @throws Exception
* the exception
*/
public void updateProperties(EntityRef entityRef,
Map properties) throws Exception;
public void deleteProperty(EntityRef entityRef, String propertyName)
throws Exception;
/**
* Gets the values from an entity list property. Lists are a special type of
* entity property that can contain an unordered set of non-duplicate
* values.
*
* @param entity
* an entity reference
* @param dictionaryName
* the property list name to retrieve.
* @return the value of the named property or null.
* @throws Exception
* the exception
*/
public Set