diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db')
10 files changed, 1006 insertions, 347 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/FdManager.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/FdManager.java index d5631a4fbc..03cd46bf74 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/FdManager.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/FdManager.java @@ -16,6 +16,7 @@ import org.eclipse.net4j.util.io.TMPUtil; import org.eclipse.net4j.util.om.trace.ContextTracer; import com.objy.db.app.Session; +import com.objy.db.app.oo; import com.objy.db.app.ooContObj; import com.objy.db.app.ooDBObj; @@ -49,7 +50,7 @@ public class FdManager private String fdDirPath = null; - private String lockserverHost = DEFAULT_VALUE; + private String lockServerHost = DEFAULT_VALUE; private String fdNumber = "12345"; @@ -61,13 +62,21 @@ public class FdManager private boolean initialized = false; - public void initialize(boolean reset) + private String configPath = "configuration"; + + private String logDirPath = null; + + protected void initialize(boolean reset) { if (fdDirPath == null) { File dataFolder = TMPUtil.createTempFolder("Objy", "data"); fdDirPath = dataFolder.getAbsolutePath(); } + if (noDefaultValueSet(logDirPath)) + { + logDirPath = fdDirPath; + } if (fdFilePath == null) { fdFilePath = fdDirPath + File.separator + fdName + ".fdb"; @@ -129,20 +138,23 @@ public class FdManager boolean bRet = false; Process proc = null; - String command = "oonewfd" - // + " -fdfilehost " + getFdFileHost() - + " -fdfilepath " + fdFilePath + " -lockserver " + getLockServerHost() + " -fdnumber " + fdNumber - + " -pagesize " + getPageSize() - // + " -jnldirpath " + jrnlDirPath - // + " -licensefile " + licenseFilePath - // + ((standAlone)?" -standalone ":" ") - + " " + bootFilePath; + StringBuilder command = new StringBuilder(256); + command.append("oonewfd"); + // command.append(" -fdfilehost ").append(getFdFileHost()); + command.append(" -fdfilepath ").append(fdFilePath); + command.append(" -lockserver ").append(getLockServerHost()); + command.append(" -fdnumber ").append(fdNumber); + command.append(" -pagesize ").append(getPageSize()); + // command.append(" -jnldirpath ").append(jrnlDirPath); + // command.append(" -licensefile ").append(licenseFilePath); + // if (standAlone) command.append(" -standalone "); + command.append(' ').append(bootFilePath); TRACER_INFO.trace("Createing FD: '" + bootFilePath + "'."); try { - proc = Runtime.getRuntime().exec(command); + proc = Runtime.getRuntime().exec(command.toString()); if (proc.waitFor() != 0) { dumpStream(proc.getErrorStream()); @@ -359,7 +371,7 @@ public class FdManager public String getFdFileHost() { - if (fdFileHost.equals(DEFAULT_VALUE)) + if (noDefaultValueSet(fdFileHost)) { // get local host try @@ -394,13 +406,13 @@ public class FdManager public String getLockServerHost() { - if (lockserverHost.equals(DEFAULT_VALUE)) + if (noDefaultValueSet(lockServerHost)) { // get local host try { InetAddress address = InetAddress.getLocalHost(); - lockserverHost = address.getHostName(); + lockServerHost = address.getHostName(); } catch (UnknownHostException e) { @@ -409,12 +421,12 @@ public class FdManager } } - return lockserverHost; + return lockServerHost; } public void setLockServerHost(String lockServerHost) { - lockserverHost = lockServerHost; + this.lockServerHost = lockServerHost; } public String getFdNumber() @@ -429,7 +441,7 @@ public class FdManager public String getPageSize() { - if (pageSize.equals(DEFAULT_VALUE)) + if (noDefaultValueSet(pageSize)) { pageSize = "8192"; } @@ -509,6 +521,7 @@ public class FdManager // ObjyConnection.INSTANCE.disconnect(); // fdManager.resetFD(); Session session = new Session(); + session.setIndexMode(oo.EXPLICIT_UPDATE); session.begin(); Iterator<?> itr = session.getFD().containedDBs(); ooDBObj dbObj = null; @@ -541,4 +554,20 @@ public class FdManager session.commit(); session.terminate(); } + + boolean noDefaultValueSet(String value) + { + return value == null || value.isEmpty() || value.equals(DEFAULT_VALUE); + } + + public void setlogDirPath(String logDirPath) + { + this.logDirPath = logDirPath; + } + + public String getLogPath() + { + return logDirPath; + } + } diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClass.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClass.java index d66a169283..5a7456f44a 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClass.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClass.java @@ -10,11 +10,20 @@ */ package org.eclipse.emf.cdo.server.internal.objectivity.db; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyArrayListId; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyArrayListString; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyFeatureMapArrayList; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyProxy; + import com.objy.as.app.Class_Position; import com.objy.as.app.d_Attribute; import com.objy.as.app.d_Class; +import com.objy.as.app.d_Ref_Type; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; /** * Wrapper around the AS class to be able to cache attributes. @@ -35,7 +44,14 @@ public class ObjyClass public ObjyClass(d_Class asClass/* , EClass eClass */) { this.asClass = asClass; - asClassName = asClass.name(); + if (asClass.namespace_name() != null) + { + asClassName = asClass.namespace_name() + ":" + asClass.name(); + } + else + { + asClassName = asClass.name(); + } } public d_Attribute resolve_attribute(String attribute_name) @@ -44,6 +60,16 @@ public class ObjyClass if (attr == null) { attr = asClass.resolve_attribute(attribute_name); + // we might get (attr == null) if the attribute is from a base class. + // so we'll try to get the attribute through the position. + if (attr == null) + { + Class_Position position = resolve_position(attribute_name); + if (position != null) + { + attr = asClass.attribute_at_position(position); + } + } attributeMap.put(attribute_name, attr); } return attr; @@ -70,4 +96,49 @@ public class ObjyClass return asClassName; } + public List<Class_Position> getListOfRefAttributes() + { + List<Class_Position> positions = new ArrayList<Class_Position>(); + + System.out.println(">>> Class: " + asClassName); + + // + @SuppressWarnings("rawtypes") + Iterator itr = asClass.attributes_plus_inherited(); + while (itr.hasNext()) + { + d_Attribute attribute = (d_Attribute)itr.next(); + if (attribute.is_type() && attribute.type_of() instanceof d_Ref_Type) + { + d_Class dClass = attribute.class_type_of(); + if (dClass.name().equals(ObjyFeatureMapArrayList.ClassName)) + { + // we'll need to copy this one. + positions.add(resolve_position(attribute.name())); + System.out.println("\t attr: " + attribute.name()); + } + else if (dClass.name().equals(ObjyArrayListString.ClassName)) + { + // we'll need to copy this one. + positions.add(resolve_position(attribute.name())); + System.out.println("\t attr: " + attribute.name()); + } + else if (dClass.name().equals(ObjyArrayListId.className)) + { + // we'll need to copy this one. + positions.add(resolve_position(attribute.name())); + System.out.println("\t attr: " + attribute.name()); + } + else if (dClass.name().equals(ObjyProxy.className)) + { + // we'll need to copy this one. + positions.add(resolve_position(attribute.name())); + System.out.println("\t attr: " + attribute.name()); + } + } + } + + return positions; + } + } diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClassProposed.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClassProposed.java index a117e5e43a..920c17a2fd 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClassProposed.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyClassProposed.java @@ -131,7 +131,10 @@ public class ObjyClassProposed } } - TRACER_DEBUG.trace("ECLASS " + eClass.getName() + " -> " + className + " -- DONE"); + if (TRACER_DEBUG.isEnabled()) + { + TRACER_DEBUG.trace("ECLASS " + eClass.getName() + " -> " + className + " -- DONE"); + } for (EClass classifier : toBeProcessed) { @@ -221,7 +224,7 @@ public class ObjyClassProposed } } - TRACER_DEBUG.trace("ECLASS " + eClass.getName() + " -> " + className + " -- DONE"); + TRACER_DEBUG.trace("evolve ECLASS " + eClass.getName() + " -> " + className + " -- DONE"); for (EClass classifier : toBeEvolve) { diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyCommitInfoHandler.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyCommitInfoHandler.java index 4159e81ab3..346b497d79 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyCommitInfoHandler.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyCommitInfoHandler.java @@ -104,7 +104,7 @@ public class ObjyCommitInfoHandler protected ooTreeSetX getTreeSet() { ooTreeSetX treeSet = null; - treeSet = (ooTreeSetX)Session.getCurrent().getFD().objectFrom(commitInfoSetId); + treeSet = (ooTreeSetX)Session.getCurrent().getFD().objectFrom(commitInfoSetId.getString()); return treeSet; } diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyConnection.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyConnection.java index d891005d95..d2928eb237 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyConnection.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyConnection.java @@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.server.internal.objectivity.db; import org.eclipse.emf.cdo.server.internal.objectivity.bundle.OM; import org.eclipse.emf.cdo.server.internal.objectivity.clustering.ObjyPlacementManager; import org.eclipse.emf.cdo.server.internal.objectivity.clustering.ObjyPlacementManagerImpl; +import org.eclipse.emf.cdo.server.objectivity.IObjectivityStoreConfig; import org.eclipse.net4j.util.om.trace.ContextTracer; @@ -65,10 +66,18 @@ public class ObjyConnection private int sessionMaxCacheSize = 1000; + private final int minInactiveSessions = 5; + + private int sessionCount = 0; + + private String logDirPath = null; + + private int logOption = oo.LogNone; + public ObjyConnection() { - readPool = new ConcurrentHashMap<String, ObjySession>(20); - writePool = new ConcurrentHashMap<String, ObjySession>(20); + readPool = new ConcurrentHashMap<String, ObjySession>(5); + writePool = new ConcurrentHashMap<String, ObjySession>(5); } /*** @@ -76,12 +85,25 @@ public class ObjyConnection * * @param fdName */ - synchronized public void connect(String fdName) + synchronized public void connect(IObjectivityStoreConfig storeConfig) + { + /**** + * If + */ + fdName = storeConfig.getFdName(); + logDirPath = storeConfig.getLogPath(); + logOption = storeConfig.getLogOption(); + connect(); + // this.store = store; + } + + synchronized public void connect(String fdName, int logOption) { /**** * If */ this.fdName = fdName; + this.logOption = logOption; connect(); // this.store = store; } @@ -101,19 +123,20 @@ public class ObjyConnection { if (Connection.current() == null) { - int options = oo.LogNone; // oo.LogAll; - Connection.setLoggingOptions(options, true, // boolean logToFiles - true, // boolean appendLogFiles, - "c:\\data", // String logDirPath, - "MainLog.txt"// String mainLogFileName - ); + if (logOption != oo.LogNone) + { + Connection.setLoggingOptions(logOption, true, // boolean logToFiles + true, // boolean appendLogFiles, + logDirPath, // String logDirPath, + "MainLog.txt"// String mainLogFileName + ); + } if (TRACER_DEBUG.isEnabled()) { TRACER_DEBUG.trace(" creating new Connection"); } connection = Connection.open(fdName, oo.openReadWrite); connection.useContextClassLoader(true); - } else { @@ -147,45 +170,51 @@ public class ObjyConnection public ObjySession getWriteSessionFromPool(String sessionName) { - synchronized (syncObject) - { - // return connection.getSessionFromPool(getSessionPoolNameWrite(), sessionName); - ObjySession session = writePool.get(sessionName); - if (session == null) - { - session = new ObjySession(sessionName, writePool, this); - writePool.put(sessionName, session); - } - session.join(); - return session; - } + return getSessionFromPool(sessionName); } public ObjySession getReadSessionFromPool(String sessionName) { + return getSessionFromPool(sessionName); + } + + protected ObjySession getSessionFromPool(String sessionName) + { synchronized (syncObject) { - // return connection.getSessionFromPool(getSessionPoolNameRead(), sessionName); + // return connection.getSessionFromPool(getSessionPoolNameWrite(), sessionName); ObjySession session = readPool.get(sessionName); if (session == null) { - session = new ObjySession(sessionName, writePool, this); - readPool.put(sessionName, session); + if (sessionCount >= minInactiveSessions) + { + // look for an inactive one, rename it and use it. + for (ObjySession objySession : readPool.values()) + { + if (objySession.isAvailable()) + { + objySession.setName(sessionName); + session = objySession; + break; + } + } + } + + // we are forced to create one. + if (session == null) + { + session = new ObjySession(sessionName, readPool, this); + ++sessionCount; + // System.out.println(">>> IS: creating new session: " + sessionName + " - total: " + sessionCount); + readPool.put(sessionName, session); + } } session.join(); + session.setAvailable(false); return session; } } - public void returnSessionToPool(ObjySession session) - { - synchronized (syncObject) - { - // TODO Auto-generated method stub - session.leave(); - } - } - public void disconnect() { if (!isConnected) @@ -213,6 +242,8 @@ public class ObjyConnection // TRACER_DEBUG.trace("ObjyConnection.disconnect() -- cleanup writePool. "); cleanupSessionPool(writePool); + sessionCount = 0; + // TRACER_DEBUG.trace("ObjyConnection.disconnect() -- cleanup any other sessions. "); // for testing we need to find out if there are any open sessions. diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObject.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObject.java index 5830678688..77d8857684 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObject.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObject.java @@ -11,6 +11,7 @@ package org.eclipse.emf.cdo.server.internal.objectivity.db; import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.id.CDOIDExternal; import org.eclipse.emf.cdo.common.model.EMFUtil; @@ -24,7 +25,10 @@ import org.eclipse.emf.cdo.server.internal.objectivity.mapper.ISingleTypeMapper; import org.eclipse.emf.cdo.server.internal.objectivity.mapper.ITypeMapper; import org.eclipse.emf.cdo.server.internal.objectivity.mapper.ObjyMapper; import org.eclipse.emf.cdo.server.internal.objectivity.mapper.SingleReferenceMapper; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyArrayListId; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyArrayListString; import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyBase; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyFeatureMapArrayList; import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyFeatureMapEntry; import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyProxy; import org.eclipse.emf.cdo.server.internal.objectivity.utils.OBJYCDOIDUtil; @@ -41,12 +45,13 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.util.FeatureMap; import com.objy.as.app.Class_Object; -import com.objy.as.app.Class_Position; import com.objy.as.app.Numeric_Value; import com.objy.as.app.Relationship_Object; import com.objy.as.app.String_Value; import com.objy.as.app.VArray_Object; -import com.objy.db.app.Session; +import com.objy.as.app.d_Attribute; +import com.objy.as.app.d_Class; +import com.objy.as.app.d_Ref_Type; import com.objy.db.app.ooId; import com.objy.db.app.ooObj; @@ -56,6 +61,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +/** + * @author Ibrahim Sallam + */ public class ObjyObject { @@ -69,42 +77,117 @@ public class ObjyObject protected Relationship_Object baseRel = null; + protected boolean hasBaseRelationshipChecked = false; + protected Relationship_Object revisionsRel = null; protected Relationship_Object lastRevisionRel = null; protected ooId objectId; + protected ooId revisionId = null; + + protected int version = Integer.MAX_VALUE; + + public static int fetchCount = 0; + + public static int updateCount = 0; + + public static long createObjectTime = 0; + + public static int createObjectCount = 0; + // protected boolean isRoot = false; + // IS: for stats. + // public static int count = 0; + // public static long tDiff = 0; + // good for fast access. - private Map<Class_Position, Object> featureMap = new HashMap<Class_Position, Object>(); + // private Map<Class_Position, Object> featureMap = new HashMap<Class_Position, Object>(); + private Map<String, Object> featureMap = new HashMap<String, Object>(); public ObjyObject(Class_Object classObject) { + // long tStart = System.currentTimeMillis(); + this.classObject = classObject; - objyClass = ObjySchema.getObjyClass(classObject.type_of().name()); + d_Class dClass = classObject.type_of(); + String fullyQualifiedClassName = null; - if (TRACER_DEBUG.isEnabled()) + try { - TRACER_DEBUG.format("...classObject type: {0} - oid: {1}", classObject.type_of().name(), classObject.objectID() - .getStoreString()); + + if (dClass.namespace_name() != null) + { + fullyQualifiedClassName = dClass.namespace_name() + ":" + dClass.name(); + } + else + { + fullyQualifiedClassName = dClass.name(); + } + + objyClass = ObjySchema.getObjyClass(fullyQualifiedClassName); + + // if (dClass.has_base_class(ObjyBase.CLASS_NAME)) + // { + // if (TRACER_DEBUG.isEnabled()) + // { + // TRACER_DEBUG.format("...classObject type: {0} - oid: {1}", classObject.type_of().name(), classObject + // .objectID().getStoreString()); + // } + // getBaseRelationship(classObject); + // if (!baseRel.exists()) + // { + // // we are the base... + // getRevisionsRelationship(classObject); + // getLastRevisionRelationship(classObject); + // } + // else + // { + // baseClassObject = baseRel.get_class_obj(); + // // TODO - we might want to delay getting the list of versions unless we need them. + // // revisionsRel = baseClassObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_REVISIONS)); + // // lastRevisionRel = baseClassObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_LAST_REVISION)); + // } + // } + setObjectId(classObject.objectID()); + version = classObject.get_numeric(objyClass.resolve_position(ObjyBase.ATT_VERSION)).intValue(); } - baseRel = classObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_BASE)); - if (!baseRel.exists()) + catch (RuntimeException ex) + { + ex.printStackTrace(); + } + + // count++; + // tDiff += System.currentTimeMillis() - tStart; + } + + private Relationship_Object getLastRevisionRelationship() + { + if (lastRevisionRel == null) { - // we are the base... - revisionsRel = classObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_REVISIONS)); lastRevisionRel = classObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_LAST_REVISION)); } - else + return lastRevisionRel; + } + + private Relationship_Object getRevisionsRelationship() + { + if (revisionsRel == null) + { + revisionsRel = classObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_REVISIONS)); + } + return revisionsRel; + } + + private Relationship_Object getBaseRelationship() + { + if (baseRel == null) { - baseClassObject = baseRel.get_class_obj(); - // TODO - we might want to delay getting the list of versions unless we need them. - // revisionsRel = baseClassObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_REVISIONS)); - // lastRevisionRel = baseClassObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_LAST_REVISION)); + baseRel = classObject.get_relationship(objyClass.resolve_position(ObjyBase.ATT_BASE)); } - setObjectId(classObject.objectID()); + return baseRel; } public ObjyClass objyClass() @@ -141,8 +224,9 @@ public class ObjyObject checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINERID); - SingleReferenceMapper.INSTANCE.setValue(this, position, containerID); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINERID); + + SingleReferenceMapper.INSTANCE.setValue(this, ObjyBase.ATT_CONTAINERID/* position */, containerID); } public Object getEContainer() @@ -152,8 +236,8 @@ public class ObjyObject checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINERID); - Object value = SingleReferenceMapper.INSTANCE.getValue(this, position); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINERID); + Object value = SingleReferenceMapper.INSTANCE.getValue(this, ObjyBase.ATT_CONTAINERID/* position */); return value; } @@ -165,8 +249,8 @@ public class ObjyObject checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINERID); - ooId childOid = get_ooId(position); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINERID); + ooId childOid = get_ooId(ObjyBase.ATT_CONTAINERID/* position */); return childOid; } @@ -177,8 +261,8 @@ public class ObjyObject checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_RESOURCEID); - SingleReferenceMapper.INSTANCE.setValue(this, position, resourceID); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_RESOURCEID); + SingleReferenceMapper.INSTANCE.setValue(this, ObjyBase.ATT_RESOURCEID/* position */, resourceID); } @@ -189,8 +273,8 @@ public class ObjyObject checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_RESOURCEID); - Object value = SingleReferenceMapper.INSTANCE.getValue(this, position); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_RESOURCEID); + Object value = SingleReferenceMapper.INSTANCE.getValue(this, ObjyBase.ATT_RESOURCEID/* position */); return value; } @@ -201,8 +285,8 @@ public class ObjyObject { checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_RESOURCEID); - ooId childOid = get_ooId(position); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_RESOURCEID); + ooId childOid = get_ooId(ObjyBase.ATT_RESOURCEID/* position */); return childOid; } @@ -212,8 +296,8 @@ public class ObjyObject { checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINER_FEATUERID); - set_numeric(position, new Numeric_Value(contFeature)); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINER_FEATUERID); + set_numeric(ObjyBase.ATT_CONTAINER_FEATUERID/* position */, new Numeric_Value(contFeature)); } public int getEContainingFeature() @@ -222,22 +306,30 @@ public class ObjyObject { checkSession(); } - Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINER_FEATUERID); - return get_numeric(position).intValue(); + // Class_Position position = objyClass.resolve_position(ObjyBase.ATT_CONTAINER_FEATUERID); + return get_numeric(ObjyBase.ATT_CONTAINER_FEATUERID/* position */).intValue(); } /** * This is used to cache the composite features, (manyAttributes, manyReference, and featureMap. TBD - verify the need * of this. */ - public Object getFeatureList(Class_Position position) + // public Object getFeatureList(Class_Position position) + // { + // return featureMap.get(position); + // } + public Object getFeatureList(String featureName) { - return featureMap.get(position); + return featureMap.get(featureName); } - public void setFeatureList(Class_Position position, Object object) + // public void setFeatureList(Class_Position position, Object object) + // { + // featureMap.put(position, object); + // } + public void setFeatureList(String featureName, Object object) { - featureMap.put(position, object); + featureMap.put(featureName, object); } public int getVersion() @@ -246,7 +338,10 @@ public class ObjyObject { checkSession(); } - int version = classObject.get_numeric(objyClass.resolve_position(ObjyBase.ATT_VERSION)).intValue(); + if (version == Integer.MAX_VALUE) + { + version = classObject.get_numeric(objyClass.resolve_position(ObjyBase.ATT_VERSION)).intValue(); + } return version; } @@ -257,7 +352,8 @@ public class ObjyObject checkSession(); } classObject.set_numeric(objyClass.resolve_position(ObjyBase.ATT_VERSION), new Numeric_Value(version)); - getVersion(); // TBD, verify the need for this call!!!! + // getVersion(); // TBD, verify the need for this call!!!! + this.version = version; } public long getCreationTime() @@ -281,56 +377,90 @@ public class ObjyObject public long getRevisedTime() { - if (TRACER_DEBUG.isEnabled()) + long revisedTime = 0; + + try { - checkSession(); + if (TRACER_DEBUG.isEnabled()) + { + checkSession(); + } + revisedTime = classObject.get_numeric(objyClass.resolve_position(ObjyBase.ATT_REVISED_TIME)).longValue(); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); } - long revisedTime = classObject.get_numeric(objyClass.resolve_position(ObjyBase.ATT_REVISED_TIME)).longValue(); + return revisedTime; } public void setRevisedTime(long revisedTime) { - if (TRACER_DEBUG.isEnabled()) + try { - checkSession(); + if (TRACER_DEBUG.isEnabled()) + { + checkSession(); + } + classObject.set_numeric(objyClass.resolve_position(ObjyBase.ATT_REVISED_TIME), new Numeric_Value(revisedTime)); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); } - classObject.set_numeric(objyClass.resolve_position(ObjyBase.ATT_REVISED_TIME), new Numeric_Value(revisedTime)); } public void setBranchId(int branchId) { - if (TRACER_DEBUG.isEnabled()) + try { - checkSession(); + if (TRACER_DEBUG.isEnabled()) + { + checkSession(); + } + classObject.set_numeric(objyClass.resolve_position(ObjyBase.ATT_BRANCHID), new Numeric_Value(branchId)); } - classObject.set_numeric(objyClass.resolve_position(ObjyBase.ATT_BRANCHID), new Numeric_Value(branchId)); + catch (RuntimeException ex) + { + ex.printStackTrace(); + } + } public long getBranchId() { - if (TRACER_DEBUG.isEnabled()) + int branchId = 0; + try { - checkSession(); + if (TRACER_DEBUG.isEnabled()) + { + checkSession(); + } + branchId = classObject.get_numeric(objyClass.resolve_position(ObjyBase.ATT_BRANCHID)).intValue(); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); } - int branchId = classObject.get_numeric(objyClass.resolve_position(ObjyBase.ATT_BRANCHID)).intValue(); return branchId; } - public ObjyObject copy(EClass eClass) + public ObjyObject copy(EClass eClass, ObjyObjectManager objyObjectManager) { ObjyObject newObjyObject = null; ooObj obj = ooObj.create_ooObj(objectId); ooObj newObj = (ooObj)obj.copy(obj); // Objy internal copy. // Dependent structures, for example array of refs are not copies, so we // have to iterate and copy (deep copy). - newObjyObject = new ObjyObject(Class_Object.class_object_from_oid(newObj.getOid())); + // newObjyObject = new ObjyObject(Class_Object.class_object_from_oid(newObj.getOid())); + newObjyObject = objyObjectManager.getObject(newObj.getOid()); try { if (TRACER_DEBUG.isEnabled()) { - TRACER_DEBUG.trace("=> ObjyObject.copy() - oid:" + ooId().getStoreString() + " version:" + getVersion()); + TRACER_DEBUG.trace("ObjyObject.copy() - oid:" + ooId().getStoreString() + " version:" + getVersion()); } for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) { @@ -342,6 +472,47 @@ public class ObjyObject if (feature.isMany()) { // copy this feature to the new object. + // copy this feature to the new object. + // get the attribute using feature name. + d_Attribute attribute = objyClass.resolve_attribute(feature.getName()); + // System.out.println("... checking feature: " + feature.getName() + - attributeType: " + // + attribute.type_of().name()); + if (attribute != null && attribute.type_of() instanceof d_Ref_Type) + { + // IS:temptest Class_Position position = objyClass.resolve_position(feature.getName()); + // ooId refOoId = get_ooId(position); + Class_Object cObj = get_class_obj(feature.getName()); + if (cObj != null) + { + // System.out.println("\t\t referenced Class_Object with OID: " +cObj.objectID().getStoreString()); + d_Class refClass = cObj.type_of(); + String refClassName = refClass.name(); + if (refClassName.equals(ObjyFeatureMapArrayList.ClassName)) + { + // we'll need to copy this one. + TRACER_DEBUG.trace("\t TBD - copying ObjyFeatureMapArrayList attr: " + attribute.name()); + } + else if (refClassName.equals(ObjyArrayListString.ClassName)) + { + // we'll need to copy this one. + TRACER_DEBUG.trace("\t TBD - copying ObjyArrayListString attr: " + attribute.name()); + } + else if (refClassName.equals(ObjyArrayListId.className)) + { + // we'll need to copy this one. + // System.out.println("\t copying ObjyArrayListId attr: " + attibute.name()); + ObjyArrayListId arrayListId = new ObjyArrayListId(cObj); + ooObj newArrayListId = arrayListId.copy(newObj); + newObjyObject.set_ooId(feature.getName(), newArrayListId.getOid()); + } + else if (refClassName.equals(ObjyProxy.className)) + { + // we'll need to copy this one. + TRACER_DEBUG.trace("\t TBD - copying ObjyProxy attr: " + attribute.name()); + } + } + } + } } } @@ -361,13 +532,15 @@ public class ObjyObject */ public void update(ObjectivityStoreAccessor storeAccessor, InternalCDORevision revision) { + updateCount++; + try { if (TRACER_DEBUG.isEnabled()) { checkSession(); - TRACER_DEBUG.trace("=> ObjyObject.update() - oid:" + ooId().getStoreString() + " - version:" + TRACER_DEBUG.trace("ObjyObject.update() - oid:" + ooId().getStoreString() + " - version:" + revision.getVersion()); } @@ -445,8 +618,14 @@ public class ObjyObject { // TODO - this code need refactoring... Object value = list.get(i); - if (value instanceof CDOIDExternal) + if (null == value) + { + values[i] = value; + continue; + } + else if (value instanceof CDOIDExternal) { + TRACER_DEBUG.trace("... CDOIDExternal inserted, at:" + i + ", content:" + ((CDOIDExternal)value).getURI()); // System.out.println("value is a proxy object - it should be handled by the mapper."); // create an ObjyProxy object to hold the the value. ObjyProxy proxyObject = ObjyProxy.createObject(ooId()); @@ -456,7 +635,7 @@ public class ObjyObject } else if (value instanceof CDOID) { - values[i] = OBJYCDOIDUtil.getooId((CDOID)list.get(i)); + values[i] = OBJYCDOIDUtil.getooId((CDOID)value); } else if (value instanceof FeatureMap.Entry) { @@ -467,6 +646,8 @@ public class ObjyObject ooId oid = null; if (entryValue instanceof CDOIDExternal) { + TRACER_DEBUG.trace("... CDOIDExternal inserted, at:" + i + ", content:" + + ((CDOIDExternal)entryValue).getURI()); // System.out.println("value is a proxy object - it should be handled by the mapper."); // create an ObjyProxy object to hold the the value. ObjyProxy proxyObject = ObjyProxy.createObject(ooId()); @@ -484,24 +665,26 @@ public class ObjyObject TRACER_DEBUG.trace("OBJY: don't know what kind of entryValue is this!!! - " + entryValue); } } - // FeatureMapEntry is a presistent class. ObjyFeatureMapEntry featureMapEntry = new ObjyFeatureMapEntry(entryFeature.getFeatureID(), oid, objectId); // this.cluster(featureMapEntry); values[i] = featureMapEntry; } + else if (value.equals(InternalCDOList.UNINITIALIZED)) + { + TRACER_DEBUG.format("...GOT UNINITIALIZED at {0}, listSize:{1}, feature:{2}, oid:{3}", i, values.length, + feature.getName(), objectId.getStoreString()); + continue; + } else { // different feature then. - // System.out.println("-->> Hmmm feature (" + i + ") -> feature:" + feature.getName() + " - value:" + - // value); values[i] = value; } } ((IManyTypeMapper)mapper).setAll(this, feature, 0, values); - // ((IManyTypeMapper)mapper).addAll(this, feature, values); } else { @@ -520,37 +703,56 @@ public class ObjyObject } } - public ObjyObject getLastRevision() + public ObjyObject getLastRevision(ObjyObjectManager objyObjectManager) { - if (!lastRevisionRel.exists()) + if (!getLastRevisionRelationship().exists()) { return this; } - Class_Object lastRevision = lastRevisionRel.get_class_obj(); - return new ObjyObject(lastRevision); + // Class_Object lastRevision = lastRevisionRel.get_class_obj(); + ooId lastRevisionOid = getLastRevisionRelationship().get_ooId(); + // return new ObjyObject(lastRevision); + return objyObjectManager.getObject(lastRevisionOid); } - public ObjyObject getRevisionByVersion(int version) + public ObjyObject getRevisionByVersion(int version, long branchId, ObjyObjectManager objyObjectManager) { ObjyObject objyRevision = null; - if (Math.abs(getVersion()) == version) + int objectVersion = getVersion(); + long objectBranchId = getBranchId(); + + if (branchId == objectBranchId && Math.abs(objectVersion) == version) { // there is a first time for everything... return this; } - Session.getCurrent().setReturn_Class_Object(true); + + // check last revision first. + objyRevision = getLastRevision(objyObjectManager); + objectVersion = objyRevision.getVersion(); + objectBranchId = objyRevision.getBranchId(); + if (branchId == objectBranchId && Math.abs(objectVersion) == version) + { + return objyRevision; + } + + // Session.getCurrent().setReturn_Class_Object(true); // int numRevisions = (int) revisions.size(); @SuppressWarnings("unchecked") - Iterator<Class_Object> itr = revisionsRel.get_iterator(); + Iterator<ooObj> itr = getRevisionsRelationship().get_iterator(); while (itr.hasNext()) { - objyRevision = new ObjyObject(itr.next()); - if (Math.abs(objyRevision.getVersion()) == version) + // objyRevision = new ObjyObject(itr.next()); + objyRevision = objyObjectManager.getObject(itr.next().getOid()); + objectVersion = objyRevision.getVersion(); + objectBranchId = objyRevision.getBranchId(); + if (branchId == objectBranchId && Math.abs(objectVersion) == version) { return objyRevision; } + objyRevision = null; } return null; @@ -558,10 +760,17 @@ public class ObjyObject public void addToRevisions(ObjyObject objyRevision) { - revisionsRel.add(objyRevision.objectId); - // set it as last rev. - lastRevisionRel.clear(); // Ouch!! performance issue... - lastRevisionRel.form(objyRevision.objectId); + try + { + getRevisionsRelationship().add(objyRevision.objectId); + // set it as last rev. + getLastRevisionRelationship().clear(); // Ouch!! performance issue... + getLastRevisionRelationship().form(objyRevision.objectId); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); + } } // /** @@ -586,6 +795,7 @@ public class ObjyObject public boolean fetch(ObjectivityStoreAccessor storeAccessor, InternalCDORevision revision, int listChunk) { boolean bRet = true; + fetchCount++; if (TRACER_DEBUG.isEnabled()) { checkSession(); @@ -596,7 +806,7 @@ public class ObjyObject { if (TRACER_DEBUG.isEnabled()) { - TRACER_DEBUG.trace("=> ObjyObject.fetch() - oid:" + ooId().getStoreString() + " version:" + getVersion()); + TRACER_DEBUG.trace("ObjyObject.fetch() - oid:" + ooId().getStoreString() + " version:" + getVersion()); } // Put the version of the objects; revision.setVersion(getVersion()); @@ -625,7 +835,7 @@ public class ObjyObject { int featureSize = size(feature); int chunkSize = featureSize; - if (listChunk != CDORevision.UNCHUNKED) + if (listChunk != CDORevision.UNCHUNKED && listChunk > 0) { chunkSize = Math.min(chunkSize, listChunk); } @@ -649,46 +859,38 @@ public class ObjyObject if (objects[i] instanceof ooId) { // TODO - this code need refactoring.... - - Class_Object refClassObject = Class_Object.class_object_from_oid((ooId)objects[i]); - - if (refClassObject.type_of().name().equals(ObjyProxy.className)) + CDOID cdoId = null; + ooId objyOid = (ooId)objects[i]; + if (objyOid.isNull()) { - // System.out.println("OBJY: Got proxy: " + refClassObject.objectID().getStoreString()); - ObjyProxy proxyObject = new ObjyProxy(refClassObject); - // cdoList.set(i, - // OBJYCDOIDUtil.createCDIDExternal(proxyObject)); - list.add(OBJYCDOIDUtil.createCDIDExternal(proxyObject)); + cdoId = OBJYCDOIDUtil.getCDOID(objyOid); } else { - CDOID childID = OBJYCDOIDUtil.getCDOID((ooId)objects[i]); - // cdoList.set(i, childID); - list.add(childID); + Class_Object refClassObject = Class_Object.class_object_from_oid((ooId)objects[i]); + + if (refClassObject.type_of().name().equals(ObjyProxy.className)) + { + // System.out.println("OBJY: Got proxy: " + refClassObject.objectID().getStoreString()); + ObjyProxy proxyObject = new ObjyProxy(refClassObject); + // cdoList.set(i, + // OBJYCDOIDUtil.createCDIDExternal(proxyObject)); + cdoId = OBJYCDOIDUtil.createCDIDExternal(proxyObject); + } + else + { + cdoId = OBJYCDOIDUtil.getCDOID(objyOid); + } + refClassObject = null; } - refClassObject = null; + list.add(cdoId); + + continue; } else if (objects[i] instanceof ObjyFeatureMapEntry) { - ObjyFeatureMapEntry mapEntry = (ObjyFeatureMapEntry)objects[i]; - ooId oid = mapEntry.getObject(); - CDOID id = null; - Class_Object refClassObject = Class_Object.class_object_from_oid(oid); - if (refClassObject.type_of().name().equals(ObjyProxy.className)) - { - // System.out.println("OBJY: Got proxy: " + refClassObject.objectID().getStoreString()); - ObjyProxy proxyObject = new ObjyProxy(refClassObject); - id = OBJYCDOIDUtil.createCDIDExternal(proxyObject); - } - else - { - id = OBJYCDOIDUtil.getCDOID(oid); - } - - EStructuralFeature entryFeature = eClass.getEStructuralFeature(mapEntry.getTagId()); - FeatureMap.Entry entry = CDORevisionUtil.createFeatureMapEntry(entryFeature, id); + FeatureMap.Entry entry = getFeatureMapEntry(eClass, (ObjyFeatureMapEntry)objects[i]); list.add(entry); - refClassObject = null; } else { @@ -733,9 +935,11 @@ public class ObjyObject * Fetch data for a specific feature from the store, and return a list of objects. Used by * ObjectivityStoreChunkAccessor */ - public Object[] fetch(ObjectivityStoreAccessor storeAccessor, EStructuralFeature feature, int startIndex, + public List<Object> fetchList(ObjectivityStoreAccessor storeAccessor, EStructuralFeature feature, int startIndex, int chunkSize) { + fetchCount++; + List<Object> results = new ArrayList<Object>(); EClass eClass = feature.getEContainingClass(); @@ -748,65 +952,91 @@ public class ObjyObject { if (TRACER_DEBUG.isEnabled()) { - TRACER_DEBUG.trace("=> ObjyObject.fetch() - feature:" + feature.getName() + "from Object: " + TRACER_DEBUG.trace("ObjyObject.fetch() - feature:" + feature.getName() + "from Object: " + ooId().getStoreString() + " version:" + getVersion()); } int featureSize = size(feature); chunkSize = Math.min(featureSize - startIndex, chunkSize); Object[] objects = getAll(feature, startIndex, chunkSize); - // if (size > 0) - { - for (int i = 0; i < chunkSize; i++) - { - if (objects[i] instanceof ooId) - { - // TODO - this code need refactoring.... + convertToCdoList(objects, results, eClass, chunkSize); + } + catch (com.objy.as.asException ex) + { + ex.printStackTrace(); + } - // System.out.println("-->> IS: getting Class_Object from OID: " - // + childObject.getStoreString()); - Class_Object refClassObject = Class_Object.class_object_from_oid((ooId)objects[i]); + return results; + } - if (refClassObject.type_of().name().equals(ObjyProxy.className)) - { - ObjyProxy proxyObject = new ObjyProxy(refClassObject); + /** + * Function thats takes a list of Objy objects and convert them to CDO IDs This function is used by queryXRefs() as + * well. + */ + protected void convertToCdoList(Object[] objects, List<Object> results, EClass eClass, int chunkSize) + { + { + for (int i = 0; i < chunkSize; i++) + { + if (objects[i] instanceof ooId) + { + // TODO - this code need refactoring.... - results.add(OBJYCDOIDUtil.createCDIDExternal(proxyObject)); - } - else - { - results.add(OBJYCDOIDUtil.getCDOID((ooId)objects[i])); - } + // System.out.println("-->> IS: getting Class_Object from OID: " + // + childObject.getStoreString()); + CDOID cdoId = null; + ooId objyOid = (ooId)objects[i]; + if (objyOid.isNull()) + { + cdoId = OBJYCDOIDUtil.getCDOID(objyOid); } - else if (objects[i] instanceof ObjyFeatureMapEntry) + else { - ObjyFeatureMapEntry mapEntry = (ObjyFeatureMapEntry)objects[i]; - ooId oid = mapEntry.getObject(); - CDOID id = null; - Class_Object refClassObject = Class_Object.class_object_from_oid(oid); + Class_Object refClassObject = Class_Object.class_object_from_oid(objyOid); + if (refClassObject.type_of().name().equals(ObjyProxy.className)) { ObjyProxy proxyObject = new ObjyProxy(refClassObject); - id = OBJYCDOIDUtil.createCDIDExternal(proxyObject); + cdoId = OBJYCDOIDUtil.createCDIDExternal(proxyObject); } else { - id = OBJYCDOIDUtil.getCDOID(oid); + cdoId = OBJYCDOIDUtil.getCDOID(objyOid); } - - EStructuralFeature entryFeature = eClass.getEStructuralFeature(mapEntry.getTagId()); - FeatureMap.Entry entry = CDORevisionUtil.createFeatureMapEntry(entryFeature, id); - results.add(entry); + refClassObject = null; } + + results.add(cdoId); + continue; + + } + else if (objects[i] instanceof ObjyFeatureMapEntry) + { + FeatureMap.Entry entry = getFeatureMapEntry(eClass, (ObjyFeatureMapEntry)objects[i]); + results.add(entry); } } } - catch (com.objy.as.asException ex) + } + + private FeatureMap.Entry getFeatureMapEntry(EClass eClass, ObjyFeatureMapEntry mapEntry) + { + ooId oid = mapEntry.getObject(); + CDOID id = null; + Class_Object refClassObject = Class_Object.class_object_from_oid(oid); + if (refClassObject.type_of().name().equals(ObjyProxy.className)) { - ex.printStackTrace(); + ObjyProxy proxyObject = new ObjyProxy(refClassObject); + id = OBJYCDOIDUtil.createCDIDExternal(proxyObject); + } + else + { + id = OBJYCDOIDUtil.getCDOID(oid); } - return results.toArray(); + EStructuralFeature entryFeature = eClass.getEStructuralFeature(mapEntry.getTagId()); + FeatureMap.Entry entry = CDORevisionUtil.createFeatureMapEntry(entryFeature, id); + return entry; } /** @@ -821,18 +1051,25 @@ public class ObjyObject { checkSession(); } + int size = 0; // Class_Position position = objyClass().resolve_position(feature.getName()); + try + { + IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); - IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); - - int size = mapper.size(this, feature); + size = mapper.size(this, feature); - if (TRACER_DEBUG.isEnabled()) + if (TRACER_DEBUG.isEnabled()) + { + // TODO - verify the message. + TRACER_DEBUG.trace("Size of object " + ooId().getStoreString() + " - is: " + size + " - feature: " + + feature.getName()); + } + } + catch (RuntimeException ex) { - // TODO - verify the message. - TRACER_DEBUG.trace("Size of object " + ooId().getStoreString() + " - is: " + size + " - feature: " - + feature.getName()); + ex.printStackTrace(); } return size; } @@ -842,6 +1079,10 @@ public class ObjyObject */ public Object get(EStructuralFeature feature) { + if (feature.isMany()) + { + return getAll(feature, 0, CDORevision.UNCHUNKED); + } return get(feature, 0); } @@ -871,15 +1112,21 @@ public class ObjyObject ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); Object value = null; - if (feature.isMany()) + try { - value = ((IManyTypeMapper)mapper).getValue(this, feature, index); + if (feature.isMany()) + { + value = ((IManyTypeMapper)mapper).getValue(this, feature, index); + } + else + { + value = ((ISingleTypeMapper)mapper).getValue(this, feature); + } } - else + catch (RuntimeException ex) { - value = ((ISingleTypeMapper)mapper).getValue(this, feature); + ex.printStackTrace(); } - return value; } @@ -904,9 +1151,17 @@ public class ObjyObject } assert feature.isMany(); + Object[] values = null; - IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); - Object[] values = mapper.getAll(this, feature, startIndex, chunkSize); + try + { + IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); + values = mapper.getAll(this, feature, startIndex, chunkSize); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); + } return values; } @@ -921,15 +1176,22 @@ public class ObjyObject assert feature.isMany(); - IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); + try + { + IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); - // -- TODO -- verify the need to this one. - // ensureObjectAttached(feature, value); + // -- TODO -- verify the need to this one. + // ensureObjectAttached(feature, value); - // I believe we do the conversion in the add() - // value = provider.convertToStore(ooObject, value); + // I believe we do the conversion in the add() + // value = provider.convertToStore(ooObject, value); - mapper.add(this, feature, index, value); + mapper.add(this, feature, index, value); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); + } } /*** @@ -944,10 +1206,16 @@ public class ObjyObject } // Class_Position position = objyClass.resolve_position(feature.getName()); + try + { + ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); - ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); - - ((IManyTypeMapper)mapper).clear(this, feature); + ((IManyTypeMapper)mapper).clear(this, feature); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); + } } public void move(EStructuralFeature feature, int targetIndex, int sourceIndex) @@ -957,10 +1225,16 @@ public class ObjyObject checkSession(); TRACER_DEBUG.trace("Move element from " + sourceIndex + " to " + targetIndex); } + try + { + ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); - ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); - - ((IManyTypeMapper)mapper).move(this, feature, targetIndex, sourceIndex); + ((IManyTypeMapper)mapper).move(this, feature, targetIndex, sourceIndex); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); + } } public Object remove(EStructuralFeature feature, int index) @@ -972,19 +1246,27 @@ public class ObjyObject } // Class_Position position = objyClass.resolve_position(feature.getName()); + Object retObject = null; - IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); + try + { + IManyTypeMapper mapper = (IManyTypeMapper)ObjyMapper.INSTANCE.getTypeMapper(feature); + + Object value = mapper.remove(this, feature, index); - Object value = mapper.remove(this, feature, index); + if (feature instanceof EAttribute) + { + return value; + } - if (feature instanceof EAttribute) + retObject = OBJYCDOIDUtil.getCDOID((ooId)value); + } + catch (RuntimeException ex) { - return value; + ex.printStackTrace(); } - Object objectFromResource = OBJYCDOIDUtil.getCDOID((ooId)value); - - return objectFromResource; + return retObject; } @@ -1004,24 +1286,30 @@ public class ObjyObject * ooObject.ooClass().resolve_position(className + "::" + feature.getName()); */ // Class_Position position = objyClass.resolve_position(feature.getName()); + try + { + ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); - ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); - - // --- TODO --- verify the need... - // ensureObjectAttached(this, feature, value); + // --- TODO --- verify the need... + // ensureObjectAttached(this, feature, value); - /*** - * I believe we do the conversion in the setValue if (feature instanceof EReference) { value = - * CDOIDUtil.getooId((CDOID)value); } - ***/ + /*** + * I believe we do the conversion in the setValue if (feature instanceof EReference) { value = + * CDOIDUtil.getooId((CDOID)value); } + ***/ - if (feature.isMany()) - { - ((IManyTypeMapper)mapper).setValue(this, feature, index, value); + if (feature.isMany()) + { + ((IManyTypeMapper)mapper).setValue(this, feature, index, value); + } + else + { + ((ISingleTypeMapper)mapper).setValue(this, feature, value); + } } - else + catch (RuntimeException ex) { - ((ISingleTypeMapper)mapper).setValue(this, feature, value); + ex.printStackTrace(); } return value; @@ -1062,120 +1350,165 @@ public class ObjyObject public void delete(ObjectivityStoreAccessor storeAccessor, ObjyObjectManager objectManager) { EClass eClass = ObjySchema.getEClass(storeAccessor.getStore(), objyClass()); - - for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) + try { - if (!(feature instanceof EAttribute || feature instanceof EReference) || !EMFUtil.isPersistent(feature)) - { - continue; - } - - if (feature.isMany()) + for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) { - // TODO - verify that we can do this to all referenced list. - // I'm not sure if it's valid when you have many-many - // relationship. - Object[] objects = getAll(feature, 0, -1); + if (!(feature instanceof EAttribute || feature instanceof EReference) || !EMFUtil.isPersistent(feature)) + { + continue; + } - for (int i = 0; i < objects.length; i++) + if (feature.isMany()) { - if (objects[i] instanceof ooId) + deleteFeatureObjects(objectManager, feature); + } + else + { + ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); + + if (mapper == null) { - ooId oid = (ooId)objects[i]; - // TODO - this code need refactoring.... - ooObj obj = ooObj.create_ooObj(oid); - if (obj.isDead()) - { - continue; - } + continue; + } + mapper.delete(this, feature); + } + } + } + catch (RuntimeException ex) + { + ex.printStackTrace(); + } + } - Class_Object refClassObject = Class_Object.class_object_from_oid(oid); + private void deleteFeatureObjects(ObjyObjectManager objectManager, EStructuralFeature feature) + { + // TODO - verify that we can do this to all referenced list. + // I'm not sure if it's valid when you have many-many relationship. + Object[] objects = getAll(feature, 0, CDORevision.UNCHUNKED); - if (refClassObject.type_of().name().equals(ObjyProxy.className)) - { - obj.delete(); - } - else - { - // if this object is a parent (resourceId or - // containerId) for obj, then we - // need to mark obj version as (-1). - ObjyObject childObjyObject = objectManager.getObject(oid); - ooId containerId = childObjyObject.getEContainerAsOid(); - ooId resourceId = childObjyObject.getEResourceAsOid(); - int childVersion = childObjyObject.getVersion(); - if (containerId.equals(objectId) || resourceId.equals(objectId)) - { - childObjyObject.setVersion(-childVersion); - } + if (objects == null) + { + return; + } - } - } - else if (objects[i] instanceof ObjyFeatureMapEntry) - { - ObjyFeatureMapEntry mapEntry = (ObjyFeatureMapEntry)objects[i]; - ooId oid = mapEntry.getObject(); - ooObj obj = ooObj.create_ooObj(oid); - obj.delete(); - } - else + for (int i = 0; i < objects.length; i++) + { + if (objects[i] instanceof ooId) + { + ooId oid = (ooId)objects[i]; + // TODO - this code need refactoring.... + ooObj obj = ooObj.create_ooObj(oid); + if (obj.isDead()) + { + continue; + } + + Class_Object refClassObject = Class_Object.class_object_from_oid(oid); + + if (refClassObject.type_of().name().equals(ObjyProxy.className)) + { + obj.delete(); + } + else + { + // if this object is a parent (resourceId or + // containerId) for obj, then we + // need to mark obj version as (-1). + ObjyObject childObjyObject = objectManager.getObject(oid); + ooId containerId = childObjyObject.getEContainerAsOid(); + ooId resourceId = childObjyObject.getEResourceAsOid(); + int childVersion = childObjyObject.getVersion(); + if (containerId.equals(objectId) || resourceId.equals(objectId)) { - // different feature then. - if (TRACER_DEBUG.isEnabled()) - { - TRACER_DEBUG.trace("-->> No process to delete() feature (" + i + ") -> feature:" + feature.getName() - + " - value:" + objects[i] + " ... nothing to do here."); - } + childObjyObject.setVersion(-childVersion); } + } } + else if (objects[i] instanceof ObjyFeatureMapEntry) + { + ObjyFeatureMapEntry mapEntry = (ObjyFeatureMapEntry)objects[i]; + ooId oid = mapEntry.getObject(); + ooObj obj = ooObj.create_ooObj(oid); + obj.delete(); + } else { - ITypeMapper mapper = ObjyMapper.INSTANCE.getTypeMapper(feature); - - if (mapper == null) + // different feature then. + if (TRACER_DEBUG.isEnabled()) { - continue; + TRACER_DEBUG.trace("-->> No process to delete() feature (" + i + ") -> feature:" + feature.getName() + + " - value:" + objects[i] + " ... nothing to do here."); } - mapper.delete(this, feature); } } } // Wrapper functions over class object. - public Numeric_Value get_numeric(Class_Position position) + // public Numeric_Value get_numeric(Class_Position position) + // { + // return classObject.get_numeric(position); + // } + public Numeric_Value get_numeric(String attributeName) { - return classObject.get_numeric(position); + return classObject.nget_numeric(attributeName); } - public String_Value get_string(Class_Position position) + // public String_Value get_string(Class_Position position) + // { + // return classObject.get_string(position); + // } + public String_Value get_string(String attributeName) { - return classObject.get_string(position); + return classObject.nget_string(attributeName); } - public void set_numeric(Class_Position position, Numeric_Value value) + // public void set_numeric(Class_Position position, Numeric_Value value) + // { + // classObject.set_numeric(position, value); + // } + public void set_numeric(String attributeName, Numeric_Value value) { - classObject.set_numeric(position, value); + classObject.nset_numeric(attributeName, value); } - public VArray_Object get_varray(Class_Position position) + // public VArray_Object get_varray(Class_Position position) + // { + // return classObject.get_varray(position); + // } + public VArray_Object get_varray(String attributeName) { - return classObject.get_varray(position); + return classObject.nget_varray(attributeName); } - public ooId get_ooId(Class_Position position) + // public ooId get_ooId(Class_Position position) + // { + // return classObject.get_ooId(position); + // } + public ooId get_ooId(String attributeName) { - return classObject.get_ooId(position); + return classObject.nget_ooId(attributeName); } - public Class_Object get_class_obj(Class_Position position) + // public Class_Object get_class_obj(Class_Position position) + // { + // return classObject.get_class_obj(position); + // } + + public Class_Object get_class_obj(String attributeName) { - return classObject.get_class_obj(position); + return classObject.nget_class_obj(attributeName); } - public void set_ooId(Class_Position position, ooId object) + // public void set_ooId(Class_Position position, ooId object) + // { + // classObject.set_ooId(position, object); + // } + + public void set_ooId(String attributeName, ooId object) { - classObject.set_ooId(position, object); + classObject.nset_ooId(attributeName, object); } /** @@ -1183,23 +1516,58 @@ public class ObjyObject */ public CDOID getRevisionId() { - ooId oid = objectId; - - if (baseClassObject != null) + if (revisionId == null) { - oid = baseClassObject.objectID(); + if (hasBaseRelationship()) + { + baseClassObject = getBaseRelationship().get_class_obj(); + revisionId = baseClassObject.objectID(); + } + else + { + revisionId = objectId; + } } - return OBJYCDOIDUtil.getCDOID(oid); + return OBJYCDOIDUtil.getCDOID(revisionId); } + private boolean hasBaseRelationship() + { + if (!hasBaseRelationshipChecked) + { + hasBaseRelationshipChecked = getBaseRelationship().exists(); + } + return hasBaseRelationshipChecked; + } + + // private boolean hasRevisionsRelationship() + // { + // if (!hasRevisionsRelChecked) + // { + // hasRevisionsRelChecked = getRevisionsRelationship().exists(); + // } + // return hasRevisionsRelChecked; + // } + // + // private boolean hasLastRevisionRelationship() + // { + // if (!hasLastRevisionRelChecked) + // { + // hasLastRevisionRelChecked = getLastRevisionRelationship().exists(); + // } + // return hasLastRevisionRelChecked; + // } + /** * Return the revision that satisfies the timeStamp and branchId constrains. + * + * @param objyObjectManager */ - public ObjyObject getRevision(long timeStamp, int branchId) + public ObjyObject getRevision(long timeStamp, int branchId, ObjyObjectManager objyObjectManager) { ObjyObject objyRevision = null; - Session.getCurrent().setReturn_Class_Object(true); + // Session.getCurrent().setReturn_Class_Object(true); // int numRevisions = (int) revisions.size(); // evaluate current first. @@ -1209,16 +1577,24 @@ public class ObjyObject } // if we don't have other revisions. - if (!lastRevisionRel.exists()) + if (!getLastRevisionRelationship().exists()) { return null; } + // check last revision first. + objyRevision = getLastRevision(objyObjectManager); + if (evaluateRevision(timeStamp, branchId, objyRevision)) + { + return objyRevision; + } + @SuppressWarnings("unchecked") - Iterator<Class_Object> itr = revisionsRel.get_iterator(); + Iterator<ooObj> itr = getRevisionsRelationship().get_iterator(); while (itr.hasNext()) { - objyRevision = new ObjyObject(itr.next()); + // objyRevision = new ObjyObject(itr.next()); + objyRevision = objyObjectManager.getObject(itr.next().getOid()); if (evaluateRevision(timeStamp, branchId, objyRevision)) { return objyRevision; @@ -1229,7 +1605,8 @@ public class ObjyObject } /** - * return true if the objyRevision satisfies the constrains. + * return true if the objyRevision satisfies the constrains. This function is only called in case of auditing, and + * branching. */ protected boolean evaluateRevision(long timeStamp, int branchId, ObjyObject objyRevision) { @@ -1237,15 +1614,15 @@ public class ObjyObject if (objyRevision.getBranchId() == branchId) { long revisedTS = objyRevision.getRevisedTime(); - if (timeStamp != 0) + if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE) { long creationTS = objyRevision.getCreationTime(); - if (creationTS <= timeStamp && (revisedTS == 0 || revisedTS >= timeStamp)) + if (creationTS <= timeStamp && (revisedTS == CDOBranchPoint.UNSPECIFIED_DATE || revisedTS >= timeStamp)) { return true; } } - else if (revisedTS == 0) // return the latest version in that branch. + else if (revisedTS == CDOBranchPoint.UNSPECIFIED_DATE) // return the latest version in that branch. { return true; } @@ -1257,14 +1634,27 @@ public class ObjyObject { ObjyClass objyClass = ObjySchema.getObjyClass(ObjyBase.CLASS_NAME); Class_Object detachedClassObject = Class_Object.new_persistent_object(objyClass.getASClass(), objectId, false); - ObjyObject detachedObjyObject = new ObjyObject(detachedClassObject); + if (TRACER_DEBUG.isEnabled()) + { + ObjyObjectManager.newInternalObjCount++; + } + ObjyObject detachedObjyObject = null; - detachedObjyObject.setVersion(-(version + 1)); - detachedObjyObject.setBranchId(branch.getID()); - detachedObjyObject.setCreationTime(timeStamp); + try + { + detachedObjyObject = new ObjyObject(detachedClassObject); - // add it to the revisions. - addToRevisions(detachedObjyObject); + detachedObjyObject.setVersion(-(version + 1)); + detachedObjyObject.setBranchId(branch.getID()); + detachedObjyObject.setCreationTime(timeStamp); + + // add it to the revisions. + addToRevisions(detachedObjyObject); + } + catch (RuntimeException ex) + { + ex.printStackTrace(); + } } } diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObjectManager.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObjectManager.java index c198bdeea7..3580b8d3c0 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObjectManager.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyObjectManager.java @@ -44,6 +44,16 @@ public class ObjyObjectManager private ObjyPlacementManager globalPlacementManager = null; + public static int newObjCount = 0; + + public static int newInternalObjCount = 0; + + public static long getObjectTime = 0; + + public static long updateObjectTime = 0; + + public static long resourceCheckAndUpdateTime = 0; + public ObjyObjectManager(ObjyPlacementManager placementManager) { globalPlacementManager = placementManager; @@ -73,6 +83,10 @@ public class ObjyObjectManager Class_Object newClassObject = newClassObject(eClass, nearObject); ObjyObject objyObject = new ObjyObject(newClassObject); idToObjyObjectMap.put(OBJYCDOIDUtil.getLong(objyObject.ooId()), objyObject); + if (TRACER_DEBUG.isEnabled()) + { + newObjCount++; + } return objyObject; } @@ -101,6 +115,10 @@ public class ObjyObjectManager // .getStoreString() : null)); Class_Object newClassObject = Class_Object.new_persistent_object(objyClass.getASClass(), nearObject, false); + if (TRACER_DEBUG.isEnabled()) + { + ObjyObjectManager.newInternalObjCount++; + } // if (init != null) // { @@ -252,8 +270,7 @@ public class ObjyObjectManager TRACER_DEBUG.trace("ObjyObjectManager.copyRevision(" + objyObject.ooId().getStoreString() + ")"); } EClass eClass = ObjySchema.getEClass(storeAccessor.getStore(), objyObject.objyClass()); - ObjyObject newObjyRevision = objyObject.copy(eClass); - objyObject.addToRevisions(newObjyRevision); + ObjyObject newObjyRevision = objyObject.copy(eClass, this); return newObjyRevision; } diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySchema.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySchema.java index 07ebcec6cf..d4a0b1cca5 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySchema.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySchema.java @@ -81,6 +81,11 @@ public class ObjySchema { d_Class newClass = getTopModule().resolve_class(name); // EClass eClass = getEClass(store, name); + // IS:TEMP + if (newClass == null) + { + TRACER_DEBUG.trace("NULL..... dClass for " + name); + } classObject = new ObjyClass(newClass); mapOfObjyClasses.put(name, classObject); } @@ -229,6 +234,12 @@ public class ObjySchema // System.out.println("OBJY: resolving class '" + className + "' in objy schema."); d_Class dClass = getTopModule().resolve_class(className); + // IS:TEMP + if (dClass == null) + { + TRACER_DEBUG.trace("NULL..... dClass for " + className); + } + ObjyClass objyClass = new ObjyClass(dClass/* , eClass */); return objyClass; } @@ -253,6 +264,11 @@ public class ObjySchema // System.out.println("OBJY: resolving class '" + className + "' in objy schema."); d_Class dClass = getTopModule().resolve_class(className); + // IS:TEMP. + if (dClass == null) + { + TRACER_DEBUG.trace("NULL..... dClass for " + className); + } ObjyClass objyClass = new ObjyClass(dClass/* , eClass */); return objyClass; } diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyScope.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyScope.java index 666696a49c..9137f7cff3 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyScope.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjyScope.java @@ -29,9 +29,9 @@ public class ObjyScope { private static final ContextTracer TRACER_DEBUG = new ContextTracer(OM.DEBUG, ObjyScope.class); - private ooContObj contObj; + private ooContObj contObj = null; - private ooDBObj dbObj; + private ooDBObj dbObj = null; private String dbName; @@ -76,13 +76,27 @@ public class ObjyScope { if (TRACER_DEBUG.isEnabled()) { - TRACER_DEBUG.trace(" DB: " + dbName + " - CT: " + contName); + TRACER_DEBUG.trace("ObjyScope - DB: " + dbName + " - CT: " + contName); } this.dbName = dbName; this.contName = contName; init(); } + // optimized version that takes an ooDBObj. + public ObjyScope(ooDBObj dbObj, String contName) + { + dbName = dbObj.getName(); + this.contName = contName; + this.dbObj = dbObj; + + if (TRACER_DEBUG.isEnabled()) + { + TRACER_DEBUG.trace("ObjyScope - DB: " + dbObj.getName() + " - CT: " + contName); + } + init(); + } + public ooId getScopeContOid() { return getContainerObj().getOid(); diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySession.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySession.java index 07ce20d1c4..4d9fb61eb9 100644 --- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySession.java +++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/db/ObjySession.java @@ -10,28 +10,40 @@ */ package org.eclipse.emf.cdo.server.internal.objectivity.db; +import org.eclipse.emf.cdo.server.internal.objectivity.bundle.OM; import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyBranchManager; +import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyLockAreaManager; import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyResourceList; import org.eclipse.emf.cdo.server.internal.objectivity.utils.ObjyDb; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import com.objy.db.CannotUpgradeLockException; import com.objy.db.app.Session; import com.objy.db.app.oo; +import com.objy.db.app.ooContObj; +import com.objy.db.app.ooId; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -/*** - * Extends the session and keep an object manager instance. - * +/* * @author ibrahim */ public class ObjySession extends Session { + private static final ContextTracer TRACER_DEBUG = new ContextTracer(OM.DEBUG, ObjySession.class); + + private static final ContextTracer TRACER_INFO = new ContextTracer(OM.INFO, ObjySession.class); + private ObjyObjectManager objectManger = null; private ObjyResourceList resourceList = null; private ObjyBranchManager branchManager = null; + private ObjyLockAreaManager lockAreaManager = null; + // private ObjectivityStore store = null; protected String sessionName; @@ -44,6 +56,8 @@ public class ObjySession extends Session { super(objyConnection.getMinSessionCacheSize(), objyConnection.getMaxSessionCacheSize()); setThreadPolicy(oo.THREAD_POLICY_UNRESTRICTED); + // setHotMode(false); + setIndexMode(oo.EXPLICIT_UPDATE); sessionName = name; sessionPool = pool; // this.store = store; @@ -64,6 +78,15 @@ public class ObjySession extends Session return branchManager; } + public ObjyLockAreaManager getLockAreaManager(String repositoryName) + { + if (lockAreaManager == null) + { + lockAreaManager = ObjyDb.getOrCreateLockAreaManager(repositoryName); + } + return lockAreaManager; + } + public void setAvailable(boolean value) { available = value; @@ -79,6 +102,11 @@ public class ObjySession extends Session return sessionName; } + public void setName(String name) + { + sessionName = name; + } + public ConcurrentHashMap<String, ObjySession> getPool() { return sessionPool; @@ -94,10 +122,70 @@ public class ObjySession extends Session } @Override + public synchronized void returnSessionToPool() + { + // System.out.println(">>> IS: returning session: " + session.getName()); + // TODO Auto-generated method stub + leave(); + setAvailable(true); + } + + @Override public synchronized void terminate() { - // System.out.println("OBJY>>> Terminating session... " + this.toString()); + // System.out.println("OBJY>>> Terminating session... " + sessionName + " - " + toString()); resourceList = null; super.terminate(); } + + public void lockContainers(Set<ooId> containerToLocks) + { + // Locks all containers for modified objects + if (!containerToLocks.isEmpty()) + { + ooId idsToLock[] = containerToLocks.toArray(new ooId[containerToLocks.size()]); + // 100920 - IS: for debugging... TBR. + // for (ooId id : idsToLock) + // { + // TRACER_INFO.trace("Locking container: " + id.getStoreString()); + // } + + int count = 10; + while (0 != count--) + { + try + { + openContainers(idsToLock, oo.openReadWrite); + break; + } + catch (CannotUpgradeLockException cule) + { + // refresh containers. + for (ooId contId : idsToLock) + { + ooContObj contObj = (ooContObj)getFD().objectFrom(contId); + contObj.refresh(oo.WRITE); + } + } + catch (Exception e) + { + TRACER_INFO.trace("Locking problem try again : " + e.getMessage()); + // this.ensureNewBeginSession(); + if (!isOpen()) + { + TRACER_INFO.trace("Objy session is not open"); + // System.exit(-1); // TODO - this is temporary for debugging... + } + try + { + wait(500); + } + catch (InterruptedException ex) + { + } + } + } + } + } + } |