Esempio n. 1
0
        /*--------------------------------------------------------------------------------------------*/
        private IWeaverQuery FinishEdgeVci <TEdge>(TEdge pEdge, string pOutV, string pInV,
                                                   string pScript) where TEdge : IWeaverEdge
        {
            Type et = typeof(TEdge);
            var  e  = WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverTitanEdgeAttribute>(et);

            string labelParam = Path.Query.AddStringParam(e.DbName);
            string propList   = WeaverUtil.BuildPropList(Path.Config, Path.Query, pEdge);

            var sb = new StringBuilder();

            AppendEdgeVciProps(sb, pOutV, et, WeaverUtil.GetElementPropertyAttributes(e.OutVertex));
            AppendEdgeVciProps(sb, pInV, et, WeaverUtil.GetElementPropertyAttributes(e.InVertex));

            const string tryLoop  = "_TRY.each{k,v->if((z=v.getProperty(k))){_PROP.put(k,z)}};";
            bool         showTry  = (sb.Length > 0);
            string       propLine = (propList.Length > 0 || showTry ?
                                     "_PROP=" + (propList.Length > 0 ? "[" + propList + "];" : "[:];") : "");

            Path.Query.FinalizeQuery(
                pScript +
                propLine +
                (showTry ? "_TRY=[" + sb + "];" + tryLoop : "") +
                "g.addEdge(" + pOutV + "," + pInV + "," + labelParam + (propLine.Length > 0 ? ",_PROP" : "") + ")"
                );

            return(Path.Query);
        }
Esempio n. 2
0
        /*--------------------------------------------------------------------------------------------*/
        private static void ConfirmVciState <TEdge, TVert> (TEdge pEdge,
                                                            Expression <Func <TVert, object> > pProperty)
            where TEdge : IWeaverEdge where TVert : IWeaverVertex
        {
            Type et = typeof(TEdge);
            Type vt = typeof(TVert);

            WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverTitanEdgeAttribute> (et);
            WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverTitanVertexAttribute> (vt);

            if (pEdge.OutVertexType != vt && pEdge.InVertexType != vt)
            {
                throw new WeaverException("Vertex type '" + vt.Name + "' is not valid for edge type '" +
                                          et.Name + "'.");
            }

            WeaverPropPair wpp = WeaverUtil.GetPropertyAttribute(pProperty);
            WeaverTitanPropertyAttribute att = WeaverTitanUtil.GetAndVerifyTitanPropertyAttribute(wpp);

            if (!att.HasTitanVertexCentricIndex(et))
            {
                throw new WeaverException("Property '" + vt.Name + "." + wpp.Info.Name + "' does not have a " +
                                          "vertex-centric index for edge '" + et.Name + "'.");
            }
        }
Esempio n. 3
0
        /*--------------------------------------------------------------------------------------------*/
        private IWeaverPathPipeEnd MakePropertyKey <T>(string pElement, Expression <Func <T, object> > pProp,
                                                       IWeaverVarAlias pGroupVar = null) where T : IWeaverElement
        {
            WeaverPropPair wpp = WeaverUtil.GetPropertyAttribute(pProp);
            WeaverTitanPropertyAttribute att = WeaverTitanUtil.GetAndVerifyTitanPropertyAttribute(wpp);
            Type pt = wpp.Info.PropertyType;

            AddCustom("makeType()");
            AddCustom("dataType(" + WeaverTitanPropertyAttribute.GetTitanTypeName(pt) + ".class)");
            AddCustom("name(" + Path.Query.AddParam(new WeaverQueryVal(att.DbName)) + ")");
            AddCustom("unique(OUT)");             //WeaverConfig enforces unique property DbNames

            if (pGroupVar != null)
            {
                AddCustom("group(" + pGroupVar.Name + ")");
            }

            if (att.TitanIndex)
            {
                AddCustom("indexed(" + pElement + ".class)");
            }

            if (att.TitanElasticIndex)
            {
                AddCustom("indexed('search'," + pElement + ".class)");
            }

            return(AddCustom("makePropertyKey()"));
        }
Esempio n. 4
0
        /*--------------------------------------------------------------------------------------------*/
        private void AppendEdgeVciProps(StringBuilder pStr, string pAlias, Type pEdgeType,
                                        IEnumerable <WeaverPropPair> pProps)
        {
            foreach (WeaverPropPair wpp in pProps)
            {
                WeaverTitanPropertyAttribute att =
                    WeaverTitanUtil.GetAndVerifyTitanPropertyAttribute(wpp, true);

                if (att == null || !att.HasTitanVertexCentricIndex(pEdgeType))
                {
                    continue;
                }

                pStr.Append((pStr.Length > 0 ? "," : "") + att.DbName + ":" + pAlias);
            }
        }
Esempio n. 5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public IWeaverQuery TypeGroupOf <T>(int pId) where T : IWeaverVertex
        {
            if (pId < 2)
            {
                throw new WeaverException("Group ID must be greater than 1.");
            }

            WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverVertexAttribute>(typeof(T));
            var q = new WeaverQuery();

            q.FinalizeQuery(
                "com.thinkaurelius.titan.core.TypeGroup.of(" +
                q.AddParam(new WeaverQueryVal(pId)) + ",'group')"
                );

            return(q);
        }
Esempio n. 6
0
        /*--------------------------------------------------------------------------------------------*/
        public IWeaverPathPipeEnd BuildEdgeLabel <T>(
            Func <string, IWeaverVarAlias> pGetPropVarAliasByDbName) where T : IWeaverEdge
        {
            Type et  = typeof(T);
            var  e   = WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverTitanEdgeAttribute>(et);
            var  ivc = e.InConn;
            var  ovc = e.OutConn;

            var props = new List <WeaverPropPair>();

            props.AddRange(WeaverUtil.GetElementPropertyAttributes(e.OutVertex));
            props.AddRange(WeaverUtil.GetElementPropertyAttributes(e.InVertex));

            var keys = new HashSet <string>();
            var sigs = new HashSet <string>();

            foreach (WeaverPropPair wpp in props)
            {
                WeaverTitanPropertyAttribute att =
                    WeaverTitanUtil.GetAndVerifyTitanPropertyAttribute(wpp, true);

                if (att == null)
                {
                    continue;
                }

                string alias = pGetPropVarAliasByDbName(att.DbName).Name;

                if (att.HasTitanVertexCentricIndex(et))
                {
                    keys.Add(alias);
                    continue;
                }

                sigs.Add(alias);
            }

            ////

            AddCustom("makeType()");
            AddCustom("name(" + Path.Query.AddParam(new WeaverQueryVal(e.DbName)) + ")");

            if (keys.Count > 0)
            {
                AddCustom("primaryKey(" + string.Join(",", keys) + ")");
            }

            if (sigs.Count > 0)
            {
                AddCustom("signature(" + string.Join(",", sigs) + ")");
            }

            // An edge label is out-unique, if a vertex has at most one outgoing edge for that label.
            // "father" is of an out-unique edge label, since each god has at most one father.
            // https://github.com/thinkaurelius/titan/wiki/Type-Definition-Overview

            if (ivc == WeaverEdgeConn.InOne || ivc == WeaverEdgeConn.InZeroOrOne)
            {
                AddCustom("unique(IN)");
            }

            if (ovc == WeaverEdgeConn.OutOne || ovc == WeaverEdgeConn.OutZeroOrOne)
            {
                AddCustom("unique(OUT)");
            }

            return(AddCustom("makeEdgeLabel()"));
        }
Esempio n. 7
0
 /*--------------------------------------------------------------------------------------------*/
 public IWeaverPathPipeEnd MakeEdgePropertyKey <T>(Expression <Func <T, object> > pProperty,
                                                   IWeaverVarAlias pGroupVar = null) where T : IWeaverEdge
 {
     WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverTitanEdgeAttribute>(typeof(T));
     return(MakePropertyKey("Edge", pProperty, pGroupVar));
 }