FileDocCategorySizeDatePackage
BaseEntity.javaAPI DocExample7537Thu Aug 24 21:50:32 BST 2000com.imaginary.lwp

BaseEntity

public abstract class BaseEntity extends UnicastRemoteObject implements Entity, Persistent

Fields Summary
private static HashMap
supporters
private transient PersistenceSupport
handler
private transient Transaction
lock
private transient long
lastTouched
private String
lastUpdateID
private long
lastUpdateTime
private long
objectID
Constructors Summary
public BaseEntity()

    
        
        super();
        handler = getPersistenceSupport(getClass().getName());
        lastTouched = System.currentTimeMillis();
    
Methods Summary
public synchronized voidcommit(Transaction trans)

        lastUpdateID = trans.getIdentifier().getUserID();
        lastUpdateTime = trans.getTimestamp();
        lock = null;
    
public final synchronized voidcreate(Transaction trans)

        handler.create(trans, new Memento(this));
    
public booleanequals(java.lang.Object target)

        if( !Entity.class.isAssignableFrom(target.getClass()) ) {
            return false;
        }
        else {
            Entity ent = (Entity)target;

            try {
                long oid = ent.getObjectID();

                if( oid == objectID ) {
                    return true;
                }
                else {
                    return false;
                }
            }
            catch( RemoteException e ) {
                e.printStackTrace();
                return false;
            }
        }
    
public BaseFacadegetFacade()

        String cname = getFacadeClass();

        try {
            BaseFacade ref;

            ref = (BaseFacade)Class.forName(cname).newInstance();
            ref.assign(objectID, this);
            return ref;
        }
        catch( Exception e ) {
            e.printStackTrace();
            return null;
        }
    
public java.lang.StringgetFacadeClass()

        String cname = getClass().getName();
        int len = cname.length();
        
        if( cname.substring(len-4).equals("Impl") ) {
            return (cname.substring(0, len-4) + "Facade");
        }
        else {
            return cname + "Facade";
        }
    
public synchronized longgetLastTouched()

        return lastTouched;
    
public synchronized java.lang.StringgetLastUpdateID()

        return lastUpdateID;
    
public synchronized longgetLastUpdateTime()

        return lastUpdateTime;
    
public longgetObjectID()

        return objectID;
    
static PersistenceSupportgetPersistenceSupport(java.lang.String cname)


        
        synchronized( supporters ) {
            if( supporters.containsKey(cname) ) {
                return (PersistenceSupport)supporters.get(cname);
            }
            else {
                PersistenceSupport sp;
                
                try {
                    String hcls, prop;

                    prop = LWPProperties.HNDLR_PREFIX + cname;
                    hcls = System.getProperty(prop);
                    sp = (PersistenceSupport)Class.forName(hcls).newInstance();
                    supporters.put(cname, sp);
                    return sp;
                }
                catch( Exception e ) {
                    throw new ConfigurationException(e.getMessage());
                }
            }
        }
    
public inthashCode()

        return (new Long(objectID)).hashCode();
    
public synchronized booleanisChanged(long luit)

        lastTouched = System.currentTimeMillis();
        if( luit == lastUpdateTime ) {
            return false;
        }
        else {
            return true;
        }
    
public final synchronized voidload(Transaction trans, long oid)

        Memento mem = new Memento();

        handler.load(trans, mem, oid);
        try {
            mem.map(this);
        }
        catch( NoSuchFieldException e ) {
            e.printStackTrace();
            throw new PersistenceException(e.getMessage());
        }
    
private voidlock(Transaction trans)

        if( lock == null ) {
            lock = trans;
        }
        else {
            if( !lock.equals(trans) ) {
                throw new TransactionException("Attempt to access " +
                                               getClass().getName() + " by " +
                                               trans.getIdentifier().getUserID() +
                                               "denied due to lock held by " +
                                               lock.getIdentifier().getUserID());
            }
        }
    
protected final synchronized voidprepareCreate(Identifier id)

        Transaction trans = Transaction.getCurrent(id);

        lock(trans);
        if( !Identifier.validateCreate(id, this) ) {
            throw new SecurityException("Illegal create attempt on class " +
                                        getClass().getName() + " by " +
                                        id.getUserID());
        }
        try {
            objectID = SequenceGenerator.nextObjectID();
        }
        catch( PersistenceException e ) {
            throw new TransactionException("Failed to generate new objectID.");
        }
        trans.prepareCreate(this);
    
protected final synchronized voidprepareRead(Identifier id)

        if( !Identifier.validateRead(id, this) ) {
            throw new SecurityException("Illegal read attempt on class " +
                                        getClass().getName() + " by " +
                                        id.getUserID());
        }
    
protected final synchronized voidprepareRemove(Identifier id)

        Transaction trans = Transaction.getCurrent(id);
        
        lock(trans);
        if( !Identifier.validateRemove(id, this) ) {
            throw new SecurityException("Illegal delete attempt on class " +
                                        getClass().getName() + " by " +
                                        id.getUserID());
        }
        trans.prepareRemove(this);
    
protected final synchronized voidprepareStore(Identifier id)

        Transaction trans = Transaction.getCurrent(id);

        lock(trans);
        if( !Identifier.validateStore(id, this) ) {
            throw new SecurityException("Illegal update attempt on class " +
                                        getClass().getName() + " by " +
                                        id.getUserID());
        }
        trans.prepareStore(this);
    
public synchronized voidreload(Transaction trans)

        lastUpdateID = "unknown";
        lastUpdateTime = -1L;
        lock = null;
        load(trans, objectID);
    
public final synchronized voidremove(Transaction trans)

        handler.remove(trans, objectID);
    
public final synchronized voidstore(Transaction trans)

        handler.store(trans, new Memento(this));