org.objectweb.speedo.mim.lib
Class SpeedoHomeImpl

java.lang.Object
  extended byorg.objectweb.speedo.mim.lib.SpeedoHomeImpl
All Implemented Interfaces:
SpeedoHome, UserCacheManager
Direct Known Subclasses:
SpeedoGenClassHome

public abstract class SpeedoHomeImpl
extends java.lang.Object
implements SpeedoHome

Author:
S.Chassande-Barrioz

Nested Class Summary
protected static class SpeedoHomeImpl.UC
           
 
Field Summary
protected  java.util.Map namedQueries
           
protected  ProxyManagerFactory pmf
           
protected  TransactionalPersistenceManager tpm
           
protected  SpeedoHomeImpl.UC[] userCaches
           
 
Fields inherited from interface org.objectweb.speedo.mim.api.SpeedoHome
ALL, CACHED, FIXED, NO_CACHE
 
Constructor Summary
SpeedoHomeImpl()
           
SpeedoHomeImpl(TransactionalPersistenceManager _tpm, ProxyManagerFactory _pmf)
           
 
Method Summary
 boolean activeUserCache(java.lang.String cacheName)
          Initializes the user cache
 QueryDefinition addNamedQuery(java.lang.String name, QueryDefinition query)
          Defines a named query
protected  SpeedoHomeImpl.UC addUserCache(java.lang.String userCacheName, java.lang.String[] fields, int id)
           
 boolean allLoaded()
           
 void attachCopy(SpeedoProxy sp, ProxyManager pm, java.util.Map map, java.lang.Object clone, SpeedoAccessor sa, boolean makeTransactional)
           
 SpeedoProxy detachCopy(SpeedoProxy sp, ProxyManager pm, java.util.Map map, java.lang.Object clone, java.util.Collection fgHints)
           
 java.util.Collection fgGetFieldsToLoad(java.lang.String fgName)
          This default implementation does nothing and returns null.
 java.util.Collection fgGetFieldsToLoad(java.lang.String fgName, boolean onlyDirectRef)
           
 java.util.Collection fgGetNestedFetchGroups(java.lang.String fgName)
          This default implementation does nothing and returns null.
 boolean fgIsDefined(java.lang.String fgName)
          This default implementation returns always false.
 java.util.Collection getActiveUserCache()
          Retrieves the list of user cache which has been initialized.
 java.lang.Class getClassForQuery(java.lang.String className, java.lang.String queryName)
           
 java.lang.String[] getIndexededFieldsFromUserCache(int cacheId)
          Retrieves the name of the fields used as index in an user cache.
 QueryDefinition getNamedQuery(java.lang.String name)
          Retrieves a query defintion from its name.
 java.lang.String getPath()
           
 boolean getPrefetchOnExtent()
           
 boolean getPrefetchOnGenClass()
           
 boolean getPrefetchOnQuery()
           
 ProxyManagerFactory getProxyManagerFactory()
           
 SpeedoAccessor getSpeedoAccessor(SpeedoProxy sp)
          It retrieves the SpeedoAccessor instance used in the current context.
 TransactionalPersistenceManager getTransactionalPersistenceManager()
           
 UserCache getUserCache(int cacheId)
          Retrives a user cache
 int getUserCacheId(java.util.Collection fieldNames)
          Retrieves the name of the user cache which index is exactly composed by some field names.
 int[] getUserCacheIds()
          Retrieves the array of the user cache identifiers
 java.lang.String getUserCacheName(int cacheId)
          Retrives the name of an user cache from its int identifier.
 boolean hasToFix()
           
 void initSH()
           
protected  boolean isAbstract()
           
 boolean isCacheable()
          Indicates if the state of persistent instance managed by this home, are kept between two transaction.
 boolean isFieldLockingLevel()
          Indicates if the locking level must be the field.
protected  SpeedoProxy newSpeedoProxyInstance(java.lang.Class clazz)
          Create a new instance of a SpeedoProxy which the clas is given in parameter.
 SpeedoAccessor readIntention(SpeedoProxy sp, long[] fields)
          Notifies the transactional persistency manager of a read intention for the given persistent instance.
 QueryDefinition removeNamedQuery(java.lang.String name)
          Remove a named query
 void setCachePolicy(byte v)
          Permit to Indicate if the state of persistent instance managed by this home, are kept between two transaction.
 void setFieldLockingLevel(boolean val)
          Permits to Indicate if the locking level must be the field.
 void setPrefetchOnExtent(boolean prefetch)
          Indicates if the prefetching must be activated on extents when they return instance corresponding to this home.
 void setPrefetchOnGenClass(boolean prefetch)
          Indicates if the prefetching must be activated genclass loading.
 void setPrefetchOnQuery(boolean prefetch)
          Indicates if the prefetching must be activated on queries when they return instance corresponding to this home.
 void setProxyManagerFactory(ProxyManagerFactory _pmf)
          It assignes a PersistenceManagerFactory
 void setTransactionalPersistenceManager(TransactionalPersistenceManager _tpm)
          It assignes a TransactionalPersistenceManager
 void userCacheEntryUnbound(java.lang.Object oid)
          An entry of user cache has been unbound from the real cache.
 SpeedoAccessor writeIntention(SpeedoProxy sp, long[] fields)
           
 SpeedoAccessor writeIntention(SpeedoProxy sp, long[] fields, java.lang.Object thinLock)
          Notifies the transactional persistency manager of a write intention for the given persistent instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.speedo.mim.api.SpeedoHome
getClassProperties, getProjectName, getVersioningStrategy, isDetachable
 

Field Detail

tpm

protected TransactionalPersistenceManager tpm

pmf

protected ProxyManagerFactory pmf

namedQueries

protected java.util.Map namedQueries

userCaches

protected SpeedoHomeImpl.UC[] userCaches
Constructor Detail

SpeedoHomeImpl

public SpeedoHomeImpl()

SpeedoHomeImpl

public SpeedoHomeImpl(TransactionalPersistenceManager _tpm,
                      ProxyManagerFactory _pmf)
Method Detail

isAbstract

protected boolean isAbstract()
Returns:
false because it corresponds to most of case Subclass to change the behavior

newSpeedoProxyInstance

protected SpeedoProxy newSpeedoProxyInstance(java.lang.Class clazz)
                                      throws java.lang.Exception
Create a new instance of a SpeedoProxy which the clas is given in parameter. The default implementation does a simple 'clazz.newInstance()'.

Throws:
java.lang.Exception

isCacheable

public boolean isCacheable()
Description copied from interface: SpeedoHome
Indicates if the state of persistent instance managed by this home, are kept between two transaction.

Specified by:
isCacheable in interface SpeedoHome
Returns:
true means the state is kept between transaction.

allLoaded

public boolean allLoaded()
Specified by:
allLoaded in interface SpeedoHome

hasToFix

public boolean hasToFix()
Specified by:
hasToFix in interface SpeedoHome

setCachePolicy

public void setCachePolicy(byte v)
Description copied from interface: SpeedoHome
Permit to Indicate if the state of persistent instance managed by this home, are kept between two transaction.

Specified by:
setCachePolicy in interface SpeedoHome

isFieldLockingLevel

public boolean isFieldLockingLevel()
Description copied from interface: SpeedoHome
Indicates if the locking level must be the field. A false value (default) means the locking level has to be done at instance level.

Specified by:
isFieldLockingLevel in interface SpeedoHome

setFieldLockingLevel

public void setFieldLockingLevel(boolean val)
Description copied from interface: SpeedoHome
Permits to Indicate if the locking level must be the field. A false value (default) means the locking level has to be done at instance level.

Specified by:
setFieldLockingLevel in interface SpeedoHome

fgGetNestedFetchGroups

public java.util.Collection fgGetNestedFetchGroups(java.lang.String fgName)
This default implementation does nothing and returns null. Subclass to change the behavior


fgIsDefined

public boolean fgIsDefined(java.lang.String fgName)
This default implementation returns always false. Subclass to change the behavior


fgGetFieldsToLoad

public java.util.Collection fgGetFieldsToLoad(java.lang.String fgName)
This default implementation does nothing and returns null. Subclass to change the behavior


getProxyManagerFactory

public final ProxyManagerFactory getProxyManagerFactory()
Specified by:
getProxyManagerFactory in interface SpeedoHome
Returns:
the PersistenceManagerFactory which represents the data support inside which the proxy is persistent.

setProxyManagerFactory

public final void setProxyManagerFactory(ProxyManagerFactory _pmf)
It assignes a PersistenceManagerFactory

Specified by:
setProxyManagerFactory in interface SpeedoHome
Parameters:
_pmf - is the PersistenceManagerFactory which represents the data support inside which the proxy is persistent.

getTransactionalPersistenceManager

public final TransactionalPersistenceManager getTransactionalPersistenceManager()
Specified by:
getTransactionalPersistenceManager in interface SpeedoHome
Returns:
the TransactionalPersistenceManager which manage the concurrency, loading, ... of the proxy.

setTransactionalPersistenceManager

public final void setTransactionalPersistenceManager(TransactionalPersistenceManager _tpm)
It assignes a TransactionalPersistenceManager

Specified by:
setTransactionalPersistenceManager in interface SpeedoHome
Parameters:
_tpm - is the TransactionalPersistenceManager which manage the concurrency, loading, ... of the proxy.

readIntention

public final SpeedoAccessor readIntention(SpeedoProxy sp,
                                          long[] fields)
Notifies the transactional persistency manager of a read intention for the given persistent instance.

Specified by:
readIntention in interface SpeedoHome
Parameters:
sp - is the SpeedoProxy which the read access is requested.
fields - the ids of the fields that may be accessed by the caller of this method. If the i-th bit of 'fields' is set to 1, then the i-th field of the given speedo accessor may be accessed by the caller of this method.

writeIntention

public final SpeedoAccessor writeIntention(SpeedoProxy sp,
                                           long[] fields)
Specified by:
writeIntention in interface SpeedoHome

writeIntention

public SpeedoAccessor writeIntention(SpeedoProxy sp,
                                     long[] fields,
                                     java.lang.Object thinLock)
Notifies the transactional persistency manager of a write intention for the given persistent instance.

Specified by:
writeIntention in interface SpeedoHome
Parameters:
sp - is the SpeedoProxy which the write access is requested.
fields - the ids of the fields that may be accessed by the caller of this method. If the i-th bit of 'fields' is set to 1, then the i-th field of the given speedo accessor may be accessed by the caller of this method.
thinLock - permits to allocate a lock on only a part of the resource. The locking size is thinner than a lock on the persistent object entirely. This parameter can be typically used to lock at the field or the genclass element levels.

getSpeedoAccessor

public final SpeedoAccessor getSpeedoAccessor(SpeedoProxy sp)
It retrieves the SpeedoAccessor instance used in the current context. If the proxy is not active then the reference accessor is returned. If there is an active then the $classNameFields used in the context is returned. Be careul, if the persistent object is not used in the current context, then a null value will be returned, because no SpeedoAccessor is registered in the working set.

Specified by:
getSpeedoAccessor in interface SpeedoHome

detachCopy

public final SpeedoProxy detachCopy(SpeedoProxy sp,
                                    ProxyManager pm,
                                    java.util.Map map,
                                    java.lang.Object clone,
                                    java.util.Collection fgHints)
Specified by:
detachCopy in interface SpeedoHome

attachCopy

public final void attachCopy(SpeedoProxy sp,
                             ProxyManager pm,
                             java.util.Map map,
                             java.lang.Object clone,
                             SpeedoAccessor sa,
                             boolean makeTransactional)
Specified by:
attachCopy in interface SpeedoHome

fgGetFieldsToLoad

public final java.util.Collection fgGetFieldsToLoad(java.lang.String fgName,
                                                    boolean onlyDirectRef)

setPrefetchOnExtent

public void setPrefetchOnExtent(boolean prefetch)
Description copied from interface: SpeedoHome
Indicates if the prefetching must be activated on extents when they return instance corresponding to this home.

Specified by:
setPrefetchOnExtent in interface SpeedoHome

getPrefetchOnExtent

public boolean getPrefetchOnExtent()
Specified by:
getPrefetchOnExtent in interface SpeedoHome

setPrefetchOnGenClass

public void setPrefetchOnGenClass(boolean prefetch)
Description copied from interface: SpeedoHome
Indicates if the prefetching must be activated genclass loading. This method is only applicable for gen class home.

Specified by:
setPrefetchOnGenClass in interface SpeedoHome

getPrefetchOnGenClass

public boolean getPrefetchOnGenClass()
Specified by:
getPrefetchOnGenClass in interface SpeedoHome

setPrefetchOnQuery

public void setPrefetchOnQuery(boolean prefetch)
Description copied from interface: SpeedoHome
Indicates if the prefetching must be activated on queries when they return instance corresponding to this home.

Specified by:
setPrefetchOnQuery in interface SpeedoHome

getPrefetchOnQuery

public boolean getPrefetchOnQuery()
Specified by:
getPrefetchOnQuery in interface SpeedoHome

initSH

public void initSH()
Specified by:
initSH in interface SpeedoHome

getClassForQuery

public java.lang.Class getClassForQuery(java.lang.String className,
                                        java.lang.String queryName)

addNamedQuery

public final QueryDefinition addNamedQuery(java.lang.String name,
                                           QueryDefinition query)
Description copied from interface: SpeedoHome
Defines a named query

Specified by:
addNamedQuery in interface SpeedoHome
Parameters:
name - is the name identifying the query
query - is the definition of the query
Returns:
the old query definition corresponding to the name, if it existed one.

removeNamedQuery

public final QueryDefinition removeNamedQuery(java.lang.String name)
Description copied from interface: SpeedoHome
Remove a named query

Specified by:
removeNamedQuery in interface SpeedoHome
Parameters:
name - is the name of the query definition to remove
Returns:
the removed query definition (null if not found)

getNamedQuery

public final QueryDefinition getNamedQuery(java.lang.String name)
Description copied from interface: SpeedoHome
Retrieves a query defintion from its name. If the name is not known, the null value is returned.

Specified by:
getNamedQuery in interface SpeedoHome
Parameters:
name - is the name the wanted query definition

getPath

public java.lang.String getPath()
Specified by:
getPath in interface SpeedoHome

addUserCache

protected SpeedoHomeImpl.UC addUserCache(java.lang.String userCacheName,
                                         java.lang.String[] fields,
                                         int id)

getUserCacheName

public java.lang.String getUserCacheName(int cacheId)
Retrives the name of an user cache from its int identifier.

Specified by:
getUserCacheName in interface UserCacheManager
Parameters:
cacheId - the identifier of an user cache
Returns:
the name of the user cache, or a null value if the identifier does not match an existing user cache.

activeUserCache

public boolean activeUserCache(java.lang.String cacheName)
Description copied from interface: UserCacheManager
Initializes the user cache

Specified by:
activeUserCache in interface UserCacheManager
Parameters:
cacheName - is the name of the user cache to initialize
Returns:
indicates if the cache has been initialized correctly

getUserCache

public UserCache getUserCache(int cacheId)
Description copied from interface: UserCacheManager
Retrives a user cache

Specified by:
getUserCache in interface UserCacheManager
Returns:
the user cache instance if found, null otherwise

getUserCacheIds

public int[] getUserCacheIds()
Description copied from interface: UserCacheManager
Retrieves the array of the user cache identifiers

Specified by:
getUserCacheIds in interface UserCacheManager

getIndexededFieldsFromUserCache

public java.lang.String[] getIndexededFieldsFromUserCache(int cacheId)
Description copied from interface: UserCacheManager
Retrieves the name of the fields used as index in an user cache. Be careful to respect the order of the array.

Specified by:
getIndexededFieldsFromUserCache in interface UserCacheManager
Returns:
an array of String containg the name of the fields used as index. (Never null !!!!)

getUserCacheId

public int getUserCacheId(java.util.Collection fieldNames)
Description copied from interface: UserCacheManager
Retrieves the name of the user cache which index is exactly composed by some field names.

Specified by:
getUserCacheId in interface UserCacheManager
Parameters:
fieldNames - is the collection of field names (String). The order of the collection is not important here.
Returns:
an user cache name if it has been found, null otherwise.

getActiveUserCache

public java.util.Collection getActiveUserCache()
Description copied from interface: UserCacheManager
Retrieves the list of user cache which has been initialized.

Specified by:
getActiveUserCache in interface UserCacheManager
Returns:
a collection of UserCache instance

userCacheEntryUnbound

public void userCacheEntryUnbound(java.lang.Object oid)
Description copied from interface: UserCacheManager
An entry of user cache has been unbound from the real cache. A typical implementation, undinds from active user caches, the entry. To do this the a persistent object which has been previously unexported.

Specified by:
userCacheEntryUnbound in interface UserCacheManager
Parameters:
oid - is the identifier of the persistent object to unbind