Package org.apache.openjpa.jdbc.sql

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


        // 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


        // create where condition limiting instances to this page
        JDBCStore store = getStore();
        Select sel = store.getSQLFactory().newSelect();
        DBDictionary dict = store.getDBDictionary();
        SQLBuffer buf = new SQLBuffer(dict);
        Column[] pks = mapping.getPrimaryKeyColumns();
        if (pks.length == 1)
            createInContains(sel, dict, buf, mapping, pks, start, end);
        else
            orContains(sel, buf, mapping, pks, start, end);
View Full Code Here

    public SQLBuffer getClassConditions(Select sel, Joins joins,
        ClassMapping base, boolean subclasses) {
        // add conditions making sure no subclass tables have records for
        // this instance
        ClassMapping[] subs = base.getJoinablePCSubclassMappings();
        SQLBuffer buf = null;
        Column[] pks;
        for (int i = 0; i < subs.length; i++) {
            pks = subs[i].getPrimaryKeyColumns();
            if (pks.length == 0)
                continue;

            if (buf == null) {
                // make sure the base class is aliased first so that we don't
                // end up with our outer joins before the inner ones
                buf = new SQLBuffer(sel.getConfiguration().
                    getDBDictionaryInstance());
                sel.getColumnAlias(base.getPrimaryKeyColumns()[0], joins);
            } else
                buf.append(" AND ");
            buf.append(sel.getColumnAlias(pks[0], joins)).append(" IS NULL");
        }
        return buf;
    }
View Full Code Here

    }

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

    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

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

        DBDictionary dict = _conf.getDBDictionaryInstance();
        DBIdentifier tableName = resolveTableIdentifier(mapping, _pkColumn.getTable());
        SQLBuffer insert = new SQLBuffer(dict).append("INSERT INTO ").
            append(tableName).append(" (").
            append(_pkColumn).append(", ").append(_seqColumn).
            append(") VALUES (").
            appendValue(pk, _pkColumn).append(", ").
            appendValue(_intValue, _seqColumn).append(")");
View Full Code Here

        Object pk = getPrimaryKey(mapping);
        if (pk == null)
            return -1;

        DBDictionary dict = _conf.getDBDictionaryInstance();
        SQLBuffer sel = new SQLBuffer(dict).append(_seqColumn);
        SQLBuffer where = new SQLBuffer(dict).append(_pkColumn).append(" = ").
            appendValue(pk, _pkColumn);
        DBIdentifier tableName = resolveTableIdentifier(mapping, _seqColumn.getTable());
        SQLBuffer tables = new SQLBuffer(dict).append(tableName);

        SQLBuffer select = dict.toSelect(sel, null, tables, where, null, null,
                null, false, dict.supportsSelectForUpdate, 0, Long.MAX_VALUE,
                false, true);

        PreparedStatement stmnt = null;
        ResultSet rs = null;
View Full Code Here

        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(Numbers.valueOf(cur + inc), _seqColumn).
                    append(" WHERE ").append(where).append(" AND ").
                    append(_seqColumn).append(" = ").
                    appendValue(Numbers.valueOf(cur), _seqColumn);
View Full Code Here

            && (((Union)selector).getSelects().length != 1)))
            return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-multi-select").getMessage());
        select = extractImplementation(selector);
        if (select == null)
            return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-select").getMessage());
        SQLBuffer buffer = selector.getSQL();
        if (buffer == null)
            return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-sql").getMessage());;
        setTargetQuery(buffer.getSQL());
        setParameters(buffer.getParameters());
        setUserParameterPositions(buffer.getUserParameters());
        _initialized = true;
       
        return null;
    }
View Full Code Here

            PreparedSQLStoreQuery psq = (PreparedSQLStoreQuery) q;
            PreparedQueryImpl pq = psq.getPreparedQuery();
            JDBCStore store = psq.getStore();
            DBDictionary dict = store.getDBDictionary();

            SQLBuffer buf = new SQLBuffer(dict).append(pq.getTargetQuery());
            Connection conn = store.getConnection();
            JDBCFetchConfiguration fetch = (JDBCFetchConfiguration)q.getContext().getFetchConfiguration();

            ResultObjectProvider rop;
            PreparedStatement stmnt = null;
            try {
                stmnt = !range.lrs ? buf.prepareStatement(conn) : buf.prepareStatement(conn, fetch, -1, -1);

                int index = 0;
                for (int i = 0; i < params.length; i++) {
                    dict.setUnknown(stmnt, ++index, params[i], null);
                }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.sql.SQLBuffer$Subselect

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.