private Cacheable getCacheable(Element element, XMLContext.Default defaults){ if ( element != null ) { String attValue = element.attributeValue( "cacheable" ); if ( attValue != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( Cacheable.class ); ad.setValue( "value", Boolean.valueOf( attValue ) ); return AnnotationFactory.create( ad ); } } if ( defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( Cacheable.class ); } else { return null; } }
private static Cache determineCacheSettings(XClass clazzToProcess, Mappings mappings) { Cache cacheAnn = clazzToProcess.getAnnotation( Cache.class ); if ( cacheAnn != null ) { return cacheAnn; } Cacheable cacheableAnn = clazzToProcess.getAnnotation( Cacheable.class ); SharedCacheMode mode = determineSharedCacheMode( mappings ); switch ( mode ) { case ALL: { cacheAnn = buildCacheMock( clazzToProcess.getName(), mappings ); break; } case ENABLE_SELECTIVE: { if ( cacheableAnn != null && cacheableAnn.value() ) { cacheAnn = buildCacheMock( clazzToProcess.getName(), mappings ); } break; } case DISABLE_SELECTIVE: { if ( cacheableAnn == null || cacheableAnn.value() ) { cacheAnn = buildCacheMock( clazzToProcess.getName(), mappings ); } break; } default: { // treat both NONE and UNSPECIFIED the same break; } } return cacheAnn; }
protected void initByAnno(Class<?> thisType, AnnotationProvider annos) { // schema初始化 Table table = annos.getAnnotation(javax.persistence.Table.class); if (table != null) { if (table.schema().length() > 0) { schema = MetaHolder.getMappingSchema(table.schema());// 重定向 } if (table.name().length() > 0) { tableName = table.name(); } for(javax.persistence.Index index: table.indexes()){ this.indexes.add(IndexDef.create(index)); } for(javax.persistence.UniqueConstraint unique: table.uniqueConstraints()){ this.uniques.add(new UniqueConstraintDef(unique)); } } if (tableName == null) { // 表名未指定,缺省生成 boolean needTranslate = JefConfiguration.getBoolean(DbCfg.TABLE_NAME_TRANSLATE, false); if (needTranslate) { tableName = DbUtils.upperToUnderline(thisType.getSimpleName()); } else { tableName = thisType.getSimpleName(); } } BindDataSource bindDs = annos.getAnnotation(BindDataSource.class); if (bindDs != null) { this.bindDsName = MetaHolder.getMappingSite(StringUtils.trimToNull(bindDs.value())); } Cacheable cache = annos.getAnnotation(Cacheable.class); this.cacheable = cache != null && cache.value(); EasyEntity entity = annos.getAnnotation(EasyEntity.class); if (entity != null) { this.useOuterJoin = entity.useOuterJoin(); } }
@Override public boolean isCacheable() { return annotationOf(Entity.class).map(Entity::cacheable) .orElse( annotationOf(Cacheable.class).map(Cacheable::value).orElse(true)); }