Package org.apache.cayenne.query

Examples of org.apache.cayenne.query.SQLTemplate


        for (int i = 1; i < bufferChain.size(); i++) {
            main.append(bufferChain.get(i));
        }

        String sql = main.length() > 0 ? main.toString() : null;
        SQLTemplate query = new SQLTemplate(compiledExpression
                .getRootDescriptor()
                .getObjectClass(), sql);
        query.setParameters(boundParameters);
        return query;
    }
View Full Code Here


   * @param access the minimum access to look for
   * @return List of distinct command groups
   */
  @SuppressWarnings("unchecked")
  public static List<String> getGroups(int access) {
    List<Command> cmds = DatabaseContext.getContext().performQuery(new SQLTemplate(Command.class,
        "SELECT " +
        "#result('max(name)' 'String' 'name'), " +
        "#result('max(description)' 'String' 'description'), " +
        "#result('min(access)' 'Integer' 'access'), " +
        "#result('cmdgroup' 'String' 'cmdgroup') " +
View Full Code Here

    public void testJointPrefetchSQLTemplate() throws Exception {
        createTestData("testJointPrefetch1");

        // correctly naming columns is the key..
        SQLTemplate q = new SQLTemplate(
                Artist.class,
                "SELECT distinct "
                        + "#result('ESTIMATED_PRICE' 'BigDecimal' '' 'paintingArray.ESTIMATED_PRICE'), "
                        + "#result('PAINTING_TITLE' 'String' '' 'paintingArray.PAINTING_TITLE'), "
                        + "#result('GALLERY_ID' 'int' '' 'paintingArray.GALLERY_ID'), "
                        + "#result('PAINTING_ID' 'int' '' 'paintingArray.PAINTING_ID'), "
                        + "#result('ARTIST_NAME' 'String'), "
                        + "#result('DATE_OF_BIRTH' 'java.util.Date'), "
                        + "#result('t0.ARTIST_ID' 'int' '' 'ARTIST_ID') "
                        + "FROM ARTIST t0, PAINTING t1 "
                        + "WHERE t0.ARTIST_ID = t1.ARTIST_ID");

        PrefetchTreeNode prefetch = q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
        assertEquals(
                "Default semantics for SQLTemplate is assumed to be joint.",
                PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS,
                prefetch.getSemantics());
        q.setFetchingDataRows(false);

        DataContext context = createDataContext();

        List objects = context.performQuery(q);
View Full Code Here

    /**
     * Tests that joined entities can have non-standard type mappings.
     */
    public void testJointPrefetchDataTypes() throws Exception {
        // prepare... can't load from XML, as it doesn't yet support dates..
        SQLTemplate artistSQL = new SQLTemplate(
                Artist.class,
                "insert into ARTIST (ARTIST_ID, ARTIST_NAME, DATE_OF_BIRTH) "
                        + "values (33001, 'a1', #bind($date 'DATE'))");
        artistSQL.setParameters(Collections.singletonMap("date", new Date(System
                .currentTimeMillis())));
        SQLTemplate paintingSQL = new SQLTemplate(
                Painting.class,
                "INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) "
                        + "VALUES (33001, 'p1', 33001, 1000)");
        DataContext context = createDataContext();

View Full Code Here

        CharPkTestEntity object = (CharPkTestEntity) ctxt.newObject("CharPkTestEntity");
        object.setOtherCol("object-XYZ");
        object.setPkCol("PK1");
        ctxt.commitChanges();

        SQLTemplate q = new SQLTemplate(
                CharPkTestEntity.class,
                "SELECT * FROM CHAR_PK_TEST");

        q.setFetchingDataRows(true);

        List<?> rows = ctxt.performQuery(q);
        assertNotNull(rows);
        assertEquals(1, rows.size());
        Map row = (Map) rows.get(0);
View Full Code Here

        ctxt.commitChanges();

        ctxt.deleteObject(object);
        ctxt.commitChanges();

        SQLTemplate q = new SQLTemplate(
                CharPkTestEntity.class,
                "SELECT * FROM CHAR_PK_TEST");
        q.setFetchingDataRows(true);

        List<?> rows = ctxt.performQuery(q);
        assertNotNull(rows);
        assertEquals(0, rows.size());
    }
View Full Code Here

        ctxt.commitChanges();

        object.setOtherCol("UPDATED");
        ctxt.commitChanges();

        SQLTemplate q = new SQLTemplate(
                CharPkTestEntity.class,
                "SELECT * FROM CHAR_PK_TEST");
        q.setFetchingDataRows(true);

        List<?> rows = ctxt.performQuery(q);
        assertNotNull(rows);
        assertEquals(1, rows.size());
        Map row = (Map) rows.get(0);
View Full Code Here

        context = createDataContext();
    }

    public void testRelationshipToAbstractSuper() {
        context
                .performGenericQuery(new SQLTemplate(
                        AbstractPerson.class,
                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (1, 'AA', 'EE')"));

        context.performGenericQuery(new SQLTemplate(
                PersonNotes.class,
                "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (1, 'AA', 1)"));

        PersonNotes note = Cayenne.objectForPK(context, PersonNotes.class, 1);
        assertNotNull(note);
View Full Code Here

        assertTrue(note.getPerson() instanceof Employee);
    }

    public void testRelationshipAbstractFromSuperPrefetchingJoint() {
        context
                .performGenericQuery(new SQLTemplate(
                        AbstractPerson.class,
                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (3, 'AA', 'EE')"));

        context.performGenericQuery(new SQLTemplate(
                PersonNotes.class,
                "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'AA', 3)"));
        context.performGenericQuery(new SQLTemplate(
                PersonNotes.class,
                "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (4, 'BB', 3)"));

        SelectQuery query = new SelectQuery(AbstractPerson.class);
        query.addPrefetch(AbstractPerson.NOTES_PROPERTY).setSemantics(
View Full Code Here

        }
    }

    public void testRelationshipAbstractFromSuperPrefetchingDisjoint() {
        context
                .performGenericQuery(new SQLTemplate(
                        AbstractPerson.class,
                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (3, 'AA', 'EE')"));

        context.performGenericQuery(new SQLTemplate(
                PersonNotes.class,
                "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'AA', 3)"));
        context.performGenericQuery(new SQLTemplate(
                PersonNotes.class,
                "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (4, 'BB', 3)"));

        SelectQuery query = new SelectQuery(AbstractPerson.class);
        query.addPrefetch(AbstractPerson.NOTES_PROPERTY);
View Full Code Here

TOP

Related Classes of org.apache.cayenne.query.SQLTemplate

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.