/*--------------------------------------------------------------------------------------------*/
        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()"));
        }
        /*--------------------------------------------------------------------------------------------*/
        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 + "'.");
            }
        }
Exemple #3
0
        public void HasTitanVertexCentricIndexNull()
        {
            var prop = new WeaverTitanPropertyAttribute("test");

            prop.EdgesForVertexCentricIndexing = null;

            Assert.False(prop.HasTitanVertexCentricIndex(typeof(Empty)), "Incorrect result: Empty.");
        }
Exemple #4
0
        public void HasTitanVertexCentricIndex()
        {
            var prop = new WeaverTitanPropertyAttribute("test");

            prop.EdgesForVertexCentricIndexing = new [] { typeof(One), typeof(Two) };

            Assert.True(prop.HasTitanVertexCentricIndex(typeof(One)), "Incorrect result: One.");
            Assert.True(prop.HasTitanVertexCentricIndex(typeof(Two)), "Incorrect result: Two.");
            Assert.False(prop.HasTitanVertexCentricIndex(typeof(Empty)), "Incorrect result: Empty.");
        }
Exemple #5
0
        /*--------------------------------------------------------------------------------------------*/
        public static WeaverTitanPropertyAttribute GetAndVerifyTitanPropertyAttribute(
            WeaverPropPair pPair, bool pIgnoreNonTitan = false)
        {
            WeaverTitanPropertyAttribute a = (pPair.Attrib as WeaverTitanPropertyAttribute);

            if (!pIgnoreNonTitan && a == null)
            {
                throw new WeaverException("Property '" + pPair.Info.Name + "' must have a " +
                                          typeof(WeaverTitanPropertyAttribute).Name + ".");
            }

            return(a);
        }
        /*--------------------------------------------------------------------------------------------*/
        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);
            }
        }
        /*--------------------------------------------------------------------------------------------*/
        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()"));
        }
 ////////////////////////////////////////////////////////////////////////////////////////////////
 /*--------------------------------------------------------------------------------------------*/
 public string GetTitanTypeName()
 {
     return(WeaverTitanPropertyAttribute.GetTitanTypeName(Type));
 }
Exemple #9
0
 public void GetTitanTypeNameStatic(Type pType, string pExpect)
 {
     Assert.AreEqual(pExpect, WeaverTitanPropertyAttribute.GetTitanTypeName(pType), "Incorrect result.");
 }