FileDocCategorySizeDatePackage
Project.javaAPI DocGlassfish v2 API28739Tue May 22 16:54:52 BST 2007oracle.toplink.essentials.sessions

Project

public class Project extends Object implements Serializable, Cloneable
Purpose: Maintain all of the TopLink configuration information for a system.

Responsibilities:

  • Project wide parameters (name, default for use method accessing, and base filepath for other INI files)
  • JDBC Login information
  • Descriptors
  • Validate Descriptors (instance variable & method access)
  • Maintain sequencing information & other project wide parameters
  • Construct valid DatabaseLogin objects for each platform (with sequence info set)
see
DatabaseLogin

Fields Summary
protected String
name
protected Login
datasourceLogin
protected Map
descriptors
protected Vector
orderedDescriptors
protected Vector
defaultReadOnlyClasses
Holds the default set of read-only classes that apply to each UnitOfWork.
protected Map
aliasDescriptors
Cache the EJBQL descriptor aliases.
protected boolean
hasIsolatedClasses
Cache if any descriptor is isolated. (set during initialization)
protected boolean
hasGenericHistorySupport
Cache if any descriptor has history. (set during initialization)
protected boolean
hasProxyIndirection
Cache if any descriptor is using ProxyIndirection. (set during initialization
protected boolean
isPureCMP2Project
Cache if all descriptors are CMP1/2
protected Map
sqlResultSetMappings
This a collection of 'maps' that allow users to map custom SQL to query results
Constructors Summary
public Project()
PUBLIC: Create a new project.

        this.name = "";
        this.descriptors = new HashMap();
        this.defaultReadOnlyClasses = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
        this.orderedDescriptors = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
        this.hasIsolatedClasses = false;
        this.hasGenericHistorySupport = false;
        this.isPureCMP2Project = false;
        this.hasProxyIndirection = false;
    
public Project(Login login)
PUBLIC: Create a new project that will connect through the login information. This method can be used if the project is being create in code instead of being read from a file.

        this();
        this.datasourceLogin = login;
    
public Project(DatabaseLogin login)
PUBLIC: Create a new project that will connect through JDBC using the login information. This method can be used if the project is being create in code instead of being read from a file.

        this();
        this.datasourceLogin = login;
    
Methods Summary
public voidaddAlias(java.lang.String alias, oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
PUBLIC: Add an alias for the descriptor.

        if (aliasDescriptors == null) {
            aliasDescriptors = new Hashtable(10);
        }
        aliasDescriptors.put(alias, descriptor);
    
public voidaddAliasesFromProject(oracle.toplink.essentials.sessions.Project project)
INTERNAL: Get the descriptors from the project, and associate the aliases for each descriptor with the descriptor.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            if (descriptor.getAlias() != null) {
                addAlias(descriptor.getAlias(), descriptor);
            }
        }
    
public voidaddDefaultReadOnlyClass(java.lang.Class readOnlyClass)
PUBLIC: Add the read-only class which apply to each UnitOfWork created by default.

        getDefaultReadOnlyClasses().addElement(readOnlyClass);
    
public voidaddDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
PUBLIC: Add the descriptor to the project.

        getOrderedDescriptors().add(descriptor);
        String alias = descriptor.getAlias();
        if (alias != null) {
            addAlias(alias, descriptor);
        }

        // Avoid loading class definition at this point if we haven't done so yet.
        if ((descriptors != null) && !descriptors.isEmpty()) {
            getDescriptors().put(descriptor.getJavaClass(), descriptor);
        }
    
public voidaddDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl session)
INTERNAL: Used by the BuilderInterface when reading a Project from INI files.

        getOrderedDescriptors().add(descriptor);
        String alias = descriptor.getAlias();
        if (alias != null) {
            addAlias(alias, descriptor);
        }

        // Avoid loading class definition at this point if we haven't done so yet.
        if ((descriptors != null) && !descriptors.isEmpty()) {
            getDescriptors().put(descriptor.getJavaClass(), descriptor);
        }
        session.initializeDescriptorIfSessionAlive(descriptor);
    
public voidaddDescriptors(java.util.Vector descriptors, oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl session)
INTERNAL: Add the descriptors to the session. All persistent classes must have a descriptor registered for them with the session. This method allows for a batch of descriptors to be added at once so that TopLink can resolve the dependancies between the descriptors and perform initialization optimally.

        for (Enumeration enumeration = descriptors.elements(); enumeration.hasMoreElements();) {
            ClassDescriptor descriptor = (ClassDescriptor)enumeration.nextElement();
            getDescriptors().put(descriptor.getJavaClass(), descriptor);
            String alias = descriptor.getAlias();
            if (alias != null) {
                addAlias(alias, descriptor);
            }
        }

        if (session.isConnected()) {
            session.initializeDescriptors(descriptors);
            // The commit order must be maintain whenever new descriptors are added.
            session.getCommitManager().initializeCommitOrder();
        }

        getOrderedDescriptors().addAll(descriptors);
    
public voidaddDescriptors(oracle.toplink.essentials.sessions.Project project, oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl session)
PUBLIC: Merge the descriptors from another project into this one. All persistent classes must have a descriptor registered for them with the session. This method allows for a batch of descriptors to be added at once so that TopLink can resolve the dependancies between the descriptors and perform initialization optimially.

        Iterator descriptors = project.getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            getDescriptors().put(descriptor.getJavaClass(), descriptor);
            String alias = descriptor.getAlias();
            if (alias != null) {
                addAlias(alias, descriptor);
            }
        }

        if (session.isConnected()) {
            session.initializeDescriptors(project.getDescriptors());
            // The commit order must be maintained whenever new descriptors are added.
            session.getCommitManager().initializeCommitOrder();
        }

        getOrderedDescriptors().addAll(project.getOrderedDescriptors());
    
public voidaddSQLResultSetMapping(oracle.toplink.essentials.queryframework.SQLResultSetMapping sqlResultSetMapping)
PUBLIC: Add a named SQLResultSetMapping to this project. These SQLResultSetMappings can be later used by ResultSetMappingQueries to map Custom sql results to results as defined by the SQLResultSetMappings.

        if (sqlResultSetMapping == null || sqlResultSetMapping.getName() == null){
            return;
        }
        if (this.sqlResultSetMappings == null){
            this.sqlResultSetMappings = new HashMap();
        }
        this.sqlResultSetMappings.put(sqlResultSetMapping.getName(), sqlResultSetMapping);
    
public voidapplyLogin()
INTERNAL: Default apply login implementation. Defined for generated subclasses that may not have a login. BUG#2669342

        // Do nothing by default.
    
public voidassumeExistenceForDoesExist()
PUBLIC: Switch all descriptors to assume existence for non-null primary keys.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.getQueryManager().assumeExistenceForDoesExist();
        }
    
public voidcheckCacheForDoesExist()
PUBLIC: Switch all descriptors to check the cache for existence.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.getQueryManager().checkCacheForDoesExist();
        }
    
public voidcheckDatabaseForDoesExist()
PUBLIC: Switch all descriptors to check the database for existence.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.getQueryManager().checkDatabaseForDoesExist();
        }
    
public java.lang.Objectclone()
INTERNAL: Clones the descriptor

        try {
            return super.clone();
        } catch (Exception exception) {
            return null;
        }
    
public voidconformAllDescriptors()
PUBLIC: Set all this project's descriptors to conform all read queries within the context of the unit of work.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.setShouldAlwaysConformResultsInUnitOfWork(true);
        }
    
public voidconvertClassNamesToClasses(java.lang.ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this project to actual class-based settings

param
classLoader

        Iterator ordered = orderedDescriptors.iterator();
        while (ordered.hasNext()){
            ClassDescriptor descriptor = (ClassDescriptor)ordered.next();
            descriptor.convertClassNamesToClasses(classLoader);
        }
        // convert class names to classes for each SQLResultSetMapping
        if (sqlResultSetMappings != null) {
            for (Iterator mappingIt = sqlResultSetMappings.keySet().iterator(); mappingIt.hasNext();) {
                SQLResultSetMapping mapping = (SQLResultSetMapping) sqlResultSetMappings.get(mappingIt.next());
                mapping.convertClassNamesToClasses(classLoader);
            }
        }
    
public oracle.toplink.essentials.sessions.DatabaseSessioncreateDatabaseSession()
PUBLIC: Factory method to create session. This returns an implementor of the DatabaseSession interface, which can be used to login and add descriptors from other projects. The Session interface however should be used for reading and writing once connected for complete portability.

        return new DatabaseSessionImpl(this);
    
public oracle.toplink.essentials.threetier.ServercreateServerSession()
PUBLIC: Factory method to create a server session. This returns an implementor of the Server interface, which can be used to login and add descriptors from other projects, configure connection pooling and acquire client sessions.

        return new ServerSession(this);
    
public oracle.toplink.essentials.threetier.ServercreateServerSession(int min, int max)
PUBLIC: Factory method to create a server session. This returns an implementor of the Server interface, which can be used to login and add descriptors from other projects, configure connection pooling and acquire client sessions. Configure the min and max number of connections for the default pool.

        return new ServerSession(this, min, max);
    
public oracle.toplink.essentials.threetier.ServercreateServerSession(oracle.toplink.essentials.threetier.ConnectionPolicy defaultConnectionPolicy)
PUBLIC: Factory method to create a server session. This returns an implementor of the Server interface, which can be used to login and add descriptors from other projects, configure connection pooling and acquire client sessions. Configure the default connection policy to be used. This policy is used on the "acquireClientSession()" protocol.

        return new ServerSession(this, defaultConnectionPolicy);
    
public java.util.MapgetAliasDescriptors()
INTERNAL: Returns the alias descriptors hashtable.

        return aliasDescriptors;
    
public oracle.toplink.essentials.descriptors.ClassDescriptorgetClassDescriptor(java.lang.Class theClass)
PUBLIC: Return the descriptor specified for the class.

		ClassDescriptor desc = getDescriptor(theClass);
		if (desc instanceof ClassDescriptor) {
			return (ClassDescriptor)desc;
		} else {
			throw ValidationException.cannotCastToClass(desc, desc.getClass(), ClassDescriptor.class);
		}
    
public oracle.toplink.essentials.descriptors.ClassDescriptorgetClassDescriptorForAlias(java.lang.String alias)
PUBLIC: Return the descriptor for the alias.

        ClassDescriptor d = null;
        if (aliasDescriptors != null) {
            d = (ClassDescriptor)aliasDescriptors.get(alias);
        }
        return d;
    
public oracle.toplink.essentials.sessions.LogingetDatasourceLogin()
PUBLIC: Return the login, the login holds any database connection information given. This return the Login interface and may need to be cast to the datasource specific implementation.

        return datasourceLogin;
    
public java.util.VectorgetDefaultReadOnlyClasses()
PUBLIC: Returns the default set of read-only classes.

        return defaultReadOnlyClasses;
    
public oracle.toplink.essentials.descriptors.ClassDescriptorgetDescriptor(java.lang.Class theClass)
PUBLIC: Return the descriptor specified for the class.

        return (ClassDescriptor)getDescriptors().get(theClass);
    
public oracle.toplink.essentials.descriptors.ClassDescriptorgetDescriptorForAlias(java.lang.String alias)
PUBLIC: Return the descriptor for the alias.

deprecated
Replaced by {@link #getClassDescriptorForAlias(String)}

        ClassDescriptor d = null;
        if (aliasDescriptors != null) {
            d = (ClassDescriptor)aliasDescriptors.get(alias);
        }
        return d;
    
public java.util.MapgetDescriptors()
PUBLIC: Return the descriptors.

        // Lazy initialize class references from orderedDescriptors when reading from XML.
        if (descriptors.isEmpty() && (!orderedDescriptors.isEmpty())) {
            for (Iterator iterator = orderedDescriptors.iterator(); iterator.hasNext();) {
                ClassDescriptor descriptor = (ClassDescriptor)iterator.next();
                descriptors.put(descriptor.getJavaClass(), descriptor);
            }
        }
        return descriptors;
    
public oracle.toplink.essentials.sessions.DatabaseLogingetLogin()
INTERNAL: Return the login, the login holds any database connection information given. This has been replaced by getDatasourceLogin to make use of the Login interface to support non-relational datasources, if DatabaseLogin API is required it will need to be cast.

        return (DatabaseLogin)datasourceLogin;
    
public java.lang.StringgetName()
PUBLIC: get the name of the project.

        return name;
    
public java.util.VectorgetOrderedDescriptors()
INTERNAL: Return the descriptors in the order added. Used to maitain consistent order in XML.

        return orderedDescriptors;
    
public oracle.toplink.essentials.queryframework.SQLResultSetMappinggetSQLResultSetMapping(java.lang.String sqlResultSetMapping)
PUBLIC: Get a named SQLResultSetMapping from this project. These SQLResultSetMappings can be used by ResultSetMappingQueries to map Custom sql results to results as defined by the SQLResultSetMappings.

        if (sqlResultSetMapping == null || this.sqlResultSetMappings == null){
            return null;
        }
        return (SQLResultSetMapping)this.sqlResultSetMappings.get(sqlResultSetMapping);
    
public booleanhasGenericHistorySupport()
INTERNAL: Answers if at least one Descriptor or Mapping had a HistoryPolicy at initialize time.

        return hasGenericHistorySupport;
    
public booleanhasIsolatedClasses()
INTERNAL: Return if any descriptors are isolated. Set to true during descriptor initialize if any descriptor is isolated. Determines if an isolated client session is required.

        return hasIsolatedClasses;
    
public booleanhasProxyIndirection()
INTERNAL: Return if any descriptors use ProxyIndirection. Set to true during descriptor initialize if any descriptor uses ProxyIndirection Determines if ProxyIndirectionPolicy.getValueFromProxy should be called.

        return this.hasProxyIndirection;
    
public booleanisPureCMP2Project()
INTERNAL: Return if all descriptors are for CMP1 or CMP2 beans. Set to true during descriptor initialize. Allows certain optimizations to be made.

        return isPureCMP2Project;
    
public voidsetAliasDescriptors(java.util.Map aHashtable)
INTERNAL: Set the alias descriptors hashtable.

        aliasDescriptors = aHashtable;
    
public voidsetDatasourceLogin(oracle.toplink.essentials.sessions.Login datasourceLogin)
PUBLIC: Set the login to be used to connect to the database for this project.

        this.datasourceLogin = datasourceLogin;
    
public voidsetDefaultReadOnlyClasses(java.util.Vector newValue)
PUBLIC: Set the read-only classes which apply to each UnitOfWork create by default.

        this.defaultReadOnlyClasses = (Vector)newValue.clone();
    
public voidsetDescriptors(java.util.Map descriptors)
INTERNAL: Set the descriptors registered with this session.

        this.descriptors = descriptors;
        for (Iterator iterator = descriptors.values().iterator(); iterator.hasNext();) {
            ClassDescriptor descriptor = (ClassDescriptor)iterator.next();
            String alias = descriptor.getAlias();
            if (alias != null) {
                addAlias(alias, descriptor);
            }
        }
    
public voidsetHasGenericHistorySupport(boolean hasGenericHistorySupport)
INTERNAL: Set to true during descriptor initialize if any descriptor has hsitory.

        this.hasGenericHistorySupport = hasGenericHistorySupport;
    
public voidsetHasIsolatedClasses(boolean hasIsolatedClasses)
INTERNAL: Set to true during descriptor initialize if any descriptor is isolated. Determines if an isolated client session is required.

        this.hasIsolatedClasses = hasIsolatedClasses;
    
public voidsetHasProxyIndirection(boolean hasProxyIndirection)
INTERNAL: Set to true during descriptor initialize if any descriptor uses ProxyIndirection Determines if ProxyIndirectionPolicy.getValueFromProxy should be called.

        this.hasProxyIndirection = hasProxyIndirection;
    
public voidsetIsPureCMP2Project(boolean isPureCMP2Project)
INTERNAL: Set if all descriptors are for CMP1 or CMP2 beans. Set to true during descriptor initialize. Allows certain optimizations to be made.

        this.isPureCMP2Project = isPureCMP2Project;
    
public voidsetLogin(oracle.toplink.essentials.sessions.DatabaseLogin datasourceLogin)
PUBLIC: Set the login to be used to connect to the database for this project.

        this.datasourceLogin = datasourceLogin;
    
public voidsetLogin(oracle.toplink.essentials.sessions.Login datasourceLogin)
PUBLIC: Set the login to be used to connect to the database for this project.

        this.datasourceLogin = datasourceLogin;
    
public voidsetName(java.lang.String name)
PUBLIC: Set the name of the project.

        this.name = name;
    
public voidsetOrderedDescriptors(java.util.Vector orderedDescriptors)
INTERNAL: Set the descriptors order. Used to maitain consistent order in XML.

        this.orderedDescriptors = orderedDescriptors;
        for (Enumeration e = orderedDescriptors.elements(); e.hasMoreElements();) {
            ClassDescriptor descriptor = (ClassDescriptor)e.nextElement();
            String alias = descriptor.getAlias();
            if (alias != null) {
                addAlias(alias, descriptor);
            }
        }
    
public java.lang.StringtoString()
INTERNAL:

        return Helper.getShortClassName(getClass()) + "(" + getName() + ")";
    
public voiduseCacheIdentityMap()
PUBLIC: Switch all descriptors to use the cache identity map.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useCacheIdentityMap();
        }
    
public voiduseCacheIdentityMap(int cacheSize)
PUBLIC: Switch all descriptors to use the cache identity map the size.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useCacheIdentityMap();
            descriptor.setIdentityMapSize(cacheSize);
        }
    
public voiduseFullIdentityMap()
PUBLIC: Switch all descriptors to use the full identity map.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useFullIdentityMap();
        }
    
public voiduseFullIdentityMap(int initialCacheSize)
PUBLIC: Switch all descriptors to use the full identity map with initial cache size.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useFullIdentityMap();
            descriptor.setIdentityMapSize(initialCacheSize);
        }
    
public voiduseNoIdentityMap()
PUBLIC: Switch all descriptors to use no identity map.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useNoIdentityMap();
        }
    
public voiduseSoftCacheWeakIdentityMap()
PUBLIC: Switch all descriptors to use the soft cache weak identity map.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useSoftCacheWeakIdentityMap();
        }
    
public voiduseSoftCacheWeakIdentityMap(int cacheSize)
PUBLIC: Switch all descriptors to use the soft cache weak identity map with soft cache size.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useSoftCacheWeakIdentityMap();
            descriptor.setIdentityMapSize(cacheSize);
        }
    
public voiduseWeakIdentityMap()
PUBLIC: Switch all descriptors to use the weak identity map.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useWeakIdentityMap();
        }
    
public voiduseWeakIdentityMap(int initialCacheSize)
PUBLIC: Switch all descriptors to use the weak identity map.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            descriptor.useWeakIdentityMap();
            descriptor.setIdentityMapSize(initialCacheSize);
        }
    
public booleanusesOptimisticLocking()
INTERNAL: Asks each descriptor if is uses optimistic locking.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            if (descriptor.usesOptimisticLocking()) {
                return true;
            }
        }
        return false;
    
public booleanusesSequencing()
INTERNAL: Asks each descriptor if is uses sequencing.

        Iterator descriptors = getDescriptors().values().iterator();
        while (descriptors.hasNext()) {
            ClassDescriptor descriptor = (ClassDescriptor)descriptors.next();
            if (descriptor.usesSequenceNumbers()) {
                return true;
            }
        }
        return false;