static bool CheckUpdate() { //update the rootpage of a table SchemaRecord table_before = icatalog.GetTableSchemaRecord("Student"); Console.WriteLine(table_before.RootPage); icatalog.TryUpdateSchemaRecord("Student", 2); SchemaRecord table_after = icatalog.GetTableSchemaRecord("Student"); Console.WriteLine(table_after.RootPage); Debug.Assert(table_after.RootPage == 2); //update the rootpage of an index SchemaRecord index_before = icatalog.GetIndexSchemaRecord("index_for_student_id"); Console.WriteLine(index_before.RootPage); icatalog.TryUpdateSchemaRecord("index_for_student_id", 3); SchemaRecord index_after = icatalog.GetIndexSchemaRecord("index_for_student_id"); Console.WriteLine(index_after.RootPage); Debug.Assert(index_after.RootPage == 3); //try to update the table or index that does not exist //will print false bool test1 = icatalog.TryUpdateSchemaRecord("HHH", 5); bool test2 = icatalog.TryUpdateSchemaRecord("hhh", 6); Console.WriteLine(test1); Console.WriteLine(test2); Debug.Assert(test1 == false); Debug.Assert(test2 == false); return(true); }
public SchemaRuleCommand(SchemaRecord recordsBefore, SchemaRecord recordsAfter, SchemaRule schemaRule) { Setup(Iterables.first(recordsAfter).Id, Mode.fromRecordState(Iterables.first(recordsAfter))); this.RecordsBeforeConflict = recordsBefore; this.RecordsAfterConflict = recordsAfter; this.SchemaRuleConflict = schemaRule; }
/// <inheritdoc /> public virtual async Task <string> CreateSchemaAsync(IAgentContext context, string issuerDid, string name, string version, string[] attributeNames) { var schema = await AnonCreds.IssuerCreateSchemaAsync(issuerDid, name, version, attributeNames.ToJson()); var schemaRecord = new SchemaRecord { Id = schema.SchemaId, Name = name, Version = version, AttributeNames = attributeNames }; var paymentInfo = await paymentService.GetTransactionCostAsync(context, TransactionTypes.SCHEMA); await LedgerService.RegisterSchemaAsync(context, issuerDid, schema.SchemaJson, paymentInfo); await RecordService.AddAsync(context.Wallet, schemaRecord); if (paymentInfo != null) { await RecordService.UpdateAsync(context.Wallet, paymentInfo.PaymentAddress); } return(schemaRecord.Id); }
//return the schema record of the table named table name public List <SchemaRecord> GetTablesSchemaRecord() { List <SchemaRecord> list = new List <SchemaRecord>(); for (int i = 0; i < tables.Count; i++) { SchemaRecord target_table = GetTableSchemaRecord(tables[i].table_name); list.Add(target_table); } return(list); }
internal virtual void DropSchemaRule(SchemaRule rule) { RecordAccess_RecordProxy <SchemaRecord, SchemaRule> change = _recordChangeSet.SchemaRuleChanges.getOrLoad(rule.Id, rule); SchemaRecord records = change.ForChangingData(); foreach (DynamicRecord record in records) { record.InUse = false; } records.InUse = false; }
private void ChangeSchemaRule(SchemaRule rule, SchemaRule updatedRule) { //Read the current record RecordAccess_RecordProxy <SchemaRecord, SchemaRule> change = _recordChangeSet.SchemaRuleChanges.getOrLoad(rule.Id, rule); SchemaRecord records = change.ForReadingData(); //Register the change of the record RecordAccess_RecordProxy <SchemaRecord, SchemaRule> recordChange = _recordChangeSet.SchemaRuleChanges.setRecord(rule.Id, records, updatedRule); SchemaRecord dynamicRecords = recordChange.ForChangingData(); //Update the record dynamicRecords.DynamicRecords = _schemaStore.allocateFrom(updatedRule); }
//return all the indices of the table named 'tableName' public List <SchemaRecord> GetIndicesSchemaRecord(string tableName) { List <SchemaRecord> list = new List <SchemaRecord>(); for (int i = 0; i < index.Count; i++) { if (index[i].table_name == tableName) { SchemaRecord target_index = GetIndexSchemaRecord(index[i].index_name); list.Add(target_index); } } return(list); }
/// <inheritdoc /> public virtual async Task <string> CreateSchemaAsync(Pool pool, Wallet wallet, string issuerDid, string name, string version, string[] attributeNames) { var schema = await AnonCreds.IssuerCreateSchemaAsync(issuerDid, name, version, attributeNames.ToJson()); var schemaRecord = new SchemaRecord { SchemaId = schema.SchemaId }; await LedgerService.RegisterSchemaAsync(pool, wallet, issuerDid, schema.SchemaJson); await RecordService.AddAsync(wallet, schemaRecord); return(schemaRecord.SchemaId); }
public async Task <GetSchemaResponse> Handle ( GetSchemaRequest aGetSchemaRequest, CancellationToken aCancellationToken ) { IAgentContext agentContext = await AgentProvider.GetContextAsync(); List <SchemaRecord> schemaRecords = await SchemaService.ListSchemasAsync(agentContext.Wallet); SchemaRecord schemaRecord = schemaRecords.FirstOrDefault(aSchemaRecord => aSchemaRecord.Id == aGetSchemaRequest.SchemaId); var response = new GetSchemaResponse(aGetSchemaRequest.CorrelationId, schemaRecord); return(await Task.Run(() => response)); }
// create statement private void HandleStatement(CreateStatement statement) { _catalogManager.CheckValidation(statement); switch (statement.CreateType) { case CreateType.Table: int newTableRoot = _recordManager.CreateTable(); _catalogManager.CreateStatement(statement, newTableRoot); break; case CreateType.Index: SchemaRecord tableSchema = _catalogManager.GetTableSchemaRecord(statement.TableName); int newIndexRoot = _recordManager.CreateIndex(tableSchema.RootPage, statement.AttributeName, tableSchema.SQL.AttributeDeclarations); _catalogManager.CreateStatement(statement, newIndexRoot); break; } }
protected void OnCredentialDefintionSelect() { OfferCredentialRequest.CredentialPreviewAttributes.Clear(); if (!string.IsNullOrEmpty(OfferCredentialRequest.CredentialDefinitionId)) { string schemaId = CredentialDefinitionState.CredentialDefinitions[OfferCredentialRequest.CredentialDefinitionId].SchemaId; SchemaRecord schemaRecord = SchemaState.Schemas[schemaId]; foreach (string name in schemaRecord.AttributeNames) { OfferCredentialRequest .CredentialPreviewAttributes .Add ( new CredentialPreviewAttribute(name, string.Empty) ); } } }
private void HandleStatement(InsertStatement statement) { _catalogManager.CheckValidation(statement); // get table schema SchemaRecord schema = _catalogManager.GetTableSchemaRecord(statement.TableName); // adjust inlined type in insert statement if (schema.SQL.AttributeDeclarations.Count != statement.Values.Count) { throw new Exception("number of columns between \"create table\" and \"insert statement\' do not match"); } int i; for (i = 0; i < statement.Values.Count; i++) { statement.Values[i].CharLimit = schema.SQL.AttributeDeclarations[i].CharLimit; } // find out primary key from insert values AtomValue primaryKey = statement.Values[schema.SQL.AttributeDeclarations.FindIndex(x => x.AttributeName == schema.SQL.PrimaryKey)]; // insert into index trees List <SchemaRecord> indexSchemas = _catalogManager.GetIndicesSchemaRecord(statement.TableName); foreach (SchemaRecord indexSchema in indexSchemas) { // find indexed value from insert values AtomValue indexedValue = statement.Values[schema.SQL.AttributeDeclarations.FindIndex(x => x.AttributeName == indexSchema.SQL.AttributeName)]; // wrap up indexed value and primary key List <AtomValue> indexPrimaryKeyPair = new List <AtomValue>() { indexedValue, primaryKey }; // insert into index trees int newIndexRoot = _recordManager.InsertRecord(indexPrimaryKeyPair, indexedValue, indexSchema.RootPage); _catalogManager.TryUpdateSchemaRecord(indexSchema.Name, newIndexRoot); } // insert into table tree int newRoot = _recordManager.InsertRecord(statement.Values, primaryKey, schema.RootPage); _catalogManager.TryUpdateSchemaRecord(statement.TableName, newRoot); }
// delete statement // NOTICE: relative index trees will NOT change accordingly private void HandleStatement(DeleteStatement statement) { // get table and indices _catalogManager.CheckValidation(statement); SchemaRecord tableSchema = _catalogManager.GetTableSchemaRecord(statement.TableName); List <SchemaRecord> indexSchemas = _catalogManager.GetIndicesSchemaRecord(statement.TableName); // TODO // delete index records from index trees // __problem__: // attribute names := (priKey, a, b, c) // condition := b < 3 and c > 5 // fun facts: b and c both have index trees // issue: to delete the records satisfying the condition above // delete record from table tree int newTableRootPage = _recordManager.DeleteRecords(statement.Condition, tableSchema.SQL.PrimaryKey, tableSchema.SQL.AttributeDeclarations, tableSchema.RootPage); _catalogManager.TryUpdateSchemaRecord(statement.TableName, newTableRootPage); }
//return the schema record of the table named table name public SchemaRecord GetTableSchemaRecord(string tableName) { SchemaRecord s = new SchemaRecord(); s.Type = SchemaTypes.Table; s.Name = tableName; //since this is the table and there is no table that is associated to it s.AssociatedTable = " "; //get the target table first, then get the schema record from the table Table target_table = return_table(tableName); s.RootPage = target_table.root_page; s.SQL = new CreateStatement(); s.SQL.CreateType = CreateType.Table; s.SQL.TableName = tableName; //there is no index information for a table s.SQL.IndexName = " "; s.SQL.AttributeName = " "; //get every attribute declaration from the target table List <AttributeDeclaration> temp = new List <AttributeDeclaration>(); for (int i = 0; i < target_table.attribute_list.Count; i++) { AttributeDeclaration attribute = new AttributeDeclaration(); attribute.Type = target_table.attribute_list[i].type; attribute.CharLimit = target_table.attribute_list[i].length; attribute.IsUnique = target_table.attribute_list[i].is_unique; attribute.AttributeName = target_table.attribute_list[i].attribute_name; temp.Add(attribute); } s.SQL.AttributeDeclarations = temp; s.SQL.PrimaryKey = target_table.primary_key; //Console.WriteLine("hhhh"); return(s); }
//return the shcema record of the index named 'index_name' //used after checking 'If_in',to make sure that the index does exist public SchemaRecord GetIndexSchemaRecord(string index_name) { SchemaRecord record = new SchemaRecord(); for (int i = 0; i < index.Count; i++) { if (index[i].index_name == index_name) { record.AssociatedTable = index[i].table_name; record.Name = index_name; record.RootPage = index[i].root_page; record.Type = SchemaTypes.Index; CreateStatement temp = new CreateStatement(); temp.CreateType = CreateType.Index; temp.TableName = index[i].table_name; temp.IsUnique = index[i].is_uniqve; temp.IndexName = index[i].index_name; temp.AttributeName = index[i].attribute_name; record.SQL = temp; } } return(record); }
protected void OnCredentialDefintionSelect() { CreateProofRequestRequest.ProofRequest.RequestedAttributes.Clear(); if (!string.IsNullOrEmpty(CredentialDefinitionId)) { Console.WriteLine("Adding All Attributes"); DefinitionRecord definitionRecord = CredentialDefinitionState.CredentialDefinitions[CredentialDefinitionId]; string schemaId = definitionRecord.SchemaId; SchemaRecord schemaRecord = SchemaState.Schemas[schemaId]; CreateProofRequestRequest.ProofRequest.Name = schemaRecord.Name; CreateProofRequestRequest.ProofRequest.Version = schemaRecord.Version; foreach (string name in schemaRecord.AttributeNames) { var restrictions = new List <AttributeFilter>(); var attributeFilter = new AttributeFilter { CredentialDefinitionId = definitionRecord.Id }; restrictions.Add(attributeFilter); var proofAttributeInfo = new ProofAttributeInfo() { Name = name, Restrictions = restrictions, }; CreateProofRequestRequest.ProofRequest .RequestedAttributes .Add($"0_{name}_uuid", proofAttributeInfo); } Console.WriteLine($"Added:{CreateProofRequestRequest.ProofRequest.RequestedAttributes.Count}"); } }
//check whether we can successfully return the schema record of a table or an index static bool CheckGetSchemaRecord() { SchemaRecord target_table = icatalog.GetTableSchemaRecord("Student"); Console.WriteLine("Schema of Table"); Console.WriteLine(target_table.Name); Console.WriteLine(target_table.RootPage); Console.WriteLine(target_table.Type); Console.WriteLine(target_table.SQL.PrimaryKey); Console.WriteLine(target_table.SQL.TableName); Console.WriteLine(target_table.SQL.Type); SchemaRecord target_index = icatalog.GetIndexSchemaRecord("index_for_student_id"); Console.WriteLine("Schema of Index"); Console.WriteLine(target_index.Name); Console.WriteLine(target_index.RootPage); Console.WriteLine(target_index.Type); Console.WriteLine(target_index.SQL.IndexName); Console.WriteLine(target_index.SQL.IsUnique); Console.WriteLine(target_index.SQL.Type); List <SchemaRecord> target_indices = icatalog.GetIndicesSchemaRecord("Student"); for (int i = 0; i < target_indices.Count; i++) { Console.WriteLine("Schema of Indices"); Console.WriteLine(target_indices[i].Name); Console.WriteLine(target_indices[i].RootPage); Console.WriteLine(target_indices[i].Type); Console.WriteLine(target_indices[i].SQL.IndexName); Console.WriteLine(target_indices[i].SQL.IsUnique); Console.WriteLine(target_indices[i].SQL.Type); } return(true); }
public GetSchemaResponse(Guid aCorrelationId, SchemaRecord aSchemaRecord) : base(aCorrelationId) { SchemaRecord = aSchemaRecord; }
private SelectResult HandleSelectStatement(SelectStatement statement) { bool isIndexTreeAvailable = false; // get table and indices _catalogManager.CheckValidation(statement); SchemaRecord tableSchema = _catalogManager.GetTableSchemaRecord(statement.FromTable); List <SchemaRecord> indexSchemas = _catalogManager.GetIndicesSchemaRecord(statement.FromTable); // select from index tree if possible AtomValue primaryKey = null; if (statement.Condition != null) { foreach (SchemaRecord indexSchema in indexSchemas) { // if there has a condition `=` on indexed column if (statement.Condition.SimpleMinterms.ContainsKey(indexSchema.SQL.AttributeName) && statement.Condition.SimpleMinterms[indexSchema.SQL.AttributeName].Operator == Operator.Equal) { isIndexTreeAvailable = true; // find out the primary key List <AtomValue> wrappedPrimaryKey = _recordManager.SelectRecord(statement.Condition.SimpleMinterms[indexSchema.SQL.AttributeName].RightOperand.ConcreteValue, indexSchema.RootPage); primaryKey = wrappedPrimaryKey?[1]; break; } } } SelectResult result = new SelectResult(); result.ColumnDeclarations = tableSchema.SQL.AttributeDeclarations; // index tree is not available if (!isIndexTreeAvailable) { // select records from table tree List <List <AtomValue> > rows = _recordManager.SelectRecords(statement, tableSchema.SQL.PrimaryKey, tableSchema.SQL.AttributeDeclarations, tableSchema.RootPage); result.Rows = rows; } // index tree is available else { // select one record from table tree List <List <AtomValue> > rows = new List <List <AtomValue> >(); if (!object.ReferenceEquals(primaryKey, null)) { List <AtomValue> recordFromTable = _recordManager.SelectRecord(primaryKey, tableSchema.RootPage); rows.Add(recordFromTable); result.Rows = rows; } else // the primary key is null. // if primaryKey is null, // it means that from the index tree it could not find the primary key. // in order words, there is not a row existing in the table tree satisfying the condition. // thus, no need to visit the table tree { // assign an empty list result.Rows = new List <List <AtomValue> >(); } } return(result); }