public override void Execute(OID oid, AttributeValuesMap values) { var candidate = values[AttributeName]; if (candidate is OID) { var candidateOid = (OID)candidate; candidate = _query.GetQueryEngine().GetObjectFromOid(candidateOid); } var l = ((IEnumerable)candidate).Cast<object>().ToList(); var localFromIndex = _fromIndex; var localEndIndex = _fromIndex + _size; // If not throw exception, we must implement // Index Out Of Bound protection if (!_throwExceptionIfOutOfBound) { // Check from index if (localFromIndex > l.Count - 1) localFromIndex = 0; // Check end index if (localEndIndex > l.Count) localEndIndex = l.Count; } _sublist = new LazySimpleListOfAoi<object>(GetInstanceBuilder(), ReturnInstance()); var count = localEndIndex - localFromIndex; var sublist = l.GetRange(localFromIndex, count); _sublist.AddAll(sublist); }
public AttributeValuesMap ReadObjectInfoValuesFromOID(ClassInfo classInfo, OID oid, bool useCache, IOdbList <string> attributeNames, IOdbList <string> relationAttributeNames, int recursionLevel) { return(null); }
public IOdbList <FieldInfo> GetAllFields(string fullClassName) { IOdbList <FieldInfo> result = null; fields.TryGetValue(fullClassName, out result); if (result != null) { return(result); } System.Collections.IDictionary attributesNames = new System.Collections.Hashtable(); result = new OdbArrayList <FieldInfo>(50); System.Reflection.FieldInfo[] superClassfields = null; System.Collections.IList classes = GetSuperClasses(fullClassName, true); for (int i = 0; i < classes.Count; i++) { System.Type clazz1 = (System.Type)classes[i]; superClassfields = clazz1.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Static); for (int j = 0; j < superClassfields.Length; j++) { // Only adds the attribute if it does not exist one with same name if (attributesNames[superClassfields[j].Name] == null) { result.Add(superClassfields[j]); attributesNames[superClassfields[j].Name] = superClassfields[j].Name; } } } result = RemoveUnnecessaryFields(result); fields[fullClassName] = result; attributesNames.Clear(); attributesNames = null; return(result); }
public ClassInfoIndex AddIndexOn(string name, string[] indexFields, bool acceptMultipleValuesForSameKey) { if (_indexes == null) { _indexes = new OdbList <ClassInfoIndex>(); } var cii = new ClassInfoIndex { ClassInfoId = _oidInfo.ID, Name = name, IsUnique = !acceptMultipleValuesForSameKey }; var attributeIds = new int[indexFields.Length]; for (var i = 0; i < indexFields.Length; i++) { attributeIds[i] = GetAttributeId(indexFields[i]); } cii.AttributeIds = attributeIds; _indexes.Add(cii); return(cii); }
public LazyOdbBtreePersister(IStorageEngine engine) { _oids = new OdbHashMap<OID, object>(); _modifiedObjectOids = new OdbHashMap<object, int>(); _modifiedObjectOidList = new OdbList<OID>(500); _engine = engine; _engine.AddCommitListener(this); }
public AttributeValuesMap ReadObjectInfoValuesFromOID(ClassInfo classInfo, OID oid, bool useCache, IOdbList <String> attributeNames, IOdbList <String> relationAttributeNames, int recursionLevel, String[] orderByFields, bool useOidForObject) { return(null); }
public LazyOdbBtreePersister(IStorageEngine engine) { _oids = new OdbHashMap <OID, object>(); _modifiedObjectOids = new OdbHashMap <object, int>(); _modifiedObjectOidList = new OdbList <OID>(500); _engine = engine; _engine.AddCommitListener(this); }
/// <summary> </summary> /// <param name="clazz">The class to instrospect /// </param> /// <param name="recursive">If true, goes does the hierarchy to try to analyse all classes /// </param> /// <param name="A">map with classname that are being introspected, to avoid recursive calls /// /// </param> /// <returns> /// </returns> private ClassInfoList InternalIntrospect(System.Type clazz, bool recursive, ClassInfoList classInfoList) { if (classInfoList != null) { ClassInfo existingCi = (ClassInfo)classInfoList.GetClassInfoWithName(OdbClassUtil.GetFullName(clazz)); if (existingCi != null) { return(classInfoList); } } ClassInfo classInfo = new ClassInfo(OdbClassUtil.GetFullName(clazz)); classInfo.SetClassCategory(GetClassCategory(OdbClassUtil.GetFullName(clazz))); if (classInfoList == null) { classInfoList = new ClassInfoList(classInfo); } else { classInfoList.AddClassInfo(classInfo); } // Field[] fields = clazz.getDeclaredFields(); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //m by cristi IOdbList <FieldInfo> fields = GetAllFields(OdbClassUtil.GetFullName(clazz)); IOdbList <ClassAttributeInfo> attributes = new OdbArrayList <ClassAttributeInfo>(fields.Count); ClassInfo ci = null; for (int i = 0; i < fields.Count; i++) { System.Reflection.FieldInfo field = (System.Reflection.FieldInfo)fields[i]; //Console.WriteLine("Field " + field.Name + " , type = " + field.FieldType); if (!ODBType.GetFromClass(field.FieldType).IsNative()) { if (recursive) { classInfoList = InternalIntrospect(field.FieldType, recursive, classInfoList); ci = classInfoList.GetClassInfoWithName(OdbClassUtil.GetFullName(field.FieldType)); } else { ci = new ClassInfo(OdbClassUtil.GetFullName(field.FieldType)); } } else { ci = null; } attributes.Add(new ClassAttributeInfo((i + 1), field.Name, field.FieldType, OdbClassUtil.GetFullName(field.FieldType), ci)); } classInfo.SetAttributes(attributes); classInfo.SetMaxAttributeId(fields.Count); return(classInfoList); }
private ClassInfo() { _attributes = null; _original = new CommittedCIZoneInfo(); _committed = new CommittedCIZoneInfo(); _uncommitted = new CIZoneInfo(); _oidInfo = new OidInfo(); Position = -1; MaxAttributeId = -1; _attributesCache = new AttributesCache(); }
/// <summary> /// introspect a list of classes /// This method return the current meta model based on the classes that currently exist in the /// execution classpath. /// </summary> /// <remarks> /// introspect a list of classes /// This method return the current meta model based on the classes that currently exist in the /// execution classpath. The result will be used to check meta model compatiblity between /// the meta model that is currently persisted in the database and the meta model /// currently executing in JVM. This is used b the automatic meta model refactoring /// </remarks> /// <returns></returns> /// <returns>A map where the key is the class name and the key is the ClassInfo: the class meta representation /// </returns> public virtual IDictionary <string, ClassInfo> Instrospect(IOdbList <ClassInfo> classInfos) { ClassInfo persistedCI = null; ClassInfo currentCI = null; IDictionary <string, ClassInfo> cis = new Dictionary <string, ClassInfo>(); // re introspect classes IEnumerator <ClassInfo> iterator = classInfos.GetEnumerator(); while (iterator.MoveNext()) { persistedCI = iterator.Current; currentCI = GetClassInfo(persistedCI.GetFullClassName(), persistedCI); cis.Add(currentCI.GetFullClassName(), currentCI); } return(cis); }
public IOdbList <FieldInfo> RemoveUnnecessaryFields(IOdbList <FieldInfo> fields) { IOdbList <FieldInfo> fieldsToRemove = new OdbArrayList <FieldInfo> (fields.Count); // Remove static fields for (int i = 0; i < fields.Count; i++) { System.Reflection.FieldInfo field = (System.Reflection.FieldInfo)fields[i]; // by osmadja if (field.IsNotSerialized || field.IsStatic) { fieldsToRemove.Add(field); } //by cristi if (field.FieldType == typeof(IntPtr)) { fieldsToRemove.Add(field); } object[] oattr = field.GetCustomAttributes(true); bool isNonPersistent = false; foreach (object at in oattr) { NonPersistentAttribute npat = at as NonPersistentAttribute; if (npat != null) { isNonPersistent = true; break; } } if (isNonPersistent || field.IsStatic) { fieldsToRemove.Add(field); } // Remove inner class fields if (field.Name.StartsWith("this$")) { fieldsToRemove.Add(field); } } fields.RemoveAll(fieldsToRemove); return(fields); }
/// <summary>Builds a class info from a class and an existing class info /// /// <pre> /// The existing class info is used to make sure that fields with the same name will have /// the same id /// </pre> /// /// </summary> /// <param name="fullClassName">The name of the class to get info /// </param> /// <param name="existingClassInfo"> /// </param> /// <returns> A ClassInfo - a meta representation of the class /// </returns> public ClassInfo GetClassInfo(System.String fullClassName, ClassInfo existingClassInfo) { ClassInfo classInfo = new ClassInfo(fullClassName); classInfo.SetClassCategory(GetClassCategory(fullClassName)); ; IOdbList <FieldInfo> fields = GetAllFields(fullClassName); IOdbList <ClassAttributeInfo> attributes = new OdbArrayList <ClassAttributeInfo>(fields.Count); int attributeId = -1; int maxAttributeId = existingClassInfo.GetMaxAttributeId(); ClassInfo ci = null; for (int i = 0; i < fields.Count; i++) { FieldInfo field = fields[i]; // Gets the attribute id from the existing class info attributeId = existingClassInfo.GetAttributeId(field.Name); if (attributeId == -1) { maxAttributeId++; // The attibute with field.getName() does not exist in existing class info // create a new id attributeId = maxAttributeId; } if (!ODBType.GetFromClass(field.FieldType).IsNative()) { ci = new ClassInfo(OdbClassUtil.GetFullName(field.FieldType)); } else { ci = null; } attributes.Add(new ClassAttributeInfo(attributeId, field.Name, field.FieldType, OdbClassUtil.GetFullName(field.FieldType), ci)); } classInfo.SetAttributes(attributes); classInfo.SetMaxAttributeId(maxAttributeId); return(classInfo); }
public override IOdbList <string> GetAllInvolvedFields () { IEnumerator iterator = criteria.GetEnumerator(); ICriterion criterion = null; IOdbList <string> fields = new OdbArrayList <string>(10); while (iterator.MoveNext()) { criterion = (ICriterion)iterator.Current; IOdbList <string> l = criterion.GetAllInvolvedFields(); // check duplicate for (int i = 0; i < l.Count; i++) { string f = l.Get(i); if (!fields.Contains(f)) { fields.Add(f); } } } return(fields); }
public override void Execute(OID oid, AttributeValuesMap values) { var candidate = values[AttributeName]; if (candidate is OID) { var candidateOid = (OID)candidate; candidate = _query.GetQueryEngine().GetObjectFromOid(candidateOid); } var l = ((IEnumerable)candidate).Cast <object>().ToList(); var localFromIndex = _fromIndex; var localEndIndex = _fromIndex + _size; // If not throw exception, we must implement // Index Out Of Bound protection if (!_throwExceptionIfOutOfBound) { // Check from index if (localFromIndex > l.Count - 1) { localFromIndex = 0; } // Check end index if (localEndIndex > l.Count) { localEndIndex = l.Count; } } _sublist = new LazySimpleListOfAoi <object>(GetInstanceBuilder(), ReturnInstance()); var count = localEndIndex - localFromIndex; var sublist = l.GetRange(localFromIndex, count); _sublist.AddAll(sublist); }
public void SetIndexes(IOdbList<ClassInfoIndex> indexes2) { _indexes = indexes2; }
/// <summary> /// introspect a list of classes /// This method return the current meta model based on the classes that currently exist in the /// execution classpath. /// </summary> /// <remarks> /// introspect a list of classes /// This method return the current meta model based on the classes that currently exist in the /// execution classpath. The result will be used to check meta model compatiblity between /// the meta model that is currently persisted in the database and the meta model /// currently executing in JVM. This is used b the automatic meta model refactoring /// </remarks> /// <returns></returns> /// <returns>A map where the key is the class name and the key is the ClassInfo: the class meta representation /// </returns> public virtual IDictionary<string, ClassInfo> Instrospect(IOdbList<ClassInfo> classInfos) { ClassInfo persistedCI = null; ClassInfo currentCI = null; IDictionary<string, ClassInfo> cis = new Dictionary<string, ClassInfo>(); // re introspect classes IEnumerator<ClassInfo> iterator = classInfos.GetEnumerator(); while (iterator.MoveNext()) { persistedCI = iterator.Current; currentCI = GetClassInfo(persistedCI.GetFullClassName(), persistedCI); cis.Add(currentCI.GetFullClassName(), currentCI); } return cis; }
protected ComposedExpression(IQuery query) : base(query) { Constraints = new OdbList<IConstraint>(5); }
public ClassInfoIndex AddIndexOn(string name, string[] indexFields, bool acceptMultipleValuesForSameKey) { if (_indexes == null) _indexes = new OdbList<ClassInfoIndex>(); var cii = new ClassInfoIndex { ClassInfoId = _oidInfo.ID, Name = name, IsUnique = !acceptMultipleValuesForSameKey }; var attributeIds = new int[indexFields.Length]; for (var i = 0; i < indexFields.Length; i++) attributeIds[i] = GetAttributeId(indexFields[i]); cii.AttributeIds = attributeIds; _indexes.Add(cii); return cii; }
public ClassInfoCompareResult(string fullClassName) { _fullClassName = fullClassName; _incompatibleChanges = new OdbList <string>(5); _compatibleChanges = new OdbList <string>(5); }
public ClassInfoCompareResult(string fullClassName) { _fullClassName = fullClassName; _incompatibleChanges = new OdbList<string>(5); _compatibleChanges = new OdbList<string>(5); }
protected override void PrepareQuery() { _sodaQuery = Query; ((IInternalQuery) _sodaQuery).SetQueryEngine(StorageEngine); _involvedFields = _sodaQuery.GetAllInvolvedFields(); }
protected ComposedExpression(IQuery query) : base(query) { Constraints = new OdbList <IConstraint>(5); }
public void SetIndexes(IOdbList <ClassInfoIndex> indexes2) { _indexes = indexes2; }
public virtual object BuildOneInstance(NonNativeObjectInfo objectInfo) { ICache cache = GetSession().GetCache(); // verify if the object is check to delete if (objectInfo.IsDeletedObject()) { throw new ODBRuntimeException(NeoDatisError.ObjectIsMarkedAsDeletedForOid.AddParameter(objectInfo.GetOid())); } // Then check if object is in cache object o = cache.GetObjectWithOid(objectInfo.GetOid()); if (o != null) { return(o); } Type instanceClazz = null; instanceClazz = classPool.GetClass(objectInfo.GetClassInfo().GetFullClassName()); try { o = classIntrospector.NewInstanceOf(instanceClazz); } catch (System.Exception e) { throw new ODBRuntimeException(NeoDatisError.InstanciationError.AddParameter(objectInfo.GetClassInfo().GetFullClassName()), e); } // This can happen if ODB can not create the instance // TODO Check if returning null is correct if (o == null) { return(null); } // Keep the initial hash code. In some cases, when the class redefines // the hash code method // Hash code can return wrong values when attributes are not set (when // hash code depends on attribute values) // Hash codes are used as the key of the map, // So at the end of this method, if hash codes are different, object // will be removed from the cache and inserted back bool hashCodeIsOk = true; int initialHashCode = 0; try { initialHashCode = o.GetHashCode(); } catch (System.Exception) { hashCodeIsOk = false; } // Adds this incomplete instance in the cache to manage cyclic reference if (hashCodeIsOk) { cache.AddObject(objectInfo.GetOid(), o, objectInfo.GetHeader()); } ClassInfo ci = objectInfo.GetClassInfo(); IOdbList <FieldInfo> fields = classIntrospector.GetAllFields(ci.GetFullClassName()); FieldInfo field = null; AbstractObjectInfo aoi = null; object value = null; for (int i = 0; i < fields.Count; i++) { field = fields[i]; // Gets the id of this field int attributeId = ci.GetAttributeId(field.Name); if (OdbConfiguration.IsDebugEnabled(LogIdDebug)) { DLogger.Debug("getting field with name " + field.Name + ", attribute id is " + attributeId); } aoi = objectInfo.GetAttributeValueFromId(attributeId); // Check consistency // ensureClassCompatibily(field, // instanceInfo.getClassInfo().getAttributeinfo(i).getFullClassname()); if (aoi != null && (!aoi.IsNull())) { if (aoi.IsNative()) { if (aoi.IsAtomicNativeObject()) { if (aoi.IsNull()) { value = null; } else { value = aoi.GetObject(); } } if (aoi.IsCollectionObject()) { value = BuildCollectionInstance((CollectionObjectInfo)aoi); // Manage a specific case of Set /* * if (typeof(Java.Util.Set).IsAssignableFrom(field.GetType()) && typeof(ICollection).IsAssignableFrom(value.GetType())) * { * Java.Util.Set s = new Java.Util.HashSet(); * s.AddAll((System.Collections.ICollection)value); * value = s; * }*/ } if (aoi.IsArrayObject()) { value = BuildArrayInstance((ArrayObjectInfo)aoi); } if (aoi.IsMapObject()) { value = BuildMapInstance((MapObjectInfo)aoi); } if (aoi.IsEnumObject()) { value = BuildEnumInstance((EnumNativeObjectInfo)aoi, field.FieldType); } } else { if (aoi.IsNonNativeObject()) { if (aoi.IsDeletedObject()) { if (NeoDatis.Odb.OdbConfiguration.DisplayWarnings()) { IError warning = NeoDatisError.AttributeReferencesADeletedObject .AddParameter(objectInfo.GetClassInfo().GetFullClassName()) .AddParameter(objectInfo.GetOid()).AddParameter(field.Name); DLogger.Info(warning.ToString()); } value = null; } else { value = BuildOneInstance((NonNativeObjectInfo)aoi); } } } if (value != null) { if (OdbConfiguration.IsDebugEnabled(LogIdDebug)) { DLogger.Debug("Setting field " + field.Name + "(" + field.GetType().FullName + ") to " + value + " / " + value.GetType().FullName); } try { field.SetValue(o, value); } catch (System.Exception e) { throw new ODBRuntimeException(NeoDatisError.InstanceBuilderWrongObjectContainerType .AddParameter(objectInfo.GetClassInfo().GetFullClassName()) .AddParameter(value.GetType().FullName).AddParameter(field.GetType().FullName), e); } } } } if (o != null && !OdbClassUtil.GetFullName(o.GetType()).Equals(objectInfo.GetClassInfo().GetFullClassName())) { new ODBRuntimeException(NeoDatisError.InstanceBuilderWrongObjectType .AddParameter(objectInfo.GetClassInfo().GetFullClassName()) .AddParameter(o.GetType().FullName)); } if (hashCodeIsOk || initialHashCode != o.GetHashCode()) { // Bug (sf bug id=1875544 )detected by glsender // This can happen when an object has redefined its own hashcode // method and depends on the field values // Then, we have to remove object from the cache and re-insert to // correct map hash code cache.RemoveObjectWithOid(objectInfo.GetOid()); // re-Adds instance in the cache cache.AddObject(objectInfo.GetOid(), o, objectInfo.GetHeader()); } if (triggerManager != null) { triggerManager.ManageSelectTriggerAfter(objectInfo.GetClassInfo().GetFullClassName (), objectInfo, objectInfo.GetOid()); } if (OdbConfiguration.ReconnectObjectsToSession()) { ICrossSessionCache crossSessionCache = CacheFactory.GetCrossSessionCache(engine.GetBaseIdentification().GetIdentification()); crossSessionCache.AddObject(o, objectInfo.GetOid()); } return(o); }
protected override void PrepareQuery() { _sodaQuery = Query; ((IInternalQuery)_sodaQuery).SetQueryEngine(StorageEngine); _involvedFields = _sodaQuery.GetAllInvolvedFields(); }
protected override void PrepareQuery() { _involvedFields = Query.GetAllInvolvedFields(); }
public IOdbList<FieldInfo> RemoveUnnecessaryFields(IOdbList<FieldInfo> fields) { IOdbList<FieldInfo> fieldsToRemove = new OdbArrayList<FieldInfo> (fields.Count); // Remove static fields for (int i = 0; i < fields.Count; i++) { System.Reflection.FieldInfo field = (System.Reflection.FieldInfo) fields[i]; // by osmadja if (field.IsNotSerialized || field.IsStatic ) { fieldsToRemove.Add(field); } //by cristi if (field.FieldType == typeof(IntPtr)) { fieldsToRemove.Add(field); } object[] oattr = field.GetCustomAttributes(true); bool isNonPersistent = false; foreach (object at in oattr) { NonPersistentAttribute npat = at as NonPersistentAttribute; if (npat != null) { isNonPersistent = true; break; } } if (isNonPersistent || field.IsStatic) { fieldsToRemove.Add(field); } // Remove inner class fields if (field.Name.StartsWith("this$")) { fieldsToRemove.Add(field); } } fields.RemoveAll(fieldsToRemove); return fields; }
private void Init() { _objectActions = new OdbList <IQueryFieldAction>(); _returnInstance = true; }