FileDocCategorySizeDatePackage
ConnectionPolicy.javaAPI DocGlassfish v2 API8547Tue May 22 16:54:54 BST 2007oracle.toplink.essentials.threetier

ConnectionPolicy

public class ConnectionPolicy extends Object implements Serializable, Cloneable

Purpose: Used to specify how a client session's should be allocated.

see
ServerSession

Fields Summary
protected Login
login
protected String
poolName
protected boolean
isLazy
protected Map
properties
This attribute provides a mechanism to pass connection information to events.
Constructors Summary
public ConnectionPolicy()
PUBLIC: A connection policy is used to define how the client session connection should be acquired.

        this.isLazy = true;
    
public ConnectionPolicy(String poolName)
PUBLIC: A connection policy is used to define how the client session connection should be acquired.

        this.isLazy = true;
        this.poolName = poolName;
    
public ConnectionPolicy(Login login)
PUBLIC: A connection policy is used to define how the client session connection should be acquired.

        this.isLazy = false;
        this.login = login;
    
Methods Summary
public java.lang.Objectclone()
INTERNAL: Clone the query

        try {
            ConnectionPolicy clone = (ConnectionPolicy)super.clone();
            if (clone.hasLogin()) {
                clone.setLogin((Login)clone.getLogin().clone());
            }
            return clone;
        } catch (CloneNotSupportedException e) {
            return null;
        }
    
public voiddontUseLazyConnection()
PUBLIC: A lazy connection only acquires a physical connection when a transaction is started and releases the connection when the transaction completes.

        setIsLazy(false);
    
public oracle.toplink.essentials.sessions.LogingetLogin()
PUBLIC: Return the login to use for this connection. Client sessions support using a seperate user login for database modification.

        return login;
    
public java.lang.StringgetPoolName()
PUBLIC: Return the pool name or null if not part of a pool.

        return poolName;
    
public java.util.MapgetProperties()
ADVANCED: This method will return the collection of custom properties set on the Connection policy. Note that this will cause the lazy initialization of the HashMap.

        if (this.properties == null) {
            this.properties = new HashMap();
        }
        return this.properties;
    
public java.lang.ObjectgetProperty(java.lang.Object object)
PUBLIC: Returns the property associated with the corresponding key. These properties will be available to connection events.

        if (this.hasProperties()) {
            return this.getProperties().get(object);
        }
        return null;
    
public booleanhasLogin()
PUBLIC: Return if a login is used, only one of login and pool can be used.

        return login != null;
    
public booleanhasProperties()
PUBLIC: Returns true if properties are available on the Connection Policy

        return (this.properties != null) && (!this.properties.isEmpty());
    
public booleanisLazy()
PUBLIC: Return if a lazy connection should be used, a lazy connection only acquire a physical connection when a transaction is started and releases the connection when the transaction completes.

        return isLazy;
    
public booleanisPooled()
INTERNAL: Return if part of a connection pool.

        return poolName != null;
    
public booleanisUserDefinedConnection()
INTERNAL: Return if part of a connection pool.

        return poolName == null;
    
public java.lang.ObjectremoveProperty(java.lang.Object key)
PUBLIC: This method is used to remove a custom property from the Connection Policy. This method will return the propery removed. If it was not found then null will be returned.

        if (this.hasProperties()) {
            return getProperties().remove(key);
        }
        return null;
    
public voidsetIsLazy(boolean isLazy)
PUBLIC: Set if a lazy connection should be used, a lazy connection only acquire a physical connection when a transaction is started and releases the connection when the transaction completes.

        this.isLazy = isLazy;
    
public voidsetLogin(oracle.toplink.essentials.sessions.Login login)
PUBLIC: Set the login to use for this connection. Client sessions support using a seperate user login for database modification. Pooled connections must use the pool's login and cannot define their own.

        this.login = login;
    
public voidsetPoolName(java.lang.String poolName)
PUBLIC: Set the pool name or null if not part of a pool.

        this.poolName = poolName;
    
public voidsetProperty(java.lang.Object key, java.lang.Object property)
PUBLIC: Use this method to set custom properties on the Connection Policy. These properties will be available from within connection events but have no effect on the connection directly.

        getProperties().put(key, property);
    
public java.lang.StringtoString()
INTERNAL: return a string representation of this ConnectionPolicy

        String type = "";
        if (isPooled()) {
            type = "(" + ToStringLocalization.buildMessage("pooled", (Object[])null) + ": " + getPoolName();
        } else {
            type = "(" + ToStringLocalization.buildMessage("login", (Object[])null) + ": " + getLogin();
        }
        if (isLazy()) {
            type = type + "," + ToStringLocalization.buildMessage("lazy", (Object[])null) + ")";
        } else {
            type = type + "," + ToStringLocalization.buildMessage("non-lazy", (Object[])null) + ")";
        }

        return Helper.getShortClassName(getClass()) + type;
    
public voiduseLazyConnection()
PUBLIC: A lazy connection only acquires a physical connection when a transaction is started and releases the connection when the transaction completes.

        setIsLazy(true);