FileDocCategorySizeDatePackage
DatasourceLogin.javaAPI DocGlassfish v2 API28294Thu Jul 19 11:52:00 BST 2007oracle.toplink.essentials.sessions

DatasourceLogin

public abstract class DatasourceLogin extends Object implements Serializable, Cloneable, Login

Purpose: Hold the configuration information necessary to connect to a datasource.

Description: This is an abstract class that defines the common datasource independent connection configuration. It is extended to support specific datasources such as JDBC, JCA, XML, etc.

Fields Summary
private static final String
versionStringTemplate
Version info
public static String
versionString
protected Properties
properties
Connection properties (e.g. user, password, and driver-specific settings)
protected Platform
platform
Implementation of platform-specific behaviors.
private boolean
isEncryptedPasswordSet
The securable object holder and flag
private transient SecurableObjectHolder
securableObjectHolder
protected Connector
connector
Provide a little flexibility for connecting to a database
protected boolean
usesExternalConnectionPooling
True if we use an external connection pool such as WebLogic's JTS driver
protected boolean
usesExternalTransactionController
True if we should use some external transaction service such as JTS.
protected int
cacheTransactionIsolation
By default concurrency is optimized and the cache is not locked during reads or writes, This allows for concurrent reading and writing and should never cause any problems. If the application uses no form of locking the last unit of work to merge changes will win, with no locking it is possible only under this senerio for two unit of works to merge changes different than the database although highly unlikely and if occured is the entire purpose of locking. This property allows for the isolation level of changes to the cache to be configured for sever situation and it is not suggest that this be changed.
public static final int
CONCURRENT_READ_WRITE
Reads and unit of work merges can occur concurrently.
public static final int
SYNCHRONIZED_WRITE
Reads can occur concurrently but unit of work merges will be serialized.
public static final int
SYNCHRONIZED_READ_ON_WRITE
Reads and unit of work merges will be serialized.
public static final int
SYNCRONIZED_OBJECT_LEVEL_READ_WRITE
Writes to the cache (merge, object build/refresh will be synchronized as will cache access (cloning) based on when access is required.
public static final int
SYNCRONIZED_OBJECT_LEVEL_READ_WRITE_DATABASE
Writes to the cache (merge, object build/refresh will be synchronized as will cache access (cloning) based on database transaction.
Constructors Summary
public DatasourceLogin()
PUBLIC: Create a new login.


              
      
        this(new DatasourcePlatform());
    
public DatasourceLogin(Platform databasePlatform)
ADVANCED: Create a new login for the given platform.

        this.platform = databasePlatform;

        this.dontUseExternalConnectionPooling();
        this.dontUseExternalTransactionController();

        this.properties = new Properties();
        this.properties.put("user", "");
        this.properties.put("password", "");
        this.isEncryptedPasswordSet = false;
        this.securableObjectHolder = new SecurableObjectHolder();
    
Methods Summary
public voidaddSequence(oracle.toplink.essentials.sequencing.Sequence sequence)
Add sequence corresponding to the name

        getDatasourcePlatform().addSequence(sequence);
    
public java.lang.Objectclone()
INTERNAL: Clone the login. This also clones the platform as it is internal to the login.

        DatasourceLogin clone = null;
        try {
            clone = (DatasourceLogin)super.clone();
        } catch (Exception exception) {
            // should not happen...do nothing
        }
        if (getConnector() != null) {
            clone.setConnector((Connector)getConnector().clone());
        }
        clone.setDatasourcePlatform((Platform)getDatasourcePlatform().clone());
        clone.setProperties((Properties)properties.clone());
        return clone;
    
public java.lang.ObjectconnectToDatasource(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor)
INTERNAL: Connect to the datasource, and return the driver level connection object.

        return getConnector().connect(prepareProperties(properties));
    
public voiddontUseExternalConnectionPooling()
PUBLIC: Do not use external connection pooling. This is appropriate if using regular TopLink connection pooling and regular JDBC drivers.

see
#useExternalConnectionPooling()

        setUsesExternalConnectionPooling(false);
    
public voiddontUseExternalTransactionController()
PUBLIC: Let TopLink control transactions instead of some external transaction service such as JTS.

see
#useExternalTransactionController()

        setUsesExternalTransactionController(false);
    
public intgetCacheTransactionIsolation()
ADVANCED: By default concurrency is optimized and the cache is not locked more than required during reads or writes, This allows for virtual concurrent reading and writing and should never cause any problems. If the application uses no form of locking the last unit of work to merge changes will win, with no locking it is possible only under this senerio for two unit of works to merge changes different than the database although highly unlikely and if occured is the entire purpose of locking and locking is the suggested solution if this is a problem. This property allows for the isolation level of changes to the cache to be configured for sever situations and it is not suggest that this be changed.

Setting are:

  • ConcurrentReadWrite - default
  • SynchronizedWrite - only allow a single writer (i.e. unit of work merge) to the cache at once
  • SynchronizedReadOnWrite - do not allow reading or other unit of work merge ehile a unit of work is in merge

            return cacheTransactionIsolation;
        
public oracle.toplink.essentials.sessions.ConnectorgetConnector()
ADVANCED: Return the connector that will instantiate the connection.

        return connector;
    
public oracle.toplink.essentials.internal.databaseaccess.PlatformgetDatasourcePlatform()
PUBLIC: Return the datasource platform specific information. This allows TopLink to configure certain advanced features for the datasource desired.

        return platform;
    
public oracle.toplink.essentials.sequencing.SequencegetDefaultSequence()
Get default sequence

        return getDatasourcePlatform().getDefaultSequence();
    
public oracle.toplink.essentials.sequencing.SequencegetDefaultSequenceToWrite()
INTERNAL: Used only for writing the login into XML or Java.

        return getDatasourcePlatform().getDefaultSequenceToWrite();
    
public java.lang.StringgetPassword()
Return the password. It will be encrypted.

        return properties.getProperty("password");
    
public oracle.toplink.essentials.internal.databaseaccess.DatabasePlatformgetPlatform()
INTERNAL: Return the database platform specific information. This allows TopLink to configure certain advanced features for the database desired. NOTE: this must only be used for relational specific usage and will not work for non-relational datasources.

        try {
            return (DatabasePlatform)getDatasourcePlatform();
        } catch (ClassCastException wrongType) {
            throw ValidationException.notSupportedForDatasource();
        }
    
public java.lang.StringgetPlatformClassName()
INTERNAL: Return the name of the database platform class.

        return getDatasourcePlatform().getClass().getName();
    
public java.util.PropertiesgetProperties()
INTERNAL: The properties are additional, driver-specific, connection information to be passed to the driver.

NOTE: Do not set the password directly by getting the properties and setting the "password" property directly. Use the method DatabaseLogin.setPassword(String).

        return properties;
    
public java.lang.ObjectgetProperty(java.lang.String name)
PUBLIC: The properties are additional, driver-specific, connection information to be passed to the driver.

NOTE: Do not set the password directly by getting the properties and setting the "password" property directly. Use the method DatabaseLogin.setPassword(String).

        return getProperties().get(name);
    
protected oracle.toplink.essentials.internal.security.SecurableObjectHoldergetSecurableObjectHolder()
INTERNAL: Return the encryption securable holder. Lazy initialize to handle serialization.

        if (securableObjectHolder == null) {
            securableObjectHolder = new SecurableObjectHolder();
            securableObjectHolder.getSecurableObject();
        }
        return securableObjectHolder;
    
public oracle.toplink.essentials.sequencing.SequencegetSequence(java.lang.String seqName)
Get sequence corresponding to the name

        return getDatasourcePlatform().getSequence(seqName);
    
public java.util.MapgetSequences()
Returns a map of sequence names to Sequences (may be null).

        return getDatasourcePlatform().getSequences();
    
public java.util.MapgetSequencesToWrite()
INTERNAL: Used only for writing the login into XML or Java.

        return getDatasourcePlatform().getSequencesToWrite();
    
public java.lang.StringgetTableQualifier()
PUBLIC: Return the qualifier for the all of the tables referenced by TopLink. This can be the creator of the table or database name the table exists on. This is required by some databases such as Oracle and DB2. This should only be used if all of the tables have the same qualifier. It can also be set on each descriptor when the table name is specified.

        return getDatasourcePlatform().getTableQualifier();
    
public java.lang.StringgetUserName()
PUBLIC: The user name is the database login name. Some databases do not require a user name or the user is obtained from the OS, in this case the user name not be specified.

        return properties.getProperty("user");
    
public static java.lang.StringgetVersion()
PUBLIC: Return the TopLink version.

return
version of TopLink

        if (versionString == null) {
            Object[] args = { Version.getProduct(), Version.getVersion(), Version.getBuildNumber() };
            versionString = MessageFormat.format(versionStringTemplate, args);
        }
        return versionString;
    
private java.util.PropertiesprepareProperties(java.util.Properties properties)
SECURE: The password in the login properties is encrypted. Return a clone of the properties with the password decrypted.

        Properties result = (Properties)properties.clone();
        String password = result.getProperty("password");
        if (password != null) {
            // Fix for bug # 2700529
            // The securable object is initialized on first call of
            // getSecurableObject. When setting an encrypted password
            // we don't make this call since it is already encrypted, hence,
            // we do not initialize the securable object on the holder.
            //
            // If neither setPassword or setEncryptedPassword is called 
            // (example, user sets properties via the setProperties method),
            // when the user tries to connect they  will get a null pointer 
            // exception. So if the holder does not hold 
            // a securable object or the setEncryptedPassword flag is not true, 
            // don't bother trying to decrypt.
            if (getSecurableObjectHolder().hasSecurableObject() || isEncryptedPasswordSet) {
                result.put("password", getSecurableObjectHolder().getSecurableObject().decryptPassword(password));
            }
        }

        return result;
    
public voidremoveAllSequences()
Remove all sequences but the default one.

        getDatasourcePlatform().removeAllSequences();
    
public voidremoveProperty(java.lang.String propertyName)
PUBLIC: Some drivers don't like the "user" and "password" properties. They can be removed with this method.

        properties.remove(propertyName);
    
public oracle.toplink.essentials.sequencing.SequenceremoveSequence(java.lang.String seqName)
Remove sequence corresponding to name. Doesn't remove default sequence.

        return getDatasourcePlatform().removeSequence(seqName);
    
public voidsetCacheTransactionIsolation(int cacheTransactionIsolation)
ADVANCED: By default concurrency is optimized and the cache is not locked more than required during reads or writes, This allows for virtual concurrent reading and writing and should never cause any problems. If the application uses no form of locking the last unit of work to merge changes will win, with no locking it is possible only under this senerio for two unit of works to merge changes different than the database although highly unlikely and if occured is the entire purpose of locking and locking is the suggested solution if this is a problem. This property allows for the isolation level of changes to the cache to be configured for sever situations and it is not suggest that this be changed.

Setting are:

  • ConcurrentReadWrite - default
  • SynchronizedWrite - only allow a single writer (i.e. unit of work merge) to the cache at once
  • SynchronizedReadOnWrite - do not allow reading or other unit of work merge ehile a unit of work is in merge

            this.cacheTransactionIsolation = cacheTransactionIsolation;
        
public voidsetConnector(oracle.toplink.essentials.sessions.Connector connector)
PUBLIC: Set the connector that will instantiate the connection. As an example, to use a JNDI-supplied DataSource, use code something like the following:
session.getLogin().setConnector(new JNDIConnector(context, dataSourceName));
session.login();
where the context is an instance of a javax.naming.Context and the dataSourceName refers to the name of the DataSource within the context.

        this.connector = connector;
    
public voidsetDatasourcePlatform(oracle.toplink.essentials.internal.databaseaccess.Platform platform)
PUBLIC: Set the database platform specific information. This allows TopLink to configure certain advanced features for the database desired.

        this.platform = platform;
    
public voidsetDefaultNullValue(java.lang.Class type, java.lang.Object value)
PUBLIC: The default value to substitute for database NULLs can be configured on a per-class basis. Example: login.setDefaultNullValue(long.class, new Long(0))

        getDatasourcePlatform().getConversionManager().setDefaultNullValue(type, value);
    
public voidsetDefaultSequence(oracle.toplink.essentials.sequencing.Sequence sequence)
Set default sequence

        getDatasourcePlatform().setDefaultSequence(sequence);
    
public voidsetEncryptedPassword(java.lang.String password)
Set the encrypted password.

        // remember that we set an encrypted password
        // flag will be needed in prepareProperties.
        isEncryptedPasswordSet = true;

        if (password != null) {
            setProperty("password", password);
        } else {// is null so remove the property
            removeProperty("password");
        }
    
public voidsetEncryptionClassName(java.lang.String encryptionClassName)
Sets the encryption class name

        getSecurableObjectHolder().setEncryptionClassName(encryptionClassName);
    
public voidsetPassword(java.lang.String password)
Set the password.

        if (password != null) {
            // first call to get will initialize the securable object
            setProperty("password", getSecurableObjectHolder().getSecurableObject().encryptPassword(password));
        } else {
            // is null so remove the property
            removeProperty("password");
        }
    
public voidsetPlatform(oracle.toplink.essentials.internal.databaseaccess.Platform platform)
INTERNAL: Set the database platform specific information. This allows TopLink to configure certain advanced features for the database desired.

        setDatasourcePlatform(platform);
    
public voidsetPlatformClassName(java.lang.String platformClassName)
INTERNAL: Set the name of the Platform to be used. Creates a new instance of the specified Class.

        Class platformClass = null;
        try {
            //First try loading with the Login's class loader
            platformClass = this.getClass().getClassLoader().loadClass(platformClassName);
            Platform platform = null;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    platform = (Platform)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(platformClass));
                } catch (PrivilegedActionException exception) {
                    throw exception.getException();
                }
            } else {
                platform = (Platform)PrivilegedAccessHelper.newInstanceFromClass(platformClass);
            }
            usePlatform(platform);
        } catch(Exception cne) {
            //next try using ConversionManager
            try {
                platformClass = ConversionManager.loadClass(platformClassName);           
                Platform platform = null;
                if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                    try {
                        platform = (Platform)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(platformClass));
                    } catch (PrivilegedActionException exception) {
                        throw ValidationException.platformClassNotFound(exception.getException(), platformClassName);  
                    }
                } else {
                    platform = (Platform)PrivilegedAccessHelper.newInstanceFromClass(platformClass);
                }
                usePlatform(platform);
            } catch(Exception cne2) {
                //if still not found, throw exception
                throw ValidationException.platformClassNotFound(cne2, platformClassName);                
            }
        }
    
public voidsetProperties(java.util.Properties properties)
PUBLIC: The properties are additional, driver-specific, connection information to be passed to the JDBC driver.

        this.properties = properties;
    
public voidsetProperty(java.lang.String propertyName, java.lang.Object propertyValue)
PUBLIC: Some JDBC drivers require additional, driver-specific, properties. Add the specified property to those to be passed to the JDBC driver.

        properties.put(propertyName, propertyValue);
    
public voidsetSequences(java.util.Map sequences)
INTERNAL: Used only for reading the login from XML.

        getDatasourcePlatform().setSequences(sequences);
    
public voidsetTableQualifier(java.lang.String qualifier)
PUBLIC: Set the default qualifier for all tables. This can be the creator of the table or database name the table exists on. This is required by some databases such as Oracle and DB2.

        getDatasourcePlatform().setTableQualifier(qualifier);
    
public voidsetTimestampQuery(oracle.toplink.essentials.queryframework.ValueReadQuery timestampQuery)
PUBLIC: Override the default query for returning a timestamp from the server.

        getDatasourcePlatform().setTimestampQuery(timestampQuery);
    
public voidsetUserName(java.lang.String name)
PUBLIC: The user name is the database login name. Some databases do not require a user name or the user is obtained from the OS, in this case this should not be specified.

        if (name != null) {
            setProperty("user", name);
        }
    
public voidsetUsesExternalConnectionPooling(boolean usesExternalConnectionPooling)
PUBLIC: Return whether TopLink uses some external connection pooling service such as a JDBC 2.0 driver.

        this.usesExternalConnectionPooling = usesExternalConnectionPooling;
    
public voidsetUsesExternalTransactionController(boolean usesExternalTransactionController)
PUBLIC: Return whether TopLink uses some external transaction service such as JTS.

        this.usesExternalTransactionController = usesExternalTransactionController;
    
public booleanshouldAllowConcurrentReadWrite()
INTERNAL: Used for cache isolation.

        return getCacheTransactionIsolation() == CONCURRENT_READ_WRITE;
    
public booleanshouldSynchronizeObjectLevelReadWrite()
INTERNAL: Used for Cache Isolation. Causes TopLink to lock at the object level on cache updates and cache access.

        return getCacheTransactionIsolation() == SYNCRONIZED_OBJECT_LEVEL_READ_WRITE;
    
public booleanshouldSynchronizeObjectLevelReadWriteDatabase()
INTERNAL: Used for Cache Isolation. Causes TopLink to lock at the object level on cache updates and cache access, based on database transaction.

        return getCacheTransactionIsolation() == SYNCRONIZED_OBJECT_LEVEL_READ_WRITE_DATABASE;
    
public booleanshouldSynchronizeWrites()
INTERNAL: Used for Cache Isolation. Causes TopLink to lock at the class level on cache updates.

        return getCacheTransactionIsolation() == SYNCHRONIZED_WRITE;
    
public booleanshouldSynchronizedReadOnWrite()
INTERNAL: Used for cache isolation.

        return getCacheTransactionIsolation() == SYNCHRONIZED_READ_ON_WRITE;
    
public booleanshouldUseExternalConnectionPooling()
PUBLIC: Return whether TopLink uses some external connection pooling (e.g. WebLogic's JTS driver).

see
#useExternalConnectionPooling()
see
#dontUseExternalConnectionPooling()

        return usesExternalConnectionPooling;
    
public booleanshouldUseExternalTransactionController()
PUBLIC: Return whether TopLink uses some external transaction service such as JTS.

see
#useExternalTransactionController()
see
#dontUseExternalTransactionController()

        return usesExternalTransactionController;
    
public java.lang.StringtoString()
PUBLIC: Print all of the connection information.

        StringWriter stringWriter = new StringWriter();
        PrintWriter writer = new PrintWriter(stringWriter);
        writer.write(Helper.getShortClassName(getClass()));
        writer.println("(");
        writer.println("\t" + ToStringLocalization.buildMessage("platform", (Object[])null) + "=> " + getDatasourcePlatform());
        if (!shouldUseExternalConnectionPooling()) {
            writer.println("\t" + ToStringLocalization.buildMessage("user_name", (Object[])null) + "=> \"" + getUserName() + "\"");
        }
        writer.print("\t");
        getConnector().toString(writer);
        writer.write(")");
        return stringWriter.toString();
    
public voiduseExternalConnectionPooling()
PUBLIC: Use external connection pooling.

see
#dontUseExternalConnectionPooling()
see
#shouldUseExternalConnectionPooling()

        setUsesExternalConnectionPooling(true);
    
public voiduseExternalTransactionController()
PUBLIC: Use an external transaction controller such as a JTS service

see
#dontUseExternalTransactionController()
see
#shouldUseExternalTransactionController()

        setUsesExternalTransactionController(true);
    
public voidusePlatform(oracle.toplink.essentials.internal.databaseaccess.Platform platform)
ADVANCED: Set the database platform to be custom platform.

        if (getDatasourcePlatform() != null) {
            getDatasourcePlatform().copyInto(platform);
        }
        setPlatform(platform);