java类javax.persistence.NamedQuery的实例源码

JPAOverriddenAnnotationReader.java 文件源码 项目:lams 阅读 34 收藏 0 点赞 0 评论 0
private NamedQueries getNamedQueries(Element tree, XMLContext.Default defaults) {
    //TODO avoid the Proxy Creation (@NamedQueries) when possible
    List<NamedQuery> queries = (List<NamedQuery>) buildNamedQueries( tree, false, defaults );
    if ( defaults.canUseJavaAnnotations() ) {
        NamedQuery annotation = getPhysicalAnnotation( NamedQuery.class );
        addNamedQueryIfNeeded( annotation, queries );
        NamedQueries annotations = getPhysicalAnnotation( NamedQueries.class );
        if ( annotations != null ) {
            for ( NamedQuery current : annotations.value() ) {
                addNamedQueryIfNeeded( current, queries );
            }
        }
    }
    if ( queries.size() > 0 ) {
        AnnotationDescriptor ad = new AnnotationDescriptor( NamedQueries.class );
        ad.setValue( "value", queries.toArray( new NamedQuery[queries.size()] ) );
        return AnnotationFactory.create( ad );
    }
    else {
        return null;
    }
}
JPAOverriddenAnnotationReader.java 文件源码 项目:lams 阅读 36 收藏 0 点赞 0 评论 0
private void addNamedQueryIfNeeded(NamedQuery annotation, List<NamedQuery> queries) {
    if ( annotation != null ) {
        String queryName = annotation.name();
        boolean present = false;
        for ( NamedQuery current : queries ) {
            if ( current.name().equals( queryName ) ) {
                present = true;
                break;
            }
        }
        if ( !present ) {
            queries.add( annotation );
        }
    }
}
QueryHintDefinition.java 文件源码 项目:lams 阅读 40 收藏 0 点赞 0 评论 0
public LockOptions determineLockOptions(NamedQuery namedQueryAnnotation) {
    LockModeType lockModeType = namedQueryAnnotation.lockMode();
    Integer lockTimeoutHint = getInteger( namedQueryAnnotation.name(), "javax.persistence.lock.timeout" );

    LockOptions lockOptions = new LockOptions( LockModeConverter.convertToLockMode( lockModeType ) );
    if ( lockTimeoutHint != null ) {
        lockOptions.setTimeOut( lockTimeoutHint );
    }

    return lockOptions;
}
QueryBinder.java 文件源码 项目:lams 阅读 37 收藏 0 点赞 0 评论 0
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() );
    }
}
QueryBinder.java 文件源码 项目:lams 阅读 36 收藏 0 点赞 0 评论 0
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() );
    }
}
MugglEntityManager.java 文件源码 项目:tap17-muggl-javaee 阅读 37 收藏 0 点赞 0 评论 0
public Object createNamedQuery(Objectref objRef) {
    String namedQuery = getStringFromObjectref(objRef);
    for(Class<?> entityClass : managedEntityClasses) {
        if(entityClass.isAnnotationPresent(NamedQuery.class)) {
            if(entityClass.getAnnotation(NamedQuery.class).name().equals(namedQuery)) {
                String jpqlQueryString = entityClass.getAnnotation(NamedQuery.class).query();
                return hqlAnalyzer.getQLSelectStatement(jpqlQueryString, null);
            }
        }
    }
    return null;
}
IssueHJIII100Test.java 文件源码 项目:hyperjaxb3 阅读 30 收藏 0 点赞 0 评论 0
public void testEntityAnnotation() throws Exception {

        Assert.assertNotNull(IssueHJIII100Type.class
                .getAnnotation(NamedQuery.class));

        Assert.assertEquals(
                1,
                IssueHJIII100Type.class.getAnnotation(NamedQuery.class).hints().length);
    }
Reflection.java 文件源码 项目:query 阅读 31 收藏 0 点赞 0 评论 0
public String getQueryString(String namedQueryName) {
    NamedQueries namedQueries = (NamedQueries) entityClass.getAnnotation(NamedQueries.class);
    for (NamedQuery namedQuery : namedQueries.value()) {
        if (namedQuery.name().equals(namedQueryName)) return namedQuery.query();
    }
    throw new QueryException("Named query " + namedQueryName + " not found in class " + entityClass.getName());
}
QueryBinder.java 文件源码 项目:lams 阅读 35 收藏 0 点赞 0 评论 0
public static void bindQueries(NamedQueries queriesAnn, Mappings mappings, boolean isDefault) {
    if ( queriesAnn == null ) return;
    for (NamedQuery q : queriesAnn.value()) {
        bindQuery( q, mappings, isDefault );
    }
}
QueryBinder.java 文件源码 项目:lams 阅读 38 收藏 0 点赞 0 评论 0
public static void bindQueries(org.hibernate.annotations.NamedQueries queriesAnn, Mappings mappings) {
    if ( queriesAnn == null ) return;
    for (org.hibernate.annotations.NamedQuery q : queriesAnn.value()) {
        bindQuery( q, mappings );
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号