Package org.apache.cayenne.ejbql

Examples of org.apache.cayenne.ejbql.EJBQLCompiledExpression


  
    private SQLTemplate translateSelect(
            String ejbql,
            final Map<Integer, Object> queryParameters) {
        EJBQLParser parser = EJBQLParserFactory.getParser();
        EJBQLCompiledExpression select = parser.compile(ejbql, getDomain()
                .getEntityResolver());
        EJBQLQuery query = new EJBQLQuery(ejbql) {

            @Override
            public Map<Integer, Object>  getPositionalParameters(){
                return queryParameters;
            }
        };

        EJBQLTranslationContext tr = new EJBQLTranslationContext(getDomain()
                .getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory());
        select.getExpression().visit(new EJBQLSelectTranslator(tr));
        return tr.getQuery();
    }
View Full Code Here


   
    // if parameter value is null (in this test x := null) we will generate "IS NULL"
    public void testEqualsNullParameter() {
        String ejbql = "select p from Painting p WHERE p.toArtist=:x";
        EJBQLParser parser = EJBQLParserFactory.getParser();
        EJBQLCompiledExpression select = parser.compile(ejbql, getDomain()
                .getEntityResolver());
        EJBQLQuery query = new EJBQLQuery(ejbql);
        query.setParameter("x", null);

        EJBQLTranslationContext tr = new EJBQLTranslationContext(getDomain()
                .getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory());
        select.getExpression().visit(new EJBQLSelectTranslator(tr));
        String sql = tr.getQuery().getDefaultTemplate();
        assertTrue(sql, sql
                .endsWith("t0.ARTIST_ID IS NULL"));
    }
View Full Code Here

   
    // if parameter value is null and more than one parameter in query
    public void testEqualsNullAndNotNullParameter() {
        String ejbql = "select p from Painting p WHERE p.toArtist=:x OR p.toArtist.artistName=:b";
        EJBQLParser parser = EJBQLParserFactory.getParser();
        EJBQLCompiledExpression select = parser.compile(ejbql, getDomain()
                .getEntityResolver());
        EJBQLQuery query = new EJBQLQuery(ejbql);
        query.setParameter("x", null);
        query.setParameter("b", "Y");

        EJBQLTranslationContext tr = new EJBQLTranslationContext(getDomain()
                .getEntityResolver(), query, select, new JdbcEJBQLTranslatorFactory());
        select.getExpression().visit(new EJBQLSelectTranslator(tr));
        String sql = tr.getQuery().getDefaultTemplate();
        assertTrue(sql, sql
                .endsWith("t0.ARTIST_ID IS NULL OR t1.ARTIST_NAME = #bind($id0)"));
    }
View Full Code Here

    }

    public void testGetExpression() {
        String ejbql = "select a FROM Artist a";
        EJBQLQuery query = new EJBQLQuery(ejbql);
        EJBQLCompiledExpression parsed = query.getExpression(getDomain()
                .getEntityResolver());
        assertNotNull(parsed);
        assertEquals(ejbql, parsed.getSource());
    }
View Full Code Here

* @since 3.0
*/
class EJBQLQueryMetadata extends BaseQueryMetadata {

    boolean resolve(EntityResolver resolver, EJBQLQuery query) {
        EJBQLCompiledExpression expression = query.getExpression(resolver);

        resultSetMapping = expression.getResult() != null ? expression
                .getResult()
                .getResolvedComponents(resolver) : null;

        ObjEntity root = expression.getRootDescriptor().getEntity();

        if (super.resolve(root, resolver, null)) {

            if (QueryCacheStrategy.NO_CACHE == getCacheStrategy()) {

View Full Code Here

        this.actionFactory = actionFactory;
    }

    public void performAction(Connection connection, OperationObserver observer)
            throws SQLException, Exception {
        EJBQLCompiledExpression compiledExpression = query
                .getExpression(getEntityResolver());
        final EJBQLTranslatorFactory translatorFactory = ((JdbcAdapter) getAdapter())
                .getEjbqlTranslatorFactory();
        final EJBQLTranslationContext context = new EJBQLTranslationContext(
                entityResolver,
                compiledExpression,
                query.getParameters(),
                translatorFactory);

        compiledExpression.getExpression().visit(new EJBQLBaseVisitor(false) {

            @Override
            public boolean visitSelect(EJBQLExpression expression) {
                EJBQLExpressionVisitor visitor = translatorFactory
                        .getSelectTranslator(context);
View Full Code Here

    public SQLResultSetMapping getResultSetMapping() {
        return resultSetMapping;
    }

    boolean resolve(EntityResolver resolver, EJBQLQuery query) {
        EJBQLCompiledExpression expression = query.getExpression(resolver);
        setResultSetMapping(expression.getResultSetMapping());
       
        ObjEntity root = expression.getRootDescriptor().getEntity();

        // TODO: andrus, 4/3/2007 - generate cache key based on EJBQL statement
        return super.resolve(root, resolver, null);
    }
View Full Code Here

* @since 3.0
*/
class EJBQLQueryMetadata extends BaseQueryMetadata {

    boolean resolve(EntityResolver resolver, EJBQLQuery query) {
        EJBQLCompiledExpression expression = query.getExpression(resolver);
        setPrefetchTree(expression.getPrefetchTree());
        resultSetMapping = expression.getResult() != null ? expression
                .getResult()
                .getResolvedComponents(resolver) : null;

        ObjEntity root = expression.getRootDescriptor().getEntity();

        if (super.resolve(root, resolver, null)) {

            if (QueryCacheStrategy.NO_CACHE == getCacheStrategy()) {

View Full Code Here

        this.actionFactory = actionFactory;
    }

    public void performAction(Connection connection, OperationObserver observer)
            throws SQLException, Exception {
        EJBQLCompiledExpression compiledExpression = query
                .getExpression(getEntityResolver());
        final EJBQLTranslatorFactory translatorFactory = ((JdbcAdapter) getAdapter())
                .getEjbqlTranslatorFactory();
        final EJBQLTranslationContext context = new EJBQLTranslationContext(
                entityResolver,
                query,
                compiledExpression,
                translatorFactory);

        compiledExpression.getExpression().visit(new EJBQLBaseVisitor(false) {

            @Override
            public boolean visitSelect(EJBQLExpression expression) {
                EJBQLExpressionVisitor visitor = translatorFactory
                        .getSelectTranslator(context);
                expression.visit(visitor);
                return false;
            }

            @Override
            public boolean visitDelete(EJBQLExpression expression) {
                EJBQLExpressionVisitor visitor = translatorFactory
                        .getDeleteTranslator(context);
                expression.visit(visitor);
                return false;
            }

            @Override
            public boolean visitUpdate(EJBQLExpression expression) {
                EJBQLExpressionVisitor visitor = translatorFactory
                        .getUpdateTranslator(context);
                expression.visit(visitor);
                return false;
            }
        });

        SQLTemplate sqlQuery = context.getQuery();

        // update with metadata
        QueryMetadata md = query.getMetaData(getEntityResolver());
        sqlQuery.setFetchLimit(md.getFetchLimit());
        sqlQuery.setFetchOffset(md.getFetchOffset());
        sqlQuery.setResult(compiledExpression.getResult());
        sqlQuery.setPageSize(md.getPageSize());
       
        if (md.getStatementFetchSize() != 0) {
            sqlQuery.setStatementFetchSize(md.getStatementFetchSize());
        }
View Full Code Here

        this.actionFactory = actionFactory;
    }

    public void performAction(Connection connection, OperationObserver observer)
            throws SQLException, Exception {
        EJBQLCompiledExpression compiledExpression = query
                .getExpression(getEntityResolver());
        final EJBQLTranslatorFactory translatorFactory = ((JdbcAdapter) getAdapter())
                .getEjbqlTranslatorFactory();
        final EJBQLTranslationContext context = new EJBQLTranslationContext(
                entityResolver,
                query,
                compiledExpression,
                translatorFactory);

        compiledExpression.getExpression().visit(new EJBQLBaseVisitor(false) {

            @Override
            public boolean visitSelect(EJBQLExpression expression) {
                EJBQLExpressionVisitor visitor = translatorFactory
                        .getSelectTranslator(context);
                expression.visit(visitor);
                return false;
            }

            @Override
            public boolean visitDelete(EJBQLExpression expression) {
                EJBQLExpressionVisitor visitor = translatorFactory
                        .getDeleteTranslator(context);
                expression.visit(visitor);
                return false;
            }

            @Override
            public boolean visitUpdate(EJBQLExpression expression) {
                EJBQLExpressionVisitor visitor = translatorFactory
                        .getUpdateTranslator(context);
                expression.visit(visitor);
                return false;
            }
        });

        SQLTemplate sqlQuery = context.getQuery();

        // update with metadata
        QueryMetadata md = query.getMetaData(getEntityResolver());
        sqlQuery.setFetchLimit(md.getFetchLimit());
        sqlQuery.setFetchOffset(md.getFetchOffset());
        sqlQuery.setResult(compiledExpression.getResult());
        sqlQuery.setPageSize(md.getPageSize());

        actionFactory.sqlAction(sqlQuery).performAction(connection, observer);
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.ejbql.EJBQLCompiledExpression

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.