pl.edu.agh.cast.model.mapper
Class Mapper

java.lang.Object
  extended by pl.edu.agh.cast.model.mapper.Mapper

public final class Mapper
extends Object

Mapper is a gate between model and persistence system. It provides mechanisms for saving and loading model objects without any direct DB interactions.

The idea of mapper is build on the presumption that any part of the model may be represented as a network of linked nodes. So

Author:
AGH CAST Team
See Also:
and, are primitives of the metamodel. Any model element is mapped to network of nodes. This is done through annotation mechanism,


Field Summary
static String DEFAULT_FOLDER
          The default name of the directory where models are stored.
static String DEFAULT_PATH
          The dafault path to the directory where models should be stored.
static String DEFAULT_ROOT
          The default root directory where models should be stored.
 
Method Summary
 void clearCache()
          Clear the object cache.
 void clearCache(boolean subLevel)
          Clear the object cache.
 void finalize()
          Close DB connection on exit.
 List find(Class klass, Map<String,Class> typeMap, SortedMap<String,Object> conditions, org.eclipse.core.resources.IProject project)
          Find objects mapped to the metamodel.
static Mapper getInstance()
          The only instance of the metamodel.
static boolean isDBPresent()
          Indicated if the Mapper was properly initialized (i.e.
 boolean remove(Mappable object, org.eclipse.core.resources.IProject project)
          Removes object from project.
 boolean save(Mappable object, boolean force, org.eclipse.core.resources.IProject project)
          Saves objects mapped to metamodel.
 boolean save(Mappable object, org.eclipse.core.resources.IProject project)
          Saves objects mapped to metamodel.
 void stats()
          Prints statistics of the mapper cache.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ROOT

public static final String DEFAULT_ROOT
The default root directory where models should be stored.


DEFAULT_FOLDER

public static final String DEFAULT_FOLDER
The default name of the directory where models are stored.

See Also:
Constant Field Values

DEFAULT_PATH

public static final String DEFAULT_PATH
The dafault path to the directory where models should be stored.

Method Detail

isDBPresent

public static boolean isDBPresent()
Indicated if the Mapper was properly initialized (i.e. the connection with the DB is established).

Returns:
True if the mapper was properly initialized.

getInstance

public static Mapper getInstance()
The only instance of the metamodel.

Returns:
The instance of the metamodel.

save

public boolean save(Mappable object,
                    org.eclipse.core.resources.IProject project)
Saves objects mapped to metamodel.

Parameters:
object - The object to be saved
project - The project which the object belongs to. If null, the object is stored in the default location (useful for testing).
Returns:
true if save was successful

save

public boolean save(Mappable object,
                    boolean force,
                    org.eclipse.core.resources.IProject project)
Saves objects mapped to metamodel.

Parameters:
object - The object to be saved
force - If true, the object is saved even if its 'saved' flag is set to true.
project - The project which the object belongs to. If null, the object is stored in the default location (useful for testing).
Returns:
true if save was successful

finalize

public void finalize()
Close DB connection on exit.

Overrides:
finalize in class Object

find

public List find(Class klass,
                 Map<String,Class> typeMap,
                 SortedMap<String,Object> conditions,
                 org.eclipse.core.resources.IProject project)
Find objects mapped to the metamodel.

Parameters:
klass - The class of the objects to be found
typeMap - The type map used in recursive object creation.

Metamodel node with given name may be mapped to different model classes. This map is used to pick the desired classes for nodes to be loaded.

By default

  • the type name of the class klass (@see pl.edu.agh.cast.metamodel.annotation.Mapping) is mapped automaticaly to the klass
  • the name of the node is considered a FQCN and the class is selected automatically
conditions - Conditions which should be met by initial set of nodes (if null, all nodes are loaded)
project - The project where the object should be looked for.
Returns:
List of objects

clearCache

public void clearCache()
Clear the object cache.


clearCache

public void clearCache(boolean subLevel)
Clear the object cache.

Parameters:
subLevel - Indicates if the sub-level cache should be clear as well.

stats

public void stats()
Prints statistics of the mapper cache.


remove

public boolean remove(Mappable object,
                      org.eclipse.core.resources.IProject project)
               throws Exception
Removes object from project.

Parameters:
object - Object to remove.
project - The project which the object belongs to.
Returns:
true if removal was successful
Throws:
Exception - When Mapper use DB persistence. Remover isn't implemented for DB persistence.


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.