@Override public String extractQueryString(Query query) { return ((JpaQuery<?>) query).getDatabaseQuery().getJPQLString(); }
private Query getQuery(DatabaseQuery query, PersistenceContext context) { String method = query.isReadQuery() ? "get" : "post"; String jpql = query.getJPQLString() == null ? "" : query.getJPQLString(); StringBuilder parameterString = new StringBuilder(); Iterator<String> argumentsIterator = query.getArguments().iterator(); while (argumentsIterator.hasNext()) { String argument = argumentsIterator.next(); Query returnQuery = null; if (version != null) { returnQuery = new Query(query.getName(), jpql, new LinkTemplate("execute", method, context.getBaseURI() + version + "/" + context.getName() + "/query/" + query.getName() + parameterString)); } else { returnQuery = new Query(query.getName(), jpql, new LinkTemplate("execute", method, context.getBaseURI() + context.getName() + "/query/" + query.getName() + parameterString)); if (query.isReportQuery()) { query.checkPrepare((AbstractSession) context.getServerSession(), new DatabaseRecord()); for (ReportItem item : ((ReportQuery) query).getItems()) { if (item.getMapping() != null) { returnQuery.getReturnTypes().add(query.getReferenceClassName() == null ? "" : query.getReferenceClass().getSimpleName());
public String toString() { String referenceClassString = ""; String nameString = ""; String queryString = ""; if (getReferenceClass() != null) { referenceClassString = "referenceClass=" + getReferenceClass().getSimpleName() + " "; } if ((getName() != null) && (!getName().equals(""))) { nameString = "name=\"" + getName() + "\" "; } if (isSQLCallQuery()) { queryString = "sql=\"" + getSQLString() + "\""; } else if (isJPQLCallQuery()) { queryString = "jpql=\"" + getJPQLString() + "\""; } return getClass().getSimpleName() + "(" + nameString + referenceClassString + queryString + ")"; }
/** * Prepare and validate. * Allow subclasses to override. */ public void prepare(DatabaseQuery query, AbstractSession session) throws QueryException { if (query.isReadAllQuery() && (!query.isReportQuery()) && query.shouldUseWrapperPolicy()) { setElementDescriptor(query.getDescriptor()); //make sure DataReadQuery points to this container policy } else if (query.isDataReadQuery()) { ((DataReadQuery)query).setContainerPolicy(this); } }
if (!this.databaseQuery.isPrepared()) { this.databaseQuery.checkPrepare(this.entityManager.getActiveSessionIfExists(), new DatabaseRecord()); } catch(RuntimeException re){ throw new IllegalArgumentException(re); if (this.databaseQuery.isObjectLevelReadQuery() && ((ObjectLevelReadQuery)this.databaseQuery).getLockModeType() != null){ this.lockMode = LockModeType.valueOf(((ObjectLevelReadQuery)this.databaseQuery).getLockModeType()); if (this.databaseQuery.isReadQuery()){ this.maxResults = ((ReadQuery)this.databaseQuery).getInternalMax(); this.firstResultIndex = ((ReadQuery)this.databaseQuery).getFirstResult();
protected SQLSelectStatement createSQLSelectStatementForAssignedExpressionForUpdateAll(Expression value) { ReportQuery reportQuery = new ReportQuery(getQuery().getReferenceClass(), value.getBuilder()); reportQuery.setDescriptor(getQuery().getDescriptor()); reportQuery.setSession(getSession()); reportQuery.addAttribute("", value); SQLSelectStatement selectStatement = ((ExpressionQueryMechanism)reportQuery.getQueryMechanism()).buildReportQuerySelectStatement(false); reportQuery.setSession(null); return selectStatement; }
/** * INTERNAL * Build the context to be used when generating the expression from the parse tree */ public GenerationContext buildContext(DatabaseQuery query, AbstractSession sessionForContext) { if (query.isObjectLevelReadQuery()) { return buildContextForReadQuery(sessionForContext); } else if (query.isUpdateAllQuery() || query.isDeleteAllQuery()) { return new GenerationContext(getContext(), sessionForContext, this); } return null; }
/** * INTERNAL: * Process the JPA named queries into EclipseLink Session queries. */ public void processJPAQueries() { List queries = getJPAQueries(); for (Iterator iterator = queries.iterator(); iterator.hasNext();) { DatabaseQuery jpaQuery = (DatabaseQuery)iterator.next(); jpaQuery.checkPrepare(this, null); DatabaseQuery databaseQuery = (DatabaseQuery)jpaQuery.getProperty("databasequery"); addQuery(databaseQuery.getName(), databaseQuery); } queries.clear(); }
/** * PUBLIC: * Return true if this query uses an JPQL query mechanism . */ public boolean isJPQLCallQuery() { Call call = getDatasourceCall(); return (call != null) && (call instanceof JPQLCall); }
public static ValidationException existingQueryTypeConflict(DatabaseQuery newQuery, DatabaseQuery existingQuery) { Object[] args = { newQuery, newQuery.getName(), newQuery.getArgumentTypes(), existingQuery, existingQuery.getName(), existingQuery.getArgumentTypes() }; ValidationException validationException = new ValidationException(ExceptionMessageGenerator.buildMessage(ValidationException.class, EXISTING_QUERY_TYPE_CONFLICT, args)); validationException.setErrorCode(EXISTING_QUERY_TYPE_CONFLICT); return validationException; }
/** * 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); } }
/** * Prepare and validate. * Set the element class. */ @Override public void prepare(DatabaseQuery query, AbstractSession session) throws QueryException { if ((getElementClass() == null) && (query.getDescriptor() != null)) { setElementClass(query.getDescriptor().getJavaClass()); } super.prepare(query, session); }
/** * Creates a new <code>JPQLQueryContext</code>. * * @param query The {@link DatabaseQuery} from which information will be queries * @param jpqlGrammar The JPQL grammar that defines how the JPQL query was parsed * @since 2.5 */ JPQLQueryContext(DatabaseQuery query, JPQLGrammar jpqlGrammar) { this(jpqlGrammar); String jpqlQuery = query.getJPQLString(); cache(query.getSession(), query, parse(jpqlQuery), jpqlQuery); }
/** * INTERNAL: * This method will be used to update the query with any settings required * For this session. It can also be used to validate execution. */ @Override public void validateQuery(DatabaseQuery query) { if (query.isObjectLevelReadQuery() && ((query.getDescriptor().getCachePolicy().isIsolated()) || ((ObjectLevelReadQuery)query).shouldUseExclusiveConnection())) { throw QueryException.isolatedQueryExecutedOnServerSession(); } }
/** * Execute the call. It is assumed the call has been fully prepared. * @exception DatabaseException - an error has occurred on the database. */ protected Object executeCall(DatasourceCall databaseCall) throws DatabaseException { // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); DatasourceCall clonedCall = (DatasourceCall)databaseCall.clone(); clonedCall.setQuery(this.query); clonedCall.translate(this.query.getTranslationRow(), getModifyRow(), sessionToUse); return sessionToUse.executeCall(clonedCall, this.query.getTranslationRow(), this.query); }
/** * INTERNAL * Verify that the alias in the SELECT is valid. * Invalid: SELECT OBJECT(badAlias) FROM Employee employee.... * Valid: SELECT OBJECT(employee) FROM Employee employee.... */ public void verifySelect(DatabaseQuery theQuery, GenerationContext generationContext) { if (theQuery.isObjectLevelReadQuery()) { //verify the selected alias, //this will throw an error if the alias is bad ((SelectNode)getQueryNode()).verifySelectedAlias(generationContext); } }
/** * INTERNAL: * Return the name to use for the query in performance monitoring. */ public void resetMonitorName() { if (getReferenceClassName() == null) { this.monitorName = getClass().getSimpleName() + ":" + getName(); } else { this.monitorName = getClass().getSimpleName() + ":" + getReferenceClassName() + ":" + getName(); } }
/** * Initialize the query-based value holder. * @param query The query that returns the object when executed. * @param row The row representation of the object. * @param mapping The mapping that is uses batch reading. */ public BatchValueHolder(ReadQuery query, AbstractRecord row, ForeignReferenceMapping mapping, DatabaseQuery originalQuery) { super(query, row, originalQuery.getSession()); this.mapping = mapping; this.argumentRow = originalQuery.getTranslationRow(); }
/** * PUBLIC: Add the argument named argumentName and its class type. This will * cause the translation of references of argumentName in the receiver's * expression, with the value of the argument as supplied to the query in * order from executeQuery(). Specifying the class type is important if * identically named queries are used but with different argument lists. */ public void addArgument(String argumentName, Class type) { addArgument(argumentName, type, false); }
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); }