protected override void ConfigureType(ICommonConfiguration configuration, Type type) { var clazz = configuration.ObjectClass(type); clazz.MaximumActivationDepth(15); clazz.UpdateDepth(1); if (Reflector.Implements(type, typeof(IThing)) || Reflector.Implements(type, typeof(IIdContent <Id>))) { clazz.ObjectField("_id").Indexed(true); // the following makes errors on closing (sometimes): see Gateway.Close(); this.Flush(); // Configuration.Add(new UniqueFieldValueConstraint(type, "_id")); } if (Reflector.Implements(type, typeof(ILink))) { clazz.UpdateDepth(1); clazz.ObjectField(RootIdField).Indexed(true); clazz.ObjectField(LeafIdField).Indexed(true); clazz.ObjectField("_markerId").Indexed(true); } else { FieldInfo fieldType = type.GetField("_data", BindingFlags.Instance | BindingFlags.NonPublic); if (fieldType != null && !Reflector.IsStorable(fieldType.FieldType)) { clazz.ObjectField("_data").Indexed(true); } } }
/// <summary> /// Gets the config from attributes. /// </summary> /// <param name="commonConfig">The common config.</param> /// <param name="entityTypes">The entity types.</param> public static void GetConfigFromAttributes(ICommonConfiguration commonConfig, Collection <Type> entityTypes) { if (entityTypes == null || entityTypes.Count == 0) { return; } if (commonConfig == null) { return; } commonConfig.MarkTransient(typeof(TransientFieldAttribute).FullName); foreach (var entityType in entityTypes) { var objectClass = commonConfig.ObjectClass(entityType); var uuidAttrib = entityType.GetAttribute <UuidClassAttribute>(); if (uuidAttrib != null) { objectClass.GenerateUUIDs(true); } var versionAttrib = entityType.GetAttribute <VersionNumberClassAttribute>(); if (versionAttrib != null) { objectClass.GenerateVersionNumbers(true); } var fields = entityType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .Where(prop => prop.GetCustomAttributes(typeof(IndexedFieldAttribute), false).Length > 0 || prop.GetCustomAttributes(typeof(UniqueFieldValueConstraintAttribute), false).Length > 0 ).ToList(); if (fields.Count == 0) { continue; } foreach (var field in from field in fields let indexAttrib = field.GetAttribute <IndexedFieldAttribute>() where indexAttrib != null select field) { objectClass.ObjectField(field.Name).Indexed(true); //No UniqueFieldValue WithOut Indexed var uniqueAttrib = field.GetAttribute <UniqueFieldValueConstraintAttribute>(); if (uniqueAttrib != null) { commonConfig.Add(new UniqueFieldValueConstraint(entityType, field.Name)); } } } }
protected override bool RefactorType(ICommonConfiguration configuration, Type type) { var result = false; var clazz = configuration.ObjectClass(type); if (Reflector.Implements(type, typeof(IThing))) { var writeDate = clazz.ObjectField("_writeDate"); var changeDate = clazz.ObjectField("_changeDate"); if (writeDate != null) { writeDate.Rename("_changeDate"); result = true; } } return(result); }
public virtual void Test() { ICommonConfigurationProvider config = ((ICommonConfigurationProvider)Subject()); Config4Impl legacy = Db4oLegacyConfigurationBridge.AsLegacy(config); ICommonConfiguration common = config.Common; common.ActivationDepth = 42; Assert.AreEqual(42, legacy.ActivationDepth()); Assert.AreEqual(42, common.ActivationDepth); // TODO: assert common.Add(new _IConfigurationItem_41()); TypeAlias alias = new TypeAlias("foo", "bar"); common.AddAlias(alias); Assert.AreEqual("bar", legacy.ResolveAliasStoredName("foo")); Assert.AreEqual("foo", legacy.ResolveAliasRuntimeName("bar")); common.RemoveAlias(alias); Assert.AreEqual("foo", legacy.ResolveAliasStoredName("foo")); common.AllowVersionUpdates = false; Assert.IsFalse(legacy.AllowVersionUpdates()); common.AutomaticShutDown = false; Assert.IsFalse(legacy.AutomaticShutDown()); common.BTreeNodeSize = 42; Assert.AreEqual(42, legacy.BTreeNodeSize()); common.Callbacks = false; Assert.AreEqual(CallBackMode.None, legacy.CallbackMode()); common.CallConstructors = false; Assert.IsTrue(legacy.CallConstructors().DefiniteNo()); common.DetectSchemaChanges = false; Assert.IsFalse(legacy.DetectSchemaChanges()); DiagnosticCollector collector = new DiagnosticCollector(); common.Diagnostic.AddListener(collector); IDiagnostic diagnostic = DummyDiagnostic(); legacy.DiagnosticProcessor().OnDiagnostic(diagnostic); collector.Verify(new object[] { diagnostic }); common.ExceptionsOnNotStorable = true; Assert.IsTrue(legacy.ExceptionsOnNotStorable()); common.InternStrings = true; Assert.IsTrue(legacy.InternStrings()); // TODO: assert common.MarkTransient("Foo"); common.MessageLevel = 3; Assert.AreEqual(3, legacy.MessageLevel()); IObjectClass objectClass = common.ObjectClass(typeof(CommonAndLocalConfigurationTestSuite.BaseConfigurationProviderTestUnit.Item )); objectClass.CascadeOnDelete(true); Assert.IsTrue(((Config4Class)legacy.ObjectClass(typeof(CommonAndLocalConfigurationTestSuite.BaseConfigurationProviderTestUnit.Item ))).CascadeOnDelete().DefiniteYes()); Assert.IsTrue(((Config4Class)common.ObjectClass(typeof(CommonAndLocalConfigurationTestSuite.BaseConfigurationProviderTestUnit.Item ))).CascadeOnDelete().DefiniteYes()); common.OptimizeNativeQueries = false; Assert.IsFalse(legacy.OptimizeNativeQueries()); Assert.IsFalse(common.OptimizeNativeQueries); common.Queries.EvaluationMode(QueryEvaluationMode.Lazy); Assert.AreEqual(QueryEvaluationMode.Lazy, legacy.EvaluationMode()); // TODO: test reflectWith() // TODO: this probably won't sharpen :/ TextWriter outStream = Sharpen.Runtime.Out; common.OutStream = outStream; Assert.AreEqual(outStream, legacy.OutStream()); IStringEncoding stringEncoding = new _IStringEncoding_113(); common.StringEncoding = stringEncoding; Assert.AreEqual(stringEncoding, legacy.StringEncoding()); common.TestConstructors = false; Assert.IsFalse(legacy.TestConstructors()); common.TestConstructors = true; Assert.IsTrue(legacy.TestConstructors()); common.UpdateDepth = 1024; Assert.AreEqual(1024, legacy.UpdateDepth()); common.WeakReferences = false; Assert.IsFalse(legacy.WeakReferences()); common.WeakReferenceCollectionInterval = 1024; Assert.AreEqual(1024, legacy.WeakReferenceCollectionInterval()); }
/// <exception cref="System.Exception"></exception> public void Run() { config.ObjectClass(typeof(Item)).UpdateDepth(Const4.Unspecified ); }