コード例 #1
0
        /*--------------------------------------------------------------------------------------------*/
        private static void AddEdge <TEdge>(ICreateOperationBuilder pCreCtx, IWeaverVarAlias pFromVar,
                                            TEdge pEdge, IWeaverVarAlias pToVar) where TEdge : IWeaverEdge
        {
            IWeaverQuery q = Weave.Inst.Graph.AddEdge(pFromVar, pEdge, pToVar);

            pCreCtx.AddQuery(q, true);
            pCreCtx.SetupLatestCommand(true);
        }
コード例 #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private static void AddVertex <T>(ICreateOperationBuilder pCreCtx, T pVertex,
                                          out IWeaverVarAlias <T> pAlias) where T : Vertex, new()
        {
            IWeaverQuery q = Weave.Inst.Graph.AddVertex(pVertex);

            q = WeaverQuery.StoreResultAsVar(pCreCtx.GetNextAliasName(), q, out pAlias);
            pCreCtx.AddQuery(q, true);
            pCreCtx.SetupLatestCommand();
        }
コード例 #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public virtual void FindDuplicateClass(
            ICreateOperationBuilder pCreCtx, string pNameKey, string pDisambLower)
        {
            Class c = Weave.Inst.Graph.V
                      .ExactIndex <Class>(x => x.NameKey, pNameKey);

            IWeaverQuery q;

            if (pDisambLower == null)
            {
                q = c.HasNot(x => x.Disamb)
                    .Property(x => x.VertexId)
                    .ToQuery();
            }
            else
            {
                q = c.Has(x => x.Disamb)
                    .CustomStep("filter{" +
                                "it.property('" + DbName.Vert.Class.Disamb + "').next().toLowerCase()==_P1" +
                                "}")
                    .Property(x => x.VertexId)
                    .ToQuery();

                q.AddParam(new WeaverQueryVal(pDisambLower));
            }

            ////

            const string            classVarName = "c";
            IWeaverVarAlias <Class> alias;

            q = WeaverQuery.StoreResultAsVar(classVarName, q, out alias);
            pCreCtx.AddQuery(q, true, classVarName + "?0:1;");

            string cmdId = pCreCtx.SetupLatestCommand(false, true);

            pCreCtx.AddCheck(new DataResultCheck(cmdId, (dr, i) => {
                if (dr.ToIntAt(i, 0) != 1)
                {
                    string name = pNameKey + (pDisambLower == null ? "" : " (" + pDisambLower + ")");
                    throw new FabDuplicateFault(typeof(Class), "Name", name, "Name+Disamb conflict.");
                }
            }));
        }
コード例 #4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private static void FindDuplicate <T>(ICreateOperationBuilder pCreCtx,
                                              Expression <Func <T, object> > pProp, string pValue, string pErrPropName)
            where T : IVertex, new()
        {
            IWeaverVarAlias alias;

            IWeaverQuery q = Weave.Inst.Graph
                             .V.ExactIndex(pProp, pValue)
                             .ToQueryAsVar(pCreCtx.GetNextAliasName(), out alias);

            pCreCtx.AddQuery(q, true, alias.Name + "?0:1;");
            string cmdId = pCreCtx.SetupLatestCommand(false, true);

            pCreCtx.AddCheck(new DataResultCheck(cmdId, (dr, i) => {
                if (dr.ToIntAt(i, 0) != 1)
                {
                    throw new FabDuplicateFault(typeof(T), pErrPropName, pValue);
                }
            }));
        }
コード例 #5
0
        /*--------------------------------------------------------------------------------------------*/
        private static IWeaverVarAlias <T> VerifyVertex <T>(ICreateOperationBuilder pCreCtx,
                                                            long pVertexId) where T : Vertex, new()
        {
            IWeaverVarAlias <T> alias;
            string var = pCreCtx.GetNextAliasName();

            IWeaverQuery q = Weave.Inst.Graph.V
                             .ExactIndex <T>(x => x.VertexId, pVertexId)
                             .ToQueryAsVar(var, out alias);

            pCreCtx.AddQuery(q, true, "if(" + var + "){" + var + "=" + var + ".next();1;}else{0;}");
            string cmdId = pCreCtx.SetupLatestCommand(false, true);

            pCreCtx.AddCheck(new DataResultCheck(cmdId, (dr, i) => {
                if (dr.ToIntAt(i, 0) != 1)
                {
                    throw new FabNotFoundFault(typeof(T), "Id=" + pVertexId + " // " + i + " / " + cmdId);
                }
            }));

            return(alias);
        }
コード例 #6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public virtual void FindDuplicateMember(
            ICreateOperationBuilder pCreCtx, long pUserId, long pAppId)
        {
            IWeaverVarAlias <Member> alias;
            const string             varName = "m";

            IWeaverQuery q = Weave.Inst.Graph.V
                             .ExactIndex <User>(x => x.VertexId, pUserId)
                             .DefinesMembers
                             .Has(x => x.AppId, WeaverStepHasOp.EqualTo, pAppId)
                             .ToQueryAsVar(varName, out alias);

            pCreCtx.AddQuery(q, true, varName + "?0:1;");
            string cmdId = pCreCtx.SetupLatestCommand(false, true);

            pCreCtx.AddCheck(new DataResultCheck(cmdId, (dr, i) => {
                if (dr.ToIntAt(i, 0) != 1)
                {
                    throw new FabDuplicateFault("A " + typeof(Member).Name + " already exists with " +
                                                typeof(App).Name + "Id=" + pAppId + " and " +
                                                typeof(User).Name + "Id=" + pUserId + ".");
                }
            }));
        }