private bool CheckIfCollectionContainsValue(System.Collections.ICollection c) { NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine = GetQuery().GetStorageEngine (); if (engine == null) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.QueryEngineNotSet ); } NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null; System.Collections.IEnumerator iterator = c.GetEnumerator(); // If the object to compared is native if (objectIsNative) { while (iterator.MoveNext()) { aoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo)iterator.Current; if (aoi == null && criterionValue == null) { return(true); } if (aoi != null && criterionValue == null) { return(false); } if (criterionValue.Equals(aoi.GetObject())) { return(true); } } return(false); } // Object is not native while (iterator.MoveNext()) { aoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo)iterator.Current; if (aoi.IsNull() && criterionValue == null && oid == null) { return(true); } if (aoi != null & oid != null) { if (aoi.IsNonNativeObject()) { NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi1 = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo )aoi; bool isEqual = nnoi1.GetOid() != null && oid != null && nnoi1.GetOid().Equals(oid ); if (isEqual) { return(true); } } } } return(false); }
public override NeoDatis.Odb.OID UpdateNonNativeObjectInfo(NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi, bool forceUpdate) { // To enable object auto-reconnect on the server side if (NeoDatis.Odb.OdbConfiguration.ReconnectObjectsToSession() && nnoi.GetHeader() .GetOid() != null) { NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession session = (NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession )sessionManager.GetSession(storageEngine.GetBaseIdentification().GetIdentification (), true); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = session.GetCache().GetObjectInfoHeaderFromOid (nnoi.GetOid(), false); // only add in th cache if object does not exist in the cache if (oih == null) { session.GetCache().AddObjectInfo(nnoi.GetHeader()); } } NeoDatis.Odb.OID roid = base.UpdateNonNativeObjectInfo(nnoi, forceUpdate); if (nnoi is NeoDatis.Odb.Core.Server.Layers.Layer2.Meta.ClientNonNativeObjectInfo) { NeoDatis.Odb.Core.Server.Layers.Layer2.Meta.ClientNonNativeObjectInfo cnnoi = (NeoDatis.Odb.Core.Server.Layers.Layer2.Meta.ClientNonNativeObjectInfo )nnoi; NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession session = (NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession )GetSession(); session.AssociateIds(cnnoi.GetOid(), cnnoi.GetLocalOid()); } return(roid); }
public override NeoDatis.Odb.OID WriteNonNativeObjectInfo(NeoDatis.Odb.OID existingOid , NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo objectInfo, long position , bool writeDataInTransaction, bool isNewObject) { // To enable object auto-reconnect on the server side if (NeoDatis.Odb.OdbConfiguration.ReconnectObjectsToSession() && objectInfo.GetHeader ().GetOid() != null) { NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession session = (NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession )sessionManager.GetSession(storageEngine.GetBaseIdentification().GetIdentification (), true); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = session.GetCache().GetObjectInfoHeaderFromOid (objectInfo.GetOid(), false); // only add in th cache if object does not exist in the cache if (oih == null) { session.GetCache().AddObjectInfo(objectInfo.GetHeader()); } } NeoDatis.Odb.OID roid = base.WriteNonNativeObjectInfo(existingOid, objectInfo, position , writeDataInTransaction, isNewObject); if (objectInfo is NeoDatis.Odb.Core.Server.Layers.Layer2.Meta.ClientNonNativeObjectInfo) { NeoDatis.Odb.Core.Server.Layers.Layer2.Meta.ClientNonNativeObjectInfo cnnoi = (NeoDatis.Odb.Core.Server.Layers.Layer2.Meta.ClientNonNativeObjectInfo )objectInfo; NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession session = (NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession )GetSession(); session.AssociateIds(roid, cnnoi.GetLocalOid()); // Adds the abstract Objectinfo in the cache session.GetCache().AddObjectInfo(cnnoi.GetHeader()); } return(roid); }
/// <returns>Returns the id.</returns> public virtual NeoDatis.Odb.OID GetOid() { if (nnoi != null) { return(nnoi.GetOid()); } return(id); }
public static NeoDatis.Tool.Wrappers.OdbComparable BuildIndexKey(string indexName , NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo oi, int[] fieldIds) { NeoDatis.Tool.Wrappers.OdbComparable[] keys = new NeoDatis.Tool.Wrappers.OdbComparable [fieldIds.Length]; NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null; System.IComparable o = null; for (int i = 0; i < fieldIds.Length; i++) { // Todo : can we assume that the object is a Comparable try { aoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo)oi.GetAttributeValueFromId (fieldIds[i]); o = (System.IComparable)aoi.GetObject(); // JDK1.4 restriction: Boolean is not Comparable in jdk1.4 if (aoi.GetOdbType().IsBoolean()) { bool b = (bool)o; if (b) { o = (byte)1; } else { o = (byte)0; } } // If the index is on NonNativeObjectInfo, then the key is the oid // of the object if (aoi.IsNonNativeObject()) { NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo )aoi; o = nnoi.GetOid(); } keys[i] = new NeoDatis.Odb.Core.Query.SimpleCompareKey(o); } catch (System.Exception) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexKeysMustImplementComparable .AddParameter(fieldIds[i]).AddParameter(oi.GetAttributeValueFromId(fieldIds[i]). GetType().FullName)); } } if (keys.Length == 1) { return(keys[0]); } return(new NeoDatis.Odb.Core.Query.ComposedCompareKey(keys)); }
public virtual void Test3() { NeoDatis.Odb.Core.Transaction.ICache cache = NeoDatis.Odb.Impl.Core.Transaction.CacheFactory .GetLocalCache(null, "temp"); NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo (this.GetType().FullName); ci.SetPosition(1); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih1 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader (); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih2 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader (); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih3 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader (); oih1.SetOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(1)); oih2.SetOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(10)); oih3.SetOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(100)); NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi1 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo (oih1, ci); NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi2 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo (oih2, ci); NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi3 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo (oih3, ci); cache.StartReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (1), nnoi1); cache.StartReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (10), nnoi2); cache.StartReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (100), nnoi3); AssertTrue(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (1))); AssertTrue(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (10))); AssertTrue(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (100))); cache.EndReadingObjectInfo(nnoi1.GetOid()); cache.EndReadingObjectInfo(nnoi2.GetOid()); cache.EndReadingObjectInfo(nnoi3.GetOid()); AssertFalse(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (1))); AssertFalse(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (10))); AssertFalse(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (100))); }
/// <exception cref="System.IO.IOException"></exception> public virtual void Test3() { NeoDatis.Odb.Core.Transaction.ICache cache = NeoDatis.Odb.Impl.Core.Transaction.CacheFactory .GetLocalCache(null, "temp"); NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo (this.GetType().FullName); ci.SetPosition(1); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih1 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader (); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih2 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader (); NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih3 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader (); oih1.SetOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(1)); oih2.SetOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(10)); oih3.SetOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(100)); NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi1 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo (oih1, ci); NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi2 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo (oih2, ci); NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi3 = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo (oih3, ci); cache.StartReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (1), nnoi1); cache.StartReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (10), nnoi2); cache.StartReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (100), nnoi3); AssertTrue(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (1))); AssertTrue(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (10))); AssertTrue(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (100))); cache.EndReadingObjectInfo(nnoi1.GetOid()); cache.EndReadingObjectInfo(nnoi2.GetOid()); cache.EndReadingObjectInfo(nnoi3.GetOid()); AssertFalse(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (1))); AssertFalse(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (10))); AssertFalse(cache.IsReadingObjectInfoWithOid(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID (100))); }
public override string ToString() { System.Text.StringBuilder buffer = new System.Text.StringBuilder(classInfo.GetFullClassName ()).Append("(").Append(GetOid()).Append(")="); if (attributeValues == null) { buffer.Append("null attribute values"); return(buffer.ToString()); } for (int i = 0; i < attributeValues.Length; i++) { if (i != 0) { buffer.Append(","); } string attributeName = (classInfo != null ? (classInfo.GetAttributeInfo(i)).GetName () : "?"); buffer.Append(attributeName).Append("="); object @object = attributeValues[i]; if (@object == null) { buffer.Append(" null java object - should not happen , "); } else { NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType .GetFromClass(attributeValues[i].GetType()); if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeNullObjectInfo) { buffer.Append("null"); continue; } if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeDeletedObjectInfo) { buffer.Append("deleted object"); continue; } if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NativeObjectInfo) { NeoDatis.Odb.Core.Layers.Layer2.Meta.NativeObjectInfo noi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NativeObjectInfo )@object; buffer.Append(noi.ToString()); continue; } if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo) { NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo )@object; buffer.Append("@").Append(nnoi.GetClassInfo().GetFullClassName()).Append("(id="). Append(nnoi.GetOid()).Append(")"); continue; } if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectReference) { buffer.Append(@object.ToString()); continue; } buffer.Append("@").Append(NeoDatis.Tool.Wrappers.OdbClassUtil.GetClassName(type.GetName ())); } } return(buffer.ToString()); }
public virtual void AddIndexOn(string className, string indexName, string[] indexFields , bool verbose, bool acceptMultipleValuesForSameKey) { NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo = GetMetaModel().GetClassInfo (className, true); if (classInfo.HasIndex(indexName)) { throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexAlreadyExist .AddParameter(indexName).AddParameter(className)); } NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex cii = classInfo.AddIndexOn(indexName , indexFields, acceptMultipleValuesForSameKey); NeoDatis.Btree.IBTree btree = null; if (acceptMultipleValuesForSameKey) { btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeMultiple(className, NeoDatis.Odb.OdbConfiguration .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister (this)); } else { btree = new NeoDatis.Odb.Impl.Core.Btree.ODBBTreeSingle(className, NeoDatis.Odb.OdbConfiguration .GetDefaultIndexBTreeDegree(), new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister (this)); } cii.SetBTree(btree); Store(cii); // Now The index must be updated with all existing objects. if (classInfo.GetNumberOfObjects() == 0) { // There are no objects. Nothing to do return; } if (verbose) { NeoDatis.Tool.DLogger.Info("Creating index " + indexName + " on class " + className + " - Class has already " + classInfo.GetNumberOfObjects() + " Objects. Updating index" ); } if (verbose) { NeoDatis.Tool.DLogger.Info(indexName + " : loading " + classInfo.GetNumberOfObjects () + " objects from database"); } // We must load all objects and insert them in the index! NeoDatis.Odb.Objects <object> objects = GetObjectInfos <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery (className), false, -1, -1, false); if (verbose) { NeoDatis.Tool.DLogger.Info(indexName + " : " + classInfo.GetNumberOfObjects() + " objects loaded" ); } NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = null; int i = 0; bool monitorMemory = NeoDatis.Odb.OdbConfiguration.IsMonitoringMemory(); while (objects.HasNext()) { nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo)objects.Next(); btree.Insert(cii.ComputeKey(nnoi), nnoi.GetOid()); if (verbose && i % 1000 == 0) { if (monitorMemory) { NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("Index " + indexName + " " + i + " objects inserted", true); } } i++; } if (verbose) { NeoDatis.Tool.DLogger.Info(indexName + " created!"); } }