protected QueryImplementor createQuery(NamedQueryDefinition queryDefinition) { String queryString = queryDefinition.getQueryString(); final QueryImpl query = new QueryImpl( this, getQueryPlan( queryString, false ).getParameterMetadata(), queryString ); query.setHibernateFlushMode( queryDefinition.getFlushMode() ); query.setComment( queryDefinition.getComment() != null ? queryDefinition.getComment() : queryDefinition.getName() ); if ( queryDefinition.getLockOptions() != null ) { query.setLockOptions( queryDefinition.getLockOptions() ); } initQueryFromNamedDefinition( query, queryDefinition ); // applyQuerySettingsAndHints( query ); return query; }
public NamedQueryDefinition createNamedQueryDefinition() { return new NamedQueryDefinition( name, query, cacheable, cacheRegion, timeout, lockOptions, fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes, firstResult, maxResults ); } }
public NamedQueryDefinition makeCopy(String name) { return new NamedQueryDefinition( name, getQuery(), isCacheable(), getCacheRegion(), getTimeout(), getLockOptions(), getFetchSize(), getFlushMode(), getCacheMode(), isReadOnly(), getComment(), getParameterTypes(), getFirstResult(), getMaxResults() ); } }
@Override public void addNamedQuery(NamedQueryDefinition def) { if ( def == null ) { throw new IllegalArgumentException( "Named query definition is null" ); } else if ( def.getName() == null ) { throw new IllegalArgumentException( "Named query definition name is null: " + def.getQueryString() ); } if ( defaultNamedQueryNames.contains( def.getName() ) ) { return; } applyNamedQuery( def.getName(), def ); }
protected void initQueryFromNamedDefinition(Query query, NamedQueryDefinition nqd) { // todo : cacheable and readonly should be Boolean rather than boolean... query.setCacheable( nqd.isCacheable() ); query.setCacheRegion( nqd.getCacheRegion() ); query.setReadOnly( nqd.isReadOnly() ); if ( nqd.getTimeout() != null ) { query.setTimeout( nqd.getTimeout() ); } if ( nqd.getFetchSize() != null ) { query.setFetchSize( nqd.getFetchSize() ); } if ( nqd.getCacheMode() != null ) { query.setCacheMode( nqd.getCacheMode() ); } if ( nqd.getComment() != null ) { query.setComment( nqd.getComment() ); } if ( nqd.getFirstResult() != null ) { query.setFirstResult( nqd.getFirstResult() ); } if ( nqd.getMaxResults() != null ) { query.setMaxResults( nqd.getMaxResults() ); } if ( nqd.getFlushMode() != null ) { query.setHibernateFlushMode( nqd.getFlushMode() ); } }
private void initQuery(Query query, NamedQueryDefinition nqd) { query.setCacheable( nqd.isCacheable() ); query.setCacheRegion( nqd.getCacheRegion() ); if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() ); if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() ); if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() ); query.setReadOnly( nqd.isReadOnly() ); if ( nqd.getComment() != null ) query.setComment( nqd.getComment() ); }
NamedQueryDefinition query = new NamedQueryDefinition( queryAnn.name(), queryName, ); if ( isDefault ) { mappings.addDefaultQuery( query.getName(), query ); mappings.addQuery( query.getName(), query ); LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
final Query query; if ( nqd != null ) { String queryString = nqd.getQueryString(); query = new QueryImpl( queryString, nqd.getFlushMode(), this, getHQLQueryPlan( queryString, false ).getParameterMetadata()
/** * Create a query from a named query with a transformed order by clause with multiple new ordery by clauses. * * @param entityManager the entity manager to build the query against * @param queryName the name of the query to transform * @param orderByFields an array of clauses to contribute to the order by * * @return the transformed query */ public static Query createQueryWithOrderBy(EntityManager entityManager, String queryName, OrderingField... orderByFields) { NamedQueryDefinition ndc = getNamedQueryDefinition(entityManager, queryName); StringBuilder query = new StringBuilder(ndc.getQueryString()); buildOrderBy(query, orderByFields); return entityManager.createQuery(query.toString()); }
String comment = cmAtt == null ? null : cmAtt.getValue(); NamedQueryDefinition namedQuery = new NamedQueryDefinition( queryName, query, ); mappings.addQuery( namedQuery.getName(), namedQuery );
public synchronized void registerNamedQueryDefinition(String name, NamedQueryDefinition definition) { if ( NamedSQLQueryDefinition.class.isInstance( definition ) ) { throw new IllegalArgumentException( "NamedSQLQueryDefinition instance incorrectly passed to registerNamedQueryDefinition" ); } if ( ! name.equals( definition.getName() ) ) { definition = definition.makeCopy( name ); } final Map<String, NamedQueryDefinition> copy = CollectionHelper.makeCopy( namedQueryDefinitionMap ); final NamedQueryDefinition previous = copy.put( name, definition ); if ( previous != null ) { log.debugf( "registering named query definition [%s] overriding previously registered definition [%s]", name, previous ); } this.namedQueryDefinitionMap = Collections.unmodifiableMap( copy ); }
public Map<?, ?> getParameterTypes(NamedQueryDefinition query) { Map<?, ?> result = query.getParameterTypes(); if (result == null) { result = new HashMap<>(); } return result; } }
private void initQuery(Query query, NamedQueryDefinition nqd) { query.setCacheable( nqd.isCacheable() ); query.setCacheRegion( nqd.getCacheRegion() ); if ( nqd.getTimeout()!=null ) query.setTimeout( nqd.getTimeout().intValue() ); if ( nqd.getFetchSize()!=null ) query.setFetchSize( nqd.getFetchSize().intValue() ); if ( nqd.getCacheMode() != null ) query.setCacheMode( nqd.getCacheMode() ); query.setReadOnly( nqd.isReadOnly() ); if ( nqd.getComment() != null ) query.setComment( nqd.getComment() ); }
NamedQueryDefinition query = new NamedQueryDefinition( queryAnn.name(), queryName, ); if ( isDefault ) { mappings.addDefaultQuery( query.getName(), query ); mappings.addQuery( query.getName(), query ); LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
log.debugf( "Checking named query: %s", namedQueryDefinition.getName() ); queryPlanCache.getHQLQueryPlan( namedQueryDefinition.getQueryString(), false, Collections.EMPTY_MAP ); errors.put( namedQueryDefinition.getName(), e );
final Query query; if ( nqd != null ) { String queryString = nqd.getQueryString(); query = new QueryImpl( queryString, nqd.getFlushMode(), this, getHQLQueryPlan( queryString, false ).getParameterMetadata()
String query = namedQueryDefinition.getQueryString();
String comment = cmAtt == null ? null : cmAtt.getValue(); NamedQueryDefinition namedQuery = new NamedQueryDefinition( queryName, query, ); mappings.addQuery( namedQuery.getName(), namedQuery );
public NamedQueryRepository( Iterable<NamedQueryDefinition> namedQueryDefinitions, Iterable<NamedSQLQueryDefinition> namedSqlQueryDefinitions, Iterable<ResultSetMappingDefinition> namedSqlResultSetMappings, Map<String, ProcedureCallMemento> namedProcedureCalls) { final HashMap<String, NamedQueryDefinition> namedQueryDefinitionMap = new HashMap<String, NamedQueryDefinition>(); for ( NamedQueryDefinition namedQueryDefinition : namedQueryDefinitions ) { namedQueryDefinitionMap.put( namedQueryDefinition.getName(), namedQueryDefinition ); } this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap ); final HashMap<String, NamedSQLQueryDefinition> namedSqlQueryDefinitionMap = new HashMap<String, NamedSQLQueryDefinition>(); for ( NamedSQLQueryDefinition namedSqlQueryDefinition : namedSqlQueryDefinitions ) { namedSqlQueryDefinitionMap.put( namedSqlQueryDefinition.getName(), namedSqlQueryDefinition ); } this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap ); final HashMap<String, ResultSetMappingDefinition> namedSqlResultSetMappingMap = new HashMap<String, ResultSetMappingDefinition>(); for ( ResultSetMappingDefinition resultSetMappingDefinition : namedSqlResultSetMappings ) { namedSqlResultSetMappingMap.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition ); } this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap ); this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCalls ); }