public Object toObjectValue(ValueMapping vm, Object val, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch) throws SQLException { if (val == null) return null; String str = (String) val; int idx = str.indexOf(':'); if (idx == -1) throw new StoreException(_loc.get("oid-invalid", str, vm)); String clsName = str.substring(0, idx); String oidStr = str.substring(idx + 1); StoreContext ctx = store.getContext(); ClassLoader loader = store.getConfiguration(). getClassResolverInstance().getClassLoader(vm.getType(), ctx.getClassLoader()); Class cls = null; try { cls = Class.forName(clsName, true, loader); } catch (ClassNotFoundException cnfe) { throw new StoreException(cnfe); } Object oid = ctx.newObjectId(cls, oidStr); return store.find(oid, vm, fetch); }
public Collection flush(Collection states, JDBCStore store) { Connection conn = store.getConnection(); try { PreparedStatementManager psMgr = newPreparedStatementManager(store, conn); return flush(states, store, psMgr); } finally { try { conn.close(); } catch (SQLException se) {} } }
/** * Constructor. Supply connection. */ public PreparedStatementManagerImpl(JDBCStore store, Connection conn) { _store = store; _dict = store.getDBDictionary(); _conn = conn; if (store.getConfiguration() != null) _log = store.getConfiguration().getLog(JDBCConfiguration.LOG_JDBC); }
public Result execute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel) throws SQLException { if (fetch == null) fetch = store.getFetchConfiguration(); return execute(store.getContext(), store, fetch, lockLevel); }
public StoredProcedureQueryExecutor(StoredProcedureQuery q, List<QueryResultMapping> resultMapping, List<Class<?>> classes) { QueryContext ctx = q.getContext(); _resultMappings = resultMapping; _resultClasses = classes; // Look for the named Stored Procedure in the database String procName = ctx.getQueryString(); _proc = getStoredProcedure(_store.getConnection(), _store.getDBDictionary(), procName); if (_proc == null) { throw new RuntimeException("Can not find stored procedure " + procName); } }
boolean forUpdate = false; if (!isAggregate() && _grouping == null) { JDBCLockManager lm = store.getLockManager(); if (lm != null) forUpdate = lm.selectForUpdate(this, lockLevel); int rsType = (isLRS && supportsRandomAccess(forUpdate)) ? -1 : ResultSet.TYPE_FORWARD_ONLY; Connection conn = store.getConnection(); PreparedStatement stmnt = null; ResultSet rs = null;
oid = null; else if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE) oid = store.newDataStoreId(((Number) val).longValue(), relMapping, field.getPolymorphic() != ValueMapping.POLY_FALSE); else { if (JavaTypes.maybePC(field.getValue()) && field.getElement().getEmbeddedMetaData() == null) { Object obj = store.find(oid, field, fetch); sm.storeObject(field.getIndex(), obj); } else
/** * Return the class loader to use for loading class names. */ private ClassLoader getClassLoader(JDBCStore store) { return store.getConfiguration().getClassResolverInstance(). getClassLoader(disc.getClassMapping().getDescribedType(), store.getContext().getClassLoader()); } }
Object oid = sm.getIntermediate(field.getIndex()); if (oid != null) { Object val = store.find(oid, field, fetch); sm.storeObject(field.getIndex(), val); return; Union union = store.getSQLFactory().newUnion(rels.length); union.setExpectedResultCount(1, false); if (fetch.getSubclassFetchMode(field.getTypeMapping())
public void setAutoAssignedValue(OpenJPAStateManager sm, JDBCStore store, Column col, Object autogen) { long id = ((Number) autogen).longValue(); sm.setObjectId(store.newDataStoreId(id, (ClassMapping) sm.getMetaData(), true)); } }
private Select createSelect(OpenJPAStateManager sm, JDBCStore store) { Select sel = store.getSQLFactory().newSelect(); sel.select(field.getColumns()[0]); sel.selectPrimaryKey(field.getDefiningMapping()); sel.wherePrimaryKey (sm.getObjectId(), field.getDefiningMapping(), store); sel.setLob(true); return sel; }
public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql) { // if no class indicator or a final class, just append true or false // depending on whether the cast matches the expected type InstanceofExpState istate = (InstanceofExpState) state; if (istate.discrim == null) { if (_cls.isAssignableFrom(istate.rel)) sql.append("1 = 1"); else sql.append("1 <> 1"); } else { ctx.store.loadSubclasses(istate.discrim.getClassMapping()); SQLBuffer buf = istate.discrim.getClassConditions(sel, istate.joins, istate.mapping, true); sql.append(buf); } sel.append(sql, istate.joins); }
public void handleCheckedException(Exception e) { if (e instanceof SQLException) throw SQLExceptions.getStore((SQLException) e, _store.getDBDictionary()); throw new StoreException(e); }
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()); } }
/** * Return the serialized bytes for the given object. */ public byte[] serialize(Object val, JDBCStore store) throws SQLException { if (val == null) return null; if (val instanceof SerializedData) return ((SerializedData) val).bytes; return Serialization.serialize(val, store.getContext()); }
public ClassMapping getValueMetaData(ExpContext ctx) { Object[] params = ctx.params; if (params[_idx] != null && params[_idx] instanceof Class) return (ClassMapping) ctx.store.getConfiguration().getMetaDataRepositoryInstance(). getMetaData((Class) params[_idx], getClass().getClassLoader(), true); return null; }
public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer buf) { DBDictionary dict = ctx.store.getDBDictionary(); dict.assertSupport(dict.supportsSubselect, "SupportsSubselect"); Select sub = ctx.store.getSQLFactory().newSelect(); sub.setParent(sel, null); ExpState estate = _exp.initialize(sub, ctx, ((NotContainsExpState) state).contains); sub.where(sub.and(null, estate.joins)); SQLBuffer where = new SQLBuffer(dict).append("("); _exp.appendTo(sub, ctx, estate, where); if (where.getSQL().length() > 1) sub.where(where.append(")")); buf.append("0 = "); buf.appendCount(sub, ctx.fetch); }
/** * Constructor. * * @param res the result data */ public MappedQueryResultObjectProvider(QueryResultMapping map, JDBCStore store, JDBCFetchConfiguration fetch, Result res) { _map = map; _store = store; _fetch = (fetch == null) ? store.getFetchConfiguration() : fetch; _mres = new MappingResult(res); }
if (store.getLockManager() != null) res.setLocking(store.getLockManager().skipRelationFieldLock()); sm.storeObject(field.getIndex(), res.load(cls, store, fetch, eagerJoin(res.newJoins(), cls, false)));
public Result execute(JDBCStore store, JDBCFetchConfiguration fetch, int lockLevel) throws SQLException { if (fetch == null) fetch = store.getFetchConfiguration(); return execute(store.getContext(), store, fetch, lockLevel); }