internal static IEnumerable <PackedObject> LoadObjects(IDataClient @this, string jsonPath, [NotNull] string collectionName) { if (collectionName == null) { throw new ArgumentNullException(nameof(collectionName)); } var json = File.ReadAllText(jsonPath); var array = JArray.Parse(json); var info = @this.GetClusterInformation(); var schemaByName = info.Schema.ToDictionary(td => td.CollectionName.ToLower()); if (!schemaByName.ContainsKey(collectionName.ToLower())) { throw new CacheException($"Collection {collectionName} not found"); } CollectionSchema collectionSchema = schemaByName[collectionName]; foreach (var item in array.Children <JObject>()) { var cachedObject = PackedObject.PackJson(item.ToString(), collectionSchema); yield return(cachedObject); } }
public QueryExecutor(IDataClient client, CollectionSchema collectionSchema, Guid sessionId, string collectionName) { _client = client; _collectionSchema = collectionSchema; _sessionId = sessionId; _collectionName = collectionName; }
public JObjectRawType(GraphQLQuery query, GraphQLService graphQLService, CollectionSchema collectionSchema, EntityService entityService) { _query = query; _graphQLService = graphQLService; _collectionSchema = collectionSchema; _entityService = entityService; Name = collectionSchema.CollectionName; var fields = entityService.GetTypes(); foreach (Field field in collectionSchema.FieldSettings) { BuildGraphField(field); } TableArgs.Add(new QueryArgument <IntGraphType> { Name = "pageNumber" }); TableArgs.Add(new QueryArgument <IntGraphType> { Name = "pageSize" }); TableArgs.Add(new QueryArgument <StringGraphType> { Name = "rawQuery" }); }
public void InitializeContext() { this.store.TransactionManager.DoWithinTransaction(() => { this.collection = this.store.ElementFactory.CreateElement <CollectionSchema>(); }); }
public void InitializeContext() { this.store.TransactionManager.DoWithinTransaction(() => { this.collection = this.store.ElementFactory.CreateElement<CollectionSchema>(); }); }
public void DeclareCollection(string collectionName, CollectionSchema schema, int shard = -1) { Parallel.ForEach(CacheClients, client => { client.DeclareCollection(collectionName, schema, shard); }); }
internal ConfigurationElementSchema FindSchema(string path) { var index = path.IndexOf(Path, StringComparison.Ordinal); if (index != 0) { return(null); } if (Path.Length != 0) { if (path.Length != Path.Length && path[Path.Length] != '/') { return(null); } } if (path == Path) { return(this); } foreach (ConfigurationElementSchema child in ChildElementSchemas) { var result = child.FindSchema(path); if (result != null) { return(result); } } return(CollectionSchema?.FindSchema(path)); }
private void InitSchema() { JArray dbEntities = service.Query("_schema", new DataModel.DataQuery() { PageNumber = 1, PageSize = int.MaxValue, RawQuery = null }).Items; foreach (JToken item in dbEntities) { CollectionSchema schema = item.ToObject <CollectionSchema>(); if (schema.CollectionName != null && !string.IsNullOrEmpty(schema.CollectionName.ToString())) { var haveIdField = schema.FieldSettings.Where(x => x.Name.Equals("_id")).Count() > 0; if (!haveIdField) { var field = new Field(); field.Name = "_id"; field.BaseType = FieldBaseType.String; field.Type = "ObjectId"; field.Required = true; schema.FieldSettings.Add(field); } entities[schema.CollectionName] = schema; } } }
public CollectionType(CollectionSchema collectionSchema, Dictionary <string, CollectionSchema> collections = null, GraphQLService graphQLService = null) { Name = collectionSchema.CollectionName; foreach (Field field in collectionSchema.FieldSettings) { InitGraphField(field, collections, graphQLService); } }
public virtual void Initialize() { this.store.TransactionManager.DoWithinTransaction(() => { this.elementOwner = this.store.ElementFactory.CreateElement <CollectionSchema>(); this.element = this.store.ElementFactory.CreateElement <CollectionSchema>(); this.elementOwner.Elements.Add(this.element); }); validationContext = new ValidationContext(ValidationCategories.Save, this.element); }
public virtual void Initialize() { this.store.TransactionManager.DoWithinTransaction(() => { this.elementOwner = this.store.ElementFactory.CreateElement<CollectionSchema>(); this.element = this.store.ElementFactory.CreateElement<CollectionSchema>(); this.elementOwner.Elements.Add(this.element); }); validationContext = new ValidationContext(ValidationCategories.Save, this.element); }
public void InitializeContext() { this.store.TransactionManager.DoWithinTransaction(() => { var patternModel = this.store.ElementFactory.CreateElement <PatternModelSchema>(); this.product = patternModel.Create <PatternSchema>(); this.view = this.product.Create <ViewSchema>(); this.element = this.view.Create <ElementSchema>(); this.collection = this.view.Create <CollectionSchema>(); }); }
public static DataStore Reindex(DataStore old, CollectionSchema newDescription) { var result = new DataStore(newDescription, old.EvictionPolicy, old._fullTextConfig); result.InternalReindex(old.InternalEnumerateAsJson() .Select(json => PackedObject.PackJson(json, newDescription))); return(result); }
public QueryVisitor([NotNull] string collectionName, [NotNull] CollectionSchema collectionSchema) { if (string.IsNullOrEmpty(collectionName)) { throw new ArgumentException("Value cannot be null or empty.", nameof(collectionName)); } _collectionSchema = collectionSchema ?? throw new ArgumentNullException(nameof(collectionSchema)); RootExpression = new OrQuery(collectionName); }
public void InitializeContext() { this.store.TransactionManager.DoWithinTransaction(() => { var patternModel = this.store.ElementFactory.CreateElement<PatternModelSchema>(); this.product = patternModel.Create<PatternSchema>(); this.view = this.product.Create<ViewSchema>(); this.element = this.view.Create<ElementSchema>(); this.collection = this.view.Create<CollectionSchema>(); }); }
public void WhenSameNamedElementAddedToDifferentOwner_ThenValidateNameIsUniqueSucceeds() { this.store.TransactionManager.DoWithinTransaction(() => { ViewSchema elementOwner2 = this.store.ElementFactory.CreateElement <ViewSchema>(); CollectionSchema element2 = this.store.ElementFactory.CreateElement <CollectionSchema>(); element2.Name = this.element.Name; elementOwner2.Elements.Add(element2); }); this.element.ValidateNameIsUnique(validationContext); Assert.True(validationContext.CurrentViolations.Count == 0); }
public void WhenSameNamedElementAddedToSameOwner_ThenValidateNameIsUniqueFails() { this.store.TransactionManager.DoWithinTransaction(() => { CollectionSchema element2 = this.store.ElementFactory.CreateElement <CollectionSchema>(); element2.Name = this.element.Name; this.elementOwner.Elements.Add(element2); }); this.element.ValidateNameIsUnique(validationContext); Assert.True(validationContext.CurrentViolations.Count == 1); Assert.True(validationContext.ValidationSubjects.IndexOf(this.element) == 0); }
/// <summary> /// If all the parameters are null the DataSource can be used only to convert an expression to a query, not to /// manipulate data /// </summary> /// <param name="connector"></param> /// <param name="collectionName"></param> /// <param name="collectionSchema"></param> /// <param name="sessionId"></param> internal DataSource([NotNull] Connector connector, [NotNull] string collectionName, [NotNull] CollectionSchema collectionSchema, Guid sessionId = default) : base(CreateParser(), new QueryExecutor(connector.Client, collectionSchema, sessionId, collectionName)) { if (connector == null) { throw new ArgumentNullException(nameof(connector)); } _client = connector.Client; _collectionName = collectionName ?? throw new ArgumentNullException(nameof(collectionName)); _collectionSchema = collectionSchema ?? throw new ArgumentNullException(nameof(collectionSchema)); }
internal void AddOrReplaceEntity(string entityName, CollectionSchema schema, DataOperation operation) { var clone = new Dictionary <string, CollectionSchema>(entities); if (clone.ContainsKey(entityName)) { clone.Remove(entityName); } if (operation == DataOperation.Write) { schema = AddIdSchemaField(schema); clone.Add(entityName, schema); } entities = clone; }
public void DeclareCollection(string collectionName, CollectionSchema schema, int shard = -1) { // do not modify the original schema = schema.Clone(); schema.CollectionName = collectionName; var request = new RegisterTypeRequest(schema, shard == -1 ? ShardIndex:shard, ShardsCount); var response = Channel.SendRequest(request); if (response is ExceptionResponse exResponse) { throw new CacheException("Error while registering a type on the server", exResponse.Message, exResponse.CallStack); } }
private CollectionSchema AddIdSchemaField(CollectionSchema schema) { bool haveIdField = schema.FieldSettings.Where(x => x.Name.Equals("_id")).Count() > 0; if (!haveIdField) { Field field = new Field { Name = "_id", //BaseType = FieldBaseType.String, Type = "ObjectId", Required = true }; schema.FieldSettings.Add(field); } return(schema); }
public static OrQuery ToQuery(this Node node, CollectionSchema schema) { OrQuery result = null; if (node.Token == "select" || node.Token == "count") { result = SelectToQuery(node, schema); } QueryHelper.OptimizeQuery(result); if (node.Token == "count") { result !.CountOnly = true; } return(result); }
public void InitializeContext() { var uriService = Mock.Of <IUriReferenceService>( u => u.ResolveUri <IInstanceBase>(It.IsAny <Uri>()) == Mock.Of <IProduct>(p => p.ToolkitInfo.Identifier == "AuthoredToolkit")); var store = new DslTestStore <PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of <IPatternManager>(p => p.InstalledToolkits == new List <IInstalledToolkitInfo>())); PatternModelSchema patternModel = null; store.TransactionManager.DoWithinTransaction(() => { patternModel = store.ElementFactory.CreateElement <PatternModelSchema>(); }); var patternSchema = patternModel.Create <PatternSchema>(); patternSchema.Name = "FooPattern"; patternSchema.PatternLink = "patternmanager://foo"; patternSchema.UriService = uriService; var view = patternSchema.Create <ViewSchema>(); view.Name = "View1"; store.TransactionManager.DoWithinTransaction(() => { var parentElement = store.ElementFactory.CreateElement <ElementSchema>("Element1"); this.collection = store.ElementFactory.CreateElement <CollectionSchema>("Collection1"); var extensionPoint = store.ElementFactory.CreateElement <ExtensionPointSchema>("ExtensionPoint1"); this.collection.ExtensionPoints.Add(extensionPoint); parentElement.Elements.Add(collection); view.Elements.Add(parentElement); }); }
/// <summary> /// Initialize an empty datastore from a type description /// </summary> /// <param name="collectionSchema"></param> /// <param name="evictionPolicy"></param> /// <param name="fullTextConfig"></param> public DataStore(CollectionSchema collectionSchema, EvictionPolicy evictionPolicy, FullTextConfig fullTextConfig) { _fullTextConfig = fullTextConfig; CollectionSchema = collectionSchema ?? throw new ArgumentNullException(nameof(collectionSchema)); EvictionPolicy = evictionPolicy ?? throw new ArgumentNullException(nameof(evictionPolicy)); //initialize the primary key dictionary DataByPrimaryKey = new Dictionary <KeyValue, PackedObject>(); //initialize the unique keys dictionaries (one by unique key) _dataByUniqueKey = new Dictionary <string, Dictionary <KeyValue, PackedObject> >(); foreach (var keyInfo in collectionSchema.UniqueKeyFields) { _dataByUniqueKey.Add(keyInfo.Name, new Dictionary <KeyValue, PackedObject>()); } //initialize the indexes (one by index key) _dataByIndexKey = new Dictionary <string, IndexBase>(); // scalar indexed fields foreach (var indexField in collectionSchema.IndexFields) { var index = IndexFactory.CreateIndex(indexField); _dataByIndexKey.Add(indexField.Name, index); } // create the full-text index if required if (collectionSchema.FullText.Count > 0) { _fullTextIndex = new FullTextIndex(fullTextConfig) { // a function that allows the full text engine to find the original line of text LineProvider = pointer => DataByPrimaryKey[pointer.PrimaryKey].TokenizedFullText[pointer.Line] } } ; }
private void InitSchema() { JArray dbEntities = crudService.Query("_schema", new DataModel.DataQuery() { PageNumber = 1, PageSize = int.MaxValue, RawQuery = null }).Items; foreach (JToken item in dbEntities) { CollectionSchema schema = item.ToObject <CollectionSchema>(); if (schema.CollectionName != null && !string.IsNullOrEmpty(schema.CollectionName.ToString())) { schema = AddIdSchemaField(schema); entities[schema.CollectionName] = schema; } } }
/// <summary> /// Declare a collection with explicit schema /// </summary> /// <param name="collectionName"></param> /// <param name="schema"></param> public void DeclareCollection(string collectionName, CollectionSchema schema) { lock (_collectionSchema) { if (_collectionSchema.TryGetValue(collectionName, out var oldSchema)) { if (!schema.Equals(oldSchema)) { throw new CacheException($"Schema declaration conflict for collection {collectionName}"); } } else { _collectionSchema[collectionName] = schema; } // redeclare anyway in case the server is a non persistent cache and it has restarted since the last declaration Client.DeclareCollection(collectionName, schema); } }
public void Serialize() { var coll = new CollectionSchema() { PluginConfiguration = new Dictionary <string, Newtonsoft.Json.Linq.JObject>() { { "prova", JObject.FromObject(new FullTextFilter() { CollectionName = "PROC", IncludedField = new List <string>() { "dd", "dd" } }) } } }; var obj = JObject.FromObject(coll); var result = obj.ToString(); }
private static void LogTypeInfo(CollectionSchema desc) { Logger.Write(""); Logger.Write("{0} ({1})", desc.CollectionName.ToUpper(), desc.CollectionName); var header = $"| {"property",45} | {"index type",13} |"; var line = new string('-', header.Length); Logger.Write(line); Logger.Write(header); Logger.Write(line); foreach (var keyInfo in desc.ServerSide) { Logger.Write($"| {keyInfo.Name,45} | {keyInfo.IndexType,13} | "); } Logger.Write(line); }
/// <summary> /// Helper function. Enumerate all the objects in the dump /// </summary> /// <param name="path">path of the dump</param> /// <param name="collectionSchema"></param> /// <param name="shardIndex"></param> /// <returns></returns> public static IEnumerable <PackedObject> ObjectsInDump(string path, CollectionSchema collectionSchema, int shardIndex = -1) { var fileMask = shardIndex != -1 ? $"{collectionSchema.CollectionName}_shard{shardIndex:D4}*.txt" : $"{collectionSchema.CollectionName}_shard*.txt"; var files = Directory.GetFiles(path, fileMask); foreach (var file in files) { var content = File.ReadAllText(file); var parts = content.Split(new[] { "\\-" }, StringSplitOptions.RemoveEmptyEntries) .Select(txt => txt.Trim()).Where(t => !string.IsNullOrWhiteSpace(t)).ToList(); foreach (var part in parts) { var cachedObject = PackedObject.PackJson(part, collectionSchema); yield return(cachedObject); } } }
public void InitializeContext() { var uriService = Mock.Of<IUriReferenceService>( u => u.ResolveUri<IInstanceBase>(It.IsAny<Uri>()) == Mock.Of<IProduct>(p => p.ToolkitInfo.Identifier == "AuthoredToolkit")); var store = new DslTestStore<PatternModelDomainModel>(); var serviceProvider = Mock.Get(store.ServiceProvider); serviceProvider.Setup(s => s.GetService(typeof(IPatternManager))).Returns( Mock.Of<IPatternManager>(p => p.InstalledToolkits == new List<IInstalledToolkitInfo>())); PatternModelSchema patternModel = null; store.TransactionManager.DoWithinTransaction(() => { patternModel = store.ElementFactory.CreateElement<PatternModelSchema>(); }); var patternSchema = patternModel.Create<PatternSchema>(); patternSchema.Name = "FooPattern"; patternSchema.PatternLink = "patternmanager://foo"; patternSchema.UriService = uriService; var view = patternSchema.Create<ViewSchema>(); view.Name = "View1"; store.TransactionManager.DoWithinTransaction(() => { this.collection = store.ElementFactory.CreateElement<CollectionSchema>("Collection1"); var extensionPoint = store.ElementFactory.CreateElement<ExtensionPointSchema>("ExtensionPoint1"); this.collection.ExtensionPoints.Add(extensionPoint); view.Elements.Add(collection); }); }
/// <summary> /// Update collection schema /// </summary> /// <param name="name">collection name</param> /// <param name="schema"></param> /// <returns></returns> CollectionSchemaDetail UpdateCollectionSchema(string name, CollectionSchema schema);
/// <summary> /// </summary> /// <param name="collectionSchema">The description of the type to be registered</param> /// <param name="shardIndex">Index of the node inside the cluster (0 based)</param> /// <param name="shardsInCluster">Nodes in cluster</param> /// <param name="collectionName"></param> public RegisterTypeRequest(CollectionSchema collectionSchema, int shardIndex = 0, int shardsInCluster = 1) { CollectionSchema = collectionSchema; ShardIndex = shardIndex; ShardsInCluster = shardsInCluster; }
/// <summary> /// Initialize for a specified cacheable data type /// </summary> /// <param name="type"></param> public QueryBuilder(Type type) { _collectionSchema = TypedSchemaFactory.FromType(type); }
/// <summary> /// Create from a <see cref="CollectionSchema" /> /// </summary> /// <param name="collectionSchema"></param> public QueryBuilder(CollectionSchema collectionSchema) { _collectionSchema = collectionSchema ?? throw new ArgumentNullException(nameof(collectionSchema)); }