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

            prop.EdgesForVertexCentricIndexing = null;

            Assert.False(prop.HasTitanVertexCentricIndex(typeof(Empty)), "Incorrect result: Empty.");
        }
Beispiel #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);
            }
        }
Beispiel #5
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()"));
        }