Examples of SQLBuffer


Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

        if (pk == null)
            throw new InvalidStateException(_loc.get("bad-seq-type",
                getClass(), mapping));

        DBDictionary dict = _conf.getDBDictionaryInstance();       
        SQLBuffer where = new SQLBuffer(dict).append(_pkColumn).append(" = ").
            appendValue(pk, _pkColumn);

        // loop until we have a successful atomic select/update sequence
        long cur = 0;
        PreparedStatement stmnt;
        ResultSet rs;
        SQLBuffer upd;
        for (int updates = 0; updates == 0;) {
            stmnt = null;
            rs = null;
            try {
                cur = getSequence(mapping, conn);
                if (cur == -1)
                    return false;

                // update the value
                upd = new SQLBuffer(dict);
                DBIdentifier tableName = resolveTableIdentifier(mapping,
                        _seqColumn.getTable());
                upd.append("UPDATE ").append(tableName).
                    append(" SET ").append(_seqColumn).append(" = ").
                    appendValue(cur + inc, _seqColumn).
                    append(" WHERE ").append(where).append(" AND ").
                    append(_seqColumn).append(" = ").
                    appendValue(cur, _seqColumn);
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

    static FinderQueryImpl newFinder(ClassMapping mapping,
        SelectExecutor select) {
        SelectImpl impl = extractImplementation(select);
        if (impl == null)
            return null;
        SQLBuffer buffer = impl.getSQL();
        Column[] pkCols = mapping.getPrimaryKeyColumns();
        boolean canCache = pkCols.length == buffer.getParameters().size();
        return (canCache)
            ? new FinderQueryImpl(mapping, impl, buffer) : null;
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

        // select existing value for update
        Column col = field.getColumns()[0];
        Select sel = store.getSQLFactory().newSelect();
        sel.select(col);
        field.wherePrimaryKey(sel, sm, store);
        SQLBuffer sql = sel.toSelect(true, fetch);

        Connection conn = store.getConnection();
        DBDictionary dict = store.getDBDictionary();
        PreparedStatement stmnt = null;
        ResultSet rs = null;
        try {
            stmnt = sql.prepareStatement(conn,
                ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
            dict.setTimeouts(stmnt, fetch, true);
            rs = stmnt.executeQuery();
            rs.next();
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

    }

    public SQLBuffer getClassConditions(Select sel, Joins joins,
        ClassMapping base, boolean subclasses) {
        Column col = disc.getColumns()[0];
        SQLBuffer sql = new SQLBuffer(sel.getConfiguration().
            getDBDictionaryInstance());
        String alias = sel.getColumnAlias(col, joins);
        boolean outer = joins != null && joins.isOuter();
        if (outer)
            sql.append("(");
        sql.append(alias);

        // if not selecting subclasses, limit to just the given class
        ClassMapping[] subs = base.getJoinablePCSubclassMappings();
        if (!outer && (!subclasses || subs.length == 0))
            return sql.append(" = ").appendValue(getDiscriminatorValue(base),
                col);

        if (outer)
            sql.append(" IS ").appendValue(null).append(" OR ").append(alias);
        sql.append(" IN (");
        sql.appendValue(getDiscriminatorValue(base), col);
        for (int i = 0; i < subs.length; i++)
            sql.append(", ").appendValue(getDiscriminatorValue(subs[i]), col);
        sql.append(")");
        if (outer)
            sql.append(")");
        return sql;
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

        }

        Column col = disc.getColumns()[0];
        DBDictionary dict = store.getDBDictionary();
        JDBCFetchConfiguration fetch = store.getFetchConfiguration();
        SQLBuffer select = dict.toSelect(new SQLBuffer(dict).append(col),
            fetch, new SQLBuffer(dict).append(col.getTable()), null, null,
            null, null, true, false, 0, Long.MAX_VALUE);

        Log log = disc.getMappingRepository().getLog();
        if (log.isTraceEnabled())
            log.trace(_loc.get("load-subs", col.getTable().getFullName()));

        ClassLoader loader = getClassLoader(store);
        Connection conn = store.getConnection();
        PreparedStatement stmnt = null;
        ResultSet rs = null;
        try {
            stmnt = select.prepareStatement(conn);
            dict.setTimeouts(stmnt, fetch, false);
            rs = stmnt.executeQuery();
            String className;
            while (rs.next()) {
                className = dict.getString(rs, 1);
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

        // create where clause; if there are no where conditions and
        // no ordering or projections, we return null to signify that this
        // query should be treated like an extent
        Select inner = sel.getFromSelect();
        SQLBuffer where = buildWhere((inner != null) ? inner : sel, ctx,
            state.filter, exps.filter);
        if (where == null && exps.projections.length == 0
            && exps.ordering.length == 0
            && (sel.getJoins() == null || sel.getJoins().isEmpty())) {
            _extent = true;
            sel.setAutoDistinct((exps.distinct & exps.DISTINCT_AUTO) != 0);
            return sel;
        }

        // now set sql criteria; it goes on the inner select if present
        if (inner != null)
            inner.where(where);
        else
            sel.where(where);

        // apply grouping and having.  this does not select the grouping
        // columns, just builds the GROUP BY clauses.  we don't build the
        // ORDER BY clauses yet because if we decide to add this select
        // to a union, the ORDER BY values get aliased differently
        if (exps.having != null) {
            Exp havingExp = (Exp) exps.having;
            SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
            havingExp.appendTo(sel, ctx, state.having, buf);
            sel.having(buf);
        }
        for (int i = 0; i < exps.grouping.length; i++)
            ((Val) exps.grouping[i]).groupBy(sel, ctx, state.grouping[i]);
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

     * Create the where sql.
     */
    private SQLBuffer buildWhere(Select sel, ExpContext ctx, ExpState state,
        Expression filter) {
        // create where buffer
        SQLBuffer where = new SQLBuffer(ctx.store.getDBDictionary());
        where.append("(");
        Exp filterExp = (Exp) filter;
        filterExp.appendTo(sel, ctx, state, where);

        if (where.sqlEquals("(") || where.sqlEquals("(1 = 1"))
            return null;
        return where.append(")");
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
    }

    private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {
        calculateValue(sel, ctx, state, null, null);
        SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
        appendTo(sel, ctx, state, buf, 0);
        return buf;
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

        sel.orderBy(_alias, asc, false);
    }

    private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {
        calculateValue(sel, ctx, state, null, null);
        SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
        appendTo(sel, ctx, state, buf, 0);
        return buf;
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.SQLBuffer

        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false, getSelectAs());
    }

    private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {
        calculateValue(sel, ctx, state, null, null);
        SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
        appendTo(sel, ctx, state, buf, 0);
        return buf;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.