public Exceptional<BinaryExpressionDefinition> GetBinaryExpression(DBContext myDBContext) { AExpressionDefinition right; var op = myDBContext.DBPluginManager.GetBinaryOperator(_OperatorSymbol); if (op == null) { return new Exceptional<BinaryExpressionDefinition>(new Error_OperatorDoesNotExist(_OperatorSymbol)); } if (op.Label == BinaryOperator.Subtraction) right = new ValueDefinition(new DBInt32(-1)); else right = new ValueDefinition(new DBInt32(1)); var binExpr = new BinaryExpressionDefinition("*", _Expression, right); binExpr.Validate(myDBContext); return new Exceptional<BinaryExpressionDefinition>(binExpr, binExpr.ValidateResult); }
/// <summary> /// This will evaluate the <paramref name="myWhereExpression"/> and add some warnings coming from /// </summary> /// <param name="myWhereExpression"></param> /// <param name="myListOfUpdates"></param> /// <returns></returns> public QueryResult Update(IEnumerable<AAttributeAssignOrUpdateOrRemove> myListOfUpdates, BinaryExpressionDefinition myWhereExpression = null) { IEnumerable<Exceptional<DBObjectStream>> _dbobjects; IEnumerable<IWarning> warnings = null; #region get GUIDs if (myWhereExpression != null) { #region get guids via where myWhereExpression.Validate(_dbContext); if (myWhereExpression.ValidateResult.Failed()) { return new QueryResult(myWhereExpression.ValidateResult); } var _tempGraphResult = myWhereExpression.Calculon(_dbContext, new CommonUsageGraph(_dbContext), false); if (_tempGraphResult.Failed()) { return new QueryResult(_tempGraphResult); } else { _dbobjects = _tempGraphResult.Value.Select(new LevelKey(_graphDBType, _dbContext.DBTypeManager), null, true); if (!_tempGraphResult.Success()) { warnings = _tempGraphResult.IWarnings; } } #endregion } else { #region get guids via guid-idx _dbobjects = _dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(_graphDBType, _dbContext.DBTypeManager), _dbContext); #endregion } #endregion var updateResult = Update(_dbobjects, myListOfUpdates); #region expressionGraph error handling if (!warnings.IsNullOrEmpty()) { updateResult.PushIWarnings(warnings); } #endregion return updateResult; }
/// <summary> /// /// </summary> /// <param name="myWhereExpression"></param> /// <param name="_dbContext"></param> /// <param name="myTypeWithUndefAttrs">Type, List of undef attrs</param> /// <param name="myDBTypeAttributeToDelete">Type, List of attributes</param> /// <param name="myReferenceTypeLookup">reference, _graphDBType</param> /// <returns></returns> public QueryResult Delete(BinaryExpressionDefinition myWhereExpression, Dictionary<GraphDBType, List<string>> myTypeWithUndefAttrs, Dictionary<GraphDBType, List<TypeAttribute>> myDBTypeAttributeToDelete, Dictionary<String, GraphDBType> myReferenceTypeLookup) { QueryResult result = new QueryResult(); try { #region get UUIDs if (myWhereExpression != null) { #region _WhereExpression myWhereExpression.Validate(_dbContext); if (myWhereExpression.ValidateResult.Failed()) { return new QueryResult(myWhereExpression.ValidateResult); } var resultGraph = myWhereExpression.Calculon(_dbContext, new CommonUsageGraph(_dbContext), false); if (resultGraph.Failed()) { return new QueryResult(resultGraph.IErrors); } IEnumerable<Exceptional<DBObjectStream>> _dbobjects; #region undefined attributes foreach (var type in myTypeWithUndefAttrs) { _dbobjects = resultGraph.Value.Select(new LevelKey(type.Key, _dbContext.DBTypeManager), null, false); foreach (var dbObj in _dbobjects) { foreach (var undefAttr in type.Value) { var removeExcept = _dbContext.DBObjectManager.RemoveUndefinedAttribute(undefAttr, dbObj.Value); if (removeExcept.Failed()) return new QueryResult(removeExcept.IErrors); } } } #endregion #region TypeAttributes to delete Boolean generateLevel = true; foreach (var aToBeDeletedAttribute in myDBTypeAttributeToDelete) { if (!resultGraph.Value.ContainsRelevantLevelForType(aToBeDeletedAttribute.Key)) { generateLevel = false; } else { generateLevel = true; } var deleteResult = DeleteDBObjects(aToBeDeletedAttribute.Key, aToBeDeletedAttribute.Value, resultGraph.Value.Select(new LevelKey(aToBeDeletedAttribute.Key, _dbContext.DBTypeManager), null, generateLevel)); if (deleteResult.Failed()) { return new QueryResult(deleteResult.IErrors); } else { if (!deleteResult.Success()) { result.PushIWarnings(deleteResult.IWarnings); } result.Vertices = deleteResult.Value; } } #endregion #region expressionGraph error handling result.PushIWarnings(resultGraph.Value.GetWarnings()); #endregion #endregion } else { if (myDBTypeAttributeToDelete.Count == 0) { #region delete only undefined attributes of types foreach (var type in myTypeWithUndefAttrs) { var listOfAffectedDBObjects = _dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(type.Key, _dbContext.DBTypeManager), _dbContext); RemoveUndefAttrs(listOfAffectedDBObjects, type.Value); } #endregion } else { #region get guids via guid-idx foreach (var attributeToDelete in myDBTypeAttributeToDelete) { var listOfAffectedDBObjects = _dbContext.DBObjectCache.SelectDBObjectsForLevelKey(new LevelKey(attributeToDelete.Key, _dbContext.DBTypeManager), _dbContext).ToList(); if (myTypeWithUndefAttrs.ContainsKey(attributeToDelete.Key)) RemoveUndefAttrs(listOfAffectedDBObjects, myTypeWithUndefAttrs[attributeToDelete.Key]); List<TypeAttribute> attributes = new List<TypeAttribute>(); foreach (var attr in attributeToDelete.Value) { attributes.Add(attr); } var Result = DeleteDBObjects(attributeToDelete.Key, attributes, listOfAffectedDBObjects); if (Result.Failed()) { return new QueryResult(Result.IErrors); } } #endregion } } #endregion } catch (GraphDBException gdbEx) { return new QueryResult(gdbEx.GraphDBErrors); } catch (Exception e) { return new QueryResult(new Error_UnknownDBError(e)); } return result; }
public QueryResult Replace(List<AAttributeAssignOrUpdate> myAttributeAssignList, BinaryExpressionDefinition myBinaryExpressionDefinition) { List<IWarning> warnings = new List<IWarning>(); IEnumerable<Exceptional<DBObjectStream>> _dbObjects = null; myBinaryExpressionDefinition.Validate(_dbContext); if (myBinaryExpressionDefinition.ValidateResult.Failed()) { return new QueryResult(myBinaryExpressionDefinition.ValidateResult); } var _whereGraphResult = myBinaryExpressionDefinition.Calculon(_dbContext, new CommonUsageGraph(_dbContext), false); if (_whereGraphResult.Success()) { _dbObjects = _whereGraphResult.Value.Select(new LevelKey(_graphDBType, _dbContext.DBTypeManager), null, true); } else { return new QueryResult(_whereGraphResult.IErrors); } #region expressionGraph error handling warnings.AddRange(_whereGraphResult.Value.GetWarnings()); #endregion if (_dbObjects.CountIsGreater(1)) { return new QueryResult(new Error_MultipleResults()); } if (_dbObjects.CountIs(0)) { warnings.Add(new Warnings.Warning_NoObjectsToReplace()); return new QueryResult(new List<IError>(), warnings); } IEnumerable<GraphDBType> parentTypes = _dbContext.DBTypeManager.GetAllParentTypes(_graphDBType, true, false); Exceptional<Boolean> checkUniqueVal = null; var attrsResult = EvaluateAttributes(myAttributeAssignList); if (!attrsResult.Success()) { return new QueryResult(attrsResult); } var assingedAttrs = attrsResult.Value.Attributes.ToDictionary(key => key.Key.Definition.UUID, value => value.Value); checkUniqueVal = _dbContext.DBIndexManager.CheckUniqueConstraint(_graphDBType, parentTypes, assingedAttrs); if (!checkUniqueVal.Success()) return new QueryResult(checkUniqueVal); var DeleteResult = DeleteDBObjects(_graphDBType, null, _dbObjects); if (!DeleteResult.Success()) { return new QueryResult(DeleteResult); } var result = Insert(attrsResult.Value, false); result.PushIWarnings(warnings); return result; }
public QueryResult InsertOrUpdate(List<AAttributeAssignOrUpdate> _AttributeAssignList, BinaryExpressionDefinition myBinaryExpressionDefinition = null) { List<IWarning> warnings = new List<IWarning>(); IEnumerable<Exceptional<DBObjectStream>> extractedDBOs = null; var manipulationAttributes = EvaluateAttributes(_AttributeAssignList); if (!manipulationAttributes.Success()) { return new QueryResult(manipulationAttributes); } var attributeAssignOrUpdateOrRemoveList = manipulationAttributes.Value.AttributeToUpdateOrAssign; if (myBinaryExpressionDefinition != null) { myBinaryExpressionDefinition.Validate(_dbContext); if (myBinaryExpressionDefinition.ValidateResult.Failed()) { return new QueryResult(myBinaryExpressionDefinition.ValidateResult); } var _whereGraphResult = myBinaryExpressionDefinition.Calculon(_dbContext, new CommonUsageGraph(_dbContext), false); if (_whereGraphResult.Success()) { extractedDBOs = _whereGraphResult.Value.Select(new LevelKey(_graphDBType, _dbContext.DBTypeManager), null, true); } else { return new QueryResult(_whereGraphResult.IErrors); } #region expressionGraph error handling warnings.AddRange(_whereGraphResult.Value.GetWarnings()); #endregion } else { extractedDBOs = new List<Exceptional<DBObjectStream>>(); } QueryResult result; if (extractedDBOs.Count() == 0) { result = Insert(manipulationAttributes.Value, true); } else { if (extractedDBOs.Count() > 1) return new QueryResult(new Error_MultipleResults()); result = Update(extractedDBOs, attributeAssignOrUpdateOrRemoveList); } result.PushIWarnings(warnings); return result; }
public QueryResult InsertOrReplace(List<AAttributeAssignOrUpdate> myAttributeAssignList, BinaryExpressionDefinition myBinaryExpressionDefinition = null) { List<IWarning> warnings = new List<IWarning>(); IEnumerable<Exceptional<DBObjectStream>> myDBObjects; #region myBinaryExpressionDefinition if (myBinaryExpressionDefinition != null) { myBinaryExpressionDefinition.Validate(_dbContext); if (myBinaryExpressionDefinition.ValidateResult.Failed()) { return new QueryResult(myBinaryExpressionDefinition.ValidateResult); } var _whereGraphResult = myBinaryExpressionDefinition.Calculon(_dbContext, new CommonUsageGraph(_dbContext), false); if (_whereGraphResult.Success()) { myDBObjects = _whereGraphResult.Value.Select(new LevelKey(_graphDBType, _dbContext.DBTypeManager), null, true); } else { return new QueryResult(_whereGraphResult.IErrors); } #region expressionGraph error handling warnings.AddRange(_whereGraphResult.Value.GetWarnings()); #endregion } else { myDBObjects = new List<Exceptional<DBObjectStream>>(); } #endregion IEnumerable<GraphDBType> parentTypes = _dbContext.DBTypeManager.GetAllParentTypes(_graphDBType, true, false); #region Get attribute assignies prior to deletion to act on errors var attrsResult = EvaluateAttributes(myAttributeAssignList); if (!attrsResult.Success()) { return new QueryResult(attrsResult); } var assingedAttrs = attrsResult.Value.Attributes.ToDictionary(key => key.Key.Definition.UUID, value => value.Value); var checkUniqueVal = _dbContext.DBIndexManager.CheckUniqueConstraint(_graphDBType, parentTypes, assingedAttrs); if (checkUniqueVal.Failed()) return new QueryResult(checkUniqueVal.IErrors); #endregion #region Delete the object if (myDBObjects.CountIsGreater(1)) { return new QueryResult(new Error_MultipleResults()); } else { if (myDBObjects.CountIs(1)) { #region delete var DeleteResult = DeleteDBObjects(_graphDBType, null, myDBObjects); if (DeleteResult.Failed()) { return new QueryResult(DeleteResult.IErrors); } #endregion } } #endregion #region Insert with new values //Insert var result = Insert(attrsResult.Value, false); result.PushIWarnings(warnings); //if there were any warnings during this process, the need to be added #endregion return result; }