Package org.dayatang.domain

Examples of org.dayatang.domain.SqlQuery


     * Test of find method with SqlQuery as parameter
     */
    @Test
    public void testSqlQueryFindWithArrayParameters() {
        String sql = "select * from dictionaries as o where o.is_disabled = ? and o.category_id = ? order by o.sort_order";
        SqlQuery query = new SqlQuery(repository, sql)
                .setParameters(false, gender.getId())
                .setResultEntityClass(Dictionary.class);
        List<Dictionary> results = repository.find(query);
        assertTrue(results.contains(male));
        assertFalse(results.contains(undergraduate));
View Full Code Here


     */
    @Test
    public void testSqlQueryFindWithMapParameters() {
        String sql = "select * from dictionaries as o where o.is_disabled = :disabled "
                + "and o.category_id = :categoryId order by o.sort_order";
        SqlQuery query = new SqlQuery(repository, sql)
                .addParameter("categoryId", gender.getId())
                .addParameter("disabled", false)
                .setResultEntityClass(Dictionary.class);
        List<Dictionary> results = repository.find(query);
        assertTrue(results.contains(male));
View Full Code Here

     */
    @Test
    public void testSqlQueryGetSingleResult() {
        String sql = "select * from dictionaries as o where o.is_disabled = false "
                + "and o.category_id = ? and o.code = ?";
        SqlQuery query = new SqlQuery(repository, sql)
                .setParameters(gender.getId(), "01")
                .setResultEntityClass(Dictionary.class);
        assertEquals(male, repository.getSingleResult(query));
    }
View Full Code Here

     * Test of getSingleResult method with JpqlQuery as parameter
     */
    @Test
    public void testSqlQueryGetSingleResultCount() {
        String queryString = "select count(*) from  categories o where o.name = :name";
        SqlQuery query = new SqlQuery(repository, queryString)
                .addParameter("name", "gender");
        assertEquals(1, ((Number)repository.getSingleResult(query)).longValue());
    }
View Full Code Here

     * Test of find method with SqlQuery as parameter and scalar as result
     */
    @Test
    public void testSqlQueryScalar() {
        String sql = "select o.code, o.text from  dictionaries o where o.category_id = :category";
        SqlQuery query = new SqlQuery(repository, sql)
                .addParameter("category", gender);
        List<Object[]> results = repository.find(query);
        for (Object[] row : results) {
            System.out.println(Arrays.toString(row));
        }
View Full Code Here

     */
    @Test
    public void testSqlQueryExecuteUpdate() {
        String description = "abcd";
        String sql = "update dictionaries set description = :description where category_id = :categoryId";
        SqlQuery query = new SqlQuery(repository, sql)
                .addParameter("description", description)
                .addParameter("categoryId", gender.getId());
        int count = repository.executeUpdate(query);
        assertTrue(count > 0);
        entityManager.clear();
View Full Code Here

TOP

Related Classes of org.dayatang.domain.SqlQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.