private void BuildClass( DocumentMapping documentMapping, bool isRoot, string path, BuildContext context ) { IList<System.Type> hierarchy = new List<System.Type>(); System.Type currClass = documentMapping.MappedClass; do { hierarchy.Add(currClass); currClass = currClass.BaseType; // NB Java stops at null we stop at object otherwise we process the class twice // We also need a null test for things like ISet which have no base class/interface } while (currClass != null && currClass != typeof(object)); for (int index = hierarchy.Count - 1; index >= 0; index--) { currClass = hierarchy[index]; /** * Override the default analyzer for the properties if the class hold one * That's the reason we go down the hierarchy */ // NB Must cast here as we want to look at the type's metadata var localAnalyzer = GetAnalyzer(currClass); var analyzer = documentMapping.Analyzer ?? localAnalyzer; // Check for any ClassBridges var classBridgeAttributes = AttributeUtil.GetAttributes<ClassBridgeAttribute>(currClass); AttributeUtil.GetClassBridgeParameters(currClass, classBridgeAttributes); // Now we can process the class bridges foreach (var classBridgeAttribute in classBridgeAttributes) { var bridge = BuildClassBridge(classBridgeAttribute, analyzer); documentMapping.ClassBridges.Add(bridge); } // NB As we are walking the hierarchy only retrieve items at this level var propertyInfos = currClass.GetProperties( BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ); foreach (var propertyInfo in propertyInfos) { BuildProperty(documentMapping, propertyInfo, analyzer, isRoot, path, context); } var fields = currClass.GetFields( BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ); foreach (var fieldInfo in fields) { BuildProperty(documentMapping, fieldInfo, analyzer, isRoot, path, context); } } }
public bool CheckDataIfExists(DocumentMapping entity) { Dictionary<string, object> parameter = new Dictionary<string, object>(); parameter.Add("Node", entity.Node); parameter.Add("Document", entity.Document); List<DocumentMapping> document = this.documentMappingRepository.CheckIfDataExists(parameter); if (document.Count() > 0) { return true; } return false; }
public DocumentMapping Build(Type type) { var documentMapping = new DocumentMapping(type) { Boost = GetBoost(type), IndexName = AttributeUtil.GetAttribute<IndexedAttribute>(type).Index }; var context = new BuildContext { Root = documentMapping, Processed = { type } }; BuildClass(documentMapping, true, string.Empty, context); BuildFilterDefinitions(documentMapping); return documentMapping; }
public ActionResult AddDocument(DocumentMappingModel model) { if (ModelState.IsValid) { DocumentMapping documentMapping = new DocumentMapping(); List<DocumentMapping> currentDocumentMapping = GetCurrentDocumentMapping(); documentMapping.Mandatory = model.Mandatory; documentMapping.Document = this.documentService.GetDataById(model.DocumentId); documentMapping.Workflow = this.workflowService.GetDataById(model.WorkflowId); if (currentDocumentMapping.Any()) { if (!currentDocumentMapping.Exists(x => x.Document.Id.Equals(documentMapping.Document.Id))) { model.DocumentMappingList.Add(documentMapping); currentDocumentMapping.Add(documentMapping); } else { ModelState.AddModelError("StatusError", "already added"); return Json(new { result = StatusCode.existed, message = MessageCode.existed, code = StatusCode.existed }); } } else { currentDocumentMapping.Add(documentMapping); } model.DocumentMappingList = currentDocumentMapping; if (Request.IsAjaxRequest()) { return PartialView("Partial/Document", model); } return Json(new { result = StatusCode.saved, message = MessageCode.saved, code = StatusCode.saved }); } return Json(new { result = StatusCode.failed, message = MessageCode.error, code = StatusCode.invalid }); }
public HierarchyArgument(DocumentMapping mapping) : base(Hierarchy, typeof(DocumentMapping)) { Mapping = mapping; }
public void SaveChanges(DocumentMapping entity) { this.documentMappingRepository.SaveChanges(entity); }
public void default_upsert_name() { var mapping = DocumentMapping.For <User>(); mapping.UpsertFunction.Name.ShouldBe("mt_upsert_user"); }
public override void GenerateBulkWriterCodeAsync(GeneratedType type, GeneratedMethod load, DocumentMapping mapping) { load.Frames.CodeAsync($"await writer.WriteAsync({typeof(DBNull).FullNameInCode()}.Value, {{0}}, {{1}});", DbType, Use.Type <CancellationToken>()); }
public void Apply(DocumentMapping mapping) { _modify(mapping); }
public void uses_ConfigureMarten_method_to_alter_mapping_upon_construction_with_the_generic_signature() { var mapping = DocumentMapping.For <ConfiguresItselfSpecifically>(); mapping.DuplicatedFields.Single().MemberName.ShouldBe(nameof(ConfiguresItselfSpecifically.Name)); }
public override void GenerateCodeToSetDbParameterValue(GeneratedMethod method, GeneratedType type, int i, Argument parameters, DocumentMapping mapping, StoreOptions options) { method.Frames.Code($"setHeaderParameter({parameters.Usage}[{i}], {{0}});", Use.Type <IMartenSession>()); }
public void select_fields_without_subclasses() { var mapping = DocumentMapping.For <User>(); mapping.SelectFields().ShouldHaveTheSameElementsAs("data", "id", DocumentMapping.VersionColumn); }
public void table_name_for_document() { DocumentMapping.For <MySpecialDocument>().Table.Name .ShouldBe("mt_doc_documentmappingtests_myspecialdocument"); }
public void picks_up_marten_attibute_on_document_type() { var mapping = DocumentMapping.For <Organization>(); mapping.PropertySearching.ShouldBe(PropertySearching.JSON_Locator_Only); }
public void select_fields_for_non_hierarchy_mapping() { var mapping = DocumentMapping.For <User>(); mapping.SelectFields().ShouldHaveTheSameElementsAs("data", "id", DocumentMapping.VersionColumn); }
public void optimistic_versioning_is_turned_off_by_default() { var mapping = DocumentMapping.For <User>(); mapping.UseOptimisticConcurrency.ShouldBeFalse(); }
public void is_hierarchy_always_true_for_interface() { DocumentMapping.For <IDoc>().IsHierarchy() .ShouldBeTrue(); }
public void is_hierarchy_always_true_for_abstract_type() { DocumentMapping.For <AbstractDoc>() .IsHierarchy().ShouldBeTrue(); }
private void BuildProperty( DocumentMapping documentMapping, MemberInfo member, Analyzer parentAnalyzer, bool isRoot, string path, BuildContext context ) { IFieldBridge bridge = null; var analyzer = GetAnalyzer(member) ?? parentAnalyzer; var boost = GetBoost(member); var getter = GetGetterFast(documentMapping.MappedClass, member); var documentIdAttribute = AttributeUtil.GetAttribute<DocumentIdAttribute>(member); if (documentIdAttribute != null) { string documentIdName = documentIdAttribute.Name ?? member.Name; bridge = GetFieldBridge(member); if (isRoot) { if (!(bridge is ITwoWayFieldBridge)) { throw new SearchException("Bridge for document id does not implement TwoWayFieldBridge: " + member.Name); } documentMapping.DocumentId = new DocumentIdMapping( documentIdName, member.Name, (ITwoWayFieldBridge)bridge, getter ) { Boost = boost }; } else { // Components should index their document id documentMapping.Fields.Add(new FieldMapping( GetAttributeName(member, documentIdName), bridge, getter ) { Store = Attributes.Store.Yes, Index = Attributes.Index.UnTokenized, Boost = boost }); } } var fieldAttributes = AttributeUtil.GetFields(member); if (fieldAttributes.Length > 0) { if (bridge == null) bridge = GetFieldBridge(member); foreach (var fieldAttribute in fieldAttributes) { var fieldAnalyzer = GetAnalyzerByType(fieldAttribute.Analyzer) ?? analyzer; var field = new FieldMapping( GetAttributeName(member, fieldAttribute.Name), bridge, getter ) { Store = fieldAttribute.Store, Index = fieldAttribute.Index, Analyzer = fieldAnalyzer }; documentMapping.Fields.Add(field); } } var embeddedAttribute = AttributeUtil.GetAttribute<IndexedEmbeddedAttribute>(member); if (embeddedAttribute != null) { int oldMaxLevel = maxLevel; int potentialLevel = embeddedAttribute.Depth + level; if (potentialLevel < 0) { potentialLevel = int.MaxValue; } maxLevel = potentialLevel > maxLevel ? maxLevel : potentialLevel; level++; System.Type elementType = embeddedAttribute.TargetElement ?? GetMemberTypeOrGenericArguments(member); var localPrefix = embeddedAttribute.Prefix == "." ? member.Name + "." : embeddedAttribute.Prefix; if (maxLevel == int.MaxValue && context.Processed.Contains(elementType)) { throw new SearchException( string.Format( "Circular reference, Duplicate use of {0} in root entity {1}#{2}", elementType.FullName, context.Root.MappedClass.FullName, path + localPrefix)); } if (level <= maxLevel) { context.Processed.Add(elementType); // push var embedded = new EmbeddedMapping(new DocumentMapping(elementType) { Boost = GetBoost(member), Analyzer = GetAnalyzer(member) ?? parentAnalyzer }, getter) { Prefix = localPrefix }; BuildClass(embedded.Class, false, path + localPrefix, context); /** * We will only index the "expected" type but that's OK, HQL cannot do downcasting either */ // ayende: because we have to deal with generic collections here, we aren't // actually using the element type to determine what the value is, since that // was resolved to the element type of the possible collection Type actualFieldType = GetMemberTypeOrGenericCollectionType(member); embedded.IsCollection = typeof(IEnumerable).IsAssignableFrom(actualFieldType); documentMapping.Embedded.Add(embedded); context.Processed.Remove(actualFieldType); // pop } else if (logger.IsDebugEnabled) { logger.Debug("Depth reached, ignoring " + path + localPrefix); } level--; maxLevel = oldMaxLevel; // set back the old max level } if (AttributeUtil.HasAttribute<ContainedInAttribute>(member)) { documentMapping.ContainedIn.Add(new ContainedInMapping(getter)); } }
public void table_name_with_schema_for_document_on_other_schema() { DocumentMapping.For <MySpecialDocument>("other").Table.QualifiedName .ShouldBe("other.mt_doc_documentmappingtests_myspecialdocument"); }
public void is_hierarchy__is_false_for_concrete_type_with_no_subclasses() { DocumentMapping.For <User>().IsHierarchy().ShouldBeFalse(); }
public void trying_to_replace_the_hilo_settings_when_not_using_hilo_for_the_sequence_throws() { Exception <InvalidOperationException> .ShouldBeThrownBy( () => { DocumentMapping.For <StringId>().HiloSettings = new HiloSettings(); }); }
public void trying_to_index_deleted_at_when_not_soft_deleted_document_throws() { Exception <InvalidOperationException> .ShouldBeThrownBy(() => DocumentMapping.For <IntId>().AddDeletedAtIndex()); }
public void upsert_name_for_document_type() { DocumentMapping.For <MySpecialDocument>().UpsertFunction.Name .ShouldBe("mt_upsert_documentmappingtests_myspecialdocument"); }
public override void GenerateBulkWriterCode(GeneratedType type, GeneratedMethod load, DocumentMapping mapping) { load.Frames.Code($"writer.Write({typeof(DBNull).FullNameInCode()}.Value, {{0}});", DbType); }
public void upsert_name_with_schema_for_document_type_on_other_schema() { DocumentMapping.For <MySpecialDocument>("other").UpsertFunction.QualifiedName .ShouldBe("other.mt_upsert_documentmappingtests_myspecialdocument"); }
internal override void RegisterForLinqSearching(DocumentMapping mapping) { // Nothing }
public void use_custom_default_id_generation_for_long_id() { DocumentMapping.For <LongId>(idGeneration: (m, o) => new CustomIdGeneration()) .IdStrategy.ShouldBeOfType <CustomIdGeneration>(); }
public static void ConfigureMarten(DocumentMapping mapping) { mapping.DdlTemplate = "blue"; }
public void use_guid_id_generation_for_guid_id() { var mapping = DocumentMapping.For <UpperCaseProperty>(); mapping.IdStrategy.ShouldBeOfType <CombGuidIdGeneration>(); }
public bool CheckDataAndCodeIfExist(DocumentMapping entity) { return false; }
public void default_upsert_name_with_schema() { var mapping = DocumentMapping.For <User>(); mapping.UpsertFunction.QualifiedName.ShouldBe("public.mt_upsert_user"); }
public long Create(DocumentMapping entity) { return this.documentMappingRepository.Create(entity); }
public void default_table_name_with_schema() { var mapping = DocumentMapping.For <User>(); mapping.Table.QualifiedName.ShouldBe("public.mt_doc_user"); }
private void BuildFilterDefinitions(DocumentMapping classMapping) { foreach (var defAttribute in AttributeUtil.GetAttributes<FullTextFilterDefAttribute>(classMapping.MappedClass, false)) { classMapping.FullTextFilterDefinitions.Add(BuildFilterDef(defAttribute)); } }
public void uses_ConfigureMarten_method_to_alter_mapping_upon_construction() { var mapping = DocumentMapping.For <ConfiguresItself>(); mapping.Alias.ShouldBe("different"); }
public void use_hilo_id_generation_for_long_id() { DocumentMapping.For <LongId>() .IdStrategy.ShouldBeOfType <HiloIdGeneration>(); }
public void doc_type_with_use_optimistic_concurrency_attribute() { DocumentMapping.For <VersionedDoc>() .UseOptimisticConcurrency.ShouldBeTrue(); }
public void use_string_id_generation_for_string() { var mapping = DocumentMapping.For <StringId>(); mapping.IdStrategy.ShouldBeOfType <StringIdGeneration>(); }
public void default_table_name_with_different_shema() { var mapping = DocumentMapping.For <User>("other"); mapping.Table.QualifiedName.ShouldBe("other.mt_doc_user"); }