📄 classicobjectcontainer.java
字号:
/** */
public synchronized void notifyAllTAs( Transaction ta ) {
env.logWriter.newEntry( this, ta.toString() + " notify all TAs...", LogWriter.DEBUG3 );
lock.notifyAll();
}
// #### methods from ClassicObjectContainer ###############################
/**
*/
public OzoneCompatible targetShadow() {
return targetShadow;
}
/**
* Liefert referenz auf das eigentliche objekt. Darf nicht
* targetShadow beruecksichtigen, da ClusterSPace darauf aufbaut.
*/
public OzoneCompatible target() {
return target;
}
/**
* Setzen oder loeschen des objektes. <method>commit()</method> ist unteilbar, deshalb
* kein snchronized.
* Achtung: object ist evtl. gerade geclustert und muss vorher
* eingelagert werden; das darf nicht hier gemacht werden, da
* diese methode auch vom store benutzt wird.
*/
protected OzoneCompatible setObject( OzoneCompatible obj ) {
OzoneCompatible old = target;
target = obj;
if (target != null) {
target.setContainer( this );
if (targetShadow != null) {
env.logWriter.newEntry( this, "setObject(): targetShadow != null !", LogWriter.WARN );
}
}
return old;
}
/** */
protected void setOwner( User newOwner ) {
permissions.setOwner( newOwner );
}
/** */
protected int touchCount() {
return touchCount;
}
/** */
protected boolean touched() {
return touched;
}
/** */
protected long touchTime() {
return touchTime;
}
/** */
protected ClusterID clusterID() {
return clusterID;
}
/** */
protected void setClusterID( ClusterID _clusterID ) {
clusterID = _clusterID;
}
/**
*/
protected Class objectClass() throws Exception {
return activatedObject().getClass();
}
/**
* Liefert referenz auf das eigentliche objekt; das objekt wird
* nachgeladen, wenn es gerade nicht aktiv ist; waehrend einer
* update-ta wird nur der clone bearbeitet und somit auch
* nicht nachgeladen
*/
protected OzoneCompatible activatedObject() throws Exception {
//meistens sollte _object initialisiert sein, deshalb wird
//das zuerst geprueft
if (target != null) {
return target;
} else if (targetShadow != null) {
return targetShadow;
} else {
clusterSpace.activateObject( this );
return target;
}
}
/** */
protected synchronized void commitTarget( Transaction ta ) {
if (targetShadow != null) {
target = targetShadow;
targetShadow = null;
targetBackup = null;
}
created = false;
lock.release( ta );
}
/** */
protected synchronized void abortTarget( Transaction ta ) {
if (targetShadow != null) {
try {
ObjectInputStream in = new ResolvingObjectInputStream( new ByteArrayInputStream( targetBackup ) );
target = (OzoneCompatible)in.readObject();
in.close();
} catch (Exception e) {
//kann/darf eigentlich nicht passieren
env.logWriter.newEntry( this, "abortObject(): ", e, LogWriter.WARN );
target = null;
}
targetShadow = null;
targetBackup = null;
}
created = false;
deleted = false;
lock.release( ta );
}
/** */
protected synchronized void upgradeLockLevel( Transaction ta, int lockLevel ) throws Exception {
activatedObject();
lock.tryAcquire( ta, Lock.LEVEL_READ );
if (lockLevel > Lock.LEVEL_READ) {
lock.tryAcquire( ta, lockLevel );
// TODO: Should new created object be shadowed or not ??
if (!isCreated()) {
createShadow();
}
}
}
/** */
protected synchronized void createShadow() throws Exception {
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream( bout );
out.writeObject( activatedObject() );
out.close();
targetBackup = bout.toByteArray();
targetShadow = target;
target = null;
} catch (Exception e) {
// darf/kann nicht passieren
env.logWriter.newEntry( this, "lockWrite(): ", e, LogWriter.WARN );
}
}
/**
* In stream schreiben - fuer DxDiskHashtable
*/
public void writeExternal( ObjectOutput out ) throws IOException {
// if (_object != null)
// System.out.print ("#");
// else if (_targetShadow != null)
// System.out.print ("*");
// else
// System.out.print ("+");
out.writeByte( subSerialVersionUID );
out.writeObject( permissions );
out.writeObject( objID );
out.writeObject( target );
out.writeObject( targetShadow );
out.writeObject( targetBackup );
out.writeObject( name );
out.writeObject( clusterID );
out.writeLong( touchTime );
out.writeShort( touchCount );
out.writeBoolean( touched );
out.writeBoolean( created );
out.writeBoolean( deleted );
out.writeObject( lock );
}
/**
* Read from the stream - fuer DxDiskHashtable. The objID is
* normally referensed from the objID of the object.
*/
public synchronized void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
env = Env.currentEnv();
clusterSpace = ((ClassicStore)env.getStoreManager()).objectSpace.clusterSpace;
byte streamVersionUID = in.readByte();
permissions = (Permissions)in.readObject();
objID = (ObjectID)in.readObject();
target = (OzoneCompatible)in.readObject();
targetShadow = (OzoneCompatible)in.readObject();
targetBackup = (byte[])in.readObject();
if (target != null) {
target.setContainer( this );
}
if (targetShadow != null) {
targetShadow.setContainer( this );
}
name = (String)in.readObject();
clusterID = (ClusterID)in.readObject();
touchTime = in.readLong();
touchCount = in.readShort();
touched = in.readBoolean();
created = in.readBoolean();
deleted = in.readBoolean();
lock = (Lock)in.readObject();
// if (_object != null)
// System.out.print (".");
// else if (_targetShadow != null)
// System.out.print (";");
// else
// System.out.print ("-");
}
/**
* Write to the Stream. Wird vom ClusterSpace verwendet.
*/
protected void storeExternal( ObjectOutput out ) throws IOException {
out.writeLong( serialVersionUID );
out.writeObject( permissions );
out.writeObject( objID );
out.writeObject( name );
out.writeObject( clusterID );
}
/**
* Read from the stream - fuer ClusterSpace. Normally, objID is
* a referenz of the objID in the object.
*/
protected void loadExternal( ObjectInput in ) throws IOException, ClassNotFoundException {
env = Env.currentEnv();
clusterSpace = ((ClassicStore)env.getStoreManager()).objectSpace.clusterSpace;
long streamSerialVersionUID = in.readLong();
permissions = (Permissions)in.readObject();
objID = (ObjectID)in.readObject();
name = (String)in.readObject();
clusterID = (ClusterID)in.readObject();
created = false;
deleted = false;
touchTime = System.currentTimeMillis();
touchCount = 1;
touched = false;
//lock = new DefaultLock();
// todo assign lock to one of the new lock implemetations
}
/**
* Search the method with the specified name and signature. Ones
* a method has been invoked it is stored in a global cache that holds
* the method objects of all database classes.
*/
private Method methodFor( String methodName, String sig, Object[] args ) throws Exception {
String key = objectClass().getName() + methodName + sig;
Method method = (Method)methodTable.elementForKey( key );
// Method method = null;
if (method == null) {
int argNum = args.length;
Class[] classes = new Class[argNum];
if (sig == null) {
//signatur aus den argumenten generieren; kann natuerlich
//falsch sein
for (int i = 0; i < argNum; i++) {
classes[i] = args[i].getClass();
}
} else {
//signatur aus dem sig-string vom proxy generieren
StringTokenizer st = new StringTokenizer( sig, OPP.SIGNATURE_DELIMITER );
int i = 0;
while (st.hasMoreTokens()) {
classes[i++] = env.classManager.classForName( st.nextToken() );
}
// classes[i++] = Class.forName (st.nextToken());
}
method = objectClass().getMethod( methodName, classes );
methodTable.addForKey( method, key );
}
return method;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -