private string CreateServiceResponse()
        {
            var workspaceElement = new XElement(
                NsApp + "workspace",
                new XElement(NsAtom + "title", "Default")
                );

            foreach (var type in _sessionFactory.GetAllClassMetadata().Values)
            {
                string name = Inflector.Pluralize(GetPersister(type).TableName);

                workspaceElement.Add(new XElement(
                                         NsApp + "collection",
                                         new XAttribute("href", name),
                                         new XElement(
                                             NsAtom + "title",
                                             name
                                             )
                                         ));
            }

            var document = new XDocument(
                new XElement(
                    NsApp + "service",
                    new XAttribute(XNamespace.Xmlns + "atom", NsAtom),
                    new XAttribute(XNamespace.Xmlns + "app", NsApp),
                    new XAttribute("xmlns", NsApp),
                    new XAttribute(XNamespace.Xml + "base", ServiceNamespace),
                    workspaceElement
                    )
                );

            return(document.ToString(SaveOptions.DisableFormatting));
        }
        /// <summary>
        /// Create an action that will evict collection and entity regions based on queryspaces (table names).
        /// </summary>
        public BulkOperationCleanupAction(ISessionImplementor session, ISet <string> querySpaces)
        {
            //from H3.2 TODO: cache the autodetected information and pass it in instead.
            this.session = session;

            ISet <string> tmpSpaces = new HashedSet <string>(querySpaces);
            ISessionFactoryImplementor           factory = session.Factory;
            IDictionary <string, IClassMetadata> acmd    = factory.GetAllClassMetadata();

            foreach (KeyValuePair <string, IClassMetadata> entry in acmd)
            {
                string           entityName   = entry.Key;
                IEntityPersister persister    = factory.GetEntityPersister(entityName);
                string[]         entitySpaces = persister.QuerySpaces;

                if (AffectedEntity(querySpaces, entitySpaces))
                {
                    if (persister.HasCache)
                    {
                        affectedEntityNames.Add(persister.EntityName);
                    }
                    ISet <string> roles = session.Factory.GetCollectionRolesByEntityParticipant(persister.EntityName);
                    if (roles != null)
                    {
                        affectedCollectionRoles.AddAll(roles);
                    }
                    for (int y = 0; y < entitySpaces.Length; y++)
                    {
                        tmpSpaces.Add(entitySpaces[y]);
                    }
                }
            }
            spaces = new List <string>(tmpSpaces);
        }
Exemple #3
0
 public ExpressionParameterVisitor(ISessionFactoryImplementor sessionFactory)
 {
     _sessionFactory       = sessionFactory;
     _allMappedCustomTypes = _sessionFactory.GetAllClassMetadata().Values
                             .SelectMany(c => c.PropertyTypes)
                             .OfType <CustomType>().ToList();
 }
Exemple #4
0
 public AssociationVisitor(ISessionFactoryImplementor sessionFactory)
 {
     _sessionFactory = sessionFactory;
     _metaData = _sessionFactory.GetAllClassMetadata();
     _proxyTypes = _sessionFactory.GetProxyMetaData(_metaData);
     _associationPathsToInclude = new List<string>();
 }
Exemple #5
0
        protected virtual bool CheckDatabaseWasCleaned()
        {
            if (sessions.GetAllClassMetadata().Count == 0)
            {
                // Return early in the case of no mappings, also avoiding
                // a warning when executing the HQL below.
                return(true);
            }

            bool empty;

            using (ISession s = sessions.OpenSession())
            {
                IList objects = s.CreateQuery("from System.Object o").List();
                empty = objects.Count == 0;
            }

            if (!empty)
            {
                log.Error("Test case didn't clean up the database after itself, re-creating the schema");
                DropSchema();
                CreateSchema();
            }

            return(empty);
        }
 public AssociationVisitor(ISessionFactoryImplementor sessionFactory)
 {
     _sessionFactory            = sessionFactory;
     _metaData                  = _sessionFactory.GetAllClassMetadata();
     _proxyTypes                = _sessionFactory.GetProxyMetaData(_metaData);
     _associationPathsToInclude = new List <string>();
 }
 public AssociationVisitor(ISessionFactoryImplementor sessionFactory, IDictionary<string, IList<string>> addedAlias)
 {
     _sessionFactory = sessionFactory;
     _metaData = _sessionFactory.GetAllClassMetadata();
     _proxyTypes = _sessionFactory.GetProxyMetaData(_metaData);
     _associationPathsToInclude = new List<string>();
     _addedAlias = addedAlias;
 }
 public void SetupTest()
 {
     _session   = Substitute.For <ISessionImplementor>();
     _factory   = Substitute.For <ISessionFactoryImplementor>();
     _persister = Substitute.For <IEntityPersister>();
     _session.Factory.Returns(_factory);
     _factory.GetAllClassMetadata().Returns(new Dictionary <string, IClassMetadata> {
         ["TestClass"] = null
     });
     _factory.GetEntityPersister("TestClass").Returns(_persister);
     _factory.GetCollectionRolesByEntityParticipant("TestClass").Returns(new HashSet <string>(new[] { "TestClass.Children" }));
     _persister.QuerySpaces.Returns(new[] { "TestClass" });
     _persister.EntityName.Returns("TestClass");
 }
        /// <summary>
        /// Get entity persisters by the given query spaces.
        /// </summary>
        /// <param name="factory">The session factory.</param>
        /// <param name="spaces">The query spaces.</param>
        /// <returns>Unique list of entity persisters, if <paramref name="spaces"/> is <c>null</c> or empty then all persisters are returned.</returns>
        public static ISet <IEntityPersister> GetEntityPersisters(this ISessionFactoryImplementor factory, ISet <string> spaces)
        {
            if (factory is SessionFactoryImpl sfi)
            {
                return(sfi.GetEntityPersisters(spaces));
            }

            ISet <IEntityPersister> persisters = new HashSet <IEntityPersister>();

            foreach (var entityName in factory.GetAllClassMetadata().Keys)
            {
                var persister = factory.GetEntityPersister(entityName);
                // NativeSql does not have query spaces so include the persister, if spaces is null or empty.
                if (spaces == null || spaces.Count == 0 || persister.QuerySpaces.Any(x => spaces.Contains(x)))
                {
                    persisters.Add(persister);
                }
            }

            return(persisters);
        }
        public static IDictionary <string, System.Type> GetEntityNameMetaData(this ISessionFactoryImplementor factory)
        {
            var metaData = factory.GetAllClassMetadata();

            var dict = new Dictionary <string, System.Type>();

            foreach (var item in metaData)
            {
                var type = item.Value.GetMappedClass(EntityMode.Poco);

                dict.Add(item.Key, type);
                if (item.Value.HasProxy)
                {
                    var proxyType = factory.GetEntityPersister(item.Key).GetConcreteProxyClass(EntityMode.Poco);
                    if (proxyType != type && !dict.ContainsKey(proxyType.FullName))
                    {
                        dict.Add(proxyType.FullName, proxyType);
                    }
                }
            }
            return(dict);
        }
 public AssociationVisitor(ISessionFactoryImplementor sessionFactory)
 {
     _sessionFactory = sessionFactory;
     _metaData = _sessionFactory.GetAllClassMetadata();
     _proxyTypes = _sessionFactory.GetProxyMetaData(_metaData);
 }
Exemple #12
0
        private static ExpressionVisitor CreateVisitorFromMapping(ISessionFactoryImplementor sessionFactory)
        {
            var types = sessionFactory.GetAllClassMetadata().Values.SelectMany(x => x.PropertyTypes).SelectMany(x => GetNodaTimeTypes(x, sessionFactory)).Distinct().ToList();

            return(new DateIntervalVisitor(sessionFactory));
        }