Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.eclipse.emf.texo.store;
  
  import java.util.List;
  import java.util.Map;
  
  import  org.eclipse.emf.common.util.URI;
  import  org.eclipse.emf.ecore.EClass;
  import  org.eclipse.emf.ecore.EStructuralFeature;
  import  org.eclipse.emf.ecore.resource.Resource;
Defines the interface for an object store. An object store can:
  • create a unique uri for an object
  • retrieve objects using an uri
  • query for an object using a string query
  • update, delete and insert objects
An object store corresponds roughly to the concept of an EMF Resource or JPA EntityManager. Compared to the EMF Resource, the main difference is that an object store does not support the concept of containment and is mostly a wrapper around specific implementations such as a JPA entity manager. The object store api is not targeted as a full replacement or wrapper over an underlying technology such as an EntityManager. The main purpose of the api is to support webservice and crud operations. An object store is uniquely identified by an URI. A main capability of an object store is to create a uniquely identifying string for an object, the uri. Creating an object store should be a light weight operation comparable to creating an EntityManager in JPA.

Author(s):
Martin Taal
 
 public abstract class ObjectStore extends DefaultObjectResolver {

  
Update an existing object in the object store. The signature of the method corresponds to the merge operation of the EntityManager.merge operation.

Parameters:
object the object to update or merge with the object store
Returns:
the object stored in the object store.
 
   public abstract <T extends Object> T update(T object);

  
Delete an existing object from the object store.

Parameters:
object
 
   public abstract <T extends Objectvoid remove(T object);

  
Insert an existing object in the object store.

Parameters:
object
 
   public abstract <T extends Objectvoid insert(T object);

  
Refresh an existing object from the object store.

Parameters:
object
 
   public abstract <T extends Objectvoid refresh(T object);

  
Query for a set of objects from the object store.

Parameters:
qry a query string which can be handled by the native implementation
namedParameters a set of parameters used in the query
firstResult the row number of the first row to return, pass -1 to not have a first row.
maxResults the number of rows to return
Returns:
the objects part of the query
 
   public abstract List<?> query(String qryStrMap<StringObjectnamedParametersint firstResultint maxResults);

  
Query for a set of objects from the object store using a predefined named query.

Parameters:
name the name of the named query
namedParameters a set of parameters used in the query
firstResult the row number of the first row to return, pass -1 to not have a first row.
maxResults the number of rows to return
Returns:
the objects part of the query
  public abstract List<?> namedQuery(String nameMap<StringObjectnamedParametersint firstResultint maxResults);

  
Query for a specific type

Parameters:
eClass the type to query
firstResult the row number of the first row to return, pass -1 to not have a first row.
maxResults the number of rows to return
Returns:
the objects part of the query
  public abstract List<?> query(EClass eClassint firstResultint maxResults);

  
Count a set of objects in the object store.

Parameters:
qry a query string which can be handled by the native implementation
namedParameters a set of parameters used in the query
Returns:
the objects part of the query
  public abstract long count(String qryMap<StringObjectnamedParameters);

  
Count a set of objects in the object store.

Parameters:
name the named query for counting
namedParameters a set of parameters used in the query
Returns:
the objects part of the query
  public abstract long countNamedQuery(String nameMap<StringObjectnamedParameters);

  
Method to indicate that a transaction is to be started by the underlying implementation.
  public void begin() {
  }

  
Method to indicate that a transaction can be committed by the underlying implementation.
  public void commit() {
  }

  
Method to indicate that a transaction can be rolled back by the underlying implementation.
  public void rollback() {
  }

  
Method to indicate that the underlying implementation can be closed.
  public void close() {
  }

  

Returns:
the underlying technical component taking care of actually storing and retrieving information. This can for example be the EntityManager which is used to access the database. Note that null is returned if there is no delegate.
  public abstract Object getDelegate();

  
Flush any changes to the underlying store.
  public void flush() {
  }

  
Return the instance of the specified class which has the id.
  public abstract <T extends Object> T get(Class<T> clzObject id);

  
Checks if an object is new for the datastore or exists. An existing object can be detached, this method will return false for detached non-new objects.

Parameters:
o the object to check
Returns:
true if the object is new, false otherwise
See also:
IdProvider.getId(Object)
  public boolean isNew(Object o) {
    return null == IdProvider.getInstance().getId(o);
  }

  
Can be used to check if an object is referenced from other objects. This is usefull when trying/planning to delete an object.

Parameters:
target the object to check if it is referenced
Returns:
true if the target is refered to from other objects, false otherwise
  public <T extends Objectboolean isReferenced(T targetboolean includeContainmentReferences) {
    final List<Objectreferees = getReferingObjects(target, 1, includeContainmentReferences);
    return !referees.isEmpty();
  }

  
Returns all objects which refer to the passed in target object. Calls getReferingObjects(Object, int) with -1 as the second parameter.

Parameters:
target the target object for which the referees need to be retrieved
includeContainmentReferences also return refering objects which reference the target through an EReference with containment==true
Returns:
the referencing objects
  public <T extends ObjectList<ObjectgetReferingObjects(T targetboolean includeContainmentReferences) {
    return getReferingObjects(target, -1, includeContainmentReferences);
  }

  
Returns all objects which refer to the passed in target object, will stop querying if maxResult has been reached.

Parameters:
target the target object for which the referees need to be retrieved
maxResult the maximum number of results to return
includeContainmentReferences also return refering objects which reference the target through an EReference with containment==true
Returns:
the referencing objects
  public abstract <T extends ObjectList<ObjectgetReferingObjects(T targetint maxResult,
      boolean includeContainmentReferences);
  protected String getJavaPropertyName(EStructuralFeature eFeature) {
    final String propertyName = ModelUtils.getEAnnotation(eFeature.);
    if (propertyName == null) {
      return eFeature.getName();
    }
    return propertyName;
  }

  
Return the (JPA) entity name for the EClass. The entity name can be used to create queries.

Parameters:
eClass the EClass for which to get the entity name
Returns:
the entity name for the EClass
  public String getEntityName(EClass eClass) {
    return eClass.getName();
  }
New to GrepCode? Check out our FAQ X