Exemplo n.º 1
0
        public void SelectMultipleFieldsMultipleRootsStatement_Success()
        {
            ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cc.From("Students");
            IRoot          r2 = cc.From("Faculties");

            cc.Select(r.Get("FirstName"), r2.Get("Name"));

            string s = cc.ToString();

            Assert.AreEqual(s, "SELECT Students.FirstName, Faculties.Name FROM Students, Faculties");
        }
Exemplo n.º 2
0
        public void Disjunction()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IPredicate criteria = cb.Disjunction();

            IParameterExpression pr = cb.Parameter(System.Data.SqlDbType.Int, "3");

            criteria = cb.Or(criteria,
                             cb.Equal(r.Get("SequenceNumber"), pr)
                             );

            pr = cb.Parameter(System.Data.SqlDbType.Int, "'Jonas'");

            criteria = cb.Or(criteria,
                             cb.Equal(r.Get("FirstName"), pr)
                             );

            pr = cb.Parameter(System.Data.SqlDbType.Int, "'Petraitis'");

            criteria = cb.Or(criteria,
                             cb.Equal(r.Get("LastName"), pr)
                             );

            Assert.AreEqual("Students.SequenceNumber = 3 OR Students.FirstName = 'Jonas' OR Students.LastName = 'Petraitis'", criteria.ExpressionValue);
        }
Exemplo n.º 3
0
        public void SelectOneFieldFromRootStatement_Success()
        {
            ICriteriaQuery cq = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cq.From("Students");

            cq.Select(r.Get("FirstName"));

            Assert.AreEqual(cq.ExpressionValue, "SELECT Students.FirstName FROM Students");
        }
Exemplo n.º 4
0
        public void NotLike_Success()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IPredicate exp = cb.NotLike(r.Get("FirstName"), cb.Literal("'Jon%'"));

            Assert.AreEqual("Students.FirstName NOT LIKE 'Jon%'", exp.ExpressionValue);
        }
Exemplo n.º 5
0
        public void Between_Success()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IPredicate exp = cb.Between(r.Get("SequenceNumber"), cb.Literal("2"), cb.Literal("3"));

            Assert.AreEqual("Students.SequenceNumber BETWEEN 2 AND 3", exp.ExpressionValue);
        }
Exemplo n.º 6
0
        public void EqualWithoutQuotes()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IPredicate exp = cb.Equal(r.Get("FirstName"), r.Get("LastName"));

            Assert.AreEqual("Students.FirstName = Students.LastName", exp.ExpressionValue);
        }
Exemplo n.º 7
0
        public void EqualWithQuotes()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IPredicate exp = cb.Equal(cb.Literal("'FirstName'"), cb.Literal("'Jonas'"));

            Assert.AreEqual("'FirstName' = 'Jonas'", exp.ExpressionValue);
        }
Exemplo n.º 8
0
        public void IsNotNull()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IPredicate exp = cb.IsNotNull(r.Get("LastName"));

            Assert.AreEqual("Students.LastName IS NOT NULL", exp.ExpressionValue);
        }
Exemplo n.º 9
0
        public void DistinctSelectMultipleFieldsStatement_Success()
        {
            ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cc.From("Students");

            cc.Select("FirstName", "LastName").Distinct(true);

            string s = cc.ToString();

            Assert.AreEqual(s, "SELECT DISTINCT FirstName, LastName FROM Students");
        }
Exemplo n.º 10
0
        public void SelectFieldWithAliasStatement_Success()
        {
            ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cc.From("Students");

            cc.Select(r.Get("FirstName").Alias("Name"));

            string s = cc.ToString();

            Assert.AreEqual(s, "SELECT Students.FirstName AS Name FROM Students");
        }
Exemplo n.º 11
0
        public void SelectAllFieldsStatement_Success()
        {
            ICriteriaQuery cc = EJBContainer.Instance.EntityManager.GetCriteriaBuilder().CreateQuery();
            IRoot          r  = cc.From("Students");

            cc.Select("*");

            string s = cc.ToString();

            Assert.AreEqual(s, "SELECT * FROM Students");
        }
Exemplo n.º 12
0
        public void SelectWhere()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cc = cb.CreateQuery();
            IRoot            r  = cc.From("Students");

            cc.Select(r.Get("FirstName"));

            cc.Where(cb.Equal(r.Get("FirstName"), cb.Literal("'Jonas'")));

            Assert.AreEqual("SELECT Students.FirstName FROM Students WHERE Students.FirstName = 'Jonas'", cc.ExpressionValue);
        }
Exemplo n.º 13
0
        public void OrderByMultipleFieldsDescAsc()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cc = cb.CreateQuery();
            IRoot            r  = cc.From("Students");

            cc.Select(r.Get("FirstName"), r.Get("LastName"));

            cc.OrderBy(cb.Desc(r.Get("FirstName")), cb.Asc(r.Get("LastName")));

            Assert.AreEqual("SELECT Students.FirstName, Students.LastName FROM Students ORDER BY Students.FirstName DESC, Students.LastName ASC", cc.ExpressionValue);
        }
Exemplo n.º 14
0
        public void ParameterExpressoin_IntType()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IParameterExpression pr = cb.Parameter(System.Data.SqlDbType.Int, "3");

            IPredicate exp = cb.Equal(r.Get("SequenceNumber"), pr);

            Assert.AreEqual("Students.SequenceNumber = 3", exp.ExpressionValue);
        }
Exemplo n.º 15
0
        public void ParameterExpressoin_StringType()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IParameterExpression pr = cb.Parameter(System.Data.SqlDbType.VarChar, "Jonas");

            IPredicate exp = cb.Equal(r.Get("FirstName"), pr);

            Assert.AreEqual("Students.FirstName = 'Jonas'", exp.ExpressionValue);
        }
Exemplo n.º 16
0
        public void Not()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cq = cb.CreateQuery();
            IRoot            r  = cq.From("Students");

            IPredicate exp = cb.Equal(r.Get("SequenceNumber"), cb.Literal("2"));

            IPredicate pred = cb.Not(exp);

            Assert.AreEqual("NOT (Students.SequenceNumber = 2)", pred.ExpressionValue);
        }
Exemplo n.º 17
0
        public void RightJoin()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();
            ICriteriaQuery   cc = cb.CreateQuery();

            IRoot r = cc.From("Students");

            IJoin facultiesJoin = r.Join("Faculties", JoinType.Right, "Faculty_Id", "Id");

            cc.Select(r.Get("Firstname"), facultiesJoin.Get("Name"));

            Assert.AreEqual("SELECT Students.Firstname, Faculties.Name FROM Students RIGHT JOIN Faculties ON Students.Faculty_Id = Faculties.Id", cc.ExpressionValue);
        }
Exemplo n.º 18
0
        public void Or()
        {
            ICriteriaBuilder cb = EJBContainer.Instance.EntityManager.GetCriteriaBuilder();

            ICriteriaQuery cc = cb.CreateQuery();

            IRoot r = cc.From("Students");

            IPredicate left = cb.Equal(r.Get("Name"), cb.Literal("'Jonas'"));

            IPredicate right = cb.Equal(r.Get("Faculty_Id"), cb.Literal("3"));

            IExpression expr = cb.Or(left, right);

            Assert.AreEqual("Students.Name = 'Jonas' OR Students.Faculty_Id = 3", expr.ExpressionValue);
        }