/** * INTERNAL: * Copy all setting from the query. * This is used to morph queries from one type to the other. * By default this calls prepareFromQuery, but additional properties may be required * to be copied as prepareFromQuery only copies properties that affect the SQL. */ public void copyFromQuery(DatabaseQuery query) { super.copyFromQuery(query); if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; this.fetchSize = readQuery.fetchSize; this.firstResult = readQuery.firstResult; this.maxRows = readQuery.maxRows; this.queryResultCachingPolicy = readQuery.queryResultCachingPolicy; } }
/** * INTERNAL: * Copy all setting from the query. * This is used to morph queries from one type to the other. * By default this calls prepareFromQuery, but additional properties may be required * to be copied as prepareFromQuery only copies properties that affect the SQL. */ public void copyFromQuery(DatabaseQuery query) { super.copyFromQuery(query); if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; this.fetchSize = readQuery.fetchSize; this.firstResult = readQuery.firstResult; this.maxRows = readQuery.maxRows; this.queryResultCachingPolicy = readQuery.queryResultCachingPolicy; } }
/** * INTERNAL: * Copy all setting from the query. * This is used to morph queries from one type to the other. * By default this calls prepareFromQuery, but additional properties may be required * to be copied as prepareFromQuery only copies properties that affect the SQL. */ public void copyFromQuery(DatabaseQuery query) { super.copyFromQuery(query); if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; this.fetchSize = readQuery.fetchSize; this.firstResult = readQuery.firstResult; this.maxRows = readQuery.maxRows; this.queryResultCachingPolicy = readQuery.queryResultCachingPolicy; } }
/** * INTERNAL: * Return the results from executing the database query. * the arguments should be a database row with raw data values. * No modify queries are allowed through a HistoricalSession. */ public Object internalExecuteQuery(DatabaseQuery query, AbstractRecord databaseRow) throws DatabaseException { if (!query.isReadQuery()) { throw QueryException.invalidQueryOnHistoricalSession(query); } else { return super.internalExecuteQuery(query, databaseRow); } }
/** * INTERNAL: * Return the results from executing the database query. * the arguments should be a database row with raw data values. * No modify queries are allowed through a HistoricalSession. */ public Object internalExecuteQuery(DatabaseQuery query, AbstractRecord databaseRow) throws DatabaseException { if (!query.isReadQuery()) { throw QueryException.invalidQueryOnHistoricalSession(query); } else { return super.internalExecuteQuery(query, databaseRow); } }
/** * INTERNAL: * Return the results from executing the database query. * the arguments should be a database row with raw data values. * No modify queries are allowed through a HistoricalSession. */ public Object internalExecuteQuery(DatabaseQuery query, AbstractRecord databaseRow) throws DatabaseException { if (!query.isReadQuery()) { throw QueryException.invalidQueryOnHistoricalSession(query); } else { return super.internalExecuteQuery(query, databaseRow); } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((Boolean)valueToApply).booleanValue()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ((ReadQuery) query).setMaxRows(QueryHintsHandler.parseIntegerHint(valueToApply, QueryHints.JDBC_MAX_ROWS)); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ((ReadQuery) query).setFetchSize(QueryHintsHandler.parseIntegerHint(valueToApply, QueryHints.JDBC_FETCH_SIZE)); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ((ReadQuery) query).setFirstResult(QueryHintsHandler.parseIntegerHint(valueToApply, QueryHints.JDBC_FIRST_RESULT)); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } ((ReadQuery)query).getQueryResultsCachePolicy().setIsNullIgnored(((Boolean)valueToApply).booleanValue()); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } ((ReadQuery)query).getQueryResultsCachePolicy().setInvalidateOnChange(((Boolean)valueToApply).booleanValue()); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; if (readQuery.getQueryResultsCachePolicy() == null) { readQuery.cacheQueryResults(); } try { Time time = Helper.timeFromString((String)valueToApply); Calendar calendar = Calendar.getInstance(); calendar.setTime(time); readQuery.getQueryResultsCachePolicy().setCacheInvalidationPolicy( new DailyCacheInvalidationPolicy(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), 0)); } catch (ConversionException exception) { throw QueryException.queryHintContainedInvalidIntegerValue(QueryHints.QUERY_RESULTS_CACHE_EXPIRY_TIME_OF_DAY, valueToApply, exception); } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; if (readQuery.getQueryResultsCachePolicy() == null) { readQuery.cacheQueryResults(); } try { readQuery.getQueryResultsCachePolicy().setMaximumCachedResults(Integer.parseInt((String)valueToApply)); } catch (NumberFormatException exception) { throw QueryException.queryHintContainedInvalidIntegerValue(QueryHints.QUERY_RESULTS_CACHE_SIZE, valueToApply, exception); } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { ReadQuery readQuery = (ReadQuery)query; if (readQuery.getQueryResultsCachePolicy() == null) { readQuery.cacheQueryResults(); } try { readQuery.getQueryResultsCachePolicy().setCacheInvalidationPolicy( new TimeToLiveCacheInvalidationPolicy(Integer.parseInt((String)valueToApply))); } catch (NumberFormatException exception) { throw QueryException.queryHintContainedInvalidIntegerValue(QueryHints.QUERY_RESULTS_CACHE_EXPIRY, valueToApply, exception); } } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
DatabaseQuery applyToDatabaseQuery(Object valueToApply, DatabaseQuery query, ClassLoader loader, AbstractSession activeSession) { if (query.isReadQuery()) { if (((ReadQuery)query).getQueryResultsCachePolicy() == null) { ((ReadQuery)query).cacheQueryResults(); } if (((ReadQuery)query).getQueryResultsCachePolicy().getCacheInvalidationPolicy() == null) { ((ReadQuery)query).getQueryResultsCachePolicy().setCacheInvalidationPolicy(new TimeToLiveCacheInvalidationPolicy()); } ((ReadQuery)query).getQueryResultsCachePolicy().getCacheInvalidationPolicy().setIsInvalidationRandomized(((Boolean)valueToApply).booleanValue()); } else { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint",new Object[]{getQueryId(query), name, getPrintValue(valueToApply)})); } return query; } }
/** * PUBLIC: * Return the query from the set of pre-defined queries with the given name and argument types. * This allows for common queries to be pre-defined, reused and executed by name. * This method should be used if the Session has multiple queries with the same name but * different arguments. * If only one query exists, it will be returned regardless of the arguments. * If multiple queries exist, the first query that has corresponding argument types will be returned * * @see #getQuery(String) */ public DatabaseQuery getQuery(String name, Vector arguments) { DatabaseQuery query = getLocalQuery(name, arguments); // CR#3711: Check if a query with the same name exists for this descriptor. // If not, recursively check descriptors of parent classes. If nothing is // found in parents, return null. if (query == null) { DatabaseQuery parentQuery = getQueryFromParent(name, arguments); if ((parentQuery != null) && parentQuery.isReadQuery()) { parentQuery = (DatabaseQuery)parentQuery.clone(); ((ObjectLevelReadQuery)parentQuery).setReferenceClass(this.descriptor.getJavaClass()); addQuery(name, parentQuery); } return parentQuery; } return query; }
/** * Configure the firstResult, maxRows and lock mode in the EclipseLink * ReadQuery. */ protected void propagateResultProperties() { DatabaseQuery databaseQuery = getDatabaseQueryInternal(); if (databaseQuery.isReadQuery()) { ReadQuery readQuery = (ReadQuery) databaseQuery; if (maxResults >= 0) { cloneSharedQuery(); readQuery = (ReadQuery) getDatabaseQueryInternal(); int maxRows = maxResults + ((firstResultIndex >= 0) ? firstResultIndex : 0); readQuery.setMaxRows(maxRows); } if (firstResultIndex > UNDEFINED) { cloneSharedQuery(); readQuery = (ReadQuery) getDatabaseQueryInternal(); readQuery.setFirstResult(firstResultIndex); } } }
public void addNamedQuery(String name, Query query) { DatabaseQuery unwrapped = (DatabaseQuery) query.unwrap(DatabaseQuery.class).clone(); if (((QueryImpl)query).lockMode != null){ ((ObjectLevelReadQuery)unwrapped).setLockModeType(((QueryImpl)query).lockMode.name(), session); } if (unwrapped.isReadQuery()){ ((ReadQuery)unwrapped).setInternalMax((((QueryImpl)query).getMaxResultsInternal())); if (query.getFirstResult() != QueryImpl.UNDEFINED){ ((ReadQuery)unwrapped).setFirstResult(query.getFirstResult()); } } this.getServerSession().addQuery(name, unwrapped, true); }
public void addNamedQuery(String name, Query query) { QueryImpl queryImpl = query.unwrap(QueryImpl.class); DatabaseQuery unwrapped = (DatabaseQuery) queryImpl.getDatabaseQueryInternal().clone(); if (queryImpl.lockMode != null){ ((ObjectLevelReadQuery)unwrapped).setLockModeType(queryImpl.lockMode.name(), getServerSession()); } if (unwrapped.isReadQuery()){ ((ReadQuery)unwrapped).setInternalMax((queryImpl.getMaxResultsInternal())); ((ReadQuery)unwrapped).setFirstResult((queryImpl.getFirstResult())); } this.getServerSession().addQuery(name, unwrapped, true); }