Search in sources :

Example 16 with Query

use of org.hibernate.query.Query in project microservices by pwillhan.

the class App method nameParameters.

private static Query nameParameters(Session session) {
    Query query = session.createQuery("select t from Transaction t where t.amount > :amount and t.transactionType = 'Withdrawl'");
    System.out.println("Please specify an amount:");
    Scanner scanner = new Scanner(System.in);
    query.setParameter("amount", new BigDecimal(scanner.next()));
    return query;
}
Also used : Scanner(java.util.Scanner) Query(org.hibernate.query.Query) BigDecimal(java.math.BigDecimal)

Example 17 with Query

use of org.hibernate.query.Query in project jbosstools-hibernate by jbosstools.

the class QueryFacadeTest method beforeEach.

@BeforeEach
public void beforeEach() {
    Query<?> queryProxy = (Query<?>) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { Query.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            methodName = method.getName();
            arguments = args;
            if ("list".equals(method.getName())) {
                return LIST;
            } else if ("getReturnAliases".equals(method.getName())) {
                return RETURN_ALIASES;
            } else if ("getReturnTypes".equals(method.getName())) {
                return RETURN_TYPES;
            } else
                return null;
        }
    });
    query = new AbstractQueryFacade(FACADE_FACTORY, queryProxy) {
    };
}
Also used : Query(org.hibernate.query.Query) AbstractQueryFacade(org.jboss.tools.hibernate.runtime.common.AbstractQueryFacade) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with Query

use of org.hibernate.query.Query in project jbosstools-hibernate by jbosstools.

the class QueryFacadeTest method beforeEach.

@BeforeEach
public void beforeEach() {
    Query<?> queryProxy = (Query<?>) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { Query.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            methodName = method.getName();
            arguments = args;
            if ("list".equals(method.getName())) {
                return LIST;
            } else if ("getReturnAliases".equals(method.getName())) {
                return RETURN_ALIASES;
            } else if ("getReturnTypes".equals(method.getName())) {
                return RETURN_TYPES;
            } else
                return null;
        }
    });
    query = new AbstractQueryFacade(FACADE_FACTORY, queryProxy) {
    };
}
Also used : Query(org.hibernate.query.Query) AbstractQueryFacade(org.jboss.tools.hibernate.runtime.common.AbstractQueryFacade) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with Query

use of org.hibernate.query.Query in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateQuery.

@Test
public void testCreateQuery() {
    Query<?> query = (Query<?>) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { Query.class }, new TestInvocationHandler());
    IQuery facade = facadeFactory.createQuery(query);
    assertSame(query, ((IFacade) facade).getTarget());
}
Also used : IQuery(org.jboss.tools.hibernate.runtime.spi.IQuery) IQuery(org.jboss.tools.hibernate.runtime.spi.IQuery) Query(org.hibernate.query.Query) PersistentClass(org.hibernate.mapping.PersistentClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) Test(org.junit.jupiter.api.Test)

Example 20 with Query

use of org.hibernate.query.Query in project jbosstools-hibernate by jbosstools.

the class QueryFacadeTest method beforeEach.

@BeforeEach
public void beforeEach() {
    Query<?> queryProxy = (Query<?>) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { Query.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            methodName = method.getName();
            arguments = args;
            if ("list".equals(method.getName())) {
                return LIST;
            } else if ("getReturnAliases".equals(method.getName())) {
                return RETURN_ALIASES;
            } else if ("getReturnTypes".equals(method.getName())) {
                return RETURN_TYPES;
            } else
                return null;
        }
    });
    query = new AbstractQueryFacade(FACADE_FACTORY, queryProxy) {
    };
}
Also used : Query(org.hibernate.query.Query) AbstractQueryFacade(org.jboss.tools.hibernate.runtime.common.AbstractQueryFacade) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Query (org.hibernate.query.Query)157 Test (org.junit.Test)44 Session (org.hibernate.Session)39 List (java.util.List)24 ArrayList (java.util.ArrayList)19 TestForIssue (org.hibernate.testing.TestForIssue)19 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)17 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 HashMap (java.util.HashMap)15 Map (java.util.Map)14 NativeQuery (org.hibernate.query.NativeQuery)14 AbstractJPATest (org.hibernate.test.jpa.AbstractJPATest)11 SessionFactory (org.hibernate.SessionFactory)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 Method (java.lang.reflect.Method)7 SQLException (java.sql.SQLException)7 Collectors (java.util.stream.Collectors)7 AbstractQueryFacade (org.jboss.tools.hibernate.runtime.common.AbstractQueryFacade)7 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)6