/** * Initialize this instance from the values held in the * specified {@link Query}. */ public void setFrom(Query query) { _language = query.getLanguage(); _candidate = query.getCandidateType(); _res = query.getResultType(); _query = query.getQueryString(); }
/** * Return a key for the given query, or null if it is not cacheable. */ public static QueryKey newInstance(Query q, Object[] args) { // compile to make sure info encoded in query string is available // via API calls (candidate class, result class, etc) q.compile(); return newInstance(q, false, args, q.getCandidateType(), q.hasSubclasses(), q.getStartRange(), q.getEndRange(), null); }
public Broker getBroker() { try { return _query.getBroker(); } catch (RuntimeException re) { throw translate(re); } }
/** * Pours the post-compilation state held by this receiver to the given * query. */ public void setInto(Query q) { q.setQuery(_id); q.setCandidateType(_candidate, _subclasses); }
/** * Set query template information into the given concrete * query instance. However, the language, query string, and * candidate class are assumed to be declared in the query * instantiation, and hints are not transferred. */ public void setInto(Query query) { if (_candidate != null) query.setCandidateType(_candidate, true); if (!StringUtils.isEmpty(_query)) query.setQuery(_query); if (_res != null) query.setResultType(_res); if (_readOnly != null) query.setReadOnly(_readOnly.booleanValue()); if (_resultSetMappingName != null) query.setResultMapping(null, _resultSetMappingName); }
/** * Constructor; supply factory exception translator and delegate. * * @param em The EntityManager which created this query * @param ret Exception translator for this query * @param query The underlying "kernel" query. */ public QueryImpl(EntityManagerImpl em, RuntimeExceptionTranslator ret, org.apache.openjpa.kernel.Query query, QueryMetaData qmd) { super(qmd, em); _query = new DelegatingQuery(query, ret); _lock = new ReentrantLock(); if(query.getLanguage() == QueryLanguages.LANG_SQL) { _convertPositionalParams = false; } else { Compatibility compat = query.getStoreContext().getConfiguration().getCompatibilityInstance(); _convertPositionalParams = compat.getConvertPositionalParametersToNamed(); } }
/** * Ignores this query from PreparedQueryCache by recreating the original * query if it has been cached. */ void ignorePreparedQuery() { PreparedQuery cached = _em.getPreparedQuery(_id); if (cached == null) return; Broker broker = _em.getBroker(); // Critical assumption: Only JPQL queries are cached and more // importantly, the identifier of the prepared query is the original // JPQL String String JPQL = JPQLParser.LANG_JPQL; String jpql = _id; org.apache.openjpa.kernel.Query newQuery = broker.newQuery(JPQL, jpql); newQuery.getFetchConfiguration().copy(_query.getFetchConfiguration()); newQuery.compile(); _query = new DelegatingQuery(newQuery, _em.getExceptionTranslator()); }
public String getLanguage() { try { return _query.getLanguage(); } catch (RuntimeException re) { throw translate(re); } }
public void setResultMapping(Class scope, String name) { try { _query.setResultMapping(scope, name); } catch (RuntimeException re) { throw translate(re); } }
public void setCandidateType(Class cls, boolean subs) { try { _query.setCandidateType(cls, subs); } catch (RuntimeException re) { throw translate(re); } }
public Class getCandidateType() { try { return _query.getCandidateType(); } catch (RuntimeException re) { throw translate(re); } }
public FetchConfiguration getFetchConfiguration() { try { return _query.getFetchConfiguration(); } catch (RuntimeException re) { throw translate(re); } }
public boolean setQuery(Object query) { try { return _query.setQuery(query); } catch (RuntimeException re) { throw translate(re); } }
public StoreContext getStoreContext() { try { return _query.getStoreContext(); } catch (RuntimeException re) { throw translate(re); } }
public boolean hasSubclasses() { try { return _query.hasSubclasses(); } catch (RuntimeException re) { throw translate(re); } }
public void compile() { try { _query.compile(); } catch (RuntimeException re) { throw translate(re); } }
/** * Set query template information into the given concrete * query instance. However, the language, query string, and * candidate class are assumed to be declared in the query * instantiation, and hints are not transferred. */ public void setInto(Query query) { if (_candidate != null) query.setCandidateType(_candidate, true); if (!StringUtils.isEmpty(_query)) query.setQuery(_query); if (_res != null) query.setResultType(_res); if (_readOnly != null) query.setReadOnly(_readOnly.booleanValue()); if (_resultSetMappingName != null) query.setResultMapping(null, _resultSetMappingName); }
/** * Constructor; supply factory exception translator and delegate. * * @param em The EntityManager which created this query * @param ret Exception translator for this query * @param query The underlying "kernel" query. */ public QueryImpl(EntityManagerImpl em, RuntimeExceptionTranslator ret, org.apache.openjpa.kernel.Query query, QueryMetaData qmd) { super(qmd, em); _query = new DelegatingQuery(query, ret); _lock = new ReentrantLock(); if(query.getLanguage() == QueryLanguages.LANG_SQL) { _convertPositionalParams = false; } else { Compatibility compat = query.getStoreContext().getConfiguration().getCompatibilityInstance(); _convertPositionalParams = compat.getConvertPositionalParametersToNamed(); } }
/** * Pours the post-compilation state held by this receiver to the given * query. */ public void setInto(Query q) { q.setQuery(_id); q.setCandidateType(_candidate, _subclasses); }
/** * Ignores this query from PreparedQueryCache by recreating the original * query if it has been cached. */ void ignorePreparedQuery() { PreparedQuery cached = _em.getPreparedQuery(_id); if (cached == null) return; Broker broker = _em.getBroker(); // Critical assumption: Only JPQL queries are cached and more // importantly, the identifier of the prepared query is the original // JPQL String String JPQL = JPQLParser.LANG_JPQL; String jpql = _id; org.apache.openjpa.kernel.Query newQuery = broker.newQuery(JPQL, jpql); newQuery.getFetchConfiguration().copy(_query.getFetchConfiguration()); newQuery.compile(); _query = new DelegatingQuery(newQuery, _em.getExceptionTranslator()); }