📄 cacheobjectcontainer.java
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id: CacheObjectContainer.java,v 1.8 2003/04/06 13:57:32 mediumnet Exp $
package org.ozoneDB;
import org.ozoneDB.DxLib.DxCollection;
import org.ozoneDB.core.*;
import org.ozoneDB.io.stream.ResolvingObjectInputStream;
import java.io.*;
import java.lang.reflect.Constructor;
/**
* An implementation of {@link ObjectContainer} that works together with {@link
* ClientCacheDatabase} to provide an client site cache. A client program never
* needs to directly deal with it.
*
*
* @author <a href="http://www.softwarebuero.de/">SMB</a>
* @version $Revision: 1.8 $Date: 2003/04/06 13:57:32 $
*/
public final class CacheObjectContainer implements ObjectContainer, Serializable {
private static long touchCount;
private transient ClientCacheDatabase db;
protected transient AbstractTransaction tx;
private transient long lastTouched;
/**
* True if the container has to be synched with the server.
*/
private transient boolean dirty;
private int state;
/**
* The time when this container was fetched from the server. This is
* initialized and used by the server only.
*/
private long modTime;
private OzoneCompatible target;
private ObjectID id;
private String name;
private int access;
public CacheObjectContainer( ObjectContainer rhs ) {
this( rhs.target(), rhs.id(), rhs.name(), OzoneInterface.Public );
modTime = rhs.modTime();
}
public CacheObjectContainer( OzoneCompatible _target, ObjectID _id, String _name, int _access ) {
target = _target;
target.setContainer( this );
id = _id;
name = _name;
access = _access;
state = STATE_CLEAN;
touch();
}
public int access() {
return access;
}
public int state() {
return state;
}
public boolean dirty() {
return dirty;
}
public void setDirty( boolean _dirty ) {
dirty = _dirty;
}
public void raiseState( int newState ) {
int oldState = state;
state = newState > state ? newState : state;
if (state >= STATE_MODIFIED) {
dirty = true;
}
// don't write containers back to the server that has been created and
// deleted in one transaction
if (state == STATE_DELETED && oldState == STATE_CREATED) {
dirty = false;
}
}
public void clearState() {
state = STATE_CLEAN;
dirty = false;
}
public void touch() {
touchCount++;
}
public long lastTouched() {
return lastTouched;
}
public long modTime() {
return modTime;
}
protected void setModTime( long _modTime ) {
modTime = _modTime;
}
public Lock lock() {
throw new RuntimeException( "Method not implemented." );
}
public DxCollection allLockers() {
throw new RuntimeException( "Method not implemented." );
}
public void setTarget( OzoneCompatible _target ) {
if (target != null) {
target.setContainer( null );
}
target = _target;
target.setContainer( this );
}
public OzoneCompatible target() {
return target;
}
public Class targetClass() {
return target.getClass();
}
public void setDatabase( ClientCacheDatabase _db ) {
db = _db;
}
public OzoneInterface database() {
return db;
}
public ObjectID id() {
return id;
}
public Permissions permissions() {
throw new RuntimeException( "Method not implemented." );
}
public String name() {
return name;
}
public void setName( String _name ) {
name = _name;
}
public OzoneProxy ozoneProxy() {
try {
String implName = targetClass().getName();
String proxyName;
if (implName.endsWith( ObjectContainer.IMPLNAME_POSTFIX )) {
proxyName = implName.substring( 0, implName.length() - 5 );
} else {
proxyName = implName + PROXYNAME_POSTFIX;
}
// todo: uncommented until verified that it works
//Class cl = Class.forName( proxyName );
Class cl = Env.currentEnv().classManager.classForName(proxyName);
Class[] argTypes = {ObjectID.class, OzoneInterface.class};
Constructor ctor = cl.getConstructor( argTypes );
// System.out.println ("creating proxy: " + cl.getName());
Object[] args = {id(), database()};
return (OzoneProxy)ctor.newInstance( args );
} catch (Exception e) {
throw new RuntimeException( e.toString() );
}
}
public OzoneCompatible targetClone() throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream( 2048 );
ObjectOutputStream out = new ObjectOutputStream( bout );
out.writeObject( target() );
out.close();
ObjectInputStream in = new ResolvingObjectInputStream( new ByteArrayInputStream( bout.toByteArray() ) );
Object targetClone = in.readObject();
in.close();
return (OzoneCompatible)targetClone;
}
public Object invokeTarget( Env env, String methodName, String sig, Object[] args ) throws Exception {
throw new RuntimeException( "Method not implemented." );
}
public Object invokeTarget( Env env, int methodIndex, Object[] args ) throws Exception {
throw new RuntimeException( "Method not implemented." );
}
public void createTarget( Env env, Class cl, String sig, Object[] args ) throws Exception {
throw new RuntimeException( "Method not implemented." );
}
public void deleteTarget() {
throw new RuntimeException( "Method not implemented." );
}
public void nameTarget( String _name ) {
throw new RuntimeException( "Method not implemented." );
}
public void finalizeTarget() throws Exception {
throw new RuntimeException( "Method not implemented." );
}
/**
Pins this ObjectContainer.
Every caller of this method must pair this call with a call to {@link #unpin}.
An ObjectContainer remains in main memory at least as long as it is pinned.
*/
public void pin() {
throw new RuntimeException("Method not implemented.");
}
/**
Unpins this ObjectContainer.
This method must be called exactly once for every call to {@link #pin}.
*/
public void unpin() {
throw new RuntimeException("Method not implemented.");
}
/**
Returns wether this ObjectContainer is pinned.
*/
public boolean isPinned() {
throw new RuntimeException("Method not implemented.");
}
/**
Ensures that the garbageCollectionLevel is at least the given currentGarbageCollectionLevel.
The return value is meaningful if the supplied newGarbageCollectionLevel is the currentGarbageCollectionLevel
@return
<=0 if this object still has to be processed.
This is the case if it belongs to the surelyReachable set but not to the processedReachable set
> otherwise
<0 if this object has been updated
=0 if this object has not been updated, it is surelyReachable
>0 if this object has not been updated, it is processedReachable
*/
public int ensureGarbageCollectionLevel(int newGarbageCollectionLevel) {
throw new RuntimeException("Method not implemented.");
}
/**
Returns the garbageCollectionLevel this ObjectContainer has reached due to (not) calling {@link #ensureGarbageCollectionLevel}.
*/
public int getGarbageCollectionLevel() {
throw new RuntimeException("Method not implemented.");
}
public void invokeOnActivate() {
throw new RuntimeException("Method not implemented.");
}
public boolean shouldOnActivateBeCalled() {
throw new RuntimeException("Method not implemented.");
}
public void invokeOnPassivate() {
throw new RuntimeException("Method not implemented.");
}
public boolean shouldOnPassivateBeCalled() {
throw new RuntimeException("Method not implemented.");
}
public void setShouldCallOnPassivate(boolean shouldOnPassivateBeCalled) {
throw new RuntimeException("Method not implemented.");
}
public void setShouldCallOnActivate(boolean shouldOnActivateBeCalled) {
throw new RuntimeException("Method not implemented.");
}
public void requireWriteLocking() {
throw new RuntimeException("Method not implemented.");
}
}
// :indentSize=4:tabSize=4:noTabs=true:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -