Java 类org.hibernate.engine.spi.NamedQueryDefinition 实例源码

项目:lams    文件:AbstractSessionImpl.java   
@Override
public Query createQuery(NamedQueryDefinition namedQueryDefinition) {
    String queryString = namedQueryDefinition.getQueryString();
    final Query query = new QueryImpl(
            queryString,
            namedQueryDefinition.getFlushMode(),
            this,
            getHQLQueryPlan( queryString, false ).getParameterMetadata()
    );
    query.setComment( "named HQL query " + namedQueryDefinition.getName() );
    if ( namedQueryDefinition.getLockOptions() != null ) {
        query.setLockOptions( namedQueryDefinition.getLockOptions() );
    }

    return query;
}
项目:lams    文件:AbstractSessionImpl.java   
@Override
public Query getNamedQuery(String queryName) throws MappingException {
    errorIfClosed();
    NamedQueryDefinition nqd = factory.getNamedQuery( queryName );
    final Query query;
    if ( nqd != null ) {
        query = createQuery( nqd );
    }
    else {
        NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
        if ( nsqlqd==null ) {
            throw new MappingException( "Named query not known: " + queryName );
        }

        query = createSQLQuery( nsqlqd );
        nqd = nsqlqd;
    }
    initQuery( query, nqd );
    return query;
}
项目:lams    文件:NamedQueryRepository.java   
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 );
}
项目:lams    文件:NamedQueryRepository.java   
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 );
}
项目:lams    文件:NamedQueryRepository.java   
public synchronized void registerNamedSQLQueryDefinition(String name, NamedSQLQueryDefinition definition) {
    if ( ! name.equals( definition.getName() ) ) {
        definition = definition.makeCopy( name );
    }

    final Map<String, NamedSQLQueryDefinition> copy = CollectionHelper.makeCopy( namedSqlQueryDefinitionMap );
    final NamedQueryDefinition previous = copy.put( name, definition );
    if ( previous != null ) {
        log.debugf(
                "registering named SQL query definition [%s] overriding previously registered definition [%s]",
                name,
                previous
        );
    }

    this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( copy );
}
项目:base-framework    文件:BasicHibernateDao.java   
/**
 * 根据hql创建Hibernate Query对象
 * 
 * @param queryOrNamedQuery hql 或者Hibernate的NamedQuery
 * @param values
 *            数量可变的参数,按顺序绑定.
 *            
 * @return {@link Query}
 */
protected Query createQuery(String queryOrNamedQuery, Object... values) {
    Assert.hasText(queryOrNamedQuery, "queryOrNamedQuery不能为空");

    SessionFactoryImpl factory = (SessionFactoryImpl) sessionFactory;
    NamedQueryDefinition nqd = factory.getNamedQuery( queryOrNamedQuery );
    Query query = null;

    if (nqd != null) {
        query = getSession().getNamedQuery(queryOrNamedQuery);
    } else {
        query = getSession().createQuery(queryOrNamedQuery);
    }

    setQueryValues(query, values);
    return query;
}
项目:lams    文件:HbmBinder.java   
private static void bindNamedQuery(Element queryElem, String path, Mappings mappings) {
    String queryName = queryElem.attributeValue( "name" );
    if (path!=null) queryName = path + '.' + queryName;
    String query = queryElem.getText();
    LOG.debugf( "Named query: %s -> %s", queryName, query );

    boolean cacheable = "true".equals( queryElem.attributeValue( "cacheable" ) );
    String region = queryElem.attributeValue( "cache-region" );
    Attribute tAtt = queryElem.attribute( "timeout" );
    Integer timeout = tAtt == null ? null : Integer.valueOf( tAtt.getValue() );
    Attribute fsAtt = queryElem.attribute( "fetch-size" );
    Integer fetchSize = fsAtt == null ? null : Integer.valueOf( fsAtt.getValue() );
    Attribute roAttr = queryElem.attribute( "read-only" );
    boolean readOnly = roAttr != null && "true".equals( roAttr.getValue() );
    Attribute cacheModeAtt = queryElem.attribute( "cache-mode" );
    String cacheMode = cacheModeAtt == null ? null : cacheModeAtt.getValue();
    Attribute cmAtt = queryElem.attribute( "comment" );
    String comment = cmAtt == null ? null : cmAtt.getValue();

    NamedQueryDefinition namedQuery = new NamedQueryDefinitionBuilder().setName( queryName )
            .setQuery( query )
            .setCacheable( cacheable )
            .setCacheRegion( region )
            .setTimeout( timeout )
            .setFetchSize( fetchSize )
            .setFlushMode( FlushMode.interpretExternalSetting( queryElem.attributeValue( "flush-mode" ) ) )
            .setCacheMode( CacheMode.interpretExternalSetting( cacheMode ) )
            .setReadOnly( readOnly )
            .setComment( comment )
            .setParameterTypes( getParameterTypes( queryElem ) )
            .createNamedQueryDefinition();

    mappings.addQuery( namedQuery.getName(), namedQuery );
}
项目:lams    文件:QueryBinder.java   
public static void bindQuery(NamedQuery queryAnn, Mappings mappings, boolean isDefault) {
    if ( queryAnn == null ) return;
    if ( BinderHelper.isEmptyAnnotationValue( queryAnn.name() ) ) {
        throw new AnnotationException( "A named query must have a name when used in class or package level" );
    }
    //EJBQL Query
    QueryHintDefinition hints = new QueryHintDefinition( queryAnn.hints() );
    String queryName = queryAnn.query();
    NamedQueryDefinition queryDefinition = new NamedQueryDefinitionBuilder( queryAnn.name() )
            .setLockOptions( hints.determineLockOptions( queryAnn ) )
            .setQuery( queryName )
            .setCacheable( hints.getBoolean( queryName, QueryHints.CACHEABLE ) )
            .setCacheRegion( hints.getString( queryName, QueryHints.CACHE_REGION ) )
            .setTimeout( hints.getTimeout( queryName ) )
            .setFetchSize( hints.getInteger( queryName, QueryHints.FETCH_SIZE ) )
            .setFlushMode( hints.getFlushMode( queryName ) )
            .setCacheMode( hints.getCacheMode( queryName ) )
            .setReadOnly( hints.getBoolean( queryName, QueryHints.READ_ONLY ) )
            .setComment( hints.getString( queryName, QueryHints.COMMENT ) )
            .setParameterTypes( null )
            .createNamedQueryDefinition();

    if ( isDefault ) {
        mappings.addDefaultQuery( queryDefinition.getName(), queryDefinition );
    }
    else {
        mappings.addQuery( queryDefinition.getName(), queryDefinition );
    }
    if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Binding named query: %s => %s", queryDefinition.getName(), queryDefinition.getQueryString() );
    }
}
项目:lams    文件:QueryBinder.java   
public static void bindQuery(org.hibernate.annotations.NamedQuery queryAnn, Mappings mappings) {
    if ( queryAnn == null ) return;
    if ( BinderHelper.isEmptyAnnotationValue( queryAnn.name() ) ) {
        throw new AnnotationException( "A named query must have a name when used in class or package level" );
    }
    FlushMode flushMode;
    flushMode = getFlushMode( queryAnn.flushMode() );

    NamedQueryDefinition query = new NamedQueryDefinitionBuilder().setName( queryAnn.name() )
            .setQuery( queryAnn.query() )
            .setCacheable( queryAnn.cacheable() )
            .setCacheRegion(
                    BinderHelper.isEmptyAnnotationValue( queryAnn.cacheRegion() ) ?
                            null :
                            queryAnn.cacheRegion()
            )
            .setTimeout( queryAnn.timeout() < 0 ? null : queryAnn.timeout() )
            .setFetchSize( queryAnn.fetchSize() < 0 ? null : queryAnn.fetchSize() )
            .setFlushMode( flushMode )
            .setCacheMode( getCacheMode( queryAnn.cacheMode() ) )
            .setReadOnly( queryAnn.readOnly() )
            .setComment( BinderHelper.isEmptyAnnotationValue( queryAnn.comment() ) ? null : queryAnn.comment() )
            .setParameterTypes( null )
            .createNamedQueryDefinition();

    mappings.addQuery( query.getName(), query );
    if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Binding named query: %s => %s", query.getName(), query.getQueryString() );
    }
}
项目:lams    文件:MetadataImpl.java   
@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() );
    }
    namedQueryDefs.put( def.getName(), def );
}
项目:lams    文件:AbstractSessionImpl.java   
private void initQuery(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.setFlushMode( nqd.getFlushMode() );
    }
}
项目:lemon    文件:SessionFactoryWrapper.java   
public NamedQueryDefinition getNamedQuery(String queryName) {
    return sessionFactoryImplementor.getNamedQuery(queryName);
}
项目:lemon    文件:SessionFactoryWrapper.java   
public void registerNamedQueryDefinition(String name,
        NamedQueryDefinition definition) {
    sessionFactoryImplementor
            .registerNamedQueryDefinition(name, definition);
}
项目:lams    文件:Configuration.java   
protected void reset() {
        metadataSourceQueue = new MetadataSourceQueue();
        createReflectionManager();

        classes = new HashMap<String,PersistentClass>();
        imports = new HashMap<String,String>();
        collections = new HashMap<String,Collection>();
        tables = new TreeMap<String,Table>();

        namedQueries = new HashMap<String,NamedQueryDefinition>();
        namedSqlQueries = new HashMap<String,NamedSQLQueryDefinition>();
        sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
        namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>();
        namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>(  );
        typeDefs = new HashMap<String,TypeDef>();
        filterDefinitions = new HashMap<String, FilterDefinition>();
        fetchProfiles = new HashMap<String, FetchProfile>();
        auxiliaryDatabaseObjects = new ArrayList<AuxiliaryDatabaseObject>();

        tableNameBinding = new HashMap();
        columnNameBindingPerTable = new HashMap();

        secondPasses = new ArrayList<SecondPass>();
        propertyReferences = new ArrayList<Mappings.PropertyReference>();
        extendsQueue = new HashMap<ExtendsQueueEntry, String>();

        xmlHelper = new XMLHelper();
        interceptor = EmptyInterceptor.INSTANCE;
        properties = Environment.getProperties();
        entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER;

        sqlFunctions = new HashMap<String, SQLFunction>();

        entityTuplizerFactory = new EntityTuplizerFactory();
//      componentTuplizerFactory = new ComponentTuplizerFactory();

        identifierGeneratorFactory = new DefaultIdentifierGeneratorFactory();

        mappedSuperClasses = new HashMap<Class<?>, MappedSuperclass>();

        metadataSourcePrecedence = Collections.emptyList();

        namedGenerators = new HashMap<String, IdGenerator>();
        joins = new HashMap<String, Map<String, Join>>();
        classTypes = new HashMap<String, AnnotatedClassType>();
        generatorTables = new HashMap<String, Properties>();
        defaultNamedQueryNames = new HashSet<String>();
        defaultNamedNativeQueryNames = new HashSet<String>();
        defaultSqlResultSetMappingNames = new HashSet<String>();
        defaultNamedProcedure =  new HashSet<String>(  );
        defaultNamedGenerators = new HashSet<String>();
        uniqueConstraintHoldersByTable = new HashMap<Table, List<UniqueConstraintHolder>>();
        jpaIndexHoldersByTable = new HashMap<Table,List<JPAIndexHolder>>(  );
        mappedByResolver = new HashMap<String, String>();
        propertyRefResolver = new HashMap<String, String>();
        caches = new ArrayList<CacheHolder>();
        namingStrategyDelegator = LegacyNamingStrategyDelegator.DEFAULT_INSTANCE;
        setEntityResolver( new EJB3DTDEntityResolver() );
        anyMetaDefs = new HashMap<String, AnyMetaDef>();
        propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String, PropertyData>>();
        propertiesAnnotatedWithIdAndToOne = new HashMap<XClass, Map<String, PropertyData>>();
        specjProprietarySyntaxEnabled = System.getProperty( "hibernate.enable_specj_proprietary_syntax" ) != null;
    }
项目:lams    文件:Configuration.java   
public Map<String, NamedQueryDefinition> getNamedQueries() {
    return namedQueries;
}
项目:lams    文件:Configuration.java   
public NamedQueryDefinition getQuery(String name) {
    return namedQueries.get( name );
}
项目:lams    文件:Configuration.java   
public void addQuery(String name, NamedQueryDefinition query) throws DuplicateMappingException {
    if ( !defaultNamedQueryNames.contains( name ) ) {
        applyQuery( name, query );
    }
}
项目:lams    文件:Configuration.java   
private void applyQuery(String name, NamedQueryDefinition query) {
    checkQueryName( name );
    namedQueries.put( name.intern(), query );
}
项目:lams    文件:Configuration.java   
public void addDefaultQuery(String name, NamedQueryDefinition query) {
    applyQuery( name, query );
    defaultNamedQueryNames.add( name );
}
项目:lams    文件:MetadataImpl.java   
public NamedQueryDefinition getNamedQuery(String name) {
    if ( name == null ) {
        throw new IllegalArgumentException( "null is not a valid query name" );
    }
    return namedQueryDefs.get( name );
}
项目:lams    文件:MetadataImpl.java   
@Override
public Iterable<NamedQueryDefinition> getNamedQueryDefinitions() {
    return namedQueryDefs.values();
}
项目:lams    文件:SessionFactoryImpl.java   
public void registerNamedQueryDefinition(String name, NamedQueryDefinition definition) {
    namedQueryRepository.registerNamedQueryDefinition( name, definition );
}
项目:lams    文件:SessionFactoryImpl.java   
public NamedQueryDefinition getNamedQuery(String queryName) {
    return namedQueryRepository.getNamedQueryDefinition( queryName );
}
项目:lams    文件:NamedQueryRepository.java   
public NamedQueryDefinition getNamedQueryDefinition(String queryName) {
    return namedQueryDefinitionMap.get( queryName );
}
项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
public NamedQueryDefinition getNamedQuery(String queryName) {
    return namedQueries.get(queryName);
}
项目:lams    文件:Mappings.java   
/**
 * Get named query metadata by name.
 *
 * @param name The named query name
 * @return The query metadata, or null.
 */
public NamedQueryDefinition getQuery(String name);
项目:lams    文件:Mappings.java   
/**
 * Adds metadata for a named query to this repository.
 *
 * @param name The name
 * @param query The metadata
 * @throws DuplicateMappingException If a query already exists with that name.
 */
public void addQuery(String name, NamedQueryDefinition query) throws DuplicateMappingException;
项目:lams    文件:Mappings.java   
public void addDefaultQuery(String name, NamedQueryDefinition query);
项目:lams    文件:Metadata.java   
public Iterable<NamedQueryDefinition> getNamedQueryDefinitions();
项目:lams    文件:MetadataImplementor.java   
public void addNamedQuery(NamedQueryDefinition def);