Package org.apache.openjpa.jdbc.sql

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


    }

    private boolean exists(ClassMapping mapping, Object oid, Object context) {
        // add where conditions on base class to avoid joins if subclass
        // doesn't use oid as identifier
        Select sel = _sql.newSelect();
        while (mapping.getJoinablePCSuperclassMapping() != null)
            mapping = mapping.getJoinablePCSuperclassMapping();

        sel.wherePrimaryKey(oid, mapping, this);
        try {
            return sel.getCount(this) != 0;
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, _dict);
        }
    }
View Full Code Here


     */
    private Result getInitializeStateResult(OpenJPAStateManager sm,
        ClassMapping mapping, JDBCFetchConfiguration fetch, int subs)
        throws SQLException {
        List params = new ArrayList();
        Select sel = newSelect(sm, mapping, fetch, subs, params);
        if (sel == null) return null;
        return sel.execute(this, fetch, params);
    }
View Full Code Here

        }
        
        JDBCFetchConfiguration fetchClone = new JDBCFetchConfigurationImpl();
        fetchClone.copy(fetch);
        SelectKey selKey = new SelectKey(mapping, null, fetchClone);
        Select sel = null;
        boolean found = true;
        Object obj = selectImplCacheMap.get(selKey);
        if (obj == null) {
            synchronized (selectImplCacheMap) {
                obj = selectImplCacheMap.get(selKey);
                if (obj == null) {
                    // Not found in cache, create a new select
                    obj = newSelect(sm, mapping, fetch, subs);
                    found = false;
                }
                   
                if (obj == null) {
                    // If the generated SelectImpl is null, store a generic
                    // known object in the cache as a placeholder. Some map
                    // implementations do not allow null values.
                    obj = _nullCacheValue;
                    found = false;
                }
                else if (obj != _nullCacheValue)
                {
                    sel = (Select)obj;
                    if (sel.getSQL() == null) {
                        sel.setSQL(this, fetch);
                        found = false;
                    }
                }
                if (!found) {
                    addToSqlCache(selectImplCacheMap, selKey, obj);
                }
            }
        }

        if (obj != null && obj != _nullCacheValue)
            sel = (Select) obj;

        Log log = _conf.getLog(JDBCConfiguration.LOG_JDBC);
        if (log.isTraceEnabled()) {
            if (!found)
                log.trace(_loc.get("cache-missed", mapping, this.getClass()));
            else
                log.trace(_loc.get("cache-hit", mapping, this.getClass()));
        }

        if (sel == null)
            return null;
       
        Object oid = sm.getObjectId();
        Column[] cols = mapping.getPrimaryKeyColumns();
        sel.wherePrimaryKey(mapping, cols, cols, oid, this,
          null, null, params);
        return sel;
    }
View Full Code Here

        return sel;
    }

    protected Select newSelect(OpenJPAStateManager sm,
        ClassMapping mapping, JDBCFetchConfiguration fetch, int subs) {
        Select sel = _sql.newSelect();
        if (!select(sel, mapping, subs, sm, null, fetch,
            JDBCFetchConfiguration.EAGER_JOIN, true, false))
            return null;
        sel.wherePrimaryKey(sm.getObjectId(), mapping, this);
        sel.setExpectedResultCount(1, false);
        return sel;
    }
View Full Code Here

        // it if needed
        ClassMapping base = mapping;
        while (base.getJoinablePCSuperclassMapping() != null)
            base = base.getJoinablePCSuperclassMapping();

        Select sel = _sql.newSelect();
        sel.select(base.getPrimaryKeyColumns());
        sel.wherePrimaryKey(sm.getObjectId(), base, this);
        Result exists = sel.execute(this, fetch);
        try {
            if (isEmptyResult(exists))
                return false;

            // record locked?
View Full Code Here

            //### select is kind of a big object, and in some cases we don't
            //### use it... would it be worth it to have a small shell select
            //### object that only creates a real select when actually used?

            Select sel = _sql.newSelect();
            if (select(sel, mapping, Select.SUBS_EXACT, sm, fields, jfetch,
                EagerFetchModes.EAGER_JOIN, true, false)) {
                sel.wherePrimaryKey(sm.getObjectId(), mapping, this);
                res = sel.execute(this, jfetch, lockLevel);
                try {
                   if (isEmptyResult(res))
                        return false;
                    load(mapping, sm, jfetch, res);
                } finally {
View Full Code Here

            if (rops != null) {
                for (int i = 0; i < mappings.length; i++) {
                    if (rops[i] != null)
                        continue;

                    Select sel = _sql.newSelect();
                    sel.setLRS(true);
                    BitSet paged = selectExtent(sel, mappings[i], jfetch,
                        subclasses);
                    if (paged == null)
                        rops[i] = new InstanceResultObjectProvider(sel,
                            mappings[i], this, jfetch);
View Full Code Here

        ClassMapping mapping = (ClassMapping) sm.getMetaData();
        while (mapping.getJoinablePCSuperclassMapping() != null)
            mapping = mapping.getJoinablePCSuperclassMapping();

        // select only the PK columns, since we just want to lock
        Select select = _store.getSQLFactory().newSelect();
        select.select(mapping.getPrimaryKeyColumns());
        select.wherePrimaryKey(id, mapping, _store);
        SQLBuffer sql = select.toSelect(true, _store.getFetchConfiguration());

        ensureStoreManagerTransaction();
        Connection conn = _store.getConnection();
        PreparedStatement stmnt = null;
        ResultSet rs = null;
View Full Code Here

            rop = executeUnion(union, mappings, exps, states, ctx, paged);
        } else {
            if (sels.size() > 1)
                rops = new ResultObjectProvider[sels.size()];

            Select sel;
            BitSet paged;
            for (int i = 0, idx = 0; i < sels.size(); i++) {
                sel = (Select) sels.get(i);
                paged = populateSelect(sel, (ClassMapping) selMappings.get(i),
                    subclassBits.get(i), (JDBCExpressionFactory) facts[idx],
View Full Code Here

        QueryExpressionsState[] states, ExpContext ctx, int subclassMode) {
        Number optHint = (Number) ctx.fetch.getHint
            (QueryHints.HINT_RESULT_COUNT);
        ClassMapping[] verts;
        boolean unionable = true;
        Select sel;
        for (int i = 0; i < mappings.length; i++) {
            // determine vertical mappings to select separately
            verts = getVerticalMappings(mappings[i], subclasses, exps[i],
                subclassMode);
            if (verts.length == 1 && subclasses)
                subclassBits.set(sels.size());

            // create criteria select and clone for each vert mapping
            sel = ((JDBCExpressionFactory) facts[i]).getSelectConstructor().
                evaluate(ctx, null, null, exps[i], states[i]);
            if (optHint != null)
               sel.setExpectedResultCount(optHint.intValue(), true);
            else if (this.ctx.isUnique())
                sel.setExpectedResultCount(1, false);
            for (int j = 0; j < verts.length; j++) {
                selMappings.add(verts[j]);
                if (j == verts.length - 1) {
                    nextBits.set(sels.size());
                    sels.add(sel);
                } else
                    sels.add(sel.fullClone(1));
            }

            // turn off unioning if a given independent mapping requires
            // multiple selects, or if we're using FROM selects
            if (verts.length > 1 || sel.getFromSelect() != null)
                unionable = false;
        }
        return unionable;
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.sql.Select

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.