Package org.apache.openjpa.jdbc.kernel

Examples of org.apache.openjpa.jdbc.kernel.JDBCStore


            getValueMappedBy() != null;
        final ClassMapping[] clss = (derivedVal)
            ? _strat.getIndependentKeyMappings(false)
            : _strat.getIndependentValueMappings(false);
        final OpenJPAStateManager sm = assertOwner();
        final JDBCStore store = getStore();
        Union union = store.getSQLFactory().newUnion
            (Math.max(1, clss.length));
        union.select(new Union.Selector() {
            public void select(Select sel, int idx) {
                ClassMapping cls = (clss.length == 0) ? null : clss[idx];
                sel.whereForeignKey(_strat.getJoinForeignKey(cls),
                    sm.getObjectId(), _strat.getFieldMapping().
                    getDefiningMapping(), store);
            }
        });

        try {
            return union.getCount(store);
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, store.getDBDictionary());
        }
    }
View Full Code Here


        final ClassMapping[] clss = ((key && !derivedKey) || derivedVal)
            ? _strat.getIndependentKeyMappings(derivedVal)
            : _strat.getIndependentValueMappings(derivedKey);
        final OpenJPAStateManager sm = assertOwner();
        final JDBCStore store = getStore();

        Union union = store.getSQLFactory().newUnion
            (Math.max(1, clss.length));
        union.select(new Union.Selector() {
            public void select(Select sel, int idx) {
                ClassMapping cls = (clss.length == 0) ? null : clss[idx];
                sel.whereForeignKey(_strat.getJoinForeignKey(cls),
                    sm.getObjectId(), _strat.getFieldMapping().
                    getDefiningMapping(), store);

                Joins joins = null;
                Column[] cols;
                Object val;
                if (key) {
                    if (derivedKey)
                        joins = _strat.joinValueRelation(sel.newJoins(), cls);
                    val = _strat.toKeyDataStoreValue(obj, store);
                    cols = _strat.getKeyColumns(cls);
                } else {
                    if (derivedVal)
                        joins = _strat.joinKeyRelation(sel.newJoins(), cls);
                    val = _strat.toDataStoreValue(obj, store);
                    cols = _strat.getValueColumns(cls);
                }
                Object[] vals = (cols.length == 1) ? null : (Object[]) val;
                SQLBuffer sql = new SQLBuffer(store.getDBDictionary());
                for (int i = 0; i < cols.length; i++) {
                    if (i > 0)
                        sql.append(" AND ");

                    sql.append(sel.getColumnAlias(cols[i], joins));
                    if (vals == null)
                        sql.append((val == null) ? " IS " : " = ").
                            appendValue(val, cols[i]);
                    else
                        sql.append((vals[i] == null) ? " IS " : " = ").
                            appendValue(vals[i], cols[i]);
                }
                sel.where(sql, joins);
            }
        });

        try {
            return union.getCount(store) > 0;
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, store.getDBDictionary());
        }
    }
View Full Code Here

        }
    }

    protected Collection keys(final Object obj) {
        final OpenJPAStateManager sm = assertOwner();
        final JDBCStore store = getStore();
        if (_strat.getFieldMapping().getKey().getValueMappedBy() != null) {
            Object key = _strat.deriveKey(store, obj);
            if (hasKey(key))
                return Collections.singleton(key);
            return Collections.EMPTY_LIST;
        }

        final ClassMapping[] clss = _strat.getIndependentKeyMappings(true);
        final JDBCFetchConfiguration fetch = store.getFetchConfiguration();
        final Joins[] resJoins = new Joins[Math.max(1, clss.length)];

        Union union = store.getSQLFactory().newUnion
            (Math.max(1, clss.length));
        if (fetch.getSubclassFetchMode(_strat.getFieldMapping().
            getKeyMapping().getTypeMapping()) != fetch.EAGER_JOIN)
            union.abortUnion();
        union.select(new Union.Selector() {
            public void select(Select sel, int idx) {
                ClassMapping cls = (clss.length == 0) ? null : clss[idx];
                sel.whereForeignKey(_strat.getJoinForeignKey(cls),
                    sm.getObjectId(), _strat.getFieldMapping().
                    getDefiningMapping(), store);
                if (_strat.getFieldMapping().getElement().getValueMappedBy()
                    != null)
                    resJoins[idx] = _strat.joinKeyRelation(sel.newJoins(),
                        cls);

                Object val = _strat.toDataStoreValue(obj, store);
                Column[] cols = _strat.getValueColumns(cls);
                Object[] vals = (cols.length == 1) ? null : (Object[]) val;
                SQLBuffer sql = new SQLBuffer(store.getDBDictionary());
                for (int i = 0; i < cols.length; i++) {
                    if (i > 0)
                        sql.append(" AND ");

                    sql.append(sel.getColumnAlias(cols[i]));
                    if (vals == null)
                        sql.append((val == null) ? " IS " : " = ").
                            appendValue(val, cols[i]);
                    else
                        sql.append((vals[i] == null) ? " IS " : " = ").
                            appendValue(vals[i], cols[i]);
                }
                sel.where(sql);

                if (resJoins[idx] == null)
                    resJoins[idx] = _strat.joinKeyRelation(sel.newJoins(),
                        cls);
                _strat.selectKey(sel, cls, sm, store, fetch, resJoins[idx]);
            }
        });

        Result res = null;
        Collection keys = new ArrayList(3);
        try {
            res = union.execute(store, fetch);
            while (res.next())
                keys.add(_strat.loadKey(sm, store, fetch, res,
                    resJoins[res.indexOf()]));
            return keys;
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, store.getDBDictionary());
        } finally {
            if (res != null)
                res.close();
        }
    }
View Full Code Here

        }
    }

    protected Object value(final Object obj) {
        final OpenJPAStateManager sm = assertOwner();
        final JDBCStore store = getStore();
        if (_strat.getFieldMapping().getElement().getValueMappedBy() != null) {
            Object val = _strat.deriveValue(store, obj);
            if (hasValue(val))
                return val;
            return null;
        }

        final JDBCFetchConfiguration fetch = store.getFetchConfiguration();
        final ClassMapping[] clss = _strat.getIndependentValueMappings(true);
        final Joins[] resJoins = new Joins[Math.max(1, clss.length)];
        Union union = store.getSQLFactory().newUnion(Math.max(1, clss.length));
        union.setExpectedResultCount(1, false);
        if (fetch.getSubclassFetchMode(_strat.getFieldMapping().
            getElementMapping().getTypeMapping())
            != JDBCFetchConfiguration.EAGER_JOIN)
            union.abortUnion();
        union.select(new Union.Selector() {
            public void select(Select sel, int idx) {
                ClassMapping cls = (clss.length == 0) ? null : clss[idx];
                sel.whereForeignKey(_strat.getJoinForeignKey(cls),
                    sm.getObjectId(), _strat.getFieldMapping().
                    getDefiningMapping(), store);
                if (_strat.getFieldMapping().getKey().getValueMappedBy()
                    != null)
                    resJoins[idx] = _strat.joinValueRelation(sel.newJoins(),
                        cls);

                Object key = _strat.toKeyDataStoreValue(obj, store);
                Column[] cols = _strat.getKeyColumns(cls);
                Object[] vals = (cols.length == 1) ? null : (Object[]) key;
                SQLBuffer sql = new SQLBuffer(store.getDBDictionary());
                for (int i = 0; i < cols.length; i++) {
                    if (i > 0)
                        sql.append(" AND ");

                    sql.append(sel.getColumnAlias(cols[i], resJoins[idx]));
                    if (vals == null)
                        sql.append((key == null) ? " IS " : " = ").
                            appendValue(key, cols[i]);
                    else
                        sql.append((vals[i] == null) ? " IS " : " = ").
                            appendValue(vals[i], cols[i]);
                }
                sel.where(sql, resJoins[idx]);

                if (resJoins[idx] == null)
                    resJoins[idx] = _strat.joinValueRelation(sel.newJoins(),
                        cls);
                _strat.selectValue(sel, cls, sm, store, fetch, resJoins[idx]);
            }
        });

        Result res = null;
        try {
            res = union.execute(store, fetch);
            if (res.next())
                return _strat.loadValue(sm, store, fetch, res,
                    resJoins[res.indexOf()]);
            return null;
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, store.getDBDictionary());
        } finally {
            if (res != null)
                res.close();
        }
    }
View Full Code Here

        }
    }

    protected Iterator itr() {
        OpenJPAStateManager sm = assertOwner();
        JDBCStore store = getStore();
        JDBCFetchConfiguration fetch = store.getFetchConfiguration();
        try {
            Joins[] joins = new Joins[2];
            Result[] res = _strat.getResults(sm, store, fetch, fetch.EAGER_JOIN,
                joins, true);
            return new ResultIterator(sm, store, fetch, res, joins);
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, store.getDBDictionary());
        }
    }
View Full Code Here

        EntityManager em =emf.createEntityManager();
        startTx(em);
        RuntimeTest1 a = new RuntimeTest1("a-name", 10);
        em.persist(a);
        em.flush();
        JDBCStore store = (JDBCStore) getStoreManager(em, true);
        Connection conn = store.getConnection();
        ClassMapping mapping = store.getConfiguration().
                getMappingRepositoryInstance().getMapping(RuntimeTest1.class,
                null, true);
        FieldMapping fm = mapping.getFieldMapping("stringField");
        String tableName =
            store.getConfiguration().getDBDictionaryInstance().getFullName(
                    fm.getTable(), false);
        String colName = fm.getColumns()[0].getName();
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery("SELECT " + colName + " FROM "
                + tableName + " WHERE " + colName + " = 'a-name'");
View Full Code Here

        throws Exception {
       
        EntityManager em = currentEntityManager();
        Broker broker = JPAFacadeHelper.toBroker(em);
      
        JDBCStore store = (JDBCStore)broker.getStoreManager();

        Connection conn = store.getConnection();
        Statement stmnt = conn.createStatement();
        ResultSet rs = stmnt.executeQuery("SELECT * FROM RAWSQL "
        + "ORDER BY INTFIELD");
        ResultSetResult res = new ResultSetResult(rs,
        store.getConfiguration().getDBDictionaryInstance());
        ResultObjectProvider rop = new GenericResultObjectProvider
        (RawSQL.class, store, null, res);
        ResultList rl = new EagerResultList(rop);
        check(rl, broker);
        rl.close();
View Full Code Here

        if (edata == null || !(edata instanceof ConnectionInfo))
            return null;

        Result result = ((ConnectionInfo) edata).result;
        if (result instanceof ResultSetResult) {
            JDBCStore store = ((ResultSetResult) result).getStore();
            for (SliceStoreManager slice : _slices) {
                if (slice == store) {
                    return slice.getName();
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.kernel.JDBCStore

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.