void Awake() { // Configure the Logger with your desired prefix and log level. DLogger.Configure("My Game", DLogger.LogLevels.Info); // Log at the Debug Log Level (Less). DLogger.Debug("script1 - This debug message will not recorded."); // Log at the Info Log Level (Equal). DLogger.Info("script1 - I configured my logger in script1"); }
/// <summary> /// Adds a write action to the transaction /// </summary> /// <param name="writeAction"> The write action to be added </param> /// <param name="persistWriteAction"> To indicate if write action must be persisted </param> private void AddWriteAction(WriteAction writeAction, bool persistWriteAction) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("OdbTransaction: Adding WriteAction in Transaction of session {0}", _session.GetId())); } if (writeAction.IsEmpty()) { return; } CheckRollback(); if (!_hasBeenPersisted && persistWriteAction) { Persist(); } if (persistWriteAction) { writeAction.PersistMeTo(_fsi); } // Only adds the write action to the list if the transaction keeps all in // memory if (_hasAllWriteActionsInMemory) { _writeActions.Add(writeAction); } _numberOfWriteActions++; if (_hasAllWriteActionsInMemory && _numberOfWriteActions > StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction) { _hasAllWriteActionsInMemory = false; foreach (var defaultWriteAction in _writeActions) { defaultWriteAction.Clear(); } _writeActions.Clear(); if (OdbConfiguration.IsLoggingEnabled()) { var numberOfWriteActions = _numberOfWriteActions.ToString(); var maxNumberOfWriteObjectPerTransactionAsString = StorageEngineConstant.MaxNumberOfWriteObjectPerTransaction.ToString(); DLogger.Info("OdbTransaction: Number of objects has exceeded the max number " + numberOfWriteActions + "/" + maxNumberOfWriteObjectPerTransactionAsString + ": switching to persistent transaction managment"); } } }
void Start() { // No level will log. DLogger.All("I will not show up in the console because logging is off."); DLogger.Trace("I will not show up in the console because logging is off."); DLogger.Debug("I will not show up in the console because logging is off."); DLogger.Info("I will not show up in the console because logging is off."); DLogger.Warn("I will not show up in the console because logging is off."); DLogger.Error("I will not show up in the console because logging is off."); DLogger.Fatal("I will not show up in the console because logging is off."); }
public virtual NeoDatis.Odb.Objects <T> GetObjects <T>(NeoDatis.Odb.Core.Query.IQuery query, bool inMemory, int startIndex, int endIndex) { try { return(storageEngine.GetObjects <T>(query, inMemory, startIndex, endIndex)); } catch (ODBRuntimeException e) { DLogger.Info(e); throw e; } }
// Use this for initialization void Awake() { // Configure the Logger with your desired prefix and log level. DLogger.Configure("My Game", DLogger.LogLevels.Debug); // Log at the Debug Log Level (Equal). DLogger.Debug("This debug message will be recorded."); // Log at the Trace Log Level (Lower). DLogger.Trace("This trace message will not be recorded."); // Log at the Info Log Level (Higher). DLogger.Info("This info message will be recored."); // Log at the Info Log Level (Higher). DLogger.Log("This general log (info) message will be recorded."); }
/// <summary> /// Receive the current class info (loaded from current classes present on runtime and check against the persisted meta model /// </summary> public bool Check(IDictionary <Type, ClassInfo> currentCIs, IMetaModelService metaModelService) { foreach (var persistedCI in metaModelService.GetAllClasses()) { CheckClass(currentCIs, persistedCI); } foreach (var result in _results) { DLogger.Info(string.Format("MetaModelCompabilityChecker: Class {0} has changed :", result.GetFullClassName())); DLogger.Info("MetaModelCompabilityChecker: " + result); } return(_results.Count != 0); }
/// <summary> /// Used to rebuild an index /// </summary> public void RebuildIndex(string className, string indexName) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("StorageEngine: Rebuilding index {0} on class {1}", indexName, className)); } var classInfo = GetMetaModel().GetClassInfo(className, true); var classInfoIndex = GetClassInfoIndex(className, indexName, classInfo); DeleteIndex(className, indexName); AddIndexOn(className, indexName, classInfo.GetAttributeNames(classInfoIndex.AttributeIds), !classInfoIndex.IsUnique); }
private void UpdateMetaModel() { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info("StorageEngine: Automatic refactoring : updating meta model"); } var metaModel = GetMetaModel(); var storedClasses = metaModel.GetAllClasses().ToList(); foreach (var userClass in storedClasses) { _objectWriter.UpdateClassInfo(userClass, true); } }
public void Register_logger_and_check_logged_messages() { var logger = new FakeLogger(); OdbConfiguration.RegisterLogger(logger); DLogger.Info("info"); DLogger.Debug("debug"); DLogger.Warning("warning"); DLogger.Error("error"); Assert.That(logger.GetInfoMessage(), Is.EqualTo("info")); Assert.That(logger.GetDebugMessage(), Is.EqualTo("debug")); Assert.That(logger.GetWarningMessage(), Is.EqualTo("warning")); Assert.That(logger.GetErrorMessage(), Is.EqualTo("error")); }
public void DeleteIndex(string className, string indexName) { var classInfo = GetMetaModel().GetClassInfo(className, true); var classInfoIndex = GetClassInfoIndex(className, indexName, classInfo); if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("StorageEngine: Deleting index {0} on class {1}", indexName, className)); } Delete(classInfoIndex); classInfo.RemoveIndex(classInfoIndex); if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("StorageEngine: Index {0} deleted", indexName)); } }
public override void DefragmentTo(string newFileName) { var start = OdbTime.GetCurrentTimeInMs(); var totalNbObjects = 0L; var newStorageEngine = new StorageEngine(new FileIdentification(newFileName)); var j = 0; var criteriaQuery = new SodaQuery(typeof(object)); var defragObjects = GetObjects <object>(criteriaQuery, true, -1, -1); foreach (var defragObject in defragObjects) { newStorageEngine.Store(defragObject); totalNbObjects++; if (OdbConfiguration.IsLoggingEnabled()) { if (j % 10000 == 0) { DLogger.Info(string.Concat("\nStorageEngine: ", totalNbObjects.ToString(), " objects saved.")); } } j++; } newStorageEngine.Close(); var time = OdbTime.GetCurrentTimeInMs() - start; if (!OdbConfiguration.IsLoggingEnabled()) { return; } var nbObjectsAsString = totalNbObjects.ToString(); var timeAsString = time.ToString(); DLogger.Info(string.Format("StorageEngine: New storage {0} created with {1} objects in {2} ms.", newFileName, nbObjectsAsString, timeAsString)); }
private void LoadWriteActions(string filename, bool apply) { if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Debug(string.Format("OdbTransaction: Load write actions of {0}", filename)); } CheckFileAccess(filename); _fsi.SetReadPosition(0); _isCommited = _fsi.ReadByte() == 1; _creationDateTime = _fsi.ReadLong(); var totalNumberOfWriteActions = _fsi.ReadLong(); if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Concat("OdbTransaction: ", _writeActions.Count.ToString(), " write actions in file")); } for (var i = 0; i < totalNumberOfWriteActions; i++) { var defaultWriteAction = WriteAction.Read(_fsi); if (apply) { defaultWriteAction.ApplyTo(_fsiToApplyWriteActions); defaultWriteAction.Clear(); } else { AddWriteAction(defaultWriteAction, false); } } if (apply) { _fsiToApplyWriteActions.Flush(); } }
private void ApplyTo() { if (!_isCommited) { DLogger.Info("OdbTransaction: can not execute a transaction that is not confirmed"); return; } if (_hasAllWriteActionsInMemory) { foreach (var wa in _writeActions) { wa.ApplyTo(_fsiToApplyWriteActions); wa.Clear(); } _fsiToApplyWriteActions.Flush(); } else { LoadWriteActions(GetName(), true); _fsiToApplyWriteActions.Flush(); } }
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); }
public void Commit() { if (OdbConfiguration.IsLoggingEnabled()) { var numberOfWriteActionsAsString = _numberOfWriteActions.ToString(); var hasAllWriteActionsInMemoryAsString = _hasAllWriteActionsInMemory.ToString(); DLogger.Info("OdbTransaction: Commiting " + numberOfWriteActionsAsString + " write actions - In Memory : " + hasAllWriteActionsInMemoryAsString + string.Format(" - sid={0}", _session.GetId())); } // Check if database has been rollbacked CheckRollback(); // call the commit listeners ManageCommitListenersBefore(); if (_currentWriteAction != null && !_currentWriteAction.IsEmpty()) { AddWriteAction(_currentWriteAction, true); _currentWriteAction = null; } if (_fsi == null && _numberOfWriteActions != 0) { throw new OdbRuntimeException(NDatabaseError.TransactionAlreadyCommitedOrRollbacked); } if (_numberOfWriteActions == 0) { // FIXME call commitMetaModel in realOnlyMode? CommitMetaModel(); // Nothing to do if (_fsi != null) { _fsi.Close(); _fsi = null; } if (_session != null) { _session.GetCache().ClearOnCommit(); } return; } // Marks the transaction as committed SetCommited(); // Apply the write actions the main database file ApplyTo(); // Commit Meta Model changes CommitMetaModel(); if (_fsi != null) { _fsi.Close(); _fsi = null; } if (_session != null) { _session.GetCache().ClearOnCommit(); } ManageCommitListenersAfter(); }
public void AddIndexOn(string className, string indexName, string[] indexFields, bool acceptMultipleValuesForSameKey) { var classInfo = GetMetaModel().GetClassInfo(className, true); if (classInfo.HasIndex(indexName)) { throw new OdbRuntimeException( NDatabaseError.IndexAlreadyExist.AddParameter(indexName).AddParameter(className)); } var classInfoIndex = classInfo.AddIndexOn(indexName, indexFields, acceptMultipleValuesForSameKey); IBTree btree; var lazyOdbBtreePersister = new LazyOdbBtreePersister(this); if (acceptMultipleValuesForSameKey) { btree = new OdbBtreeMultiple(OdbConfiguration.GetIndexBTreeDegree(), lazyOdbBtreePersister); } else { btree = new OdbBtreeSingle(OdbConfiguration.GetIndexBTreeDegree(), lazyOdbBtreePersister); } classInfoIndex.BTree = btree; Store(classInfoIndex); // Now The index must be updated with all existing objects. if (classInfo.NumberOfObjects == 0) { // There are no objects. Nothing to do return; } if (OdbConfiguration.IsLoggingEnabled()) { var numberOfObjectsAsString = classInfo.NumberOfObjects.ToString(); DLogger.Info( string.Format( "StorageEngine: Creating index {0} on class {1} - Class has already {2} Objects. Updating index", indexName, className, numberOfObjectsAsString)); DLogger.Info(string.Format("StorageEngine: {0} : loading {1} objects from database", indexName, numberOfObjectsAsString)); } // We must load all objects and insert them in the index! var criteriaQuery = new SodaQuery(classInfo.UnderlyingType); var objects = GetObjectInfos(criteriaQuery); if (OdbConfiguration.IsLoggingEnabled()) { var numberOfObjectsAsString = classInfo.NumberOfObjects.ToString(); DLogger.Info(string.Format("StorageEngine: {0} : {1} objects loaded", indexName, numberOfObjectsAsString)); } while (objects.HasNext()) { var nnoi = (NonNativeObjectInfo)objects.Next(); var odbComparable = IndexTool.BuildIndexKey(classInfoIndex.Name, nnoi, classInfoIndex.AttributeIds); btree.Insert(odbComparable, nnoi.GetOid()); } if (OdbConfiguration.IsLoggingEnabled()) { DLogger.Info(string.Format("StorageEngine: {0} created!", indexName)); } }