Browse Source
* commit 'c62448a6d47309816238394f2b2068e45190295f': (25 commits) delete sth build jackson-core-2.3,jackson-databind,jackson-annotation-2.3 配置提交到10.0上面 1 build build build build build build 1 1 1 build build build build build build ...release/9.0
superman
7 years ago
4229 changed files with 637327 additions and 43 deletions
@ -0,0 +1,58 @@
|
||||
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
destinationDir = file('build/classes/main') |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.5 |
||||
def jarname="fr-third-9.0.jar" |
||||
def classesDir='build/classes/main' |
||||
//解压lib下的jar到classes文件夹 |
||||
jar{ |
||||
baseName="fr-third-9.0" |
||||
} |
||||
|
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=[] |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
//获取什么分支名 |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1) |
||||
def srcDir="." |
||||
|
||||
task unJar{ |
||||
ant{ |
||||
mkdir(dir:"build/classes/main") |
||||
println "------------------------------------------------unjar" |
||||
|
||||
unjar(dest:"build/classes/main"){ |
||||
fileset(dir:"../../finereport-lib-base/${branchName}"){ |
||||
include(name:'3rd.jar') |
||||
} |
||||
fileset(dir:"../../finereport-lib-other/${branchName}"){ |
||||
include(name:"batik-all-1.9.jar") |
||||
} |
||||
fileset(dir:"${srcDir}/fine-poi/lib"){ |
||||
include(name:'**/*.jar') |
||||
} |
||||
fileset(dir:"${srcDir}/fine-spring/lib"){ |
||||
include(name:'aopalliance-1.0.jar') |
||||
include(name:'aspectjweaver-1.8.4.jar') |
||||
} |
||||
fileset(dir:"${srcDir}/build/libs"){ |
||||
include(name:"*.jar") |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
destinationDir = file('build/classes/2') |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.5 |
||||
def jarname="fr-third-9.0.jar" |
||||
def classesDir='build/classes/2' |
||||
//解压lib下的jar到classes文件夹 |
||||
jar{ |
||||
baseName="fr-third_2-9.0" |
||||
} |
||||
|
||||
def srcDir="." |
||||
|
||||
//设置源码路径 |
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=[ |
||||
"${srcDir}/fine-spring/src", |
||||
"${srcDir}/fine-spring/resources" |
||||
] |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
sourceSets.main.output.classesDir = file('build/classes/2') |
||||
repositories{ |
||||
mavenCentral() |
||||
} |
||||
|
||||
//获取什么分支名 |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1) |
||||
|
||||
//指定依赖 |
||||
dependencies{ |
||||
compile fileTree(dir:"${srcDir}/fine-spring/lib",include:'**/*.jar') |
||||
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-base/${branchName}",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') |
||||
testCompile 'junit:junit:4.12' |
||||
} |
||||
|
||||
//指明无法编译文件所在路径 |
||||
def dataContent ={def dir -> |
||||
copySpec{ |
||||
from ("${dir}"){ |
||||
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
task copyFiles(type:Copy,dependsOn:'compileJava'){ |
||||
copy{ |
||||
println "------------------------------------------------copyfiles" |
||||
with dataContent.call("${srcDir}/fine-spring/src") |
||||
with dataContent.call("${srcDir}/fine-spring/resources") |
||||
into "${classesDir}" |
||||
} |
||||
} |
||||
|
||||
jar.dependsOn copyFiles |
@ -0,0 +1,76 @@
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
destinationDir = file('build/classes/3') |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.5 |
||||
def jarname="fr-third-9.0.jar" |
||||
def classesDir='build/classes/3' |
||||
def ftpreport='E:/ftp/share/report/' |
||||
//解压lib下的jar到classes文件夹 |
||||
jar{ |
||||
baseName="fr-third_3-9.0" |
||||
} |
||||
|
||||
def srcDir="." |
||||
|
||||
//设置源码路径 |
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=[ |
||||
"${srcDir}/fine-jpa/src", |
||||
"${srcDir}/fine-jboss-transaction-api/src", |
||||
"${srcDir}/fine-jboss-logging/src", |
||||
"${srcDir}/fine-classmate/src" |
||||
] |
||||
} |
||||
} |
||||
|
||||
} |
||||
sourceSets.main.output.classesDir = file('build/classes/3') |
||||
|
||||
repositories{ |
||||
mavenCentral() |
||||
} |
||||
|
||||
//获取什么分支名 |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1) |
||||
|
||||
//指定依赖 |
||||
dependencies{ |
||||
compile fileTree(dir:"${srcDir}/fine-jboss-logging/lib",include:'**/*.jar') |
||||
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-base/${branchName}",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') |
||||
testCompile 'junit:junit:4.12' |
||||
} |
||||
|
||||
//指明无法编译文件所在路径 |
||||
def dataContent ={def dir -> |
||||
copySpec{ |
||||
from ("${dir}"){ |
||||
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
task copyFiles(type:Copy,dependsOn:'compileJava'){ |
||||
copy{ |
||||
println "------------------------------------------------copyfiles" |
||||
with dataContent.call("${srcDir}/fine-jpa/src") |
||||
with dataContent.call("${srcDir}/fine-jboss-transaction-api/src") |
||||
with dataContent.call("${srcDir}/fine-jboss-logging/src") |
||||
with dataContent.call("${srcDir}/fine-classmate/src") |
||||
into "${classesDir}" |
||||
} |
||||
} |
||||
|
||||
jar.dependsOn copyFiles |
@ -0,0 +1,74 @@
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
destinationDir = file('build/classes/4') |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.5 |
||||
def jarname="fr-third-9.0.jar" |
||||
def classesDir='build/classes/4' |
||||
def ftpreport='E:/ftp/share/report/' |
||||
//解压lib下的jar到classes文件夹 |
||||
jar{ |
||||
baseName="fr-third_4-9.0" |
||||
} |
||||
|
||||
def srcDir="." |
||||
|
||||
//设置源码路径 |
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=[ |
||||
"${srcDir}/fine-hibernate/src", |
||||
"${srcDir}/fine-hibernate/resources" |
||||
] |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
sourceSets.main.output.classesDir = file('build/classes/4') |
||||
|
||||
repositories{ |
||||
mavenCentral() |
||||
} |
||||
|
||||
//获取什么分支名 |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1) |
||||
|
||||
//指定依赖 |
||||
dependencies{ |
||||
compile fileTree(dir:"${srcDir}/fine-hibernate/lib",include:'**/*.jar') |
||||
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-base/${branchName}",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') |
||||
testCompile 'junit:junit:4.12' |
||||
} |
||||
|
||||
|
||||
//指明无法编译文件所在路径 |
||||
def dataContent ={def dir -> |
||||
copySpec{ |
||||
from ("${dir}"){ |
||||
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
task copyFiles(type:Copy,dependsOn:'compileJava'){ |
||||
copy{ |
||||
println "------------------------------------------------copyfiles" |
||||
with dataContent.call("${srcDir}/fine-hibernate/src") |
||||
with dataContent.call("${srcDir}/fine-hibernate/resources") |
||||
into "${classesDir}" |
||||
} |
||||
} |
||||
|
||||
jar.dependsOn copyFiles |
@ -0,0 +1,71 @@
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
destinationDir = file('build/classes/5') |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.5 |
||||
def jarname="fr-third-9.0.jar" |
||||
def classesDir='build/classes/5' |
||||
def ftpreport='E:/ftp/share/report/' |
||||
//解压lib下的jar到classes文件夹 |
||||
jar{ |
||||
baseName="fr-third_5-9.0" |
||||
} |
||||
|
||||
def srcDir="." |
||||
|
||||
//设置源码路径 |
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=[ |
||||
"${srcDir}/fine-druid/src" |
||||
] |
||||
} |
||||
} |
||||
|
||||
} |
||||
sourceSets.main.output.classesDir = file('build/classes/5') |
||||
|
||||
repositories{ |
||||
mavenCentral() |
||||
} |
||||
|
||||
//获取什么分支名 |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1) |
||||
|
||||
//指定依赖 |
||||
dependencies{ |
||||
compile fileTree(dir:"${srcDir}/fine-druid/lib",include:'ojdbc7-12.1.0.jar') |
||||
compile fileTree(dir:"${srcDir}/fine-druid/lib",include:'**/*.jar') |
||||
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-base/${branchName}",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') |
||||
testCompile 'junit:junit:4.12' |
||||
} |
||||
|
||||
//指明无法编译文件所在路径 |
||||
def dataContent ={def dir -> |
||||
copySpec{ |
||||
from ("${dir}"){ |
||||
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
task copyFiles(type:Copy,dependsOn:'compileJava'){ |
||||
copy{ |
||||
println "------------------------------------------------copyfiles" |
||||
with dataContent.call("${srcDir}/fine-druid/src") |
||||
into "${classesDir}" |
||||
} |
||||
} |
||||
|
||||
jar.dependsOn copyFiles |
@ -0,0 +1,72 @@
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
destinationDir = file('build/classes/6') |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.5 |
||||
def jarname="fr-third-9.0.jar" |
||||
def classesDir='build/classes/6' |
||||
def ftpreport='E:/ftp/share/report/' |
||||
//解压lib下的jar到classes文件夹 |
||||
jar{ |
||||
baseName="fr-third_6-9.0" |
||||
} |
||||
|
||||
def srcDir="." |
||||
|
||||
//设置源码路径 |
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=[ |
||||
"${srcDir}/fine-jackson/src", |
||||
"${srcDir}/fine-jackson/resources" |
||||
] |
||||
} |
||||
} |
||||
|
||||
} |
||||
sourceSets.main.output.classesDir = file('build/classes/6') |
||||
|
||||
repositories{ |
||||
mavenCentral() |
||||
} |
||||
|
||||
//获取什么分支名 |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1) |
||||
|
||||
//指定依赖 |
||||
dependencies{ |
||||
compile fileTree(dir:"${srcDir}/fine-jackson/lib",include:'**/*.jar') |
||||
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-base/${branchName}",include:'**/*.jar') |
||||
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') |
||||
testCompile 'junit:junit:4.12' |
||||
} |
||||
|
||||
//指明无法编译文件所在路径 |
||||
def dataContent ={def dir -> |
||||
copySpec{ |
||||
from ("${dir}"){ |
||||
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
task copyFiles(type:Copy,dependsOn:'compileJava'){ |
||||
copy{ |
||||
println "------------------------------------------------copyfiles" |
||||
with dataContent.call("${srcDir}/fine-jackson/src") |
||||
with dataContent.call("${srcDir}/fine-jackson/resources") |
||||
into "${classesDir}" |
||||
} |
||||
} |
||||
|
||||
jar.dependsOn copyFiles |
@ -0,0 +1,6 @@
|
||||
# fine-classmate |
||||
|
||||
改包名的classmate(1.3.0),以下模块需要依赖该模块: |
||||
|
||||
- fine-hibernate |
||||
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="JAVA_MODULE" version="4"> |
||||
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
||||
<exclude-output /> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
||||
</content> |
||||
<orderEntry type="inheritedJdk" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
||||
</component> |
||||
</module> |
@ -0,0 +1,115 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.io.Serializable; |
||||
import java.lang.annotation.Annotation; |
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.util.ClassKey; |
||||
|
||||
/** |
||||
* Interface for object that determines handling of annotations in regards |
||||
* to inheritance, overrides. |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public abstract class AnnotationConfiguration implements Serializable |
||||
{ |
||||
/** |
||||
* Method called to figure out how to handle instances of specified annotation |
||||
* type when used as class annotation. |
||||
*/ |
||||
public abstract AnnotationInclusion getInclusionForClass(Class<? extends Annotation> annotationType); |
||||
|
||||
/** |
||||
* Method called to figure out how to handle instances of specified annotation |
||||
* type when used as constructor annotation. |
||||
*<p> |
||||
* Note that constructor annotations can never be inherited so this just determines |
||||
* between inclusion or non-inclusion. |
||||
*/ |
||||
public abstract AnnotationInclusion getInclusionForConstructor(Class<? extends Annotation> annotationType); |
||||
|
||||
/** |
||||
* Method called to figure out how to handle instances of specified annotation |
||||
* type when used as field annotation. |
||||
*<p> |
||||
* Note that field annotations can never be inherited so this just determines |
||||
* between inclusion or non-inclusion. |
||||
*/ |
||||
public abstract AnnotationInclusion getInclusionForField(Class<? extends Annotation> annotationType); |
||||
|
||||
/** |
||||
* Method called to figure out how to handle instances of specified annotation |
||||
* type when used as method annotation. |
||||
*<p> |
||||
* Note that method annotations can be inherited for member methods, but not for static |
||||
* methods; for static methods thereby this just determines between inclusion and |
||||
* non-inclusion. |
||||
*/ |
||||
public abstract AnnotationInclusion getInclusionForMethod(Class<? extends Annotation> annotationType); |
||||
|
||||
/** |
||||
* Method called to figure out how to handle instances of specified annotation |
||||
* type when used as parameter annotation. |
||||
*<p> |
||||
* Note that parameter annotations can be inherited for member methods, but not for static |
||||
* methods; for static methods thereby this just determines between inclusion and |
||||
* non-inclusion. |
||||
*/ |
||||
public abstract AnnotationInclusion getInclusionForParameter(Class<? extends Annotation> annotationType); |
||||
|
||||
/** |
||||
* Simple implementation that can be configured with default behavior |
||||
* for unknown annotations, as well as explicit behaviors for |
||||
* enumerated annotation types. Same default is used for both class and |
||||
* member method annotations (constructor, field and static method |
||||
* annotations are never inherited) |
||||
*/ |
||||
public static class StdConfiguration extends AnnotationConfiguration implements Serializable |
||||
{ |
||||
protected final AnnotationInclusion _defaultInclusion; |
||||
|
||||
protected final HashMap<ClassKey,AnnotationInclusion> _inclusions = new HashMap<ClassKey,AnnotationInclusion>(); |
||||
|
||||
public StdConfiguration(AnnotationInclusion defaultBehavior) |
||||
{ |
||||
_defaultInclusion = defaultBehavior; |
||||
} |
||||
|
||||
@Override |
||||
public AnnotationInclusion getInclusionForClass(Class<? extends Annotation> annotationType) { |
||||
return _inclusionFor(annotationType); |
||||
} |
||||
|
||||
@Override |
||||
public AnnotationInclusion getInclusionForConstructor(Class<? extends Annotation> annotationType) { |
||||
return _inclusionFor(annotationType); |
||||
} |
||||
|
||||
@Override |
||||
public AnnotationInclusion getInclusionForField(Class<? extends Annotation> annotationType) { |
||||
return getInclusionForClass(annotationType); |
||||
} |
||||
|
||||
@Override |
||||
public AnnotationInclusion getInclusionForMethod(Class<? extends Annotation> annotationType) { |
||||
return getInclusionForClass(annotationType); |
||||
} |
||||
|
||||
@Override |
||||
public AnnotationInclusion getInclusionForParameter(Class<? extends Annotation> annotationType) { |
||||
return getInclusionForClass(annotationType); |
||||
} |
||||
|
||||
public void setInclusion(Class<? extends Annotation> annotationType, AnnotationInclusion incl) |
||||
{ |
||||
_inclusions.put(new ClassKey(annotationType), incl); |
||||
} |
||||
|
||||
protected AnnotationInclusion _inclusionFor(Class<? extends Annotation> annotationType) |
||||
{ |
||||
ClassKey key = new ClassKey(annotationType); |
||||
AnnotationInclusion beh = _inclusions.get(key); |
||||
return (beh == null) ? _defaultInclusion : beh; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
/** |
||||
* Enumeration that defines different settings for handling behavior |
||||
* of individual annotations |
||||
*/ |
||||
public enum AnnotationInclusion |
||||
{ |
||||
/** |
||||
* Value that indicates that annotation is to be ignored, not included |
||||
* in resolved bean information. |
||||
* Applicable to all member types. |
||||
*/ |
||||
DONT_INCLUDE, |
||||
|
||||
/** |
||||
* Value that indicates that annotation is to be included in results, but |
||||
* only if directly associated with included member (or attached mix-in); |
||||
* will not inherit from supertypes. |
||||
* Applicable only to member methods; if used with other members will |
||||
* mean basic inclusion. |
||||
*/ |
||||
INCLUDE_BUT_DONT_INHERIT, |
||||
|
||||
/** |
||||
* Value that indicates that annotation is to be included in results, and |
||||
* values from overridden members are inherited only if the annotation is |
||||
* marked with the {@link java.lang.annotation.Inherited} annotation. |
||||
* Applicable only to member methods; if used with other members will |
||||
* mean basic inclusion. |
||||
*/ |
||||
INCLUDE_AND_INHERIT_IF_INHERITED, |
||||
|
||||
/** |
||||
* Value that indicates that annotation is to be included in results; and |
||||
* values from overridden members are also inherited if not overridden |
||||
* by members of subtypes. |
||||
* Note that inheritance only matters with member methods; for other types |
||||
* it just means "include". |
||||
*/ |
||||
INCLUDE_AND_INHERIT |
||||
; |
||||
|
||||
} |
@ -0,0 +1,100 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.util.ClassKey; |
||||
|
||||
/** |
||||
* Interface for object that can provide mix-ins to override annotations. |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public abstract class AnnotationOverrides implements Serializable |
||||
{ |
||||
/* |
||||
/********************************************************************** |
||||
/* Public API |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Method called to find out which class(es) are to be used as source |
||||
* for annotations to mix in for given type. |
||||
* |
||||
* @return List of mix-in sources (starting with highest priority); |
||||
* can be null or empty list if no mix-ins are to be used. |
||||
*/ |
||||
public List<Class<?>> mixInsFor(Class<?> beanClass) { |
||||
return mixInsFor(new ClassKey(beanClass)); |
||||
} |
||||
|
||||
public abstract List<Class<?>> mixInsFor(ClassKey beanClass); |
||||
|
||||
/** |
||||
* Method for constructing builder for creating simple overrides provider |
||||
* that just uses direct assignments (target-to-override classes) |
||||
*/ |
||||
public static StdBuilder builder() { |
||||
return new StdBuilder(); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Helper types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* To make it easy to use simple override implementation (where overrides |
||||
* are direct and explicit), here is a build that allow constructing |
||||
* such override instance. |
||||
*/ |
||||
public static class StdBuilder |
||||
{ |
||||
protected final HashMap<ClassKey,List<Class<?>>> _targetsToOverrides = new HashMap<ClassKey,List<Class<?>>>(); |
||||
|
||||
public StdBuilder() { } |
||||
|
||||
public StdBuilder add(Class<?> target, Class<?> mixin) { |
||||
return add(new ClassKey(target), mixin); |
||||
} |
||||
|
||||
public StdBuilder add(ClassKey target, Class<?> mixin) |
||||
{ |
||||
List<Class<?>> mixins = _targetsToOverrides.get(target); |
||||
if (mixins == null) { |
||||
mixins = new ArrayList<Class<?>>(); |
||||
_targetsToOverrides.put(target, mixins); |
||||
} |
||||
mixins.add(mixin); |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Method that will construct a {@link AnnotationOverrides} instance using |
||||
* mappings that have been added using this builder |
||||
*/ |
||||
public AnnotationOverrides build() { |
||||
return new StdImpl(_targetsToOverrides); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Simple implementation configured with explicit associations with |
||||
* target class as key, and overrides as ordered list of classes |
||||
* (with first entry having precedence over later ones). |
||||
*/ |
||||
public static class StdImpl extends AnnotationOverrides |
||||
{ |
||||
protected final HashMap<ClassKey,List<Class<?>>> _targetsToOverrides; |
||||
|
||||
public StdImpl(HashMap<ClassKey,List<Class<?>>> overrides) { |
||||
_targetsToOverrides = new HashMap<ClassKey,List<Class<?>>>(overrides); |
||||
} |
||||
|
||||
@Override |
||||
public List<Class<?>> mixInsFor(ClassKey target) { |
||||
return _targetsToOverrides.get(target); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,132 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.io.Serializable; |
||||
import java.lang.annotation.Annotation; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* Container class used for storing set of annotations resolved for types (classes) |
||||
* as members (methods, fields, constructors). |
||||
* |
||||
* @author tatu |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class Annotations implements Serializable, Iterable<Annotation> |
||||
{ |
||||
private final Annotation[] NO_ANNOTATIONS = new Annotation[0]; |
||||
|
||||
protected LinkedHashMap<Class<? extends Annotation>,Annotation> _annotations; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life-cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public Annotations() { } |
||||
|
||||
/** |
||||
* Method for adding specified annotation, overriding existing value |
||||
* for the annotation type. |
||||
*/ |
||||
public void add(Annotation override) |
||||
{ |
||||
if (_annotations == null) { |
||||
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>(); |
||||
} |
||||
_annotations.put(override.annotationType(), override); |
||||
} |
||||
|
||||
/** |
||||
* Method for adding all annotations from specified set, as overrides |
||||
* to annotations this set has |
||||
*/ |
||||
public void addAll(Annotations overrides) |
||||
{ |
||||
if (_annotations == null) { |
||||
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>(); |
||||
} |
||||
for (Annotation override : overrides._annotations.values()) { |
||||
_annotations.put(override.annotationType(), override); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Method for adding specified annotation if and only if no value |
||||
* exists for the annotation type. |
||||
*/ |
||||
public void addAsDefault(Annotation defValue) |
||||
{ |
||||
Class<? extends Annotation> type = defValue.annotationType(); |
||||
if (_annotations == null) { |
||||
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>(); |
||||
_annotations.put(type, defValue); |
||||
} else if (!_annotations.containsKey(type)) { |
||||
_annotations.put(type, defValue); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public Iterator<Annotation> iterator() |
||||
{ |
||||
if (_annotations == null) { |
||||
_annotations = new LinkedHashMap<Class<? extends Annotation>,Annotation>(); |
||||
} |
||||
return _annotations.values().iterator(); |
||||
} |
||||
|
||||
public int size() { |
||||
return (_annotations == null) ? 0 : _annotations.size(); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public <A extends Annotation> A get(Class<A> cls) |
||||
{ |
||||
if (_annotations == null) { |
||||
return null; |
||||
} |
||||
return (A) _annotations.get(cls); |
||||
} |
||||
|
||||
/** |
||||
* @since 1.1.1 |
||||
*/ |
||||
public Annotation[] asArray() { |
||||
if (_annotations == null || _annotations.isEmpty()) { |
||||
return NO_ANNOTATIONS; |
||||
} |
||||
return _annotations.values().toArray(new Annotation[_annotations.size()]); |
||||
} |
||||
|
||||
/** |
||||
* @since 1.1.1 |
||||
*/ |
||||
public List<Annotation> asList() { |
||||
if (_annotations == null || _annotations.isEmpty()) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<Annotation> l = new ArrayList<Annotation>(_annotations.size()); |
||||
l.addAll(_annotations.values()); |
||||
return l; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard method overrides |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public String toString() |
||||
{ |
||||
if (_annotations == null) { |
||||
return "[null]"; |
||||
} |
||||
return _annotations.toString(); |
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
/** |
||||
* Interface that defines API for basic filtering objects, used to prune set |
||||
* of things to include in result sets like flattened member lists. |
||||
*/ |
||||
public interface Filter<T> |
||||
{ |
||||
public boolean include(T element); |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* This class is used to pass full generics type information, and |
||||
* avoid problems with type erasure (that basically removes most |
||||
* usable type references from runtime Class objects). |
||||
* It is based on ideas from |
||||
* <a href="http://gafter.blogspot.com/2006/12/super-type-tokens.html" |
||||
* >http://gafter.blogspot.com/2006/12/super-type-tokens.html</a>,
|
||||
*<p> |
||||
* Usage is by sub-classing: here is one way to instantiate reference |
||||
* to generic type <code>List<Integer></code>: |
||||
*<pre> |
||||
* GenericType type = new GenericType<List<Integer>>() { }; |
||||
*</pre> |
||||
* which can be passed to methods that accept <code>GenericReference</code>. |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public abstract class GenericType<T> |
||||
implements Serializable, java.lang.reflect.Type |
||||
{ |
||||
protected GenericType() { } |
||||
} |
@ -0,0 +1,238 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.members.RawField; |
||||
import com.fr.third.com.fasterxml.classmate.util.ClassKey; |
||||
import com.fr.third.com.fasterxml.classmate.members.HierarchicType; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawConstructor; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawMethod; |
||||
|
||||
/** |
||||
* Builder class used to completely resolve members (fields, methods, |
||||
* constructors) of {@link ResolvedType}s (generics-aware classes). |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class MemberResolver implements Serializable |
||||
{ |
||||
|
||||
/** |
||||
* Type resolved needed for resolving types of member objects |
||||
* (method argument and return; field types; constructor argument types) |
||||
*/ |
||||
protected final TypeResolver _typeResolver; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Modifiable configuration |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Configuration setting that determines whether members from |
||||
* {@link java.lang.Object} are included or not; by default |
||||
* false meaning that they are not. |
||||
*/ |
||||
protected boolean _cfgIncludeLangObject; |
||||
|
||||
/** |
||||
* Filter used for determining whether given |
||||
* field (static or member) |
||||
* is to be included in aggregation of all |
||||
* fields. |
||||
*/ |
||||
protected Filter<RawField> _fieldFilter; |
||||
|
||||
/** |
||||
* Filter used for determining whether given |
||||
* method (static or member) |
||||
* is to be included in aggregation of all |
||||
* methods. |
||||
*/ |
||||
protected Filter<RawMethod> _methodFilter; |
||||
|
||||
/** |
||||
* Filter used for determining whether given |
||||
* constructor |
||||
* is to be included in aggregation of all |
||||
* constructors. |
||||
*/ |
||||
protected Filter<RawConstructor> _constructorFilter; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle (construct and config) |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Constructor for resolver that does not include <code>java.lang.Object</code> |
||||
* in type hierarchy |
||||
*/ |
||||
public MemberResolver(TypeResolver typeResolver) |
||||
{ |
||||
_typeResolver = typeResolver; |
||||
} |
||||
|
||||
/** |
||||
* Configuration method for specifying whether members of <code>java.lang.Object</code> |
||||
* are to be included in resolution; if false, no members from {@link java.lang.Object} |
||||
* are to be included; if true, will be included. |
||||
*/ |
||||
public MemberResolver setIncludeLangObject(boolean state) { |
||||
_cfgIncludeLangObject = state; |
||||
return this; |
||||
} |
||||
|
||||
public MemberResolver setFieldFilter(Filter<RawField> f) { |
||||
_fieldFilter = f; |
||||
return this; |
||||
} |
||||
|
||||
public MemberResolver setMethodFilter(Filter<RawMethod> f) { |
||||
_methodFilter = f; |
||||
return this; |
||||
} |
||||
|
||||
public MemberResolver setConstructorFilter(Filter<RawConstructor> f) { |
||||
_constructorFilter = f; |
||||
return this; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Public API |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Method for constructing hierarchy object needed to fully resolve |
||||
* member information, including basic type flattening as well as |
||||
* addition of mix-in types in appropriate positions. |
||||
* |
||||
* @param mainType Resolved type that is the starting point (i.e. the leaf class) |
||||
* for member resolution. |
||||
* @param annotationConfig Configuration of annotation types; which ones to include, how to inherit |
||||
* @param annotationOverrides Definitions of annotation overrides to use, if any (may be null) |
||||
*/ |
||||
public ResolvedTypeWithMembers resolve(final ResolvedType mainType, |
||||
AnnotationConfiguration annotationConfig, |
||||
AnnotationOverrides annotationOverrides) |
||||
{ |
||||
// First: flatten basic type hierarchy (highest to lowest precedence)
|
||||
HashSet<ClassKey> seenTypes = new HashSet<ClassKey>(); |
||||
ArrayList<ResolvedType> types = new ArrayList<ResolvedType>(); |
||||
_gatherTypes(mainType, seenTypes, types); |
||||
|
||||
// Second step: inject mix-ins (keeping order from highest to lowest)
|
||||
HierarchicType[] htypes; |
||||
HierarchicType mainHierarchicType = null; |
||||
|
||||
// Third step: add mix-ins (if any), reverse order (lowest to highest precedence)
|
||||
if (annotationOverrides == null) { // just create hierarchic instances:
|
||||
int len = types.size(); |
||||
htypes = new HierarchicType[len]; |
||||
for (int i = 0; i < len; ++i) { |
||||
// false -> not a mix-in
|
||||
htypes[i] = new HierarchicType(types.get(i), false, i); |
||||
} |
||||
mainHierarchicType = htypes[0]; |
||||
} else { // need to add mix-ins, reorder
|
||||
ArrayList<HierarchicType> typesWithMixins = new ArrayList<HierarchicType>(); |
||||
for (ResolvedType type : types) { |
||||
// First add mix-ins (which override type itself)
|
||||
List<Class<?>> m = annotationOverrides.mixInsFor(type.getErasedType()); |
||||
if (m != null) { |
||||
for (Class<?> mixinClass : m) { |
||||
_addOverrides(typesWithMixins, seenTypes, mixinClass); |
||||
} |
||||
} |
||||
|
||||
// Then actual type:
|
||||
HierarchicType ht = new HierarchicType(type, false, typesWithMixins.size()); |
||||
if (mainHierarchicType == null) { |
||||
mainHierarchicType = ht; |
||||
} |
||||
typesWithMixins.add(ht); |
||||
} |
||||
htypes = typesWithMixins.toArray(new HierarchicType[typesWithMixins.size()]); |
||||
} |
||||
// And that's about all we need to do; rest computed lazily
|
||||
return new ResolvedTypeWithMembers(_typeResolver, annotationConfig, mainHierarchicType, htypes, |
||||
_constructorFilter, _fieldFilter, _methodFilter); |
||||
} |
||||
|
||||
private void _addOverrides(List<HierarchicType> typesWithOverrides, Set<ClassKey> seenTypes, Class<?> override) |
||||
{ |
||||
ClassKey key = new ClassKey(override); |
||||
if (!seenTypes.contains(key)) { |
||||
seenTypes.add(key); |
||||
ResolvedType resolvedOverride = _typeResolver.resolve(override); |
||||
typesWithOverrides.add(new HierarchicType(resolvedOverride, true, typesWithOverrides.size())); |
||||
for (ResolvedType r : resolvedOverride.getImplementedInterfaces()) { // interfaces?
|
||||
_addOverrides(typesWithOverrides, seenTypes, r); |
||||
} |
||||
ResolvedType superClass = resolvedOverride.getParentClass(); |
||||
_addOverrides(typesWithOverrides, seenTypes, superClass); |
||||
} |
||||
} |
||||
|
||||
private void _addOverrides(List<HierarchicType> typesWithOverrides, Set<ClassKey> seenTypes, ResolvedType override) |
||||
{ |
||||
if (override == null) return; |
||||
// first: may need to exclude Object.class:
|
||||
Class<?> raw = override.getErasedType(); |
||||
if (!_cfgIncludeLangObject && Object.class == raw) return; |
||||
ClassKey key = new ClassKey(raw); |
||||
if (!seenTypes.contains(key)) { |
||||
seenTypes.add(key); |
||||
typesWithOverrides.add(new HierarchicType(override, true, typesWithOverrides.size())); |
||||
for (ResolvedType r : override.getImplementedInterfaces()) { // interfaces?
|
||||
_addOverrides(typesWithOverrides, seenTypes, r); |
||||
} |
||||
ResolvedType superClass = override.getParentClass(); |
||||
if (superClass != null) { |
||||
_addOverrides(typesWithOverrides, seenTypes, superClass); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Internal methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected void _gatherTypes(ResolvedType currentType, Set<ClassKey> seenTypes, List<ResolvedType> types) |
||||
{ |
||||
// may get called with null if no parent type
|
||||
if (currentType == null) { |
||||
return; |
||||
} |
||||
Class<?> raw = currentType.getErasedType(); |
||||
// Also, don't include Object.class unless that's ok
|
||||
if (!_cfgIncludeLangObject && raw == Object.class) { |
||||
return; |
||||
} |
||||
// Finally, only include first instance of an interface, so:
|
||||
ClassKey key = new ClassKey(currentType.getErasedType()); |
||||
if (seenTypes.contains(key)) { |
||||
return; |
||||
} |
||||
// If all good so far, append
|
||||
seenTypes.add(key); |
||||
types.add(currentType); |
||||
/* and check supertypes; starting with interfaces. Why interfaces? |
||||
* So that "highest" interfaces get priority; otherwise we'd recurse |
||||
* super-class stack and actually start with the bottom. Usually makes |
||||
* little difference, but in cases where it does this seems like the |
||||
* correct order. |
||||
*/ |
||||
for (ResolvedType t : currentType.getImplementedInterfaces()) { |
||||
_gatherTypes(t, seenTypes, types); |
||||
} |
||||
// and then superclass
|
||||
_gatherTypes(currentType.getParentClass(), seenTypes, types); |
||||
} |
||||
} |
@ -0,0 +1,403 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.members.RawConstructor; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawField; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawMethod; |
||||
|
||||
import java.lang.reflect.Constructor; |
||||
import java.lang.reflect.Field; |
||||
import java.lang.reflect.Method; |
||||
import java.lang.reflect.Modifier; |
||||
import java.lang.reflect.Type; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
public abstract class ResolvedType |
||||
implements Type |
||||
{ |
||||
public final static ResolvedType[] NO_TYPES = new ResolvedType[0]; |
||||
|
||||
protected final static RawConstructor[] NO_CONSTRUCTORS = new RawConstructor[0]; |
||||
protected final static RawField[] NO_FIELDS = new RawField[0]; |
||||
protected final static RawMethod[] NO_METHODS = new RawMethod[0]; |
||||
|
||||
protected final Class<?> _erasedType; |
||||
|
||||
/** |
||||
* Type bindings active when resolving members (methods, fields, |
||||
* constructors) of this type |
||||
*/ |
||||
protected final TypeBindings _typeBindings; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected ResolvedType(Class<?> cls, TypeBindings bindings) |
||||
{ |
||||
_erasedType = cls; |
||||
_typeBindings = (bindings == null) ? TypeBindings.emptyBindings() : bindings; |
||||
} |
||||
|
||||
/** |
||||
* Method that can be used to check if call to {@link TypeResolver#resolveSubtype(ResolvedType, Class)} |
||||
* may ever succeed; if false, it will fail with an exception, if true, it may succeed. |
||||
*/ |
||||
public abstract boolean canCreateSubtypes(); |
||||
|
||||
/** |
||||
* Method that can be used to check if call to {@link TypeResolver#resolveSubtype(ResolvedType, Class)} |
||||
* will succeed for specific type; if false, it will fail with an exception; if tru it |
||||
* will succeed. |
||||
*/ |
||||
public final boolean canCreateSubtype(Class<?> subtype) { |
||||
return canCreateSubtypes() && _erasedType.isAssignableFrom(subtype); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Returns type-erased Class<?> that this resolved type has. |
||||
*/ |
||||
public Class<?> getErasedType() { return _erasedType; } |
||||
|
||||
/** |
||||
* Returns parent class of this type, if it has one; primitive types |
||||
* and interfaces have no parent class, nor does Object type |
||||
* {@link java.lang.Object}. |
||||
* Also, placeholders for cyclic (recursive) types return null for |
||||
* this method. |
||||
*/ |
||||
public abstract ResolvedType getParentClass(); |
||||
|
||||
/** |
||||
* Accessor that must be used to find out actual type in |
||||
* case of "self-reference"; case where type refers |
||||
* recursive to itself (like, <code>T implements Comparable<T></code>). |
||||
* For all other types returns null but for self-references "real" type. |
||||
* Separate accessor is provided to avoid accidental infinite loops. |
||||
*/ |
||||
public abstract ResolvedType getSelfReferencedType(); |
||||
|
||||
/** |
||||
* Method that can be used to access element type of array types; will return |
||||
* null for non-array types, and non-null type for array types. |
||||
*/ |
||||
public abstract ResolvedType getArrayElementType(); |
||||
|
||||
/** |
||||
* Returns ordered list of interfaces (in declaration order) that this type |
||||
* implements. |
||||
* |
||||
* @return List of interfaces this type implements, if any; empty list if none |
||||
*/ |
||||
public abstract List<ResolvedType> getImplementedInterfaces(); |
||||
|
||||
/** |
||||
* Returns list of generic type declarations for this type, in order they |
||||
* are declared in class description. |
||||
*/ |
||||
public List<ResolvedType> getTypeParameters() { |
||||
return _typeBindings.getTypeParameters(); |
||||
} |
||||
|
||||
/** |
||||
* Method for accessing bindings of type variables to resolved types in context |
||||
* of this type. It has same number of entries as return List of |
||||
* {@link #getTypeParameters}, accessible using declared name to which they |
||||
* bind; for example, {@link java.util.Map} has 2 type bindings; one for |
||||
* key type (name "K", from Map.java) and one for value type |
||||
* (name "V", from Map.java). |
||||
*/ |
||||
public TypeBindings getTypeBindings() { return _typeBindings; } |
||||
|
||||
/** |
||||
* Method that will try to find type parameterization this type |
||||
* has for specified super type |
||||
* |
||||
* @return List of type parameters for specified supertype (which may |
||||
* be empty, if supertype is not a parametric type); null if specified |
||||
* type is not a super type of this type |
||||
*/ |
||||
public List<ResolvedType> typeParametersFor(Class<?> erasedSupertype) |
||||
{ |
||||
ResolvedType type = findSupertype(erasedSupertype); |
||||
if (type != null) { |
||||
return type.getTypeParameters(); |
||||
} |
||||
// nope; doesn't look like we extend or implement super type in question
|
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* Method for finding super type of this type that has specified type |
||||
* erased signature. If supertype is an interface which is implemented |
||||
* using multiple inheritance paths, preference is given to interfaces |
||||
* implemented "highest up the stack" (directly implemented interfaces |
||||
* over interfaces superclass implements). |
||||
*/ |
||||
public ResolvedType findSupertype(Class<?> erasedSupertype) |
||||
{ |
||||
if (erasedSupertype == _erasedType) { |
||||
return this; |
||||
} |
||||
// Check super interfaces first:
|
||||
if (erasedSupertype.isInterface()) { |
||||
for (ResolvedType it : getImplementedInterfaces()) { |
||||
ResolvedType type = it.findSupertype(erasedSupertype); |
||||
if (type != null) { |
||||
return type; |
||||
} |
||||
} |
||||
} |
||||
// and if not found, super class and its supertypes
|
||||
ResolvedType pc = getParentClass(); |
||||
if (pc != null) { |
||||
ResolvedType type = pc.findSupertype(erasedSupertype); |
||||
if (type != null) { |
||||
return type; |
||||
} |
||||
} |
||||
// nope; doesn't look like we extend or implement super type in question
|
||||
return null; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for simple properties |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public abstract boolean isInterface(); |
||||
public final boolean isConcrete() { return !isAbstract(); } |
||||
public abstract boolean isAbstract(); |
||||
|
||||
/** |
||||
* Method that indicates whether this type is an array type. |
||||
*/ |
||||
public abstract boolean isArray(); |
||||
|
||||
/** |
||||
* Method that indicates whether this type is one of small number of primitive |
||||
* Java types; not including array types of primitive types but just basic |
||||
* primitive types. |
||||
*/ |
||||
public abstract boolean isPrimitive(); |
||||
|
||||
public final boolean isInstanceOf(Class<?> type) { |
||||
return type.isAssignableFrom(_erasedType); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for raw (minimally procesed) members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public List<RawConstructor> getConstructors() { return Collections.emptyList(); } |
||||
public List<RawField> getMemberFields() { return Collections.emptyList(); } |
||||
public List<RawMethod> getMemberMethods() { return Collections.emptyList(); } |
||||
public List<RawField> getStaticFields() { return Collections.emptyList(); } |
||||
public List<RawMethod> getStaticMethods() { return Collections.emptyList(); } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* String representations |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Method that returns full generic signature of the type; suitable |
||||
* as signature for things like ASM package. |
||||
*/ |
||||
public String getSignature() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
return appendSignature(sb).toString(); |
||||
} |
||||
|
||||
/** |
||||
* Method that returns type erased signature of the type; suitable |
||||
* as non-generic signature some packages need |
||||
*/ |
||||
public String getErasedSignature() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
return appendErasedSignature(sb).toString(); |
||||
} |
||||
|
||||
/** |
||||
* Human-readable full description of type, which includes specification |
||||
* of super types (in brief format) |
||||
*/ |
||||
public String getFullDescription() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
return appendFullDescription(sb).toString(); |
||||
} |
||||
|
||||
/** |
||||
* Human-readable brief description of type, which does not include |
||||
* information about super types. |
||||
*/ |
||||
public String getBriefDescription() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
return appendBriefDescription(sb).toString(); |
||||
} |
||||
|
||||
public abstract StringBuilder appendBriefDescription(StringBuilder sb); |
||||
public abstract StringBuilder appendFullDescription(StringBuilder sb); |
||||
public abstract StringBuilder appendSignature(StringBuilder sb); |
||||
public abstract StringBuilder appendErasedSignature(StringBuilder sb); |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public String toString() { |
||||
return getBriefDescription(); |
||||
} |
||||
|
||||
@Override public int hashCode() { |
||||
return _erasedType.getName().hashCode() + _typeBindings.hashCode(); |
||||
} |
||||
|
||||
@Override public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
// sub-types must be same:
|
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
// Should be possible to actually implement here...
|
||||
ResolvedType other = (ResolvedType) o; |
||||
if (other._erasedType != _erasedType) { |
||||
return false; |
||||
} |
||||
// and type bindings must match as well
|
||||
return _typeBindings.equals(other._typeBindings); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Helper methods for sub-classes; string construction |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected StringBuilder _appendClassSignature(StringBuilder sb) |
||||
{ |
||||
sb.append('L'); |
||||
sb = _appendClassName(sb); |
||||
int count = _typeBindings.size(); |
||||
if (count > 0) { |
||||
sb.append('<'); |
||||
for (int i = 0; i < count; ++i) { |
||||
sb = _typeBindings.getBoundType(i).appendErasedSignature(sb); |
||||
} |
||||
sb.append('>'); |
||||
} |
||||
sb.append(';'); |
||||
return sb; |
||||
} |
||||
|
||||
protected StringBuilder _appendErasedClassSignature(StringBuilder sb) |
||||
{ |
||||
sb.append('L'); |
||||
sb = _appendClassName(sb); |
||||
sb.append(';'); |
||||
return sb; |
||||
} |
||||
|
||||
protected StringBuilder _appendClassDescription(StringBuilder sb) |
||||
{ |
||||
sb.append(_erasedType.getName()); |
||||
int count = _typeBindings.size(); |
||||
if (count > 0) { |
||||
sb.append('<'); |
||||
for (int i = 0; i < count; ++i) { |
||||
if (i > 0) { |
||||
sb.append(','); |
||||
} |
||||
sb = _typeBindings.getBoundType(i).appendBriefDescription(sb); |
||||
} |
||||
sb.append('>'); |
||||
} |
||||
return sb; |
||||
} |
||||
|
||||
protected StringBuilder _appendClassName(StringBuilder sb) |
||||
{ |
||||
String name = _erasedType.getName(); |
||||
for (int i = 0, len = name.length(); i < len; ++i) { |
||||
char c = name.charAt(i); |
||||
if (c == '.') c = '/'; |
||||
sb.append(c); |
||||
} |
||||
return sb; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Helper methods for sub-classes; gathering members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* @param statics Whether to return static methods (true) or member methods (false) |
||||
*/ |
||||
protected RawField[] _getFields(boolean statics) |
||||
{ |
||||
ArrayList<RawField> fields = new ArrayList<RawField>(); |
||||
for (Field f : _erasedType.getDeclaredFields()) { |
||||
// Only skip synthetic fields, which should not really be exposed
|
||||
if (!f.isSynthetic()) { |
||||
if (Modifier.isStatic(f.getModifiers()) == statics) { |
||||
fields.add(new RawField(this, f)); |
||||
} |
||||
} |
||||
} |
||||
if (fields.isEmpty()) { |
||||
return NO_FIELDS; |
||||
} |
||||
return fields.toArray(new RawField[fields.size()]); |
||||
} |
||||
|
||||
/** |
||||
* @param statics Whether to return static methods (true) or member methods (false) |
||||
*/ |
||||
protected RawMethod[] _getMethods(boolean statics) |
||||
{ |
||||
ArrayList<RawMethod> methods = new ArrayList<RawMethod>(); |
||||
for (Method m : _erasedType.getDeclaredMethods()) { |
||||
// Only skip synthetic fields, which should not really be exposed
|
||||
if (!m.isSynthetic()) { |
||||
if (Modifier.isStatic(m.getModifiers()) == statics) { |
||||
methods.add(new RawMethod(this, m)); |
||||
} |
||||
} |
||||
} |
||||
if (methods.isEmpty()) { |
||||
return NO_METHODS; |
||||
} |
||||
return methods.toArray(new RawMethod[methods.size()]); |
||||
} |
||||
|
||||
protected RawConstructor[] _getConstructors() |
||||
{ |
||||
ArrayList<RawConstructor> ctors = new ArrayList<RawConstructor>(); |
||||
for (Constructor<?> c : _erasedType.getDeclaredConstructors()) { |
||||
// Only skip synthetic fields, which should not really be exposed
|
||||
if (!c.isSynthetic()) { |
||||
ctors.add(new RawConstructor(this, c)); |
||||
} |
||||
} |
||||
if (ctors.isEmpty()) { |
||||
return NO_CONSTRUCTORS; |
||||
} |
||||
return ctors.toArray(new RawConstructor[ctors.size()]); |
||||
} |
||||
} |
@ -0,0 +1,721 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.lang.annotation.Annotation; |
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.reflect.Constructor; |
||||
import java.lang.reflect.Field; |
||||
import java.lang.reflect.Method; |
||||
import java.lang.reflect.Type; |
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.members.HierarchicType; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawConstructor; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawField; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawMethod; |
||||
import com.fr.third.com.fasterxml.classmate.members.ResolvedConstructor; |
||||
import com.fr.third.com.fasterxml.classmate.members.ResolvedField; |
||||
import com.fr.third.com.fasterxml.classmate.members.ResolvedMethod; |
||||
import com.fr.third.com.fasterxml.classmate.util.MethodKey; |
||||
|
||||
/** |
||||
* Class that contains information about fully resolved members of a |
||||
* type; resolution meaning that masking is handled for methods, and |
||||
* all inheritable annotations are flattened using optional overrides |
||||
* as well ("mix-in annotations"). |
||||
* Instances are created by {@link MemberResolver}. |
||||
*<p> |
||||
* Note that instances are not thread-safe, as the expectation is that instances |
||||
* will not be shared (unlike raw members or resolved types) |
||||
*/ |
||||
public class ResolvedTypeWithMembers |
||||
{ |
||||
private final static ResolvedType[] NO_RESOLVED_TYPES = new ResolvedType[0]; |
||||
|
||||
private final static ResolvedMethod[] NO_RESOLVED_METHODS = new ResolvedMethod[0]; |
||||
private final static ResolvedField[] NO_RESOLVED_FIELDS = new ResolvedField[0]; |
||||
private final static ResolvedConstructor[] NO_RESOLVED_CONSTRUCTORS = new ResolvedConstructor[0]; |
||||
|
||||
/** |
||||
* Default annotation configuration is to ignore all annotations types. |
||||
*/ |
||||
protected final static AnnotationConfiguration DEFAULT_ANNOTATION_CONFIG |
||||
= new AnnotationConfiguration.StdConfiguration(AnnotationInclusion.DONT_INCLUDE); |
||||
|
||||
/** |
||||
* Need to be able to resolve member types still |
||||
*/ |
||||
protected final TypeResolver _typeResolver; |
||||
|
||||
/** |
||||
* Handler for resolving annotation information |
||||
*/ |
||||
protected final AnnotationHandler _annotationHandler; |
||||
|
||||
/** |
||||
* Leaf of the type hierarchy, i.e. type from which this hierarchy |
||||
* was generated. |
||||
*/ |
||||
protected final HierarchicType _mainType; |
||||
|
||||
/** |
||||
* All types that hierarchy contains, in order of increasing precedence |
||||
* (that is, later entries override members of earlier members) |
||||
*/ |
||||
protected final HierarchicType[] _types; |
||||
|
||||
/** |
||||
* Filter to use for selecting fields to include |
||||
*/ |
||||
protected Filter<RawField> _fieldFilter; |
||||
|
||||
/** |
||||
* Filter to use for selecting constructors to include |
||||
*/ |
||||
protected Filter<RawConstructor> _constructorFilter; |
||||
|
||||
/** |
||||
* Filter to use for selecting methods to include |
||||
*/ |
||||
protected Filter<RawMethod> _methodFilter; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Lazily constructed members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected ResolvedMethod[] _staticMethods = null; |
||||
|
||||
protected ResolvedField[] _staticFields = null; |
||||
|
||||
protected ResolvedMethod[] _memberMethods = null; |
||||
|
||||
protected ResolvedField[] _memberFields = null; |
||||
|
||||
protected ResolvedConstructor[] _constructors = null; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle at this point |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public ResolvedTypeWithMembers(TypeResolver typeResolver, AnnotationConfiguration annotationConfig, |
||||
HierarchicType mainType, HierarchicType[] types, |
||||
Filter<RawConstructor> constructorFilter, Filter<RawField> fieldFilter, Filter<RawMethod> methodFilter) |
||||
{ |
||||
_typeResolver = typeResolver; |
||||
_mainType = mainType; |
||||
_types = types; |
||||
if (annotationConfig == null) { |
||||
annotationConfig = DEFAULT_ANNOTATION_CONFIG; |
||||
} |
||||
_annotationHandler = new AnnotationHandler(annotationConfig); |
||||
_constructorFilter = constructorFilter; |
||||
_fieldFilter = fieldFilter; |
||||
_methodFilter = methodFilter; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Public API, access to component types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public int size() { return _types.length; } |
||||
|
||||
/** |
||||
* Accessor for getting full type hierarchy as priority-ordered list, from |
||||
* the lowest precedence to highest precedence (main type, its mix-in overrides) |
||||
*/ |
||||
public List<HierarchicType> allTypesAndOverrides() { |
||||
return Arrays.asList(_types); |
||||
} |
||||
|
||||
/** |
||||
* Accessor for getting subset of type hierarchy which only contains main type |
||||
* and possible overrides (mix-ins) it has, but not supertypes or their overrides. |
||||
*/ |
||||
public List<HierarchicType> mainTypeAndOverrides() |
||||
{ |
||||
List<HierarchicType> l = Arrays.asList(_types); |
||||
int end = _mainType.getPriority() + 1; |
||||
if (end < l.size()) { |
||||
l = l.subList(0, end); |
||||
} |
||||
return l; |
||||
} |
||||
|
||||
/** |
||||
* Accessor for finding just overrides for the main type (if any). |
||||
*/ |
||||
public List<HierarchicType> overridesOnly() |
||||
{ |
||||
int index = _mainType.getPriority(); |
||||
if (index == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
List<HierarchicType> l = Arrays.asList(_types); |
||||
return l.subList(0, index); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Public API, actual resolution of members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Method for finding all static fields of the main type (except for ones |
||||
* possibly filtered out by filter) and applying annotation overrides, if any, |
||||
* to annotations. |
||||
* |
||||
* @since 1.2.0 |
||||
*/ |
||||
public ResolvedField[] getStaticFields() |
||||
{ |
||||
if (_staticFields == null) { |
||||
_staticFields = resolveStaticFields(); |
||||
} |
||||
return _staticFields; |
||||
} |
||||
|
||||
/** |
||||
* Method for finding all static methods of the main type (except for ones |
||||
* possibly filtered out by filter) and applying annotation overrides, if any, |
||||
* to annotations. |
||||
*/ |
||||
public ResolvedMethod[] getStaticMethods() |
||||
{ |
||||
if (_staticMethods == null) { |
||||
_staticMethods = resolveStaticMethods(); |
||||
} |
||||
return _staticMethods; |
||||
} |
||||
|
||||
public ResolvedField[] getMemberFields() |
||||
{ |
||||
if (_memberFields == null) { |
||||
_memberFields = resolveMemberFields(); |
||||
} |
||||
return _memberFields; |
||||
} |
||||
|
||||
public ResolvedMethod[] getMemberMethods() |
||||
{ |
||||
if (_memberMethods == null) { |
||||
_memberMethods = resolveMemberMethods(); |
||||
} |
||||
return _memberMethods; |
||||
} |
||||
|
||||
public ResolvedConstructor[] getConstructors() |
||||
{ |
||||
if (_constructors == null) { |
||||
_constructors = resolveConstructors(); |
||||
} |
||||
return _constructors; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Internal methods: actual resolution |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Method that will actually resolve full information (types, annotations) |
||||
* for constructors of the main type. |
||||
*/ |
||||
protected ResolvedConstructor[] resolveConstructors() |
||||
{ |
||||
// First get static methods for main type, filter
|
||||
LinkedHashMap<MethodKey, ResolvedConstructor> constructors = new LinkedHashMap<MethodKey, ResolvedConstructor>(); |
||||
for (RawConstructor constructor : _mainType.getType().getConstructors()) { |
||||
// no filter for constructors (yet?)
|
||||
if (_constructorFilter == null || _constructorFilter.include(constructor)) { |
||||
constructors.put(constructor.createKey(), resolveConstructor(constructor)); |
||||
} |
||||
} |
||||
// then apply overrides (mix-ins):
|
||||
for (HierarchicType type : overridesOnly()) { |
||||
for (RawConstructor raw : type.getType().getConstructors()) { |
||||
ResolvedConstructor constructor = constructors.get(raw.createKey()); |
||||
// must override something, otherwise to ignore
|
||||
if (constructor != null) { |
||||
for (Annotation ann : raw.getAnnotations()) { |
||||
if (_annotationHandler.includeMethodAnnotation(ann)) { |
||||
constructor.applyOverride(ann); |
||||
} |
||||
} |
||||
|
||||
// and parameter annotations
|
||||
Annotation[][] params = raw.getRawMember().getParameterAnnotations(); |
||||
for (int i = 0; i < params.length; i++) { |
||||
for (Annotation annotation : params[i]) { |
||||
if (_annotationHandler.includeParameterAnnotation(annotation)) { |
||||
constructor.applyParamOverride(i, annotation); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (constructors.size() == 0) { |
||||
return NO_RESOLVED_CONSTRUCTORS; |
||||
} |
||||
return constructors.values().toArray(new ResolvedConstructor[constructors.size()]); |
||||
} |
||||
|
||||
/** |
||||
* Method for fully resolving field definitions and associated annotations. |
||||
* Neither field definitions nor associated annotations inherit, but we may |
||||
* still need to add annotation overrides, as well as filter out filters |
||||
* and annotations that caller is not interested in. |
||||
*/ |
||||
protected ResolvedField[] resolveMemberFields() |
||||
{ |
||||
LinkedHashMap<String, ResolvedField> fields = new LinkedHashMap<String, ResolvedField>(); |
||||
|
||||
/* Fields need different handling: must start from bottom; and annotations only get added |
||||
* as overrides, never as defaults. And sub-classes fully mask fields. This makes |
||||
* handling bit simpler than that of member methods. |
||||
*/ |
||||
for (int typeIndex = _types.length; --typeIndex >= 0; ) { |
||||
HierarchicType thisType = _types[typeIndex]; |
||||
// If it's just a mix-in, add annotations as overrides
|
||||
if (thisType.isMixin()) { |
||||
for (RawField raw : thisType.getType().getMemberFields()) { |
||||
if ((_fieldFilter != null) && !_fieldFilter.include(raw)) { |
||||
continue; |
||||
} |
||||
ResolvedField field = fields.get(raw.getName()); |
||||
if (field != null) { |
||||
for (Annotation ann : raw.getAnnotations()) { |
||||
if (_annotationHandler.includeMethodAnnotation(ann)) { |
||||
field.applyOverride(ann); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else { // If actual type, add fields, masking whatever might have existed before:
|
||||
for (RawField field : thisType.getType().getMemberFields()) { |
||||
if ((_fieldFilter != null) && !_fieldFilter.include(field)) { |
||||
continue; |
||||
} |
||||
fields.put(field.getName(), resolveField(field)); |
||||
} |
||||
} |
||||
} |
||||
// and that's it?
|
||||
if (fields.size() == 0) { |
||||
return NO_RESOLVED_FIELDS; |
||||
} |
||||
return fields.values().toArray(new ResolvedField[fields.size()]); |
||||
} |
||||
|
||||
protected ResolvedMethod[] resolveMemberMethods() |
||||
{ |
||||
LinkedHashMap<MethodKey, ResolvedMethod> methods = new LinkedHashMap<MethodKey, ResolvedMethod>(); |
||||
LinkedHashMap<MethodKey, Annotations> overrides = new LinkedHashMap<MethodKey, Annotations>(); |
||||
LinkedHashMap<MethodKey, Annotations[]> paramOverrides = new LinkedHashMap<MethodKey, Annotations[]>(); |
||||
|
||||
/* Member methods are handled from top to bottom; and annotations are tracked |
||||
* alongside (for overrides), as well as "merged down" for inheritable |
||||
* annotations. |
||||
*/ |
||||
for (HierarchicType type : allTypesAndOverrides()) { |
||||
for (RawMethod method : type.getType().getMemberMethods()) { |
||||
// First: ignore methods caller is not interested
|
||||
if (_methodFilter != null && !_methodFilter.include(method)) { |
||||
continue; |
||||
} |
||||
|
||||
MethodKey key = method.createKey(); |
||||
ResolvedMethod old = methods.get(key); |
||||
|
||||
// Ok, now, mix-ins only contribute annotations; whereas 'real' types methods
|
||||
if (type.isMixin()) { // mix-in: only get annotations
|
||||
for (Annotation ann : method.getAnnotations()) { |
||||
// If already have a method, must be inheritable to include
|
||||
if (old != null) { |
||||
if (!methodCanInherit(ann)) { |
||||
continue; |
||||
} |
||||
// and if so, apply as default (i.e. do not override)
|
||||
old.applyDefault(ann); |
||||
} else { // If no method, need to add to annotation override map
|
||||
Annotations oldAnn = overrides.get(key); |
||||
if (oldAnn == null) { |
||||
oldAnn = new Annotations(); |
||||
oldAnn.add(ann); |
||||
overrides.put(key, oldAnn); |
||||
} else { |
||||
oldAnn.addAsDefault(ann); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// override argument annotations
|
||||
final Annotation[][] argAnnotations = method.getRawMember().getParameterAnnotations(); |
||||
if (old == null) { // no method (yet), add argument annotations to override map
|
||||
Annotations[] oldParamAnns = paramOverrides.get(key); |
||||
if (oldParamAnns == null) { // no existing argument annotations for method
|
||||
oldParamAnns = new Annotations[argAnnotations.length]; |
||||
for (int i = 0; i < argAnnotations.length; i++) { |
||||
oldParamAnns[i] = new Annotations(); |
||||
for (final Annotation annotation : argAnnotations[i]) { |
||||
if (parameterCanInherit(annotation)) { |
||||
oldParamAnns[i].add(annotation); |
||||
} |
||||
} |
||||
} |
||||
paramOverrides.put(key, oldParamAnns); |
||||
} else { |
||||
for (int i = 0; i < argAnnotations.length; i++) { |
||||
for (final Annotation annotation : argAnnotations[i]) { |
||||
if (parameterCanInherit(annotation)) { |
||||
oldParamAnns[i].addAsDefault(annotation); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else { // already have a method, apply argument annotations as defaults
|
||||
for (int i = 0; i < argAnnotations.length; i++) { |
||||
for (final Annotation annotation : argAnnotations[i]) { |
||||
if (parameterCanInherit(annotation)) { |
||||
old.applyParamDefault(i, annotation); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else { // "real" methods; add if not present, possibly add defaults as well
|
||||
if (old == null) { // new one to add
|
||||
ResolvedMethod newMethod = resolveMethod(method); |
||||
methods.put(key, newMethod); |
||||
// But we may also have annotation overrides, so:
|
||||
Annotations overrideAnn = overrides.get(key); |
||||
if (overrideAnn != null) { |
||||
newMethod.applyOverrides(overrideAnn); |
||||
} |
||||
// and apply parameter annotation overrides
|
||||
Annotations[] annotations = paramOverrides.get(key); |
||||
if (annotations != null) { |
||||
for (int i = 0; i < annotations.length; i++) { |
||||
newMethod.applyParamOverrides(i, annotations[i]); |
||||
} |
||||
} |
||||
} else { // method masked by something else? can only contribute annotations
|
||||
for (Annotation ann : method.getAnnotations()) { |
||||
if (methodCanInherit(ann)) { |
||||
old.applyDefault(ann); |
||||
} |
||||
} |
||||
// and parameter annotations
|
||||
final Annotation[][] parameterAnnotations = method.getRawMember().getParameterAnnotations(); |
||||
for (int i = 0; i < parameterAnnotations.length; i++) { |
||||
for (final Annotation annotation : parameterAnnotations[i]) { |
||||
if (parameterCanInherit(annotation)) { |
||||
old.applyParamDefault(i, annotation); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (methods.size() == 0) { |
||||
return NO_RESOLVED_METHODS; |
||||
} |
||||
return methods.values().toArray(new ResolvedMethod[methods.size()]); |
||||
} |
||||
|
||||
/** |
||||
* Method for fully resolving static field definitions and associated annotations. |
||||
* Neither field definitions nor associated annotations inherit, but we may |
||||
* still need to add annotation overrides, as well as filter out filters |
||||
* and annotations that caller is not interested in. |
||||
* |
||||
* @since 1.2.0 |
||||
*/ |
||||
protected ResolvedField[] resolveStaticFields() |
||||
{ |
||||
// First get static methods for main type, filter
|
||||
LinkedHashMap<String, ResolvedField> fields = new LinkedHashMap<String, ResolvedField>(); |
||||
for (RawField field : _mainType.getType().getStaticFields()) { |
||||
if (_fieldFilter == null || _fieldFilter.include(field)) { |
||||
fields.put(field.getName(), resolveField(field)); |
||||
} |
||||
} |
||||
// then apply overrides (mix-ins):
|
||||
for (HierarchicType type : overridesOnly()) { |
||||
for (RawField raw : type.getType().getStaticFields()) { |
||||
ResolvedField field = fields.get(raw.getName()); |
||||
// must override something, otherwise to ignore
|
||||
if (field != null) { |
||||
for (Annotation ann : raw.getAnnotations()) { |
||||
if (_annotationHandler.includeFieldAnnotation(ann)) { |
||||
field.applyOverride(ann); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
// and that's it?
|
||||
if (fields.isEmpty()) { |
||||
return NO_RESOLVED_FIELDS; |
||||
} |
||||
return fields.values().toArray(new ResolvedField[ fields.size()]); |
||||
} |
||||
|
||||
/** |
||||
* Method that will actually resolve full information (types, annotations) |
||||
* for static methods, using configured filter. |
||||
*/ |
||||
protected ResolvedMethod[] resolveStaticMethods() |
||||
{ |
||||
// First get static methods for main type, filter
|
||||
LinkedHashMap<MethodKey, ResolvedMethod> methods = new LinkedHashMap<MethodKey, ResolvedMethod>(); |
||||
for (RawMethod method : _mainType.getType().getStaticMethods()) { |
||||
if (_methodFilter == null || _methodFilter.include(method)) { |
||||
methods.put(method.createKey(), resolveMethod(method)); |
||||
} |
||||
} |
||||
// then apply overrides (mix-ins):
|
||||
for (HierarchicType type : overridesOnly()) { |
||||
for (RawMethod raw : type.getType().getStaticMethods()) { |
||||
ResolvedMethod method = methods.get(raw.createKey()); |
||||
// must override something, otherwise to ignore
|
||||
if (method != null) { |
||||
for (Annotation ann : raw.getAnnotations()) { |
||||
if (_annotationHandler.includeMethodAnnotation(ann)) { |
||||
method.applyOverride(ann); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (methods.size() == 0) { |
||||
return NO_RESOLVED_METHODS; |
||||
} |
||||
return methods.values().toArray(new ResolvedMethod[methods.size()]); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Helper methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Method for resolving individual constructor completely |
||||
*/ |
||||
protected ResolvedConstructor resolveConstructor(RawConstructor raw) |
||||
{ |
||||
final ResolvedType context = raw.getDeclaringType(); |
||||
final TypeBindings bindings = context.getTypeBindings(); |
||||
Constructor<?> ctor = raw.getRawMember(); |
||||
Type[] rawTypes = ctor.getGenericParameterTypes(); |
||||
ResolvedType[] argTypes; |
||||
if (rawTypes == null || rawTypes.length == 0) { |
||||
argTypes = NO_RESOLVED_TYPES; |
||||
} else { |
||||
argTypes = new ResolvedType[rawTypes.length]; |
||||
for (int i = 0, len = rawTypes.length; i < len; ++i) { |
||||
argTypes[i] = _typeResolver.resolve(bindings, rawTypes[i]); |
||||
} |
||||
} |
||||
// And then annotations
|
||||
Annotations anns = new Annotations(); |
||||
for (Annotation ann : ctor.getAnnotations()) { |
||||
if (_annotationHandler.includeConstructorAnnotation(ann)) { |
||||
anns.add(ann); |
||||
} |
||||
} |
||||
|
||||
ResolvedConstructor constructor = new ResolvedConstructor(context, anns, ctor, argTypes); |
||||
|
||||
// and parameter annotations
|
||||
Annotation[][] annotations = ctor.getParameterAnnotations(); |
||||
for (int i = 0; i < argTypes.length; i++) { |
||||
for (Annotation ann : annotations[i]) { |
||||
constructor.applyParamOverride(i, ann); |
||||
} |
||||
} |
||||
|
||||
return constructor; |
||||
} |
||||
|
||||
/** |
||||
* Method for resolving individual field completely |
||||
*/ |
||||
protected ResolvedField resolveField(RawField raw) |
||||
{ |
||||
final ResolvedType context = raw.getDeclaringType(); |
||||
Field field = raw.getRawMember(); |
||||
ResolvedType type = _typeResolver.resolve(context.getTypeBindings(), field.getGenericType()); |
||||
// And then annotations
|
||||
Annotations anns = new Annotations(); |
||||
for (Annotation ann : field.getAnnotations()) { |
||||
if (_annotationHandler.includeFieldAnnotation(ann)) { |
||||
anns.add(ann); |
||||
} |
||||
} |
||||
return new ResolvedField(context, anns, field, type); |
||||
} |
||||
|
||||
/** |
||||
* Method for resolving individual method completely |
||||
*/ |
||||
protected ResolvedMethod resolveMethod(RawMethod raw) |
||||
{ |
||||
final ResolvedType context = raw.getDeclaringType(); |
||||
final TypeBindings bindings = context.getTypeBindings(); |
||||
Method m = raw.getRawMember(); |
||||
Type rawType = m.getGenericReturnType(); |
||||
ResolvedType rt = (rawType == Void.TYPE) ? null : _typeResolver.resolve(bindings, rawType); |
||||
Type[] rawTypes = m.getGenericParameterTypes(); |
||||
ResolvedType[] argTypes; |
||||
if (rawTypes == null || rawTypes.length == 0) { |
||||
argTypes = NO_RESOLVED_TYPES; |
||||
} else { |
||||
argTypes = new ResolvedType[rawTypes.length]; |
||||
for (int i = 0, len = rawTypes.length; i < len; ++i) { |
||||
argTypes[i] = _typeResolver.resolve(bindings, rawTypes[i]); |
||||
} |
||||
} |
||||
// And then annotations
|
||||
Annotations anns = new Annotations(); |
||||
for (Annotation ann : m.getAnnotations()) { |
||||
if (_annotationHandler.includeMethodAnnotation(ann)) { |
||||
anns.add(ann); |
||||
} |
||||
} |
||||
|
||||
ResolvedMethod method = new ResolvedMethod(context, anns, m, rt, argTypes); |
||||
|
||||
// and argument annotations
|
||||
Annotation[][] annotations = m.getParameterAnnotations(); |
||||
for (int i = 0; i < argTypes.length; i++) { |
||||
for (Annotation ann : annotations[i]) { |
||||
method.applyParamOverride(i, ann); |
||||
} |
||||
} |
||||
return method; |
||||
} |
||||
|
||||
protected boolean methodCanInherit(Annotation annotation) { |
||||
AnnotationInclusion annotationInclusion = _annotationHandler.methodInclusion(annotation); |
||||
if (annotationInclusion == AnnotationInclusion.INCLUDE_AND_INHERIT_IF_INHERITED) { |
||||
return annotation.annotationType().isAnnotationPresent(Inherited.class); |
||||
} |
||||
return (annotationInclusion == AnnotationInclusion.INCLUDE_AND_INHERIT); |
||||
} |
||||
|
||||
protected boolean parameterCanInherit(Annotation annotation) { |
||||
AnnotationInclusion annotationInclusion = _annotationHandler.parameterInclusion(annotation); |
||||
if (annotationInclusion == AnnotationInclusion.INCLUDE_AND_INHERIT_IF_INHERITED) { |
||||
return annotation.annotationType().isAnnotationPresent(Inherited.class); |
||||
} |
||||
return (annotationInclusion == AnnotationInclusion.INCLUDE_AND_INHERIT); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Helper types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Helper class we use to reduce number of calls to {@link AnnotationConfiguration}; |
||||
* mostly because determination may be expensive. |
||||
*/ |
||||
private final static class AnnotationHandler |
||||
{ |
||||
private final AnnotationConfiguration _annotationConfig; |
||||
|
||||
private HashMap<Class<? extends Annotation>, AnnotationInclusion> _fieldInclusions; |
||||
private HashMap<Class<? extends Annotation>, AnnotationInclusion> _constructorInclusions; |
||||
private HashMap<Class<? extends Annotation>, AnnotationInclusion> _methodInclusions; |
||||
private HashMap<Class<? extends Annotation>, AnnotationInclusion> _parameterInclusions; |
||||
|
||||
public AnnotationHandler(AnnotationConfiguration annotationConfig) { |
||||
_annotationConfig = annotationConfig; |
||||
} |
||||
|
||||
public boolean includeConstructorAnnotation(Annotation ann) |
||||
{ |
||||
Class<? extends Annotation> annType = ann.annotationType(); |
||||
if (_constructorInclusions == null) { |
||||
_constructorInclusions = new HashMap<Class<? extends Annotation>, AnnotationInclusion>(); |
||||
} else { |
||||
AnnotationInclusion incl = _constructorInclusions.get(annType); |
||||
if (incl != null) { |
||||
return (incl != AnnotationInclusion.DONT_INCLUDE); |
||||
} |
||||
} |
||||
AnnotationInclusion incl = _annotationConfig.getInclusionForConstructor(annType); |
||||
_constructorInclusions.put(annType, incl); |
||||
return (incl != AnnotationInclusion.DONT_INCLUDE); |
||||
} |
||||
|
||||
public boolean includeFieldAnnotation(Annotation ann) |
||||
{ |
||||
Class<? extends Annotation> annType = ann.annotationType(); |
||||
if (_fieldInclusions == null) { |
||||
_fieldInclusions = new HashMap<Class<? extends Annotation>, AnnotationInclusion>(); |
||||
} else { |
||||
AnnotationInclusion incl = _fieldInclusions.get(annType); |
||||
if (incl != null) { |
||||
return (incl != AnnotationInclusion.DONT_INCLUDE); |
||||
} |
||||
} |
||||
AnnotationInclusion incl = _annotationConfig.getInclusionForField(annType); |
||||
_fieldInclusions.put(annType, incl); |
||||
return (incl != AnnotationInclusion.DONT_INCLUDE); |
||||
} |
||||
|
||||
public boolean includeMethodAnnotation(Annotation ann) |
||||
{ |
||||
return methodInclusion(ann) != AnnotationInclusion.DONT_INCLUDE; |
||||
} |
||||
|
||||
public AnnotationInclusion methodInclusion(Annotation ann) |
||||
{ |
||||
Class<? extends Annotation> annType = ann.annotationType(); |
||||
if (_methodInclusions == null) { |
||||
_methodInclusions = new HashMap<Class<? extends Annotation>, AnnotationInclusion>(); |
||||
} else { |
||||
AnnotationInclusion incl = _methodInclusions.get(annType); |
||||
if (incl != null) { |
||||
return incl; |
||||
} |
||||
} |
||||
AnnotationInclusion incl = _annotationConfig.getInclusionForMethod(annType); |
||||
_methodInclusions.put(annType, incl); |
||||
return incl; |
||||
} |
||||
|
||||
public boolean includeParameterAnnotation(Annotation ann) |
||||
{ |
||||
return parameterInclusion(ann) != AnnotationInclusion.DONT_INCLUDE; |
||||
} |
||||
|
||||
public AnnotationInclusion parameterInclusion(Annotation ann) |
||||
{ |
||||
Class<? extends Annotation> annType = ann.annotationType(); |
||||
if (_parameterInclusions == null) { |
||||
_parameterInclusions = new HashMap<Class<? extends Annotation>, AnnotationInclusion>(); |
||||
} else { |
||||
AnnotationInclusion incl = _parameterInclusions.get(annType); |
||||
if (incl != null) { |
||||
return incl; |
||||
} |
||||
} |
||||
AnnotationInclusion incl = _annotationConfig.getInclusionForParameter(annType); |
||||
_parameterInclusions.put(annType, incl); |
||||
return incl; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,237 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.lang.reflect.TypeVariable; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* Helper class used for storing binding of local type variables to |
||||
* matching resolved types, in context of a single class. |
||||
*/ |
||||
public final class TypeBindings |
||||
{ |
||||
private final static String[] NO_STRINGS = new String[0]; |
||||
|
||||
private final static ResolvedType[] NO_TYPES = new ResolvedType[0]; |
||||
|
||||
private final static TypeBindings EMPTY = new TypeBindings(NO_STRINGS, NO_TYPES, null); |
||||
|
||||
/** |
||||
* Array of type (type variable) names. |
||||
*/ |
||||
private final String[] _names; |
||||
|
||||
/** |
||||
* Types matching names |
||||
*/ |
||||
private final ResolvedType[] _types; |
||||
|
||||
/** |
||||
* Names of potentially unresolved type variables. |
||||
* |
||||
* @since 2.3 |
||||
*/ |
||||
private final String[] _unboundVariables; |
||||
|
||||
private final int _hashCode; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Construction |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
private TypeBindings(String[] names, ResolvedType[] types, String[] uvars) |
||||
{ |
||||
_names = (names == null) ? NO_STRINGS : names; |
||||
_types = (types == null) ? NO_TYPES : types; |
||||
if (_names.length != _types.length) { |
||||
throw new IllegalArgumentException("Mismatching names ("+_names.length+"), types ("+_types.length+")"); |
||||
} |
||||
int h = 1; |
||||
for (int i = 0, len = _types.length; i < len; ++i) { |
||||
h += _types[i].hashCode(); |
||||
} |
||||
_unboundVariables = uvars; |
||||
_hashCode = h; |
||||
} |
||||
|
||||
public static TypeBindings emptyBindings() { |
||||
return EMPTY; |
||||
} |
||||
|
||||
/** |
||||
* Factory method for constructing bindings for given class using specified type |
||||
* parameters. |
||||
*/ |
||||
public static TypeBindings create(Class<?> erasedType, List<ResolvedType> typeList) |
||||
{ |
||||
ResolvedType[] types = (typeList == null || typeList.isEmpty()) ? |
||||
NO_TYPES : typeList.toArray(new ResolvedType[typeList.size()]); |
||||
return create(erasedType, types); |
||||
} |
||||
|
||||
public static TypeBindings create(Class<?> erasedType, ResolvedType[] types) |
||||
{ |
||||
if (types == null) { |
||||
types = NO_TYPES; |
||||
} |
||||
TypeVariable<?>[] vars = erasedType.getTypeParameters(); |
||||
String[] names; |
||||
if (vars == null || vars.length == 0) { |
||||
names = NO_STRINGS; |
||||
} else { |
||||
int len = vars.length; |
||||
names = new String[len]; |
||||
for (int i = 0; i < len; ++i) { |
||||
names[i] = vars[i].getName(); |
||||
} |
||||
} |
||||
// Check here to give better error message
|
||||
if (names.length != types.length) { |
||||
throw new IllegalArgumentException("Can not create TypeBinding for class "+erasedType.getName() |
||||
+" with "+types.length+" type parameter" |
||||
+((types.length == 1) ? "" : "s")+": class expects "+names.length); |
||||
} |
||||
return new TypeBindings(names, types, null); |
||||
} |
||||
|
||||
/** |
||||
* Method for creating an instance that has same bindings as this object, |
||||
* plus an indicator for additional type variable that may be unbound within |
||||
* this context; this is needed to resolve recursive self-references. |
||||
* |
||||
* @since 1.3 (renamed from "withAdditionalBinding" in 1.2) |
||||
*/ |
||||
public TypeBindings withUnboundVariable(String name) |
||||
{ |
||||
int len = (_unboundVariables == null) ? 0 : _unboundVariables.length; |
||||
String[] names = (len == 0) |
||||
? new String[1] : Arrays.copyOf(_unboundVariables, len+1); |
||||
names[len] = name; |
||||
return new TypeBindings(_names, _types, names); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Find type bound to specified name, if there is one; returns bound type if so, null if not. |
||||
*/ |
||||
public ResolvedType findBoundType(String name) |
||||
{ |
||||
for (int i = 0, len = _names.length; i < len; ++i) { |
||||
if (name.equals(_names[i])) { |
||||
return _types[i]; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public boolean isEmpty() { |
||||
return (_types.length == 0); |
||||
} |
||||
|
||||
/** |
||||
* Returns number of bindings contained |
||||
*/ |
||||
public int size() { |
||||
return _types.length; |
||||
} |
||||
|
||||
public String getBoundName(int index) |
||||
{ |
||||
if (index < 0 || index >= _names.length) { |
||||
return null; |
||||
} |
||||
return _names[index]; |
||||
} |
||||
|
||||
public ResolvedType getBoundType(int index) |
||||
{ |
||||
if (index < 0 || index >= _types.length) { |
||||
return null; |
||||
} |
||||
return _types[index]; |
||||
} |
||||
|
||||
/** |
||||
* Accessor for getting bound types in declaration order |
||||
*/ |
||||
public List<ResolvedType> getTypeParameters() |
||||
{ |
||||
if (_types.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_types); |
||||
} |
||||
|
||||
/** |
||||
* @since 2.3 |
||||
*/ |
||||
public boolean hasUnbound(String name) { |
||||
if (_unboundVariables != null) { |
||||
for (int i = _unboundVariables.length; --i >= 0; ) { |
||||
if (name.equals(_unboundVariables[i])) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public String toString() |
||||
{ |
||||
if (_types.length == 0) { |
||||
return ""; |
||||
} |
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.append('<'); |
||||
for (int i = 0, len = _types.length; i < len; ++i) { |
||||
if (i > 0) { |
||||
sb.append(','); |
||||
} |
||||
sb = _types[i].appendBriefDescription(sb); |
||||
} |
||||
sb.append('>'); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
@Override public int hashCode() { return _hashCode; } |
||||
|
||||
@Override public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
TypeBindings other = (TypeBindings) o; |
||||
int len = _types.length; |
||||
if (len != other.size()) { |
||||
return false; |
||||
} |
||||
ResolvedType[] otherTypes = other._types; |
||||
for (int i = 0; i < len; ++i) { |
||||
if (!otherTypes[i].equals(_types[i])) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Package accessible methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected ResolvedType[] typeParameterArray() { |
||||
return _types; |
||||
} |
||||
} |
@ -0,0 +1,552 @@
|
||||
package com.fr.third.com.fasterxml.classmate; |
||||
|
||||
import java.io.Serializable; |
||||
import java.lang.reflect.*; |
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.util.ClassKey; |
||||
import com.fr.third.com.fasterxml.classmate.util.ClassStack; |
||||
import com.fr.third.com.fasterxml.classmate.util.ResolvedTypeCache; |
||||
import com.fr.third.com.fasterxml.classmate.types.ResolvedArrayType; |
||||
import com.fr.third.com.fasterxml.classmate.types.ResolvedInterfaceType; |
||||
import com.fr.third.com.fasterxml.classmate.types.ResolvedObjectType; |
||||
import com.fr.third.com.fasterxml.classmate.types.ResolvedPrimitiveType; |
||||
import com.fr.third.com.fasterxml.classmate.types.ResolvedRecursiveType; |
||||
import com.fr.third.com.fasterxml.classmate.types.TypePlaceHolder; |
||||
|
||||
/** |
||||
* Object that is used for resolving generic type information of a class
|
||||
* so that it is accessible using simple API. Resolved types are also starting |
||||
* point for accessing resolved (generics aware) return and argument types |
||||
* of class members (methods, fields, constructors). |
||||
*<p> |
||||
* Note that resolver instances are stateful in that resolvers cache resolved |
||||
* types for efficiency. Since this is internal state and not directly visible |
||||
* to callers, access to state is fully synchronized so that access from |
||||
* multiple threads is safe. |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class TypeResolver implements Serializable |
||||
{ |
||||
private final static ResolvedType[] NO_TYPES = new ResolvedType[0]; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Pre-created instances |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* We will also need to return "unknown" type for cases where type variable binding |
||||
* is not found ('raw' instances of generic types); easiest way is to |
||||
* pre-create type for <code>java.lang.Object</code> |
||||
*/ |
||||
private final static ResolvedObjectType sJavaLangObject = |
||||
ResolvedObjectType.create(Object.class, null, null, null); |
||||
|
||||
/** |
||||
* Since number of primitive types is small, and they are frequently needed, |
||||
* let's actually pre-create them for efficient reuse. Same goes for limited number |
||||
* of other "standard" types... |
||||
*/ |
||||
protected final static HashMap<ClassKey, ResolvedType> _primitiveTypes; |
||||
static { |
||||
_primitiveTypes = new HashMap<ClassKey, ResolvedType>(16); |
||||
for (ResolvedPrimitiveType type : ResolvedPrimitiveType.all()) { |
||||
_primitiveTypes.put(new ClassKey(type.getErasedType()), type); |
||||
} |
||||
// should we include "void"? might as well...
|
||||
_primitiveTypes.put(new ClassKey(Void.TYPE), ResolvedPrimitiveType.voidType()); |
||||
// and at least java.lang.Object should be added too.
|
||||
_primitiveTypes.put(new ClassKey(Object.class), sJavaLangObject); |
||||
// but most other types can be added dynamically
|
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Caching |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Simple cache of types resolved by this resolved; capped to last 200 resolved types. |
||||
* Caching works because type instances themselves are mostly immutable; |
||||
* and properly synchronized in cases where transient data (raw members) are |
||||
* accessed. |
||||
*/ |
||||
protected final ResolvedTypeCache _resolvedTypes = new ResolvedTypeCache(200); |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public TypeResolver() { } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Factory methods, with explicit parameterization |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Factory method for resolving given base type |
||||
* using specified types as type parameters. |
||||
* Sample usage would be: |
||||
*<pre> |
||||
* ResolvedType type = TypeResolver.resolve(List.class, Integer.class); |
||||
*</pre> |
||||
* which would be equivalent to |
||||
*<pre> |
||||
* ResolvedType type = TypeResolver.resolve(new GenericType<List<Integer>>() { }); |
||||
*</pre> |
||||
* Note that you can mix different types of type parameters, whether already |
||||
* resolved ({@link ResolvedType}), type-erased ({@link java.lang.Class}) or |
||||
* generic type reference ({@link GenericType}). |
||||
*/ |
||||
public ResolvedType resolve(Type type, Type... typeParameters) |
||||
{ |
||||
boolean noParams = (typeParameters == null || typeParameters.length == 0); |
||||
TypeBindings bindings; |
||||
Class<?> rawBase; |
||||
|
||||
if (type instanceof Class<?>) { |
||||
bindings = TypeBindings.emptyBindings(); |
||||
if (noParams) { |
||||
return _fromClass(null, (Class<?>) type, bindings); |
||||
} |
||||
rawBase = (Class<?>) type; |
||||
} else if (type instanceof GenericType<?>) { |
||||
bindings = TypeBindings.emptyBindings(); |
||||
if (noParams) { |
||||
return _fromGenericType(null, (GenericType<?>) type, bindings); |
||||
} |
||||
ResolvedType rt = _fromAny(null, type, bindings); |
||||
rawBase = rt.getErasedType(); |
||||
} else if (type instanceof ResolvedType) { |
||||
ResolvedType rt = (ResolvedType) type; |
||||
if (noParams) { |
||||
return rt; |
||||
} |
||||
bindings = rt.getTypeBindings(); |
||||
rawBase = rt.getErasedType(); |
||||
} else { |
||||
bindings = TypeBindings.emptyBindings(); |
||||
if (noParams) { |
||||
return resolve(bindings, type); |
||||
} |
||||
// Quite convoluted... but necessary to find Class<?> underlying it all
|
||||
ResolvedType rt = _fromAny(null, type, bindings); |
||||
rawBase = rt.getErasedType(); |
||||
} |
||||
|
||||
// Next: resolve type parameters
|
||||
int len = typeParameters.length; |
||||
ResolvedType[] resolvedParams = new ResolvedType[len]; |
||||
for (int i = 0; i < len; ++i) { |
||||
resolvedParams[i] = _fromAny(null, typeParameters[i], bindings); |
||||
} |
||||
return _fromClass(null, rawBase, TypeBindings.create(rawBase, resolvedParams)); |
||||
} |
||||
|
||||
/** |
||||
* Factory method for constructing array type of given element type. |
||||
*/ |
||||
public ResolvedArrayType arrayType(Type elementType) |
||||
{ |
||||
ResolvedType resolvedElementType = resolve(TypeBindings.emptyBindings(), elementType); |
||||
// Arrays are cumbersome for some reason:
|
||||
Object emptyArray = Array.newInstance(resolvedElementType.getErasedType(), 0); |
||||
// Should we try to use cache? It's bit tricky, so let's not bother yet
|
||||
return new ResolvedArrayType(emptyArray.getClass(), TypeBindings.emptyBindings(), |
||||
resolvedElementType); |
||||
} |
||||
|
||||
/** |
||||
* Factory method for resolving specified Java {@link java.lang.reflect.Type}, given |
||||
* {@link TypeBindings} needed to resolve any type variables. |
||||
*<p> |
||||
* Use of this method is discouraged (use if and only if you really know what you |
||||
* are doing!); but if used, type bindings passed should come from {@link ResolvedType} |
||||
* instance of declaring class (or interface). |
||||
*<p> |
||||
* NOTE: order of arguments was reversed for 0.8, to avoid problems with |
||||
* overload varargs method. |
||||
*/ |
||||
public ResolvedType resolve(TypeBindings typeBindings, Type jdkType) |
||||
{ |
||||
return _fromAny(null, jdkType, typeBindings); |
||||
} |
||||
|
||||
/** |
||||
* Factory method for constructing sub-classing specified type; class specified |
||||
* as sub-class must be compatible according to basic Java inheritance rules |
||||
* (subtype must properly extend or implement specified supertype). |
||||
*<p> |
||||
* A typical use case here is to refine a generic type; for example, given |
||||
* that we have generic type like <code>List<Integer></code>, but we want |
||||
* a more specific implementation type like |
||||
* class <code>ArrayList</code> but with same parameterization (here just <code>Integer</code>), |
||||
* we could achieve it by: |
||||
*<pre> |
||||
* ResolvedType mapType = typeResolver.resolve(List.class, Integer.class); |
||||
* ResolveType concreteMapType = typeResolver.resolveSubType(mapType, ArrayList.class); |
||||
*</pre> |
||||
* (in this case, it would have been simpler to resolve directly; but in some |
||||
* cases we are handled supertype and want to refine it, in which case steps |
||||
* would be the same but separated by other code) |
||||
*<p> |
||||
* Note that this method will fail if extension can not succeed; either because |
||||
* this type is not extendable (sub-classable) -- which is true for primitive |
||||
* and array types -- or because given class is not a subtype of this type. |
||||
* To check whether subtyping could succeed, you can call |
||||
* {@link ResolvedType#canCreateSubtypes()} to see if supertype can ever |
||||
* be extended. |
||||
* |
||||
* @param supertype Type to subtype (extend) |
||||
* @param subtype Type-erased sub-class or sub-interface
|
||||
* |
||||
* @return Resolved subtype |
||||
* |
||||
* @throws IllegalArgumentException If this type can be extended in general, but not into specified sub-class
|
||||
* @throws UnsupportedOperationException If this type can not be sub-classed |
||||
*/ |
||||
public ResolvedType resolveSubtype(ResolvedType supertype, Class<?> subtype) |
||||
throws IllegalArgumentException, UnsupportedOperationException |
||||
{ |
||||
// first: if it's a recursive reference, find out referred-to type
|
||||
ResolvedType refType = supertype.getSelfReferencedType(); |
||||
if (refType != null) { |
||||
supertype = refType; |
||||
} |
||||
// Then, trivial check for case where subtype is supertype...
|
||||
if (supertype.getErasedType() == subtype) { |
||||
return supertype; |
||||
} |
||||
|
||||
if (!supertype.canCreateSubtypes()) { |
||||
throw new UnsupportedOperationException("Can not subtype primitive or array types (type "+supertype.getFullDescription()+")"); |
||||
} |
||||
// In general, must be able to subtype as per JVM rules:
|
||||
Class<?> superclass = supertype.getErasedType(); |
||||
if (!superclass.isAssignableFrom(subtype)) { |
||||
throw new IllegalArgumentException("Can not sub-class "+supertype.getBriefDescription() |
||||
+" into "+subtype.getName()); |
||||
} |
||||
// Ok, then, let us instantiate type with placeholders
|
||||
ResolvedType resolvedSubtype; |
||||
int paramCount = subtype.getTypeParameters().length; |
||||
TypePlaceHolder[] placeholders; |
||||
|
||||
if (paramCount == 0) { // no generics
|
||||
placeholders = null; |
||||
resolvedSubtype = resolve(subtype); |
||||
} else { |
||||
placeholders = new TypePlaceHolder[paramCount]; |
||||
for (int i = 0; i < paramCount; ++i) { |
||||
placeholders[i] = new TypePlaceHolder(i); |
||||
} |
||||
resolvedSubtype = resolve(subtype, placeholders); |
||||
} |
||||
ResolvedType rawSupertype = resolvedSubtype.findSupertype(superclass); |
||||
if (rawSupertype == null) { // sanity check, should never occur
|
||||
throw new IllegalArgumentException("Internal error: unable to locate supertype ("+subtype.getName()+") for type "+supertype.getBriefDescription()); |
||||
} |
||||
// Ok, then, let's find and verify type assignments
|
||||
_resolveTypePlaceholders(supertype, rawSupertype); |
||||
|
||||
// And then re-construct, if necessary
|
||||
if (paramCount == 0) { // if no type parameters, fine as is
|
||||
return resolvedSubtype; |
||||
} |
||||
// but with type parameters, need to reconstruct
|
||||
ResolvedType[] typeParams = new ResolvedType[paramCount]; |
||||
for (int i = 0; i < paramCount; ++i) { |
||||
ResolvedType t = placeholders[i].actualType(); |
||||
/* Is it ok for it to be left unassigned? For now let's not |
||||
* allow that |
||||
*/ |
||||
if (t == null) { |
||||
throw new IllegalArgumentException("Failed to find type parameter #"+(i+1)+"/" |
||||
+paramCount+" for "+subtype.getName()); |
||||
} |
||||
typeParams[i] = t; |
||||
} |
||||
return resolve(subtype, typeParams); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Misc other methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Helper method that can be used to checked whether given resolved type |
||||
* (with erased type of <code>java.lang.Object</code>) is a placeholder |
||||
* for "self-reference"; these are nasty recursive ("self") types |
||||
* needed with some interfaces |
||||
*/ |
||||
public static boolean isSelfReference(ResolvedType type) |
||||
{ |
||||
return (type instanceof ResolvedRecursiveType); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Internal methods, second-level factory methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
private ResolvedType _fromAny(ClassStack context, Type mainType, TypeBindings typeBindings) |
||||
{ |
||||
if (mainType instanceof Class<?>) { |
||||
return _fromClass(context, (Class<?>) mainType, typeBindings); |
||||
} |
||||
if (mainType instanceof ResolvedType) { |
||||
return (ResolvedType) mainType; |
||||
} |
||||
if (mainType instanceof ParameterizedType) { |
||||
return _fromParamType(context, (ParameterizedType) mainType, typeBindings); |
||||
} |
||||
if (mainType instanceof GenericType<?>) { |
||||
return _fromGenericType(context, (GenericType<?>) mainType, typeBindings); |
||||
} |
||||
if (mainType instanceof GenericArrayType) { |
||||
return _fromArrayType(context, (GenericArrayType) mainType, typeBindings); |
||||
} |
||||
if (mainType instanceof TypeVariable<?>) { |
||||
return _fromVariable(context, (TypeVariable<?>) mainType, typeBindings); |
||||
} |
||||
if (mainType instanceof WildcardType) { |
||||
return _fromWildcard(context, (WildcardType) mainType, typeBindings); |
||||
} |
||||
// should never get here...
|
||||
throw new IllegalArgumentException("Unrecognized type class: "+mainType.getClass().getName()); |
||||
} |
||||
|
||||
private ResolvedType _fromClass(ClassStack context, Class<?> rawType, TypeBindings typeBindings) |
||||
{ |
||||
// First: a primitive type perhaps?
|
||||
ResolvedType type = _primitiveTypes.get(new ClassKey(rawType)); |
||||
if (type != null) { |
||||
return type; |
||||
} |
||||
// Second: recursive reference?
|
||||
if (context == null) { |
||||
context = new ClassStack(rawType); |
||||
} else { |
||||
ClassStack prev = context.find(rawType); |
||||
if (prev != null) { |
||||
// Self-reference: needs special handling, then...
|
||||
ResolvedRecursiveType selfRef = new ResolvedRecursiveType(rawType, typeBindings); |
||||
prev.addSelfReference(selfRef); |
||||
return selfRef; |
||||
} |
||||
// no, can just add
|
||||
context = context.child(rawType); |
||||
} |
||||
|
||||
// If not, already recently resolved?
|
||||
ResolvedType[] typeParameters = typeBindings.typeParameterArray(); |
||||
ResolvedTypeCache.Key key = _resolvedTypes.key(rawType, typeParameters); |
||||
|
||||
type = _resolvedTypes.find(key); |
||||
if (type == null) { |
||||
type = _constructType(context, rawType, typeBindings); |
||||
_resolvedTypes.put(key, type); |
||||
} |
||||
context.resolveSelfReferences(type); |
||||
return type; |
||||
} |
||||
|
||||
/** |
||||
* Factory method for resolving given generic type, defined by using sub-class
|
||||
* instance of {@link GenericType} |
||||
*/ |
||||
private ResolvedType _fromGenericType(ClassStack context, GenericType<?> generic, TypeBindings typeBindings) |
||||
{ |
||||
/* To allow multiple levels of inheritance (just in case someone |
||||
* wants to go to town with inheritance of GenericType), |
||||
* we better resolve the whole thing; then dig out |
||||
* type parameterization... |
||||
*/ |
||||
ResolvedType type = _fromClass(context, generic.getClass(), typeBindings); |
||||
ResolvedType genType = type.findSupertype(GenericType.class); |
||||
if (genType == null) { // sanity check; shouldn't occur
|
||||
throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); |
||||
} |
||||
TypeBindings b = genType.getTypeBindings(); |
||||
ResolvedType[] params = b.typeParameterArray(); |
||||
if (params.length == 0) { |
||||
throw new IllegalArgumentException("Unparameterized GenericType instance ("+generic.getClass().getName()+")"); |
||||
} |
||||
return params[0]; |
||||
} |
||||
|
||||
private ResolvedType _constructType(ClassStack context, Class<?> rawType, TypeBindings typeBindings) |
||||
{ |
||||
// Ok: no easy shortcut, let's figure out type of type...
|
||||
if (rawType.isArray()) { |
||||
ResolvedType elementType = _fromAny(context, rawType.getComponentType(), typeBindings); |
||||
return new ResolvedArrayType(rawType, typeBindings, elementType); |
||||
} |
||||
// For other types super interfaces are needed...
|
||||
if (rawType.isInterface()) { |
||||
return new ResolvedInterfaceType(rawType, typeBindings, |
||||
_resolveSuperInterfaces(context, rawType, typeBindings)); |
||||
|
||||
} |
||||
return new ResolvedObjectType(rawType, typeBindings, |
||||
_resolveSuperClass(context, rawType, typeBindings), |
||||
_resolveSuperInterfaces(context, rawType, typeBindings)); |
||||
} |
||||
|
||||
private ResolvedType[] _resolveSuperInterfaces(ClassStack context, Class<?> rawType, TypeBindings typeBindings) |
||||
{ |
||||
Type[] types = rawType.getGenericInterfaces(); |
||||
if (types == null || types.length == 0) { |
||||
return NO_TYPES; |
||||
} |
||||
int len = types.length; |
||||
ResolvedType[] resolved = new ResolvedType[len]; |
||||
for (int i = 0; i < len; ++i) { |
||||
resolved[i] = _fromAny(context, types[i], typeBindings); |
||||
} |
||||
return resolved; |
||||
} |
||||
|
||||
/** |
||||
* NOTE: return type changed in 1.0.1 from {@link ResolvedObjectType} to |
||||
* {@link ResolvedType}, since it was found that other types may |
||||
* be returned... |
||||
* |
||||
* @return Usually a {@link ResolvedObjectType}, but possibly also |
||||
* {@link ResolvedRecursiveType} |
||||
*/ |
||||
private ResolvedType _resolveSuperClass(ClassStack context, Class<?> rawType, TypeBindings typeBindings) |
||||
{ |
||||
Type parent = rawType.getGenericSuperclass(); |
||||
if (parent == null) { |
||||
return null; |
||||
} |
||||
return _fromAny(context, parent, typeBindings); |
||||
} |
||||
|
||||
private ResolvedType _fromParamType(ClassStack context, ParameterizedType ptype, TypeBindings parentBindings) |
||||
{ |
||||
/* First: what is the actual base type? One odd thing is that 'getRawType' |
||||
* returns Type, not Class<?> as one might expect. But let's assume it is |
||||
* always of type Class: if not, need to add more code to resolve it... |
||||
*/ |
||||
Class<?> rawType = (Class<?>) ptype.getRawType(); |
||||
Type[] params = ptype.getActualTypeArguments(); |
||||
int len = params.length; |
||||
ResolvedType[] types = new ResolvedType[len]; |
||||
|
||||
for (int i = 0; i < len; ++i) { |
||||
types[i] = _fromAny(context, params[i], parentBindings); |
||||
} |
||||
// Ok: this gives us current bindings for this type:
|
||||
TypeBindings newBindings = TypeBindings.create(rawType, types); |
||||
return _fromClass(context, rawType, newBindings); |
||||
} |
||||
|
||||
private ResolvedType _fromArrayType(ClassStack context, GenericArrayType arrayType, TypeBindings typeBindings) |
||||
{ |
||||
ResolvedType elementType = _fromAny(context, arrayType.getGenericComponentType(), typeBindings); |
||||
// Figuring out raw class for generic array is actually bit tricky...
|
||||
Object emptyArray = Array.newInstance(elementType.getErasedType(), 0); |
||||
return new ResolvedArrayType(emptyArray.getClass(), typeBindings, elementType); |
||||
} |
||||
|
||||
private ResolvedType _fromWildcard(ClassStack context, WildcardType wildType, TypeBindings typeBindings) |
||||
{ |
||||
/* Similar to challenges with TypeVariable, we may have multiple upper bounds. |
||||
* But it is also possible that if upper bound defaults to Object, we might want to |
||||
* consider lower bounds instead? |
||||
* For now, we won't try anything more advanced; above is just for future reference. |
||||
*/ |
||||
return _fromAny(context, wildType.getUpperBounds()[0], typeBindings); |
||||
} |
||||
|
||||
private ResolvedType _fromVariable(ClassStack context, TypeVariable<?> variable, TypeBindings typeBindings) |
||||
{ |
||||
// ideally should find it via bindings:
|
||||
String name = variable.getName(); |
||||
ResolvedType type = typeBindings.findBoundType(name); |
||||
|
||||
if (type != null) { |
||||
return type; |
||||
} |
||||
|
||||
/* but if not, use bounds... note that approach here is simplistic; not taking |
||||
* into account possible multiple bounds, nor consider upper bounds. |
||||
*/ |
||||
/* 02-Mar-2011, tatu: As per issue#4, need to avoid self-reference cycles here; |
||||
* can be handled by (temporarily) adding binding: |
||||
*/ |
||||
if (typeBindings.hasUnbound(name)) { |
||||
return sJavaLangObject; |
||||
} |
||||
typeBindings = typeBindings.withUnboundVariable(name); |
||||
|
||||
Type[] bounds = variable.getBounds(); |
||||
return _fromAny(context, bounds[0], typeBindings); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Internal methods, replacing and verifying type placeholders |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Method called to verify that types match; and if there are |
||||
*/ |
||||
private void _resolveTypePlaceholders(ResolvedType expectedType, ResolvedType actualType) |
||||
throws IllegalArgumentException |
||||
{ |
||||
List<ResolvedType> expectedTypes = expectedType.getTypeParameters(); |
||||
List<ResolvedType> actualTypes = actualType.getTypeParameters(); |
||||
for (int i = 0, len = expectedTypes.size(); i < len; ++i) { |
||||
ResolvedType exp = expectedTypes.get(i); |
||||
ResolvedType act = actualTypes.get(i); |
||||
if (!_typesMatch(exp, act)) { |
||||
throw new IllegalArgumentException("Type parameter #"+(i+1)+"/"+len+" differs; expected " |
||||
+exp.getBriefDescription()+", got "+act.getBriefDescription()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private boolean _typesMatch(ResolvedType exp, ResolvedType act) |
||||
{ |
||||
// Simple equality check, except for one thing: place holders for 'act'
|
||||
if (act instanceof TypePlaceHolder) { |
||||
((TypePlaceHolder) act).actualType(exp); |
||||
return true; |
||||
} |
||||
// but due to recursive nature can't call equality...
|
||||
if (exp.getErasedType() != act.getErasedType()) { |
||||
return false; |
||||
} |
||||
// But we can check type parameters "blindly"
|
||||
List<ResolvedType> expectedTypes = exp.getTypeParameters(); |
||||
List<ResolvedType> actualTypes = act.getTypeParameters(); |
||||
for (int i = 0, len = expectedTypes.size(); i < len; ++i) { |
||||
ResolvedType exp2 = expectedTypes.get(i); |
||||
ResolvedType act2 = actualTypes.get(i); |
||||
if (!_typesMatch(exp2, act2)) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Helper classes |
||||
/********************************************************************** |
||||
*/ |
||||
} |
@ -0,0 +1,68 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.ResolvedTypeWithMembers; |
||||
|
||||
/** |
||||
* Container class used to enclose information about a single {@link ResolvedType} |
||||
* that is part of {@link ResolvedTypeWithMembers}. |
||||
*/ |
||||
public final class HierarchicType |
||||
{ |
||||
/** |
||||
* Whether this type instance represents a mix-in; if so, it can only result in |
||||
* addition of annotations but not in addition of actual members. |
||||
*/ |
||||
protected final boolean _isMixin; |
||||
|
||||
protected final ResolvedType _type; |
||||
|
||||
/** |
||||
* Relative priority of this type in hierarchy; higher priority members can override |
||||
* lower priority members. Priority values are unique and are based on type index |
||||
* (starting from 0), although they are not to be used for indexing. |
||||
*/ |
||||
protected final int _priority; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public HierarchicType(ResolvedType type, boolean mixin, int priority) |
||||
{ |
||||
_type = type; |
||||
_isMixin = mixin; |
||||
_priority = priority; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public ResolvedType getType() { return _type; } |
||||
public Class<?> getErasedType() { return _type.getErasedType(); } |
||||
public boolean isMixin() { return _isMixin; } |
||||
public int getPriority() { return _priority; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public String toString() { return _type.toString(); } |
||||
@Override public int hashCode() { return _type.hashCode(); } |
||||
|
||||
@Override |
||||
public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
HierarchicType other = (HierarchicType) o; |
||||
return _type.equals(other._type); |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.reflect.Constructor; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.util.MethodKey; |
||||
|
||||
public final class RawConstructor extends RawMember |
||||
{ |
||||
protected final Constructor<?> _constructor; |
||||
|
||||
protected final int _hashCode; |
||||
|
||||
public RawConstructor(ResolvedType context, Constructor<?> constructor) |
||||
{ |
||||
super(context); |
||||
_constructor = constructor; |
||||
_hashCode = (_constructor == null ? 0 : _constructor.hashCode()); |
||||
} |
||||
|
||||
/** |
||||
* Although constructors are different from other methods, we can use |
||||
* {@link MethodKey} easily. |
||||
*/ |
||||
public MethodKey createKey() |
||||
{ |
||||
String name = "<init>"; // do not use _constructor.getName() to allow for 'mix-ins'
|
||||
Class<?>[] argTypes = _constructor.getParameterTypes(); // return of Constructor#getParameterTypes will never be null
|
||||
return new MethodKey(name, argTypes); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public Constructor<?> getRawMember() { |
||||
return _constructor; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public int hashCode() |
||||
{ |
||||
return _hashCode; |
||||
} |
||||
|
||||
@Override public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
RawConstructor other = (RawConstructor) o; |
||||
return (other._constructor == _constructor); |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.reflect.Field; |
||||
import java.lang.reflect.Modifier; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
public final class RawField extends RawMember |
||||
{ |
||||
protected final Field _field; |
||||
|
||||
private final int _hashCode; |
||||
|
||||
public RawField(ResolvedType context, Field field) |
||||
{ |
||||
super(context); |
||||
_field = field; |
||||
_hashCode = (_field == null ? 0 : _field.hashCode()); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public Field getRawMember() { |
||||
return _field; |
||||
} |
||||
|
||||
public boolean isTransient() { |
||||
return Modifier.isTransient(getModifiers()); |
||||
} |
||||
|
||||
public boolean isVolatile() { |
||||
return Modifier.isVolatile(getModifiers()); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
RawField other = (RawField) o; |
||||
return (other._field == _field); |
||||
} |
||||
|
||||
@Override public int hashCode() |
||||
{ |
||||
return _hashCode; |
||||
} |
||||
} |
@ -0,0 +1,98 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.annotation.Annotation; |
||||
import java.lang.reflect.AnnotatedElement; |
||||
import java.lang.reflect.Member; |
||||
import java.lang.reflect.Modifier; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
/** |
||||
* Base class for all "raw" member (field, method, constructor) types; raw means that |
||||
* actual types are not yet resolved, but relationship to declaring type is |
||||
* retained for eventual resolution. |
||||
* Instances are typically created by {@link ResolvedType} |
||||
* when requested, and form the input to eventual full flattening of type members. |
||||
*/ |
||||
public abstract class RawMember |
||||
{ |
||||
/** |
||||
* {@link ResolvedType} (class with generic type parameters) that declared |
||||
* this member |
||||
*/ |
||||
protected final ResolvedType _declaringType; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected RawMember(ResolvedType context) |
||||
{ |
||||
_declaringType = context; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public final ResolvedType getDeclaringType() { |
||||
return _declaringType; |
||||
} |
||||
|
||||
public abstract Member getRawMember(); |
||||
|
||||
public String getName() { |
||||
return getRawMember().getName(); |
||||
} |
||||
|
||||
public boolean isStatic() { |
||||
return Modifier.isStatic(getModifiers()); |
||||
} |
||||
|
||||
public boolean isFinal() { |
||||
return Modifier.isFinal(getModifiers()); |
||||
} |
||||
|
||||
public boolean isPrivate() { |
||||
return Modifier.isPrivate(getModifiers()); |
||||
} |
||||
|
||||
public boolean isProtected() { |
||||
return Modifier.isProtected(getModifiers()); |
||||
} |
||||
|
||||
public boolean isPublic() { |
||||
return Modifier.isPublic(getModifiers()); |
||||
} |
||||
|
||||
public Annotation[] getAnnotations() { |
||||
return ((AnnotatedElement) getRawMember()).getAnnotations(); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard method overrides |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
// make abstract to force implementation by sub-class
|
||||
@Override public abstract boolean equals(Object o); |
||||
|
||||
@Override public abstract int hashCode(); |
||||
|
||||
@Override public String toString() { |
||||
return getName(); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Package methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected final int getModifiers() { return getRawMember().getModifiers(); } |
||||
} |
@ -0,0 +1,74 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.lang.reflect.Modifier; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.util.MethodKey; |
||||
|
||||
public final class RawMethod extends RawMember |
||||
{ |
||||
protected final Method _method; |
||||
|
||||
protected final int _hashCode; |
||||
|
||||
public RawMethod(ResolvedType context, Method method) |
||||
{ |
||||
super(context); |
||||
_method = method; |
||||
_hashCode = (_method == null ? 0 : _method.hashCode()); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public Method getRawMember() { |
||||
return _method; |
||||
} |
||||
|
||||
public boolean isAbstract() { |
||||
return Modifier.isAbstract(getModifiers()); |
||||
} |
||||
|
||||
public boolean isStrict() { |
||||
return Modifier.isStrict(getModifiers()); |
||||
} |
||||
|
||||
public boolean isNative() { |
||||
return Modifier.isNative(getModifiers()); |
||||
} |
||||
|
||||
public boolean isSynchronized() { |
||||
return Modifier.isSynchronized(getModifiers()); |
||||
} |
||||
|
||||
public MethodKey createKey() |
||||
{ |
||||
String name = _method.getName(); |
||||
Class<?>[] argTypes = _method.getParameterTypes(); // return of Method#getParameterTypes will never be null
|
||||
return new MethodKey(name, argTypes); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public int hashCode() |
||||
{ |
||||
return _hashCode; |
||||
} |
||||
|
||||
@Override public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
RawMethod other = (RawMethod) o; |
||||
return (other._method == _method); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.reflect.Constructor; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.Annotations; |
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
/** |
||||
* Class that represents a constructor that has fully resolved generic |
||||
* type information and annotation information. |
||||
*/ |
||||
public final class ResolvedConstructor extends ResolvedParameterizedMember<Constructor<?>> |
||||
{ |
||||
public ResolvedConstructor(ResolvedType context, Annotations ann, Constructor<?> constructor, |
||||
ResolvedType[] argumentTypes) |
||||
{ |
||||
super(context, ann, constructor, null, argumentTypes); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.reflect.Field; |
||||
import java.lang.reflect.Modifier; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.Annotations; |
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
public final class ResolvedField extends ResolvedMember<Field> |
||||
implements Comparable<ResolvedField> |
||||
{ |
||||
public ResolvedField(ResolvedType context, Annotations ann, |
||||
Field field, ResolvedType type) |
||||
{ |
||||
super(context, ann, field, type); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public boolean isTransient() { |
||||
return Modifier.isTransient(getModifiers()); |
||||
} |
||||
|
||||
public boolean isVolatile() { |
||||
return Modifier.isVolatile(getModifiers()); |
||||
} |
||||
|
||||
@Override |
||||
public int compareTo(ResolvedField other) { |
||||
return getName().compareTo(other.getName()); |
||||
} |
||||
} |
@ -0,0 +1,156 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.annotation.Annotation; |
||||
import java.lang.reflect.Member; |
||||
import java.lang.reflect.Modifier; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.Annotations; |
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
/** |
||||
* Fully type-resolved equivalent of {@link RawMember}. Only members "that matter" (ones not |
||||
* overridden, or filtered out) are resolved, since resolution process can add non-trivial |
||||
* overhead. |
||||
*/ |
||||
public abstract class ResolvedMember<T extends Member> |
||||
{ |
||||
/** |
||||
* {@link ResolvedType} (class with generic type parameters) that declared |
||||
* this member |
||||
*/ |
||||
protected final ResolvedType _declaringType; |
||||
|
||||
protected final Annotations _annotations; |
||||
|
||||
protected final T _member; |
||||
|
||||
protected final ResolvedType _type; |
||||
|
||||
protected final int _hashCode; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected ResolvedMember(ResolvedType context, Annotations ann, T member, ResolvedType type) |
||||
{ |
||||
_declaringType = context; |
||||
_annotations = ann; |
||||
_member = member; |
||||
_type = type; |
||||
_hashCode = (_member == null ? 0 : _member.hashCode()); |
||||
} |
||||
|
||||
public void applyOverride(Annotation override) |
||||
{ |
||||
_annotations.add(override); |
||||
} |
||||
|
||||
public void applyOverrides(Annotations overrides) |
||||
{ |
||||
_annotations.addAll(overrides); |
||||
} |
||||
|
||||
public void applyDefault(Annotation override) |
||||
{ |
||||
_annotations.addAsDefault(override); |
||||
} |
||||
|
||||
public <A extends Annotation> A get(Class<A> cls) |
||||
{ |
||||
return _annotations.get(cls); |
||||
} |
||||
|
||||
public Annotations getAnnotations() |
||||
{ |
||||
return _annotations; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public final ResolvedType getDeclaringType() { |
||||
return _declaringType; |
||||
} |
||||
|
||||
/** |
||||
* Returns type of this member; if it has one, for methods this is the |
||||
* return type, for fields field type, and for constructors null. |
||||
*/ |
||||
public ResolvedType getType() { |
||||
return _type; |
||||
} |
||||
|
||||
/** |
||||
* Returns JDK object that represents member. |
||||
*/ |
||||
public T getRawMember() { |
||||
return _member; |
||||
} |
||||
|
||||
public String getName() { |
||||
return getRawMember().getName(); |
||||
} |
||||
|
||||
public boolean isStatic() { |
||||
return Modifier.isStatic(getModifiers()); |
||||
} |
||||
|
||||
public boolean isFinal() { |
||||
return Modifier.isFinal(getModifiers()); |
||||
} |
||||
|
||||
public boolean isPrivate() { |
||||
return Modifier.isPrivate(getModifiers()); |
||||
} |
||||
|
||||
public boolean isProtected() { |
||||
return Modifier.isProtected(getModifiers()); |
||||
} |
||||
|
||||
public boolean isPublic() { |
||||
return Modifier.isPublic(getModifiers()); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard method overrides |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public String toString() { |
||||
return getName(); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Package methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected final int getModifiers() { return getRawMember().getModifiers(); } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override public int hashCode() { |
||||
return _hashCode; |
||||
} |
||||
|
||||
@Override public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
ResolvedMember<?> other = (ResolvedMember<?>) o; |
||||
return (other._member == _member); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,65 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import java.lang.reflect.Method; |
||||
import java.lang.reflect.Modifier; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.Annotations; |
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
public final class ResolvedMethod extends ResolvedParameterizedMember<Method> |
||||
implements Comparable<ResolvedMethod> |
||||
{ |
||||
public ResolvedMethod(ResolvedType context, Annotations ann, Method method, |
||||
ResolvedType returnType, ResolvedType[] argumentTypes) |
||||
{ |
||||
super(context, ann, method, returnType, argumentTypes); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple accessors from base class
|
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public boolean isAbstract() { |
||||
return Modifier.isAbstract(getModifiers()); |
||||
} |
||||
|
||||
public boolean isStrict() { |
||||
return Modifier.isStrict(getModifiers()); |
||||
} |
||||
|
||||
public boolean isNative() { |
||||
return Modifier.isNative(getModifiers()); |
||||
} |
||||
|
||||
public boolean isSynchronized() { |
||||
return Modifier.isSynchronized(getModifiers()); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Extended API |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public ResolvedType getReturnType() { return getType(); } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard method override |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public int compareTo(ResolvedMethod other) |
||||
{ |
||||
// primary sort by name (alphabetic); secondary by arg count (ascending)
|
||||
int diff = getName().compareTo(other.getName()); |
||||
if (diff == 0) { |
||||
// subtract fine, no fear of overflow here
|
||||
diff = getArgumentCount() - other.getArgumentCount(); |
||||
} |
||||
return diff; |
||||
} |
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.fr.third.com.fasterxml.classmate.members; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.Annotations; |
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
import java.lang.annotation.Annotation; |
||||
import java.lang.reflect.Member; |
||||
|
||||
/** |
||||
* Base type for resolved members that take some parameters (e.g. methods and constructors). |
||||
*/ |
||||
public abstract class ResolvedParameterizedMember<T extends Member> extends ResolvedMember<T> { |
||||
|
||||
protected final ResolvedType[] _paramTypes; |
||||
|
||||
protected final Annotations[] _paramAnnotations; |
||||
|
||||
protected ResolvedParameterizedMember(ResolvedType context, Annotations ann, |
||||
T member, ResolvedType type, ResolvedType[] argumentTypes) { |
||||
super(context, ann, member, type); |
||||
_paramTypes = argumentTypes == null ? ResolvedType.NO_TYPES : argumentTypes; |
||||
_paramAnnotations = new Annotations[_paramTypes.length]; |
||||
} |
||||
|
||||
public Annotations getParameterAnnotations(int index) { |
||||
if (index >= _paramTypes.length) |
||||
throw new IndexOutOfBoundsException("No parameter at index " + index + ", this is greater than the total number of parameters"); |
||||
|
||||
if (_paramAnnotations[index] == null) { |
||||
_paramAnnotations[index] = new Annotations(); |
||||
} |
||||
return _paramAnnotations[index]; |
||||
} |
||||
|
||||
public void applyParamOverride(int index, Annotation override) |
||||
{ |
||||
if (index >= _paramAnnotations.length) |
||||
return; |
||||
|
||||
getParameterAnnotations(index).add(override); |
||||
} |
||||
|
||||
public void applyParamOverrides(int index, Annotations overrides) |
||||
{ |
||||
if (index >= _paramAnnotations.length) |
||||
return; |
||||
|
||||
getParameterAnnotations(index).addAll(overrides); |
||||
} |
||||
|
||||
public void applyParamDefault(int index, Annotation defaultValue) |
||||
{ |
||||
if (index >= _paramAnnotations.length) |
||||
return; |
||||
|
||||
getParameterAnnotations(index).addAsDefault(defaultValue); |
||||
} |
||||
|
||||
public <A extends Annotation> A getParam(int index, Class<A> cls) |
||||
{ |
||||
if (index >= _paramAnnotations.length) |
||||
return null; |
||||
|
||||
return _paramAnnotations[index].get(cls); |
||||
} |
||||
|
||||
/** |
||||
* Returns number of arguments method takes. |
||||
*/ |
||||
public int getArgumentCount() { |
||||
return _paramTypes.length; |
||||
} |
||||
|
||||
public ResolvedType getArgumentType(int index) |
||||
{ |
||||
if (index < 0 || index >= _paramTypes.length) { |
||||
return null; |
||||
} |
||||
return _paramTypes[index]; |
||||
} |
||||
} |
@ -0,0 +1,5 @@
|
||||
/** |
||||
* Package that contains implementations of various member types |
||||
* (methods, fields, constructors) |
||||
*/ |
||||
package com.fr.third.com.fasterxml.classmate.members; |
@ -0,0 +1,13 @@
|
||||
/** |
||||
* Package that contains main public interface of ClassMate |
||||
* package. |
||||
*<p> |
||||
* Most commonly resolution starts with {@link com.fr.third.com.fasterxml.classmate.TypeResolver}, |
||||
* using its <code>resolve()</code> method, which returns a |
||||
* {@link com.fr.third.com.fasterxml.classmate.ResolvedType} instance. |
||||
* These type objects contain all necessary information about type itself; |
||||
* but if type information on members (fields, methods, constructors, static |
||||
* members) is needed, {@link com.fr.third.com.fasterxml.classmate.MemberResolver} can |
||||
* resolve types for members: it takes {@link com.fr.third.com.fasterxml.classmate.ResolvedType}s. |
||||
*/ |
||||
package com.fr.third.com.fasterxml.classmate; |
@ -0,0 +1,108 @@
|
||||
package com.fr.third.com.fasterxml.classmate.types; |
||||
|
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.TypeBindings; |
||||
|
||||
public final class ResolvedArrayType extends ResolvedType |
||||
{ |
||||
protected final ResolvedType _elementType; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public ResolvedArrayType(Class<?> erased, TypeBindings bindings, |
||||
ResolvedType elementType) |
||||
{ |
||||
super(erased, bindings); |
||||
_elementType = elementType; |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCreateSubtypes() { |
||||
return false; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public ResolvedType getParentClass() { return null; } |
||||
|
||||
@Override |
||||
public ResolvedType getSelfReferencedType() { return null; } |
||||
|
||||
@Override |
||||
public List<ResolvedType> getImplementedInterfaces() { |
||||
return Collections.emptyList(); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple property accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public boolean isInterface() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isAbstract() { return false; } |
||||
|
||||
@Override |
||||
public ResolvedType getArrayElementType() { return _elementType; } |
||||
|
||||
@Override |
||||
public boolean isArray() { return true; } |
||||
|
||||
@Override |
||||
public boolean isPrimitive() { return false; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for raw (minimally procesed) members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
// defaults are fine (nothing to access)
|
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* String representations |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public StringBuilder appendSignature(StringBuilder sb) { |
||||
sb.append('['); |
||||
return _elementType.appendSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendErasedSignature(StringBuilder sb) { |
||||
sb.append('['); |
||||
return _elementType.appendErasedSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendBriefDescription(StringBuilder sb) |
||||
{ |
||||
sb = _elementType.appendBriefDescription(sb); |
||||
sb.append("[]"); |
||||
return sb; |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendFullDescription(StringBuilder sb) { |
||||
return appendBriefDescription(sb); |
||||
} |
||||
} |
@ -0,0 +1,162 @@
|
||||
package com.fr.third.com.fasterxml.classmate.types; |
||||
|
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.TypeBindings; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawField; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawMethod; |
||||
|
||||
public class ResolvedInterfaceType extends ResolvedType |
||||
{ |
||||
|
||||
/** |
||||
* List of interfaces this type implements; may be empty but never null |
||||
*/ |
||||
protected final ResolvedType[] _superInterfaces; |
||||
|
||||
/** |
||||
* Interfaces can have static final (constant) fields. |
||||
*/ |
||||
protected RawField[] _constantFields; |
||||
|
||||
/** |
||||
* Interface methods are all public and abstract. |
||||
*/ |
||||
protected RawMethod[] _memberMethods; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public ResolvedInterfaceType(Class<?> erased, TypeBindings bindings, |
||||
ResolvedType[] superInterfaces) |
||||
{ |
||||
super(erased, bindings); |
||||
_superInterfaces = (superInterfaces == null ? NO_TYPES : superInterfaces); |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCreateSubtypes() { |
||||
return true; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public ResolvedType getParentClass() { |
||||
// interfaces do not have parent class, just interfaces
|
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public ResolvedType getSelfReferencedType() { return null; } |
||||
|
||||
@Override |
||||
public List<ResolvedType> getImplementedInterfaces() { |
||||
return (_superInterfaces.length == 0) ? |
||||
Collections.<ResolvedType>emptyList() : Arrays.asList(_superInterfaces); |
||||
} |
||||
|
||||
@Override |
||||
public ResolvedType getArrayElementType() { // interfaces are never arrays, so:
|
||||
return null; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple property accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public boolean isInterface() { return true; } |
||||
|
||||
@Override |
||||
public boolean isAbstract() { return true; } |
||||
|
||||
@Override |
||||
public boolean isArray() { return false; } |
||||
|
||||
@Override |
||||
public boolean isPrimitive() { return false; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for raw (minimally procesed) members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public synchronized List<RawField> getStaticFields() |
||||
{ |
||||
// Interfaces can have static fields, but only as static constants...
|
||||
if (_constantFields == null) { |
||||
_constantFields = _getFields(true); |
||||
} |
||||
if (_constantFields.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_constantFields); |
||||
} |
||||
|
||||
@Override |
||||
public synchronized List<RawMethod> getMemberMethods() |
||||
{ |
||||
if (_memberMethods == null) { |
||||
_memberMethods = _getMethods(false); |
||||
} |
||||
if (_memberMethods.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_memberMethods); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* String representations |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public StringBuilder appendSignature(StringBuilder sb) { |
||||
return _appendClassSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendErasedSignature(StringBuilder sb) { |
||||
return _appendErasedClassSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendBriefDescription(StringBuilder sb) { |
||||
return _appendClassDescription(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendFullDescription(StringBuilder sb) |
||||
{ |
||||
sb = _appendClassDescription(sb); |
||||
// interfaces 'extend' other interfaces...
|
||||
int count = _superInterfaces.length; |
||||
if (count > 0) { |
||||
sb.append(" extends "); |
||||
for (int i = 0; i < count; ++i) { |
||||
if (i > 0) { |
||||
sb.append(","); |
||||
} |
||||
sb = _superInterfaces[i].appendBriefDescription(sb); |
||||
} |
||||
} |
||||
return sb; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
@ -0,0 +1,287 @@
|
||||
package com.fr.third.com.fasterxml.classmate.types; |
||||
|
||||
import java.lang.reflect.Modifier; |
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.TypeBindings; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawConstructor; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawField; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawMethod; |
||||
|
||||
/** |
||||
* Type implementation for classes that do not represent interfaces, |
||||
* primitive or array types. |
||||
*/ |
||||
public class ResolvedObjectType extends ResolvedType |
||||
{ |
||||
/** |
||||
* While fundamentally super class has to be {@link ResolvedObjectType} |
||||
* (or null for {@link java.lang.Object}), we may need to hold on to |
||||
* a {@link ResolvedRecursiveType} occasionally. |
||||
*/ |
||||
protected final ResolvedType _superClass; |
||||
|
||||
/** |
||||
* List of interfaces this type implements; may be empty but never null |
||||
*/ |
||||
protected final ResolvedType[] _superInterfaces; |
||||
|
||||
/** |
||||
* Modifiers of the underlying class. |
||||
*/ |
||||
protected final int _modifiers; |
||||
|
||||
/** |
||||
* Constructors declared by the resolved Object class. |
||||
*/ |
||||
protected RawConstructor[] _constructors; |
||||
|
||||
protected RawField[] _memberFields; |
||||
protected RawField[] _staticFields; |
||||
|
||||
protected RawMethod[] _memberMethods; |
||||
protected RawMethod[] _staticMethods; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public ResolvedObjectType(Class<?> erased, TypeBindings bindings, |
||||
ResolvedType superClass, List<ResolvedType> interfaces) |
||||
{ |
||||
this(erased, bindings, superClass, |
||||
(interfaces == null || interfaces.isEmpty()) ? NO_TYPES : |
||||
interfaces.toArray(new ResolvedType[interfaces.size()])); |
||||
} |
||||
|
||||
public ResolvedObjectType(Class<?> erased, TypeBindings bindings, |
||||
ResolvedType superClass, ResolvedType[] interfaces) |
||||
{ |
||||
super(erased, bindings); |
||||
/* 19-Aug-2014, tatu: bit unclean, but has to do for now. |
||||
* Problem is, there is no common super-type, nor can we yet |
||||
* force or coerce recursive types. Rather, they may only get |
||||
* resolved only slightly after construction. So... need to |
||||
* keep a reference. |
||||
*/ |
||||
if (superClass != null) { |
||||
if (!(superClass instanceof ResolvedObjectType) |
||||
&& !(superClass instanceof ResolvedRecursiveType) |
||||
) { |
||||
throw new IllegalArgumentException("Unexpected parent type for " |
||||
+erased.getName()+": "+superClass.getClass().getName()); |
||||
} |
||||
} |
||||
|
||||
_superClass = superClass; |
||||
_superInterfaces = (interfaces == null) ? NO_TYPES : interfaces; |
||||
_modifiers = erased.getModifiers(); |
||||
} |
||||
|
||||
@Deprecated // since 1.1; removed from 1.2 -- kept for binary backwards compatibility
|
||||
public ResolvedObjectType(Class<?> erased, TypeBindings bindings, |
||||
ResolvedObjectType superClass, List<ResolvedType> interfaces) |
||||
{ |
||||
this(erased, bindings, (ResolvedType) superClass, interfaces); |
||||
} |
||||
|
||||
@Deprecated // since 1.1; removed from 1.2 -- kept for binary backwards compatibility
|
||||
public ResolvedObjectType(Class<?> erased, TypeBindings bindings, |
||||
ResolvedObjectType superClass, ResolvedType[] interfaces) |
||||
{ |
||||
this(erased, bindings, (ResolvedType) superClass, interfaces); |
||||
} |
||||
|
||||
public static ResolvedObjectType create(Class<?> erased, TypeBindings bindings, |
||||
ResolvedType superClass, List<ResolvedType> interfaces) |
||||
{ |
||||
return new ResolvedObjectType(erased, bindings, superClass, interfaces); |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCreateSubtypes() { |
||||
return true; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public ResolvedObjectType getParentClass() { |
||||
|
||||
/* 19-Aug-2014, tatu: Ugly does it... sigh. |
||||
* But can't be helped because ResolvedRecursiveType is typically only |
||||
* resolved after instances of this type have been constructed. |
||||
* This means that resolution will need to be done somewhat dynamically. |
||||
*/ |
||||
if (_superClass == null) { |
||||
return null; |
||||
} |
||||
if (_superClass instanceof ResolvedObjectType) { |
||||
return (ResolvedObjectType) _superClass; |
||||
} |
||||
ResolvedType rt = ((ResolvedRecursiveType) _superClass).getSelfReferencedType(); |
||||
if (!(rt instanceof ResolvedObjectType)) { |
||||
throw new IllegalStateException("Internal error: self-referential parent type (" |
||||
+_superClass+") does not resolve into proper ResolvedObjectType, but instead to: " |
||||
+rt); |
||||
} |
||||
return (ResolvedObjectType) rt; |
||||
} |
||||
|
||||
@Override |
||||
public ResolvedType getSelfReferencedType() { return null; } |
||||
|
||||
@Override |
||||
public List<ResolvedType> getImplementedInterfaces() { |
||||
return (_superInterfaces.length == 0) ? |
||||
Collections.<ResolvedType>emptyList() : Arrays.asList(_superInterfaces); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public final ResolvedType getArrayElementType() { return null; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple property accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public final boolean isInterface() { return false; } |
||||
|
||||
@Override |
||||
public boolean isAbstract() { |
||||
return Modifier.isAbstract(_modifiers); |
||||
} |
||||
|
||||
@Override |
||||
public final boolean isArray() { return false; } |
||||
|
||||
@Override |
||||
public final boolean isPrimitive() { return false; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for raw (minimally procesed) members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public synchronized List<RawField> getMemberFields() |
||||
{ |
||||
if (_memberFields == null) { |
||||
_memberFields = _getFields(false); |
||||
} |
||||
if (_memberFields.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_memberFields); |
||||
} |
||||
|
||||
@Override |
||||
public synchronized List<RawField> getStaticFields() |
||||
{ |
||||
if (_staticFields == null) { |
||||
_staticFields = _getFields(true); |
||||
} |
||||
if (_staticFields.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_staticFields); |
||||
} |
||||
|
||||
@Override |
||||
public synchronized List<RawMethod> getMemberMethods() |
||||
{ |
||||
if (_memberMethods == null) { |
||||
_memberMethods = _getMethods(false); |
||||
} |
||||
if (_memberMethods.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_memberMethods); |
||||
} |
||||
|
||||
@Override |
||||
public synchronized List<RawMethod> getStaticMethods() |
||||
{ |
||||
if (_staticMethods == null) { |
||||
_staticMethods = _getMethods(true); |
||||
} |
||||
if (_staticMethods.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_staticMethods); |
||||
} |
||||
|
||||
@Override |
||||
public List<RawConstructor> getConstructors() |
||||
{ |
||||
if (_constructors == null) { |
||||
_constructors = _getConstructors(); |
||||
} |
||||
if (_constructors.length == 0) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return Arrays.asList(_constructors); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* String representations |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public StringBuilder appendSignature(StringBuilder sb) { |
||||
return _appendClassSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendErasedSignature(StringBuilder sb) { |
||||
return _appendErasedClassSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendBriefDescription(StringBuilder sb) { |
||||
return _appendClassDescription(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendFullDescription(StringBuilder sb) |
||||
{ |
||||
sb = _appendClassDescription(sb); |
||||
if (_superClass != null) { |
||||
sb.append(" extends "); |
||||
sb = _superClass.appendBriefDescription(sb); |
||||
} |
||||
// interfaces 'extend' other interfaces...
|
||||
int count = _superInterfaces.length; |
||||
if (count > 0) { |
||||
sb.append(" implements "); |
||||
for (int i = 0; i < count; ++i) { |
||||
if (i > 0) { |
||||
sb.append(","); |
||||
} |
||||
sb = _superInterfaces[i].appendBriefDescription(sb); |
||||
} |
||||
} |
||||
return sb; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,157 @@
|
||||
package com.fr.third.com.fasterxml.classmate.types; |
||||
|
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.TypeBindings; |
||||
|
||||
/** |
||||
* Type used for Java primitive types (which does not include arrays here). |
||||
*<p> |
||||
* Since set of primitive types is bounded, constructor is defined as protected, |
||||
* and class final; that is, new primitive types are not to be constructed |
||||
* by calling applications. |
||||
*/ |
||||
public final class ResolvedPrimitiveType extends ResolvedType |
||||
{ |
||||
private final static ResolvedPrimitiveType VOID = new ResolvedPrimitiveType(Void.TYPE, 'V', "void"); |
||||
|
||||
/** |
||||
* Primitive types have single-character Signature, easy and efficient |
||||
* to just store here |
||||
*/ |
||||
protected final String _signature; |
||||
|
||||
/** |
||||
* Human-readable description should be simple as well |
||||
*/ |
||||
protected final String _description; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
protected ResolvedPrimitiveType(Class<?> erased, char sig, String desc) |
||||
{ |
||||
super(erased, TypeBindings.emptyBindings()); |
||||
_signature = String.valueOf(sig); |
||||
_description = desc; |
||||
} |
||||
|
||||
public static List<ResolvedPrimitiveType> all() |
||||
{ |
||||
ArrayList<ResolvedPrimitiveType> all = new ArrayList<ResolvedPrimitiveType>(); |
||||
all.add(new ResolvedPrimitiveType(Boolean.TYPE, 'Z', "boolean")); |
||||
all.add(new ResolvedPrimitiveType(Byte.TYPE, 'B', "byte")); |
||||
all.add(new ResolvedPrimitiveType(Short.TYPE, 'S', "short")); |
||||
all.add(new ResolvedPrimitiveType(Character.TYPE, 'C', "char")); |
||||
all.add(new ResolvedPrimitiveType(Integer.TYPE, 'I', "int")); |
||||
all.add(new ResolvedPrimitiveType(Long.TYPE, 'J', "long")); |
||||
all.add(new ResolvedPrimitiveType(Float.TYPE, 'F', "float")); |
||||
all.add(new ResolvedPrimitiveType(Double.TYPE, 'D', "double")); |
||||
return all; |
||||
} |
||||
|
||||
public static ResolvedPrimitiveType voidType() |
||||
{ |
||||
return VOID; |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCreateSubtypes() { |
||||
return false; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public ResolvedType getSelfReferencedType() { return null; } |
||||
|
||||
@Override |
||||
public ResolvedType getParentClass() { return null; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple property accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public boolean isInterface() { return false; } |
||||
|
||||
@Override |
||||
public boolean isAbstract() { return false; } |
||||
|
||||
@Override |
||||
public ResolvedType getArrayElementType() { return null; } |
||||
|
||||
@Override |
||||
public boolean isArray() { return false; } |
||||
|
||||
@Override |
||||
public boolean isPrimitive() { return true; } |
||||
|
||||
@Override |
||||
public List<ResolvedType> getImplementedInterfaces() { |
||||
return Collections.emptyList(); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for raw (minimally procesed) members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
// Primitive types are simple; no fields, no methods, no constructors
|
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* String representations |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public String getSignature() { |
||||
return _signature; |
||||
} |
||||
|
||||
@Override |
||||
public String getErasedSignature() { |
||||
return _signature; |
||||
} |
||||
|
||||
@Override |
||||
public String getFullDescription() { |
||||
return _description; |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendSignature(StringBuilder sb) { |
||||
sb.append(_signature); |
||||
return sb; |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendErasedSignature(StringBuilder sb) { |
||||
sb.append(_signature); |
||||
return sb; |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendFullDescription(StringBuilder sb) { |
||||
sb.append(_description); |
||||
return sb; |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendBriefDescription(StringBuilder sb) { |
||||
sb.append(_description); |
||||
return sb; |
||||
} |
||||
} |
@ -0,0 +1,149 @@
|
||||
package com.fr.third.com.fasterxml.classmate.types; |
||||
|
||||
import java.lang.reflect.Modifier; |
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.TypeBindings; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawConstructor; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawField; |
||||
import com.fr.third.com.fasterxml.classmate.members.RawMethod; |
||||
|
||||
/** |
||||
* Specialized type placeholder used in cases where type definition is |
||||
* recursive; to avoid infinite loop, reference that would be "back" in |
||||
* hierarchy is represented by an instance of this class. |
||||
* Underlying information is achievable (for full resolution), but |
||||
* not exposed using super type (parent) accessors; and has special |
||||
* handling when used for constructing descriptions. |
||||
*/ |
||||
public class ResolvedRecursiveType extends ResolvedType |
||||
{ |
||||
/** |
||||
* Actual fully resolved type; assigned once resolution is complete |
||||
*/ |
||||
protected ResolvedType _referencedType; |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Life cycle |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public ResolvedRecursiveType(Class<?> erased, TypeBindings bindings) |
||||
{ |
||||
super(erased, bindings); |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCreateSubtypes() { |
||||
return _referencedType.canCreateSubtypes(); |
||||
} |
||||
|
||||
public void setReference(ResolvedType ref) |
||||
{ |
||||
// sanity check; should not be called multiple times
|
||||
if (_referencedType != null) { |
||||
throw new IllegalStateException("Trying to re-set self reference; old value = "+_referencedType+", new = "+ref); |
||||
} |
||||
_referencedType = ref; |
||||
} |
||||
|
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* To avoid infinite loops, will return null; |
||||
*/ |
||||
@Override |
||||
public ResolvedType getParentClass() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public ResolvedType getSelfReferencedType() { return _referencedType; } |
||||
|
||||
/** |
||||
* To avoid infinite loops, will return empty list |
||||
*/ |
||||
@Override |
||||
public List<ResolvedType> getImplementedInterfaces() { |
||||
return Collections.<ResolvedType>emptyList(); |
||||
} |
||||
|
||||
/** |
||||
* To avoid infinite loops, will return null type |
||||
*/ |
||||
@Override |
||||
public ResolvedType getArrayElementType() { // interfaces are never arrays, so:
|
||||
return null; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple property accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public boolean isInterface() { return _erasedType.isInterface(); } |
||||
|
||||
@Override |
||||
public boolean isAbstract() { return Modifier.isAbstract(_erasedType.getModifiers()); } |
||||
|
||||
@Override |
||||
public boolean isArray() { return _erasedType.isArray(); } |
||||
|
||||
@Override |
||||
public boolean isPrimitive() { return false; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for raw (minimally procesed) members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public List<RawField> getMemberFields() { return _referencedType.getMemberFields(); } |
||||
@Override |
||||
public List<RawField> getStaticFields() { return _referencedType.getStaticFields(); } |
||||
@Override |
||||
public List<RawMethod> getStaticMethods() { return _referencedType.getStaticMethods(); } |
||||
@Override |
||||
public List<RawMethod> getMemberMethods() { return _referencedType.getMemberMethods(); } |
||||
@Override |
||||
public List<RawConstructor> getConstructors() { return _referencedType.getConstructors(); } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* String representations |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public StringBuilder appendSignature(StringBuilder sb) { |
||||
// to avoid infinite recursion, only print type erased version
|
||||
return appendErasedSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendErasedSignature(StringBuilder sb) { |
||||
return _appendErasedClassSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendBriefDescription(StringBuilder sb) { |
||||
return _appendClassDescription(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendFullDescription(StringBuilder sb) |
||||
{ |
||||
// should never get called, but just in case, only print brief description
|
||||
return appendBriefDescription(sb); |
||||
} |
||||
} |
@ -0,0 +1,101 @@
|
||||
package com.fr.third.com.fasterxml.classmate.types; |
||||
|
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.TypeBindings; |
||||
|
||||
/** |
||||
* Placeholder used for resolving type assignments to figure out |
||||
* type parameters for subtypes. |
||||
*/ |
||||
public class TypePlaceHolder extends ResolvedType |
||||
{ |
||||
protected final int _ordinal; |
||||
|
||||
/** |
||||
* Type assigned during wildcard resolution |
||||
*/ |
||||
protected ResolvedType _actualType; |
||||
|
||||
public TypePlaceHolder(int ordinal) |
||||
{ |
||||
super(Object.class, TypeBindings.emptyBindings()); |
||||
_ordinal = ordinal; |
||||
} |
||||
|
||||
@Override |
||||
public boolean canCreateSubtypes() { return false; } |
||||
|
||||
public ResolvedType actualType() { return _actualType; } |
||||
public void actualType(ResolvedType t) { _actualType = t; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for related types |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public ResolvedType getParentClass() { return null; } |
||||
|
||||
@Override |
||||
public ResolvedType getSelfReferencedType() { return null; } |
||||
|
||||
@Override |
||||
public List<ResolvedType> getImplementedInterfaces() { return Collections.<ResolvedType>emptyList(); } |
||||
|
||||
@Override |
||||
public ResolvedType getArrayElementType() { return null; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Simple property accessors |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public boolean isInterface() { return false; } |
||||
|
||||
@Override |
||||
public boolean isAbstract() { return true; } |
||||
|
||||
@Override |
||||
public boolean isArray() { return false; } |
||||
|
||||
@Override |
||||
public boolean isPrimitive() { return false; } |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Accessors for raw (minimally procesed) members |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* String representations |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public StringBuilder appendSignature(StringBuilder sb) { |
||||
return _appendClassSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendErasedSignature(StringBuilder sb) { |
||||
return _appendErasedClassSignature(sb); |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendBriefDescription(StringBuilder sb) { |
||||
sb.append('<').append(_ordinal).append('>'); |
||||
return sb; |
||||
} |
||||
|
||||
@Override |
||||
public StringBuilder appendFullDescription(StringBuilder sb) { |
||||
return appendBriefDescription(sb); |
||||
} |
||||
} |
@ -0,0 +1,5 @@
|
||||
/** |
||||
* Package that contains {@link com.fr.third.com.fasterxml.classmate.ResolvedType} |
||||
* implementation classes. |
||||
*/ |
||||
package com.fr.third.com.fasterxml.classmate.types; |
@ -0,0 +1,69 @@
|
||||
package com.fr.third.com.fasterxml.classmate.util; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* Helper class used as key when we need efficient Class-to-value lookups. |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class ClassKey |
||||
implements Comparable<ClassKey>, Serializable |
||||
{ |
||||
private final String _className; |
||||
|
||||
private final Class<?> _class; |
||||
|
||||
/** |
||||
* Let's cache hash code straight away, since we are almost certain to need it. |
||||
*/ |
||||
private final int _hashCode; |
||||
|
||||
public ClassKey(Class<?> clz) |
||||
{ |
||||
_class = clz; |
||||
_className = clz.getName(); |
||||
_hashCode = _className.hashCode(); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Comparable |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public int compareTo(ClassKey other) |
||||
{ |
||||
// Just need to sort by name, ok to collide (unless used in TreeMap/Set!)
|
||||
return _className.compareTo(other._className); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
@Override |
||||
public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null) return false; |
||||
if (o.getClass() != getClass()) return false; |
||||
ClassKey other = (ClassKey) o; |
||||
|
||||
/* Is it possible to have different Class object for same name + class loader combo? |
||||
* Let's assume answer is no: if this is wrong, will need to uncomment following functionality |
||||
*/ |
||||
/* |
||||
return (other._className.equals(_className)) |
||||
&& (other._class.getClassLoader() == _class.getClassLoader()); |
||||
*/ |
||||
return other._class == _class; |
||||
} |
||||
|
||||
@Override public int hashCode() { return _hashCode; } |
||||
|
||||
@Override public String toString() { return _className; } |
||||
|
||||
} |
@ -0,0 +1,72 @@
|
||||
package com.fr.third.com.fasterxml.classmate.util; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
import com.fr.third.com.fasterxml.classmate.types.ResolvedRecursiveType; |
||||
|
||||
/** |
||||
* Simple helper class used to keep track of 'call stack' for classes being referenced |
||||
* (as well as unbound variables) |
||||
*/ |
||||
public final class ClassStack |
||||
{ |
||||
protected final ClassStack _parent; |
||||
protected final Class<?> _current; |
||||
|
||||
private ArrayList<ResolvedRecursiveType> _selfRefs; |
||||
|
||||
public ClassStack(Class<?> rootType) { |
||||
this(null, rootType); |
||||
} |
||||
|
||||
private ClassStack(ClassStack parent, Class<?> curr) { |
||||
_parent = parent; |
||||
_current = curr; |
||||
} |
||||
|
||||
/** |
||||
* @return New stack frame, if addition is ok; null if not |
||||
*/ |
||||
public ClassStack child(Class<?> cls) |
||||
{ |
||||
return new ClassStack(this, cls); |
||||
} |
||||
|
||||
/** |
||||
* Method called to indicate that there is a self-reference from |
||||
* deeper down in stack pointing into type this stack frame represents. |
||||
*/ |
||||
public void addSelfReference(ResolvedRecursiveType ref) |
||||
{ |
||||
if (_selfRefs == null) { |
||||
_selfRefs = new ArrayList<ResolvedRecursiveType>(); |
||||
} |
||||
_selfRefs.add(ref); |
||||
} |
||||
|
||||
/** |
||||
* Method called when type that this stack frame represents is |
||||
* fully resolved, allowing self-references to be completed |
||||
* (if there are any) |
||||
*/ |
||||
public void resolveSelfReferences(ResolvedType resolved) |
||||
{ |
||||
if (_selfRefs != null) { |
||||
for (ResolvedRecursiveType ref : _selfRefs) { |
||||
ref.setReference(resolved); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public ClassStack find(Class<?> cls) |
||||
{ |
||||
if (_current == cls) return this; |
||||
for (ClassStack curr = _parent; curr != null; curr = curr._parent) { |
||||
if (curr._current == cls) { |
||||
return curr; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,71 @@
|
||||
package com.fr.third.com.fasterxml.classmate.util; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* Helper class needed when storing methods in maps. |
||||
* Immutable. |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class MethodKey implements Serializable |
||||
{ |
||||
private static final Class<?>[] NO_CLASSES = new Class[0]; |
||||
|
||||
private final String _name; |
||||
|
||||
private final Class<?>[] _argumentTypes; |
||||
|
||||
private final int _hashCode; |
||||
|
||||
public MethodKey(String name) |
||||
{ |
||||
_name = name; |
||||
_argumentTypes = NO_CLASSES; |
||||
_hashCode = name.hashCode(); |
||||
} |
||||
|
||||
public MethodKey(String name, Class<?>[] argTypes) |
||||
{ |
||||
_name = name; |
||||
_argumentTypes = argTypes; |
||||
_hashCode = name.hashCode() + argTypes.length; |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Standard methods |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Equality means name is the same and argument type erasures as well. |
||||
*/ |
||||
@Override public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
MethodKey other = (MethodKey) o; |
||||
Class<?>[] otherArgs = other._argumentTypes; |
||||
int len = _argumentTypes.length; |
||||
if (otherArgs.length != len) return false; |
||||
for (int i = 0; i < len; ++i) { |
||||
if (otherArgs[i] != _argumentTypes[i]) return false; |
||||
} |
||||
return _name.equals(other._name); |
||||
} |
||||
|
||||
@Override public int hashCode() { return _hashCode; } |
||||
|
||||
@Override public String toString() |
||||
{ |
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.append(_name); |
||||
sb.append('('); |
||||
for (int i = 0, len = _argumentTypes.length; i < len; ++i) { |
||||
if (i > 0) sb.append(','); |
||||
sb.append(_argumentTypes[i].getName()); |
||||
} |
||||
sb.append(')'); |
||||
return sb.toString(); |
||||
} |
||||
} |
@ -0,0 +1,141 @@
|
||||
package com.fr.third.com.fasterxml.classmate.util; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.*; |
||||
|
||||
import com.fr.third.com.fasterxml.classmate.ResolvedType; |
||||
|
||||
/** |
||||
* Simple LRU cache used for storing up to specified number of most recently accessed |
||||
* {@link ResolvedType} instances. |
||||
* Since usage pattern is such that caller needs synchronization, cache access methods |
||||
* are fully synchronized so that caller need not do explicit synchronization. |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class ResolvedTypeCache implements Serializable |
||||
{ |
||||
protected final CacheMap _map; |
||||
|
||||
public ResolvedTypeCache(int maxEntries) { |
||||
_map = new CacheMap(maxEntries); |
||||
} |
||||
|
||||
/** |
||||
* Helper method for constructing reusable cache keys |
||||
*/ |
||||
public Key key(Class<?> simpleType) { |
||||
return new Key(simpleType); |
||||
} |
||||
|
||||
/** |
||||
* Helper method for constructing reusable cache keys |
||||
*/ |
||||
public Key key(Class<?> simpleType, ResolvedType[] tp) { |
||||
return new Key(simpleType, tp); |
||||
} |
||||
|
||||
public synchronized ResolvedType find(Key key) { |
||||
return _map.get(key); |
||||
} |
||||
|
||||
public synchronized int size() { |
||||
return _map.size(); |
||||
} |
||||
|
||||
public synchronized void put(Key key, ResolvedType type) { |
||||
_map.put(key, type); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Methods for unit tests |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
public void add(ResolvedType type) |
||||
{ |
||||
List<ResolvedType> tp = type.getTypeParameters(); |
||||
ResolvedType[] tpa = tp.toArray(new ResolvedType[tp.size()]); |
||||
put(key(type.getErasedType(), tpa), type); |
||||
} |
||||
|
||||
/* |
||||
/********************************************************************** |
||||
/* Helper classes |
||||
/********************************************************************** |
||||
*/ |
||||
|
||||
/** |
||||
* Key used for type entries. |
||||
*/ |
||||
public static class Key |
||||
{ |
||||
private final Class<?> _erasedType; |
||||
|
||||
private final ResolvedType[] _typeParameters; |
||||
|
||||
private final int _hashCode; |
||||
|
||||
public Key(Class<?> simpleType) { |
||||
this(simpleType, null); |
||||
} |
||||
|
||||
public Key(Class<?> erasedType, ResolvedType[] tp) |
||||
{ |
||||
// let's not hold on type empty arrays
|
||||
if (tp != null && tp.length == 0) { |
||||
tp = null; |
||||
} |
||||
_erasedType = erasedType; |
||||
_typeParameters = tp; |
||||
int h = erasedType.getName().hashCode(); |
||||
if (tp != null) { |
||||
h += tp.length; |
||||
} |
||||
_hashCode = h; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { return _hashCode; } |
||||
|
||||
@Override |
||||
public boolean equals(Object o) |
||||
{ |
||||
if (o == this) return true; |
||||
if (o == null || o.getClass() != getClass()) return false; |
||||
Key other = (Key) o; |
||||
if (other._erasedType != _erasedType) return false; |
||||
ResolvedType[] otherTP = other._typeParameters; |
||||
if (_typeParameters == null) { |
||||
return (otherTP == null); |
||||
} |
||||
if (otherTP == null || otherTP.length != _typeParameters.length) { |
||||
return false; |
||||
} |
||||
for (int i = 0, len = _typeParameters.length; i < len; ++i) { |
||||
if (!_typeParameters[i].equals(otherTP[i])) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Simple sub-class to get LRU cache |
||||
*/ |
||||
private final static class CacheMap |
||||
extends LinkedHashMap<ResolvedTypeCache.Key, ResolvedType> |
||||
{ |
||||
protected final int _maxEntries; |
||||
|
||||
public CacheMap(int maxEntries) { |
||||
_maxEntries = maxEntries; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean removeEldestEntry(Map.Entry<Key, ResolvedType> eldest) { |
||||
return size() > _maxEntries; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,4 @@
|
||||
/** |
||||
* Various utility classes used by ClassMate. |
||||
*/ |
||||
package com.fr.third.com.fasterxml.classmate.util; |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,9 @@
|
||||
# fine-hibernate |
||||
|
||||
改包名的hibernate(5.1.0.Final),包括: |
||||
|
||||
- hibernate-commons-annotations |
||||
- hibernate-core |
||||
- hibernate-entitymanager |
||||
- hibernate-java8 |
||||
- hibernate-jpamodelgen |
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="JAVA_MODULE" version="4"> |
||||
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
||||
<exclude-output /> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" /> |
||||
</content> |
||||
<orderEntry type="inheritedJdk" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
||||
<orderEntry type="module" module-name="fine-jboss-logging" /> |
||||
<orderEntry type="module" module-name="fine-classmate" /> |
||||
<orderEntry type="module" module-name="fine-jpa" /> |
||||
<orderEntry type="library" name="lib-hibernate" level="project" /> |
||||
<orderEntry type="module" module-name="fine-jboss-transaction-api" /> |
||||
<orderEntry type="library" name="base-lib" level="project" /> |
||||
</component> |
||||
</module> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,13 @@
|
||||
# |
||||
# Hibernate, Relational Persistence for Idiomatic Java |
||||
# |
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
# |
||||
# |
||||
# Hibernate, Relational Persistence for Idiomatic Java |
||||
# |
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
# |
||||
com.fr.third.org.hibernate.jpa.HibernatePersistenceProvider |
@ -0,0 +1,13 @@
|
||||
# |
||||
# Hibernate, Relational Persistence for Idiomatic Java |
||||
# |
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
# |
||||
# |
||||
# Hibernate, Relational Persistence for Idiomatic Java |
||||
# |
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
# |
||||
com.fr.third.org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor |
@ -0,0 +1,59 @@
|
||||
<!-- |
||||
~ Hibernate, Relational Persistence for Idiomatic Java |
||||
~ |
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
--> |
||||
|
||||
<!-- Hibernate file-based configuration document. |
||||
|
||||
<!DOCTYPE hibernate-configuration PUBLIC |
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" |
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> |
||||
|
||||
An instance of this document contains property settings and references |
||||
to mapping files for a number of SessionFactory instances to be listed |
||||
in JNDI. |
||||
|
||||
--> |
||||
|
||||
<!ELEMENT hibernate-configuration (session-factory,security?)> |
||||
|
||||
<!ELEMENT property (#PCDATA)> |
||||
<!ATTLIST property name CDATA #REQUIRED> |
||||
|
||||
<!ELEMENT mapping EMPTY> <!-- reference to a mapping file --> |
||||
<!ATTLIST mapping resource CDATA #IMPLIED> |
||||
<!ATTLIST mapping file CDATA #IMPLIED> |
||||
<!ATTLIST mapping jar CDATA #IMPLIED> |
||||
<!ATTLIST mapping package CDATA #IMPLIED> |
||||
<!ATTLIST mapping class CDATA #IMPLIED> |
||||
|
||||
<!ELEMENT class-cache EMPTY> |
||||
<!ATTLIST class-cache class CDATA #REQUIRED> |
||||
<!ATTLIST class-cache region CDATA #IMPLIED> |
||||
<!ATTLIST class-cache usage (read-only|read-write|nonstrict-read-write|transactional) #REQUIRED> |
||||
<!ATTLIST class-cache include (all|non-lazy) "all"> |
||||
|
||||
<!ELEMENT collection-cache EMPTY> |
||||
<!ATTLIST collection-cache collection CDATA #REQUIRED> |
||||
<!ATTLIST collection-cache region CDATA #IMPLIED> |
||||
<!ATTLIST collection-cache usage (read-only|read-write|nonstrict-read-write|transactional) #REQUIRED> |
||||
|
||||
<!ELEMENT event (listener*)> |
||||
<!ATTLIST event type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #REQUIRED> |
||||
|
||||
<!ELEMENT listener EMPTY> |
||||
<!ATTLIST listener type (auto-flush|merge|create|create-onflush|delete|dirty-check|evict|flush|flush-entity|load|load-collection|lock|refresh|replicate|save-update|save|update|pre-load|pre-update|pre-insert|pre-delete|pre-collection-recreate|pre-collection-remove|pre-collection-update|post-load|post-update|post-insert|post-delete|post-collection-recreate|post-collection-remove|post-collection-update|post-commit-update|post-commit-insert|post-commit-delete) #IMPLIED> |
||||
<!ATTLIST listener class CDATA #REQUIRED> |
||||
|
||||
<!ELEMENT session-factory (property*, mapping*, (class-cache|collection-cache)*, event*, listener*)> |
||||
<!ATTLIST session-factory name CDATA #IMPLIED> <!-- the JNDI name --> |
||||
|
||||
<!ELEMENT security (grant*)> |
||||
<!ATTLIST security context CDATA #REQUIRED> <!--the JACC contextID--> |
||||
|
||||
<!ELEMENT grant EMPTY> |
||||
<!ATTLIST grant role CDATA #REQUIRED> |
||||
<!ATTLIST grant entity-name CDATA #REQUIRED> |
||||
<!ATTLIST grant actions CDATA #REQUIRED> |
@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ Hibernate, Relational Persistence for Idiomatic Java |
||||
~ |
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
--> |
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" |
||||
xmlns="http://www.hibernate.org/xsd/orm/cfg" |
||||
targetNamespace="http://www.hibernate.org/xsd/orm/cfg" |
||||
elementFormDefault="qualified" |
||||
version="4.0"> |
||||
|
||||
<xs:element name="hibernate-configuration"> |
||||
<xs:complexType> |
||||
<xs:sequence> |
||||
<xs:element name="session-factory"> |
||||
<xs:complexType> |
||||
<xs:sequence> |
||||
<xs:element name="property" minOccurs="0" maxOccurs="unbounded" type="ConfigPropertyType"/> |
||||
<xs:element name="mapping" minOccurs="0" maxOccurs="unbounded" type="MappingReferenceType"/> |
||||
<xs:choice minOccurs="0" maxOccurs="unbounded"> |
||||
<xs:element name="class-cache" type="EntityCacheType"/> |
||||
<xs:element name="collection-cache" type="CollectionCacheType"/> |
||||
</xs:choice> |
||||
<xs:element name="event" minOccurs="0" maxOccurs="unbounded" type="EventListenerGroupType" /> |
||||
<xs:element name="listener" minOccurs="0" maxOccurs="unbounded" type="EventListenerType"/> |
||||
</xs:sequence> |
||||
<xs:attribute name="name" type="xs:string"/> |
||||
<!-- the JNDI name --> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
<xs:element name="security" minOccurs="0"> |
||||
<xs:complexType> |
||||
<xs:sequence> |
||||
<xs:element name="grant" minOccurs="0" maxOccurs="unbounded"> |
||||
<xs:complexType> |
||||
<xs:attribute name="actions" use="required" type="xs:string"/> |
||||
<xs:attribute name="entity-name" use="required" type="xs:string"/> |
||||
<xs:attribute name="role" use="required" type="xs:string"/> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
</xs:sequence> |
||||
<xs:attribute name="context" use="required" type="xs:string"/> |
||||
<!--the JACC contextID--> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
</xs:sequence> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
|
||||
<xs:complexType name="ConfigPropertyType" mixed="true"> |
||||
<xs:simpleContent> |
||||
<xs:extension base="xs:string"> |
||||
<xs:attribute name="name" use="required" type="xs:string"/> |
||||
</xs:extension> |
||||
</xs:simpleContent> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="MappingReferenceType"> |
||||
<xs:attribute name="class" type="xs:string"/> |
||||
<xs:attribute name="file" type="xs:string"/> |
||||
<xs:attribute name="jar" type="xs:string"/> |
||||
<xs:attribute name="package" type="xs:string"/> |
||||
<xs:attribute name="resource" type="xs:string"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="EntityCacheType"> |
||||
<xs:attribute name="class" use="required" type="xs:string"/> |
||||
<xs:attribute name="include" default="all"> |
||||
<xs:simpleType> |
||||
<xs:restriction base="xs:token"> |
||||
<xs:enumeration value="all"/> |
||||
<xs:enumeration value="non-lazy"/> |
||||
</xs:restriction> |
||||
</xs:simpleType> |
||||
</xs:attribute> |
||||
<xs:attribute name="region" type="xs:string"/> |
||||
<xs:attribute name="usage" use="required" type="CacheUsageEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="CollectionCacheType"> |
||||
<xs:attribute name="collection" use="required" type="xs:string"/> |
||||
<xs:attribute name="region" type="xs:string"/> |
||||
<xs:attribute name="usage" use="required" type="CacheUsageEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="EventListenerGroupType"> |
||||
<xs:sequence> |
||||
<xs:element name="listener" minOccurs="0" maxOccurs="unbounded" type="EventListenerType"/> |
||||
</xs:sequence> |
||||
<xs:attribute name="type" use="required" type="EventTypeEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="EventListenerType"> |
||||
<xs:attribute name="class" use="required" type="xs:string"/> |
||||
<xs:attribute name="type" type="EventTypeEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:simpleType name="EventTypeEnum"> |
||||
<xs:restriction base="xs:token"> |
||||
<xs:enumeration value="auto-flush"/> |
||||
<xs:enumeration value="create"/> |
||||
<xs:enumeration value="create-onflush"/> |
||||
<xs:enumeration value="delete"/> |
||||
<xs:enumeration value="dirty-check"/> |
||||
<xs:enumeration value="evict"/> |
||||
<xs:enumeration value="flush"/> |
||||
<xs:enumeration value="flush-entity"/> |
||||
<xs:enumeration value="load"/> |
||||
<xs:enumeration value="load-collection"/> |
||||
<xs:enumeration value="lock"/> |
||||
<xs:enumeration value="merge"/> |
||||
<xs:enumeration value="post-collection-recreate"/> |
||||
<xs:enumeration value="post-collection-remove"/> |
||||
<xs:enumeration value="post-collection-update"/> |
||||
<xs:enumeration value="post-commit-delete"/> |
||||
<xs:enumeration value="post-commit-insert"/> |
||||
<xs:enumeration value="post-commit-update"/> |
||||
<xs:enumeration value="post-delete"/> |
||||
<xs:enumeration value="post-insert"/> |
||||
<xs:enumeration value="post-load"/> |
||||
<xs:enumeration value="post-update"/> |
||||
<xs:enumeration value="pre-collection-recreate"/> |
||||
<xs:enumeration value="pre-collection-remove"/> |
||||
<xs:enumeration value="pre-collection-update"/> |
||||
<xs:enumeration value="pre-delete"/> |
||||
<xs:enumeration value="pre-insert"/> |
||||
<xs:enumeration value="pre-load"/> |
||||
<xs:enumeration value="pre-update"/> |
||||
<xs:enumeration value="refresh"/> |
||||
<xs:enumeration value="replicate"/> |
||||
<xs:enumeration value="save"/> |
||||
<xs:enumeration value="save-update"/> |
||||
<xs:enumeration value="update"/> |
||||
</xs:restriction> |
||||
</xs:simpleType> |
||||
|
||||
<xs:simpleType name="CacheUsageEnum"> |
||||
<xs:restriction base="xs:token"> |
||||
<xs:enumeration value="nonstrict-read-write"/> |
||||
<xs:enumeration value="read-only"/> |
||||
<xs:enumeration value="read-write"/> |
||||
<xs:enumeration value="transactional"/> |
||||
</xs:restriction> |
||||
</xs:simpleType> |
||||
|
||||
</xs:schema> |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,267 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- |
||||
~ Hibernate, Relational Persistence for Idiomatic Java |
||||
~ |
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
--> |
||||
|
||||
<!-- persistence.xml schema --> |
||||
<xsd:schema targetNamespace="http://java.sun.com/xml/ns/persistence" |
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
||||
xmlns:persistence="http://java.sun.com/xml/ns/persistence" |
||||
elementFormDefault="qualified" |
||||
attributeFormDefault="unqualified" |
||||
version="1.0"> |
||||
|
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
@(#)persistence_1_0.xsd 1.0 Feb 9 2006 |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:annotation> |
||||
<xsd:documentation><![CDATA[ |
||||
|
||||
This is the XML Schema for the persistence configuration file. |
||||
The file must be named "META-INF/persistence.xml" in the |
||||
persistence archive. |
||||
Persistence configuration files must indicate |
||||
the persistence schema by using the persistence namespace: |
||||
|
||||
http://java.sun.com/xml/ns/persistence |
||||
|
||||
and indicate the version of the schema by |
||||
using the version element as shown below: |
||||
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence |
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" |
||||
version="1.0"> |
||||
... |
||||
</persistence> |
||||
|
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
|
||||
<xsd:simpleType name="versionType"> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:pattern value="[0-9]+(\.[0-9]+)*"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="persistence"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="persistence-unit" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:complexType> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Configuration of a persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:sequence> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="description" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Textual description of this persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="provider" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Provider class that supplies EntityManagers for this |
||||
persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="jta-data-source" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
The container-specific name of the JTA datasource to use. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="non-jta-data-source" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
The container-specific name of a non-JTA datasource to use. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="mapping-file" type="xsd:string" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
File containing mapping information. Loaded as a resource |
||||
by the persistence provider. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="jar-file" type="xsd:string" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Jar file that should be scanned for entities. |
||||
Not applicable to Java SE persistence units. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="class" type="xsd:string" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Class to scan for annotations. It should be annotated |
||||
with either @Entity, @Embeddable or @MappedSuperclass. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="exclude-unlisted-classes" type="xsd:boolean" |
||||
default="false" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
When set to true then only listed classes and jars will |
||||
be scanned for persistent classes, otherwise the enclosing |
||||
jar or directory will also be scanned. Not applicable to |
||||
Java SE persistence units. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="properties" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
A list of vendor-specific properties. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="property" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
A name-value pair. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="name" type="xsd:string" |
||||
use="required"/> |
||||
<xsd:attribute name="value" type="xsd:string" |
||||
use="required"/> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:sequence> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
|
||||
</xsd:sequence> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:attribute name="name" type="xsd:string" use="required"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Name used in code to reference this persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:attribute name="transaction-type" |
||||
type="persistence:persistence-unit-transaction-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Type of transactions used by EntityManagers from this |
||||
persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
|
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="version" type="persistence:versionType" |
||||
fixed="1.0" use="required"/> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:simpleType name="persistence-unit-transaction-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
public enum TransactionType { JTA, RESOURCE_LOCAL }; |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:enumeration value="JTA"/> |
||||
<xsd:enumeration value="RESOURCE_LOCAL"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
|
||||
</xsd:schema> |
||||
|
@ -0,0 +1,232 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> <!-- |
||||
~ Hibernate, Relational Persistence for Idiomatic Java |
||||
~ |
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
--> <!-- persistence.xml schema --> |
||||
<xsd:schema targetNamespace="http://java.sun.com/xml/ns/persistence" |
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
||||
xmlns:persistence="http://java.sun.com/xml/ns/persistence" |
||||
elementFormDefault="qualified" |
||||
attributeFormDefault="unqualified" |
||||
version="2.0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
@(#)persistence_2_0.xsd 1.0 October 1 2009 |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:annotation> |
||||
<xsd:documentation><![CDATA[ |
||||
This is the XML Schema for the persistence configuration file. The file must be named "META-INF/persistence.xml" in the persistence archive. |
||||
Persistence configuration files must indicate the persistence schema by using the persistence namespace: |
||||
http://java.sun.com/xml/ns/persistence |
||||
and indicate the version of the schema by using the version element as shown below: |
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence |
||||
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> |
||||
... </persistence> |
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:simpleType name="versionType"> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:pattern value="[0-9]+(\.[0-9]+)*"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="persistence"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="persistence-unit" minOccurs="1" maxOccurs="unbounded"> |
||||
<xsd:complexType> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
Configuration of a persistence unit. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:sequence> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="description" type="xsd:string" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
Description of this persistence unit. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="provider" type="xsd:string" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
Provider class that supplies EntityManagers for this persistence unit. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="jta-data-source" type="xsd:string" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
The container-specific name of the JTA datasource to use. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="non-jta-data-source" type="xsd:string" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
The container-specific name of a non-JTA datasource to use. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="mapping-file" type="xsd:string" minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
File containing mapping information. Loaded as a resource by the persistence |
||||
provider. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="jar-file" type="xsd:string" minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
Jar file that is to be scanned for managed classes. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="class" type="xsd:string" minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
Managed class to be included in the persistence unit and to scan for |
||||
annotations. It should be annotated with either @Entity, @Embeddable or |
||||
@MappedSuperclass. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="exclude-unlisted-classes" |
||||
type="xsd:boolean" |
||||
default="true" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
When set to true then only listed classes and jars will be scanned for |
||||
persistent classes, otherwise the enclosing jar or directory will also be |
||||
scanned. Not applicable to Java SE persistence units. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="shared-cache-mode" type="persistence:persistence-unit-caching-type" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
Defines whether caching is enabled for the persistence unit if caching is |
||||
supported by the persistence provider. When set to ALL, all entities will be |
||||
cached. When set to NONE, no entities will be cached. When set to |
||||
ENABLE_SELECTIVE, only entities specified as cacheable will be cached. When set |
||||
to |
||||
JSR-317 Final Release |
||||
323 11/10/09 |
||||
Sun Microsystems, Inc. |
||||
Entity Packaging |
||||
Java Persistence 2.0, Final Release persistence.xml Schema |
||||
DISABLE_SELECTIVE, entities specified as not cacheable will not be cached. When |
||||
not specified or when set to UNSPECIFIED, provider defaults may apply. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="validation-mode" type="persistence:persistence-unit-validation-mode-type" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation>The validation mode to be used for the persistence unit. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:element name="properties" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
A list of standard and vendor-specific properties and hints. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="property" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation>A name-value pair.</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="name" type="xsd:string" use="required"/> |
||||
<xsd:attribute name="value" type="xsd:string" use="required"/> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:sequence> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:sequence> |
||||
<!-- **************************************************** --> |
||||
<xsd:attribute name="name" type="xsd:string" use="required"> |
||||
<xsd:annotation> |
||||
<xsd:documentation>Name used in code to reference this persistence unit. |
||||
</xsd:documentation> |
||||
|
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
<!-- **************************************************** --> |
||||
<xsd:attribute name="transaction-type" type="persistence:persistence-unit-transaction-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
Type of transactions used by EntityManagers from this persistence unit. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="version" type="persistence:versionType" |
||||
fixed="2.0" use="required"/> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<!-- **************************************************** --> |
||||
<xsd:simpleType name="persistence-unit-transaction-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation>public enum PersistenceUnitTransactionType {JTA, RESOURCE_LOCAL}; |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:enumeration value="JTA"/> |
||||
<xsd:enumeration value="RESOURCE_LOCAL"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
<!-- **************************************************** --> |
||||
<xsd:simpleType name="persistence-unit-caching-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
public enum SharedCacheMode { ALL, NONE, ENABLE_SELECTIVE, DISABLE_SELECTIVE, UNSPECIFIED}; |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:enumeration value="ALL"/> |
||||
<xsd:enumeration value="NONE"/> |
||||
<xsd:enumeration value="ENABLE_SELECTIVE"/> |
||||
<xsd:enumeration value="DISABLE_SELECTIVE"/> |
||||
<xsd:enumeration value="UNSPECIFIED"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
|
||||
<!-- **************************************************** --> |
||||
<xsd:simpleType name="persistence-unit-validation-mode-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation>public enum ValidationMode { AUTO, CALLBACK, NONE}; |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:enumeration value="AUTO"/> |
||||
<xsd:enumeration value="CALLBACK"/> |
||||
<xsd:enumeration value="NONE"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
</xsd:schema> |
@ -0,0 +1,341 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
||||
<!-- |
||||
~ Hibernate, Relational Persistence for Idiomatic Java |
||||
~ |
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
--> |
||||
<xsd:schema targetNamespace="http://xmlns.jcp.org/xml/ns/persistence" |
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
||||
xmlns:persistence="http://xmlns.jcp.org/xml/ns/persistence" |
||||
elementFormDefault="qualified" |
||||
attributeFormDefault="unqualified" |
||||
version="2.1"> |
||||
|
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
@(#)persistence_2_1.xsd 2.1 February 8, 2013 |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
|
||||
<xsd:annotation> |
||||
<xsd:documentation><![CDATA[ |
||||
|
||||
This is the XML Schema for the persistence configuration file. |
||||
The file must be named "META-INF/persistence.xml" in the |
||||
persistence archive. |
||||
|
||||
Persistence configuration files must indicate |
||||
the persistence schema by using the persistence namespace: |
||||
|
||||
http://xmlns.jcp.org/xml/ns/persistence |
||||
|
||||
and indicate the version of the schema by |
||||
using the version element as shown below: |
||||
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence |
||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" |
||||
version="2.1"> |
||||
... |
||||
</persistence> |
||||
|
||||
]]></xsd:documentation> |
||||
</xsd:annotation> |
||||
|
||||
<xsd:simpleType name="versionType"> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:pattern value="[0-9]+(\.[0-9]+)*"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="persistence"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="persistence-unit" |
||||
minOccurs="1" maxOccurs="unbounded"> |
||||
<xsd:complexType> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Configuration of a persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:sequence> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="description" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Description of this persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="provider" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Provider class that supplies EntityManagers for this |
||||
persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="jta-data-source" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
The container-specific name of the JTA datasource to use. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="non-jta-data-source" type="xsd:string" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
The container-specific name of a non-JTA datasource to use. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="mapping-file" type="xsd:string" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
File containing mapping information. Loaded as a resource |
||||
by the persistence provider. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="jar-file" type="xsd:string" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Jar file that is to be scanned for managed classes. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="class" type="xsd:string" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Managed class to be included in the persistence unit and |
||||
to scan for annotations. It should be annotated |
||||
with either @Entity, @Embeddable or @MappedSuperclass. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="exclude-unlisted-classes" type="xsd:boolean" |
||||
default="true" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
When set to true then only listed classes and jars will |
||||
be scanned for persistent classes, otherwise the |
||||
enclosing jar or directory will also be scanned. |
||||
Not applicable to Java SE persistence units. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="shared-cache-mode" |
||||
type="persistence:persistence-unit-caching-type" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Defines whether caching is enabled for the |
||||
persistence unit if caching is supported by the |
||||
persistence provider. When set to ALL, all entities |
||||
will be cached. When set to NONE, no entities will |
||||
be cached. When set to ENABLE_SELECTIVE, only entities |
||||
specified as cacheable will be cached. When set to |
||||
DISABLE_SELECTIVE, entities specified as not cacheable |
||||
will not be cached. When not specified or when set to |
||||
UNSPECIFIED, provider defaults may apply. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="validation-mode" |
||||
type="persistence:persistence-unit-validation-mode-type" |
||||
minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
The validation mode to be used for the persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:element> |
||||
|
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:element name="properties" minOccurs="0"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
A list of standard and vendor-specific properties |
||||
and hints. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="property" |
||||
minOccurs="0" maxOccurs="unbounded"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
A name-value pair. |
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="name" type="xsd:string" |
||||
use="required"/> |
||||
<xsd:attribute name="value" type="xsd:string" |
||||
use="required"/> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:sequence> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
|
||||
</xsd:sequence> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:attribute name="name" type="xsd:string" use="required"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Name used in code to reference this persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:attribute name="transaction-type" |
||||
type="persistence:persistence-unit-transaction-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
Type of transactions used by EntityManagers from this |
||||
persistence unit. |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
</xsd:attribute> |
||||
|
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="version" type="persistence:versionType" |
||||
fixed="2.1" use="required"/> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:simpleType name="persistence-unit-transaction-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
public enum PersistenceUnitTransactionType {JTA, RESOURCE_LOCAL}; |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:enumeration value="JTA"/> |
||||
<xsd:enumeration value="RESOURCE_LOCAL"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:simpleType name="persistence-unit-caching-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
public enum SharedCacheMode { ALL, NONE, ENABLE_SELECTIVE, DISABLE_SELECTIVE, UNSPECIFIED}; |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:enumeration value="ALL"/> |
||||
<xsd:enumeration value="NONE"/> |
||||
<xsd:enumeration value="ENABLE_SELECTIVE"/> |
||||
<xsd:enumeration value="DISABLE_SELECTIVE"/> |
||||
<xsd:enumeration value="UNSPECIFIED"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
|
||||
<!-- **************************************************** --> |
||||
|
||||
<xsd:simpleType name="persistence-unit-validation-mode-type"> |
||||
<xsd:annotation> |
||||
<xsd:documentation> |
||||
|
||||
public enum ValidationMode { AUTO, CALLBACK, NONE}; |
||||
|
||||
</xsd:documentation> |
||||
</xsd:annotation> |
||||
<xsd:restriction base="xsd:token"> |
||||
<xsd:enumeration value="AUTO"/> |
||||
<xsd:enumeration value="CALLBACK"/> |
||||
<xsd:enumeration value="NONE"/> |
||||
</xsd:restriction> |
||||
</xsd:simpleType> |
||||
|
||||
</xsd:schema> |
@ -0,0 +1,149 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
||||
<!-- |
||||
~ Hibernate, Relational Persistence for Idiomatic Java |
||||
~ |
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
||||
--> |
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" |
||||
xmlns="http://www.hibernate.org/xsd/orm/cfg" |
||||
targetNamespace="http://www.hibernate.org/xsd/orm/cfg" |
||||
elementFormDefault="qualified" |
||||
version="4.0"> |
||||
|
||||
<xs:element name="hibernate-configuration"> |
||||
<xs:complexType> |
||||
<xs:sequence> |
||||
<xs:element name="session-factory"> |
||||
<xs:complexType> |
||||
<xs:sequence> |
||||
<xs:element name="property" minOccurs="0" maxOccurs="unbounded" type="ConfigPropertyType"/> |
||||
<xs:element name="mapping" minOccurs="0" maxOccurs="unbounded" type="MappingReferenceType"/> |
||||
<xs:choice minOccurs="0" maxOccurs="unbounded"> |
||||
<xs:element name="class-cache" type="EntityCacheType"/> |
||||
<xs:element name="collection-cache" type="CollectionCacheType"/> |
||||
</xs:choice> |
||||
<xs:element name="event" minOccurs="0" maxOccurs="unbounded" type="EventListenerGroupType" /> |
||||
<xs:element name="listener" minOccurs="0" maxOccurs="unbounded" type="EventListenerType"/> |
||||
</xs:sequence> |
||||
<xs:attribute name="name" type="xs:string"/> |
||||
<!-- the JNDI name --> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
<xs:element name="security" minOccurs="0"> |
||||
<xs:complexType> |
||||
<xs:sequence> |
||||
<xs:element name="grant" minOccurs="0" maxOccurs="unbounded"> |
||||
<xs:complexType> |
||||
<xs:attribute name="actions" use="required" type="xs:string"/> |
||||
<xs:attribute name="entity-name" use="required" type="xs:string"/> |
||||
<xs:attribute name="role" use="required" type="xs:string"/> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
</xs:sequence> |
||||
<xs:attribute name="context" use="required" type="xs:string"/> |
||||
<!--the JACC contextID--> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
</xs:sequence> |
||||
</xs:complexType> |
||||
</xs:element> |
||||
|
||||
<xs:complexType name="ConfigPropertyType" mixed="true"> |
||||
<xs:simpleContent> |
||||
<xs:extension base="xs:string"> |
||||
<xs:attribute name="name" use="required" type="xs:string"/> |
||||
</xs:extension> |
||||
</xs:simpleContent> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="MappingReferenceType"> |
||||
<xs:attribute name="class" type="xs:string"/> |
||||
<xs:attribute name="file" type="xs:string"/> |
||||
<xs:attribute name="jar" type="xs:string"/> |
||||
<xs:attribute name="package" type="xs:string"/> |
||||
<xs:attribute name="resource" type="xs:string"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="EntityCacheType"> |
||||
<xs:attribute name="class" use="required" type="xs:string"/> |
||||
<xs:attribute name="include" default="all"> |
||||
<xs:simpleType> |
||||
<xs:restriction base="xs:token"> |
||||
<xs:enumeration value="all"/> |
||||
<xs:enumeration value="non-lazy"/> |
||||
</xs:restriction> |
||||
</xs:simpleType> |
||||
</xs:attribute> |
||||
<xs:attribute name="region" type="xs:string"/> |
||||
<xs:attribute name="usage" use="required" type="CacheUsageEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="CollectionCacheType"> |
||||
<xs:attribute name="collection" use="required" type="xs:string"/> |
||||
<xs:attribute name="region" type="xs:string"/> |
||||
<xs:attribute name="usage" use="required" type="CacheUsageEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="EventListenerGroupType"> |
||||
<xs:sequence> |
||||
<xs:element name="listener" minOccurs="0" maxOccurs="unbounded" type="EventListenerType"/> |
||||
</xs:sequence> |
||||
<xs:attribute name="type" use="required" type="EventTypeEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:complexType name="EventListenerType"> |
||||
<xs:attribute name="class" use="required" type="xs:string"/> |
||||
<xs:attribute name="type" type="EventTypeEnum"/> |
||||
</xs:complexType> |
||||
|
||||
<xs:simpleType name="EventTypeEnum"> |
||||
<xs:restriction base="xs:token"> |
||||
<xs:enumeration value="auto-flush"/> |
||||
<xs:enumeration value="create"/> |
||||
<xs:enumeration value="create-onflush"/> |
||||
<xs:enumeration value="delete"/> |
||||
<xs:enumeration value="dirty-check"/> |
||||
<xs:enumeration value="evict"/> |
||||
<xs:enumeration value="flush"/> |
||||
<xs:enumeration value="flush-entity"/> |
||||
<xs:enumeration value="load"/> |
||||
<xs:enumeration value="load-collection"/> |
||||
<xs:enumeration value="lock"/> |
||||
<xs:enumeration value="merge"/> |
||||
<xs:enumeration value="post-collection-recreate"/> |
||||
<xs:enumeration value="post-collection-remove"/> |
||||
<xs:enumeration value="post-collection-update"/> |
||||
<xs:enumeration value="post-commit-delete"/> |
||||
<xs:enumeration value="post-commit-insert"/> |
||||
<xs:enumeration value="post-commit-update"/> |
||||
<xs:enumeration value="post-delete"/> |
||||
<xs:enumeration value="post-insert"/> |
||||
<xs:enumeration value="post-load"/> |
||||
<xs:enumeration value="post-update"/> |
||||
<xs:enumeration value="pre-collection-recreate"/> |
||||
<xs:enumeration value="pre-collection-remove"/> |
||||
<xs:enumeration value="pre-collection-update"/> |
||||
<xs:enumeration value="pre-delete"/> |
||||
<xs:enumeration value="pre-insert"/> |
||||
<xs:enumeration value="pre-load"/> |
||||
<xs:enumeration value="pre-update"/> |
||||
<xs:enumeration value="refresh"/> |
||||
<xs:enumeration value="replicate"/> |
||||
<xs:enumeration value="save"/> |
||||
<xs:enumeration value="save-update"/> |
||||
<xs:enumeration value="update"/> |
||||
</xs:restriction> |
||||
</xs:simpleType> |
||||
|
||||
<xs:simpleType name="CacheUsageEnum"> |
||||
<xs:restriction base="xs:token"> |
||||
<xs:enumeration value="nonstrict-read-write"/> |
||||
<xs:enumeration value="read-only"/> |
||||
<xs:enumeration value="read-write"/> |
||||
<xs:enumeration value="transactional"/> |
||||
</xs:restriction> |
||||
</xs:simpleType> |
||||
|
||||
</xs:schema> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* Annotation related exception. |
||||
* |
||||
* The EJB3 EG will probably set a generic exception. I'll then use this one. |
||||
* |
||||
* @author Emmanuel Bernard |
||||
*/ |
||||
public class AnnotationException extends MappingException { |
||||
/** |
||||
* Constructs an AnnotationException using the given message and cause. |
||||
* |
||||
* @param msg The message explaining the reason for the exception. |
||||
* @param cause The underlying cause. |
||||
*/ |
||||
public AnnotationException(String msg, Throwable cause) { |
||||
super( msg, cause ); |
||||
} |
||||
|
||||
/** |
||||
* Constructs an AnnotationException using the given message. |
||||
* |
||||
* @param msg The message explaining the reason for the exception. |
||||
*/ |
||||
public AnnotationException(String msg) { |
||||
super( msg ); |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import com.fr.third.org.hibernate.internal.CoreMessageLogger; |
||||
|
||||
import com.fr.third.org.jboss.logging.Logger; |
||||
|
||||
/** |
||||
* Indicates failure of an assertion: a possible bug in Hibernate. |
||||
* |
||||
* @author Gavin King |
||||
*/ |
||||
public class AssertionFailure extends RuntimeException { |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger( |
||||
CoreMessageLogger.class, |
||||
AssertionFailure.class.getName() |
||||
); |
||||
|
||||
/** |
||||
* Creates an instance of AssertionFailure using the given message. |
||||
* |
||||
* @param message The message explaining the reason for the exception |
||||
*/ |
||||
public AssertionFailure(String message) { |
||||
super( message ); |
||||
LOG.failed( this ); |
||||
} |
||||
|
||||
/** |
||||
* Creates an instance of AssertionFailure using the given message and underlying cause. |
||||
* |
||||
* @param message The message explaining the reason for the exception |
||||
* @param cause The underlying cause. |
||||
*/ |
||||
public AssertionFailure(String message, Throwable cause) { |
||||
super( message, cause ); |
||||
LOG.failed( cause ); |
||||
} |
||||
} |
@ -0,0 +1,104 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* A no-op implementation of SessionEventListener. Intended as a convenient base class for developing |
||||
* SessionEventListener implementations. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
@SuppressWarnings("UnusedDeclaration") |
||||
public class BaseSessionEventListener implements SessionEventListener { |
||||
@Override |
||||
public void transactionCompletion(boolean successful) { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcConnectionAcquisitionStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcConnectionAcquisitionEnd() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcConnectionReleaseStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcConnectionReleaseEnd() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcPrepareStatementStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcPrepareStatementEnd() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcExecuteStatementStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcExecuteStatementEnd() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcExecuteBatchStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void jdbcExecuteBatchEnd() { |
||||
} |
||||
|
||||
@Override |
||||
public void cachePutStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void cachePutEnd() { |
||||
} |
||||
|
||||
@Override |
||||
public void cacheGetStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void cacheGetEnd(boolean hit) { |
||||
} |
||||
|
||||
@Override |
||||
public void flushStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void flushEnd(int numberOfEntities, int numberOfCollections) { |
||||
} |
||||
|
||||
@Override |
||||
public void partialFlushStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void partialFlushEnd(int numberOfEntities, int numberOfCollections) { |
||||
} |
||||
|
||||
@Override |
||||
public void dirtyCalculationStart() { |
||||
} |
||||
|
||||
@Override |
||||
public void dirtyCalculationEnd(boolean dirty) { |
||||
} |
||||
|
||||
@Override |
||||
public void end() { |
||||
} |
||||
} |
@ -0,0 +1,212 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import com.fr.third.org.hibernate.type.Type; |
||||
|
||||
/** |
||||
* Defines the aspects of query definition that apply to all forms of querying. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public interface BasicQueryContract { |
||||
/** |
||||
* Obtain the FlushMode in effect for this query. By default, the query inherits the FlushMode of the Session |
||||
* from which is originates. |
||||
* |
||||
* @return The query FlushMode. |
||||
* |
||||
* @see Session#getFlushMode() |
||||
* @see FlushMode |
||||
*/ |
||||
public FlushMode getFlushMode(); |
||||
|
||||
/** |
||||
* (Re)set the current FlushMode in effect for this query. |
||||
* |
||||
* @param flushMode The new FlushMode to use. |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
* |
||||
* @see #getFlushMode() |
||||
*/ |
||||
public BasicQueryContract setFlushMode(FlushMode flushMode); |
||||
|
||||
/** |
||||
* Obtain the CacheMode in effect for this query. By default, the query inherits the CacheMode of the Session |
||||
* from which is originates. |
||||
* |
||||
* NOTE: The CacheMode here only effects reading/writing of the query cache, not the |
||||
* entity/collection caches. |
||||
* |
||||
* @return The query CacheMode. |
||||
* |
||||
* @see Session#getCacheMode() |
||||
* @see CacheMode |
||||
*/ |
||||
public CacheMode getCacheMode(); |
||||
|
||||
/** |
||||
* (Re)set the current CacheMode in effect for this query. |
||||
* |
||||
* @param cacheMode The new CacheMode to use. |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
* |
||||
* @see #getCacheMode() |
||||
*/ |
||||
public BasicQueryContract setCacheMode(CacheMode cacheMode); |
||||
|
||||
/** |
||||
* Are the results of this query eligible for second level query caching? This is different that second level |
||||
* caching of any returned entities and collections. |
||||
* |
||||
* NOTE: the query being "eligible" for caching does not necessarily mean its results will be cached. Second level |
||||
* query caching still has to be enabled on the {@link SessionFactory} for this to happen. Usually that is |
||||
* controlled by the {@code hibernate.cache.use_query_cache} configuration setting. |
||||
* |
||||
* @return {@code true} if the query results are eligible for caching, {@code false} otherwise. |
||||
* |
||||
* @see com.fr.third.org.hibernate.cfg.AvailableSettings#USE_QUERY_CACHE |
||||
*/ |
||||
public boolean isCacheable(); |
||||
|
||||
/** |
||||
* Enable/disable second level query (result) caching for this query. |
||||
* |
||||
* @param cacheable Should the query results be cacheable? |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
* |
||||
* @see #isCacheable |
||||
*/ |
||||
public BasicQueryContract setCacheable(boolean cacheable); |
||||
|
||||
/** |
||||
* Obtain the name of the second level query cache region in which query results will be stored (if they are |
||||
* cached, see the discussion on {@link #isCacheable()} for more information). {@code null} indicates that the |
||||
* default region should be used. |
||||
* |
||||
* @return The specified cache region name into which query results should be placed; {@code null} indicates |
||||
* the default region. |
||||
*/ |
||||
public String getCacheRegion(); |
||||
|
||||
/** |
||||
* Set the name of the cache region where query results should be cached (if cached at all). |
||||
* |
||||
* @param cacheRegion the name of a query cache region, or {@code null} to indicate that the default region |
||||
* should be used. |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
* |
||||
* @see #getCacheRegion() |
||||
*/ |
||||
public BasicQueryContract setCacheRegion(String cacheRegion); |
||||
|
||||
/** |
||||
* Obtain the query timeout <b>in seconds</b>. This value is eventually passed along to the JDBC query via |
||||
* {@link java.sql.Statement#setQueryTimeout(int)}. Zero indicates no timeout. |
||||
* |
||||
* @return The timeout <b>in seconds</b> |
||||
* |
||||
* @see java.sql.Statement#getQueryTimeout() |
||||
* @see java.sql.Statement#setQueryTimeout(int) |
||||
*/ |
||||
public Integer getTimeout(); |
||||
|
||||
/** |
||||
* Set the query timeout <b>in seconds</b>. |
||||
* |
||||
* NOTE it is important to understand that any value set here is eventually passed directly through to the JDBC |
||||
* Statement which expressly disallows negative values. So negative values should be avoided as a general rule. |
||||
* |
||||
* @param timeout the timeout <b>in seconds</b> |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
* |
||||
* @see #getTimeout() |
||||
*/ |
||||
public BasicQueryContract setTimeout(int timeout); |
||||
|
||||
/** |
||||
* Obtain the JDBC fetch size hint in effect for this query. This value is eventually passed along to the JDBC |
||||
* query via {@link java.sql.Statement#setFetchSize(int)}. As defined b y JDBC, this value is a hint to the |
||||
* driver to indicate how many rows to fetch from the database when more rows are needed. |
||||
* |
||||
* NOTE : JDBC expressly defines this value as a hint. It may or may not have any effect on the actual |
||||
* query execution and ResultSet processing depending on the driver. |
||||
* |
||||
* @return The timeout <b>in seconds</b> |
||||
* |
||||
* @see java.sql.Statement#getFetchSize() |
||||
* @see java.sql.Statement#setFetchSize(int) |
||||
*/ |
||||
public Integer getFetchSize(); |
||||
|
||||
/** |
||||
* Sets a JDBC fetch size hint for the query. |
||||
* |
||||
* @param fetchSize the fetch size hint |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
* |
||||
* @see #getFetchSize() |
||||
*/ |
||||
public BasicQueryContract setFetchSize(int fetchSize); |
||||
|
||||
/** |
||||
* Should entities and proxies loaded by this Query be put in read-only mode? If the |
||||
* read-only/modifiable setting was not initialized, then the default |
||||
* read-only/modifiable setting for the persistence context is returned instead. |
||||
* @see Query#setReadOnly(boolean) |
||||
* @see com.fr.third.org.hibernate.engine.spi.PersistenceContext#isDefaultReadOnly() |
||||
* |
||||
* The read-only/modifiable setting has no impact on entities/proxies returned by the |
||||
* query that existed in the session before the query was executed. |
||||
* |
||||
* @return true, entities and proxies loaded by the query will be put in read-only mode |
||||
* false, entities and proxies loaded by the query will be put in modifiable mode |
||||
*/ |
||||
public boolean isReadOnly(); |
||||
|
||||
/** |
||||
* Set the read-only/modifiable mode for entities and proxies |
||||
* loaded by this Query. This setting overrides the default setting |
||||
* for the persistence context. |
||||
* @see com.fr.third.org.hibernate.engine.spi.PersistenceContext#isDefaultReadOnly() |
||||
* |
||||
* To set the default read-only/modifiable setting used for |
||||
* entities and proxies that are loaded into the session: |
||||
* @see com.fr.third.org.hibernate.engine.spi.PersistenceContext#setDefaultReadOnly(boolean) |
||||
* @see com.fr.third.org.hibernate.Session#setDefaultReadOnly(boolean) |
||||
* |
||||
* Read-only entities are not dirty-checked and snapshots of persistent |
||||
* state are not maintained. Read-only entities can be modified, but |
||||
* changes are not persisted. |
||||
* |
||||
* When a proxy is initialized, the loaded entity will have the same |
||||
* read-only/modifiable setting as the uninitialized |
||||
* proxy has, regardless of the session's current setting. |
||||
* |
||||
* The read-only/modifiable setting has no impact on entities/proxies |
||||
* returned by the query that existed in the session before the query was executed. |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
* |
||||
* @param readOnly true, entities and proxies loaded by the query will be put in read-only mode |
||||
* false, entities and proxies loaded by the query will be put in modifiable mode |
||||
*/ |
||||
public BasicQueryContract setReadOnly(boolean readOnly); |
||||
|
||||
/** |
||||
* Return the Hibernate types of the query results. |
||||
* |
||||
* @return an array of types |
||||
*/ |
||||
public Type[] getReturnTypes(); |
||||
} |
@ -0,0 +1,178 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* Provides an API for querying/managing the second level cache regions. |
||||
* <p/> |
||||
* CAUTION: None of these methods respect any isolation or transactional |
||||
* semantics associated with the underlying caches. Specifically, evictions |
||||
* perform an immediate "hard" removal outside any transactions and/or locking |
||||
* scheme(s). |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public interface Cache { |
||||
/** |
||||
* Determine whether the cache contains data for the given entity "instance". |
||||
* <p/> |
||||
* The semantic here is whether the cache contains data visible for the |
||||
* current call context. |
||||
* |
||||
* @param entityClass The entity class. |
||||
* @param identifier The entity identifier |
||||
* |
||||
* @return True if the underlying cache contains corresponding data; false |
||||
* otherwise. |
||||
*/ |
||||
public boolean containsEntity(Class entityClass, Serializable identifier); |
||||
|
||||
/** |
||||
* Determine whether the cache contains data for the given entity "instance". |
||||
* <p/> |
||||
* The semantic here is whether the cache contains data visible for the |
||||
* current call context. |
||||
* |
||||
* @param entityName The entity name. |
||||
* @param identifier The entity identifier |
||||
* |
||||
* @return True if the underlying cache contains corresponding data; false otherwise. |
||||
*/ |
||||
public boolean containsEntity(String entityName, Serializable identifier); |
||||
|
||||
/** |
||||
* Evicts the entity data for a particular entity "instance". |
||||
* |
||||
* @param entityClass The entity class. |
||||
* @param identifier The entity identifier |
||||
*/ |
||||
public void evictEntity(Class entityClass, Serializable identifier); |
||||
|
||||
/** |
||||
* Evicts the entity data for a particular entity "instance". |
||||
* |
||||
* @param entityName The entity name. |
||||
* @param identifier The entity identifier |
||||
*/ |
||||
public void evictEntity(String entityName, Serializable identifier); |
||||
|
||||
/** |
||||
* Evicts all entity data from the given region (i.e. for all entities of |
||||
* type). |
||||
* |
||||
* @param entityClass The entity class. |
||||
*/ |
||||
public void evictEntityRegion(Class entityClass); |
||||
|
||||
/** |
||||
* Evicts all entity data from the given region (i.e. for all entities of |
||||
* type). |
||||
* |
||||
* @param entityName The entity name. |
||||
*/ |
||||
public void evictEntityRegion(String entityName); |
||||
|
||||
/** |
||||
* Evict data from all entity regions. |
||||
*/ |
||||
public void evictEntityRegions(); |
||||
|
||||
/** |
||||
* Evicts all naturalId data from the given region (i.e. for all entities of |
||||
* type). |
||||
* |
||||
* @param naturalIdClass The naturalId class. |
||||
*/ |
||||
@SuppressWarnings( {"UnusedDeclaration"}) |
||||
public void evictNaturalIdRegion(Class naturalIdClass); |
||||
|
||||
/** |
||||
* Evicts all naturalId data from the given region (i.e. for all entities of |
||||
* type). |
||||
* |
||||
* @param naturalIdName The naturalId name. |
||||
*/ |
||||
public void evictNaturalIdRegion(String naturalIdName); |
||||
|
||||
/** |
||||
* Evict data from all naturalId regions. |
||||
*/ |
||||
public void evictNaturalIdRegions(); |
||||
|
||||
/** |
||||
* Determine whether the cache contains data for the given collection. |
||||
* <p/> |
||||
* The semantic here is whether the cache contains data visible for the |
||||
* current call context. |
||||
* |
||||
* @param role The name of the collection role (in form |
||||
* [owner-entity-name].[collection-property-name]) whose regions should be |
||||
* evicted. |
||||
* @param ownerIdentifier The identifier of the owning entity |
||||
* |
||||
* @return True if the underlying cache contains corresponding data; false otherwise. |
||||
*/ |
||||
@SuppressWarnings( {"UnusedDeclaration"}) |
||||
public boolean containsCollection(String role, Serializable ownerIdentifier); |
||||
|
||||
/** |
||||
* Evicts the cache data for the given identified collection instance. |
||||
* |
||||
* @param role The "collection role" (in form [owner-entity-name].[collection-property-name]). |
||||
* @param ownerIdentifier The identifier of the owning entity |
||||
*/ |
||||
public void evictCollection(String role, Serializable ownerIdentifier); |
||||
|
||||
/** |
||||
* Evicts all entity data from the given region (i.e. evicts cached data |
||||
* for all of the specified collection role). |
||||
* |
||||
* @param role The "collection role" (in form [owner-entity-name].[collection-property-name]). |
||||
*/ |
||||
public void evictCollectionRegion(String role); |
||||
|
||||
/** |
||||
* Evict data from all collection regions. |
||||
*/ |
||||
public void evictCollectionRegions(); |
||||
|
||||
/** |
||||
* Determine whether the cache contains data for the given query. |
||||
* <p/> |
||||
* The semantic here is whether the cache contains any data for the given |
||||
* region name since query result caches are not transactionally isolated. |
||||
* |
||||
* @param regionName The cache name given to the query. |
||||
* |
||||
* @return True if the underlying cache contains corresponding data; false otherwise. |
||||
*/ |
||||
@SuppressWarnings( {"UnusedDeclaration"}) |
||||
public boolean containsQuery(String regionName); |
||||
|
||||
/** |
||||
* Evicts all cached query results from the default region. |
||||
*/ |
||||
public void evictDefaultQueryRegion(); |
||||
|
||||
/** |
||||
* Evicts all cached query results under the given name. |
||||
* |
||||
* @param regionName The cache name associated to the queries being cached. |
||||
*/ |
||||
public void evictQueryRegion(String regionName); |
||||
|
||||
/** |
||||
* Evict data from all query regions. |
||||
*/ |
||||
public void evictQueryRegions(); |
||||
|
||||
/** |
||||
* Evict all data from the cache. |
||||
*/ |
||||
public void evictAllRegions(); |
||||
} |
@ -0,0 +1,94 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* Controls how the session interacts with the second-level cache and query cache. |
||||
* |
||||
* @author Gavin King |
||||
* @author Strong Liu |
||||
* @see Session#setCacheMode(CacheMode) |
||||
*/ |
||||
public enum CacheMode { |
||||
/** |
||||
* The session may read items from the cache, and add items to the cache. |
||||
*/ |
||||
NORMAL( true, true ), |
||||
/** |
||||
* The session will never interact with the cache, except to invalidate |
||||
* cache items when updates occur. |
||||
*/ |
||||
IGNORE( false, false ), |
||||
/** |
||||
* The session may read items from the cache, but will not add items, |
||||
* except to invalidate items when updates occur. |
||||
*/ |
||||
GET( false, true ), |
||||
/** |
||||
* The session will never read items from the cache, but will add items |
||||
* to the cache as it reads them from the database. |
||||
*/ |
||||
PUT( true, false ), |
||||
/** |
||||
* The session will never read items from the cache, but will add items |
||||
* to the cache as it reads them from the database. In this mode, the |
||||
* effect of <tt>hibernate.cache.use_minimal_puts</tt> is bypassed, in |
||||
* order to <em>force</em> a cache refresh. |
||||
*/ |
||||
REFRESH( true, false ); |
||||
|
||||
|
||||
private final boolean isPutEnabled; |
||||
private final boolean isGetEnabled; |
||||
|
||||
private CacheMode( boolean isPutEnabled, boolean isGetEnabled) { |
||||
this.isPutEnabled = isPutEnabled; |
||||
this.isGetEnabled = isGetEnabled; |
||||
} |
||||
|
||||
/** |
||||
* Does this cache mode indicate that reads are allowed? |
||||
* |
||||
* @return {@code true} if cache reads are allowed; {@code false} otherwise. |
||||
*/ |
||||
public boolean isGetEnabled() { |
||||
return isGetEnabled; |
||||
} |
||||
|
||||
/** |
||||
* Does this cache mode indicate that writes are allowed? |
||||
* |
||||
* @return {@code true} if cache writes are allowed; {@code false} otherwise. |
||||
*/ |
||||
public boolean isPutEnabled() { |
||||
return isPutEnabled; |
||||
} |
||||
|
||||
/** |
||||
* Used to interpret externalized forms of this enum. |
||||
* |
||||
* @param setting The externalized form. |
||||
* |
||||
* @return The matching enum value. |
||||
* |
||||
* @throws MappingException Indicates the external form was not recognized as a valid enum value. |
||||
*/ |
||||
public static CacheMode interpretExternalSetting(String setting) { |
||||
if (setting == null) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return CacheMode.valueOf( setting.toUpperCase(Locale.ROOT) ); |
||||
} |
||||
catch ( IllegalArgumentException e ) { |
||||
throw new MappingException( "Unknown Cache Mode: " + setting ); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,46 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* Intended to be thrown from {@link com.fr.third.org.hibernate.classic.Lifecycle} and {@link Interceptor} callbacks. |
||||
* <p/> |
||||
* IMPL NOTE : This is a legacy exception type from back in the day before Hibernate moved to a untyped (runtime) |
||||
* exception strategy. |
||||
* |
||||
* @author Gavin King |
||||
*/ |
||||
public class CallbackException extends HibernateException { |
||||
/** |
||||
* Creates a CallbackException using the given underlying cause. |
||||
* |
||||
* @param cause The underlying cause |
||||
*/ |
||||
public CallbackException(Exception cause) { |
||||
this( "An exception occurred in a callback", cause ); |
||||
} |
||||
|
||||
/** |
||||
* Creates a CallbackException using the given message. |
||||
* |
||||
* @param message The message explaining the reason for the exception |
||||
*/ |
||||
public CallbackException(String message) { |
||||
super( message ); |
||||
} |
||||
|
||||
/** |
||||
* Creates a CallbackException using the given message and underlying cause. |
||||
* |
||||
* @param message The message explaining the reason for the exception |
||||
* @param cause The underlying cause |
||||
*/ |
||||
public CallbackException(String message, Exception cause) { |
||||
super( message, cause ); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* Indicates the manner in which JDBC Connections should be acquired. Inverse to |
||||
* {@link com.fr.third.org.hibernate.ConnectionReleaseMode}. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public enum ConnectionAcquisitionMode { |
||||
/** |
||||
* The Connection will be acquired as soon as the Hibernate Session is opened. This |
||||
* also circumvents ConnectionReleaseMode, as the Connection will then be held until the |
||||
* Session is closed. |
||||
*/ |
||||
IMMEDIATELY, |
||||
/** |
||||
* The legacy behavior. A Connection is only acquired when (if) it is actually needed. |
||||
*/ |
||||
AS_NEEDED; |
||||
|
||||
public static ConnectionAcquisitionMode interpret(String value) { |
||||
if ( value != null |
||||
&& ( "immediate".equalsIgnoreCase( value ) || "immediately".equalsIgnoreCase( value ) ) ) { |
||||
return IMMEDIATELY; |
||||
} |
||||
|
||||
return AS_NEEDED; |
||||
} |
||||
} |
@ -0,0 +1,51 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* Defines the various policies by which Hibernate might release its underlying |
||||
* JDBC connection. Inverse of {@link ConnectionAcquisitionMode}. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public enum ConnectionReleaseMode{ |
||||
/** |
||||
* Indicates that JDBC connection should be aggressively released after each |
||||
* SQL statement is executed. In this mode, the application <em>must</em> |
||||
* explicitly close all iterators and scrollable results. This mode may |
||||
* only be used with a JTA datasource. |
||||
*/ |
||||
AFTER_STATEMENT, |
||||
|
||||
/** |
||||
* Indicates that JDBC connections should be released after each transaction |
||||
* ends (works with both JTA-registered synch and HibernateTransaction API). |
||||
* This mode may not be used with an application server JTA datasource. |
||||
* <p/> |
||||
* This is the default mode starting in 3.1; was previously {@link #ON_CLOSE}. |
||||
*/ |
||||
AFTER_TRANSACTION, |
||||
|
||||
/** |
||||
* Indicates that connections should only be released when the Session is explicitly closed |
||||
* or disconnected; this is the legacy (Hibernate2 and pre-3.1) behavior. |
||||
*/ |
||||
ON_CLOSE; |
||||
|
||||
/** |
||||
* Alias for {@link ConnectionReleaseMode#valueOf(String)} using upper-case version of the incoming name. |
||||
* |
||||
* @param name The name to parse |
||||
* |
||||
* @return The matched enum value. |
||||
*/ |
||||
public static ConnectionReleaseMode parse(final String name) { |
||||
return ConnectionReleaseMode.valueOf( name.toUpperCase(Locale.ROOT) ); |
||||
} |
||||
} |
@ -0,0 +1,566 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.util.List; |
||||
|
||||
import com.fr.third.org.hibernate.criterion.CriteriaSpecification; |
||||
import com.fr.third.org.hibernate.criterion.Criterion; |
||||
import com.fr.third.org.hibernate.criterion.Order; |
||||
import com.fr.third.org.hibernate.criterion.Projection; |
||||
import com.fr.third.org.hibernate.sql.JoinType; |
||||
import com.fr.third.org.hibernate.transform.ResultTransformer; |
||||
|
||||
|
||||
/** |
||||
* <tt>Criteria</tt> is a simplified API for retrieving entities |
||||
* by composing <tt>Criterion</tt> objects. This is a very |
||||
* convenient approach for functionality like "search" screens |
||||
* where there is a variable number of conditions to be placed |
||||
* upon the result set.<br> |
||||
* <br> |
||||
* The <tt>Session</tt> is a factory for <tt>Criteria</tt>. |
||||
* <tt>Criterion</tt> instances are usually obtained via |
||||
* the factory methods on <tt>Restrictions</tt>. eg. |
||||
* <pre> |
||||
* List cats = session.createCriteria(Cat.class) |
||||
* .add( Restrictions.like("name", "Iz%") ) |
||||
* .add( Restrictions.gt( "weight", new Float(minWeight) ) ) |
||||
* .addOrder( Order.asc("age") ) |
||||
* .list(); |
||||
* </pre> |
||||
* You may navigate associations using <tt>createAlias()</tt> or |
||||
* <tt>createCriteria()</tt>. |
||||
* <pre> |
||||
* List cats = session.createCriteria(Cat.class) |
||||
* .createCriteria("kittens") |
||||
* .add( Restrictions.like("name", "Iz%") ) |
||||
* .list(); |
||||
* </pre> |
||||
* <pre> |
||||
* List cats = session.createCriteria(Cat.class) |
||||
* .createAlias("kittens", "kit") |
||||
* .add( Restrictions.like("kit.name", "Iz%") ) |
||||
* .list(); |
||||
* </pre> |
||||
* You may specify projection and aggregation using <tt>Projection</tt> |
||||
* instances obtained via the factory methods on <tt>Projections</tt>. |
||||
* <pre> |
||||
* List cats = session.createCriteria(Cat.class) |
||||
* .setProjection( Projections.projectionList() |
||||
* .add( Projections.rowCount() ) |
||||
* .add( Projections.avg("weight") ) |
||||
* .add( Projections.max("weight") ) |
||||
* .add( Projections.min("weight") ) |
||||
* .add( Projections.groupProperty("color") ) |
||||
* ) |
||||
* .addOrder( Order.asc("color") ) |
||||
* .list(); |
||||
* </pre> |
||||
* |
||||
* @see Session#createCriteria(java.lang.Class) |
||||
* @see com.fr.third.org.hibernate.criterion.Restrictions |
||||
* @see com.fr.third.org.hibernate.criterion.Projections |
||||
* @see com.fr.third.org.hibernate.criterion.Order |
||||
* @see com.fr.third.org.hibernate.criterion.Criterion |
||||
* @see com.fr.third.org.hibernate.criterion.Projection |
||||
* @see com.fr.third.org.hibernate.criterion.DetachedCriteria a disconnected version of this API |
||||
* @author Gavin King |
||||
*/ |
||||
public interface Criteria extends CriteriaSpecification { |
||||
|
||||
/** |
||||
* Get the alias of the entity encapsulated by this criteria instance. |
||||
* |
||||
* @return The alias for the encapsulated entity. |
||||
*/ |
||||
public String getAlias(); |
||||
|
||||
/** |
||||
* Used to specify that the query results will be a projection (scalar in |
||||
* nature). Implicitly specifies the {@link #PROJECTION} result transformer. |
||||
* <p/> |
||||
* The individual components contained within the given |
||||
* {@link Projection projection} determines the overall "shape" of the |
||||
* query result. |
||||
* |
||||
* @param projection The projection representing the overall "shape" of the |
||||
* query results. |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setProjection(Projection projection); |
||||
|
||||
/** |
||||
* Add a {@link Criterion restriction} to constrain the results to be |
||||
* retrieved. |
||||
* |
||||
* @param criterion The {@link Criterion criterion} object representing the |
||||
* restriction to be applied. |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria add(Criterion criterion); |
||||
|
||||
/** |
||||
* Add an {@link Order ordering} to the result set. |
||||
* |
||||
* @param order The {@link Order order} object representing an ordering |
||||
* to be applied to the results. |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria addOrder(Order order); |
||||
|
||||
/** |
||||
* Specify an association fetching strategy for an association or a |
||||
* collection of values. |
||||
* |
||||
* @param associationPath a dot separated property path |
||||
* @param mode The fetch mode for the referenced association |
||||
* |
||||
* @return this (for method chaining) |
||||
* |
||||
* @throws HibernateException Indicates a problem applying the given fetch mode |
||||
*/ |
||||
public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException; |
||||
|
||||
/** |
||||
* Set the lock mode of the current entity. |
||||
* |
||||
* @param lockMode The lock mode to be applied |
||||
* |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setLockMode(LockMode lockMode); |
||||
|
||||
/** |
||||
* Set the lock mode of the aliased entity. |
||||
* |
||||
* @param alias The previously assigned alias representing the entity to |
||||
* which the given lock mode should apply. |
||||
* @param lockMode The lock mode to be applied |
||||
* |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setLockMode(String alias, LockMode lockMode); |
||||
|
||||
/** |
||||
* Join an association, assigning an alias to the joined association. |
||||
* <p/> |
||||
* Functionally equivalent to {@link #createAlias(String, String, JoinType )} using |
||||
* {@link JoinType#INNER_JOIN} for the joinType. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* |
||||
* @return this (for method chaining) |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createAlias(String associationPath, String alias) throws HibernateException; |
||||
|
||||
/** |
||||
* Join an association using the specified join-type, assigning an alias |
||||
* to the joined association. |
||||
* <p/> |
||||
* The joinType is expected to be one of {@link JoinType#INNER_JOIN} (the default), |
||||
* {@link JoinType#FULL_JOIN}, or {@link JoinType#LEFT_OUTER_JOIN}. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* |
||||
* @return this (for method chaining) |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createAlias(String associationPath, String alias, JoinType joinType) throws HibernateException; |
||||
|
||||
/** |
||||
* Join an association using the specified join-type, assigning an alias |
||||
* to the joined association. |
||||
* <p/> |
||||
* The joinType is expected to be one of {@link #INNER_JOIN} (the default), |
||||
* {@link #FULL_JOIN}, or {@link #LEFT_JOIN}. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* |
||||
* @return this (for method chaining) |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
* @deprecated use {@link #createAlias(String, String, com.fr.third.org.hibernate.sql.JoinType)} |
||||
*/ |
||||
@Deprecated |
||||
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException; |
||||
|
||||
/** |
||||
* Join an association using the specified join-type, assigning an alias |
||||
* to the joined association. |
||||
* <p/> |
||||
* The joinType is expected to be one of {@link JoinType#INNER_JOIN} (the default), |
||||
* {@link JoinType#FULL_JOIN}, or {@link JoinType#LEFT_OUTER_JOIN}. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* @param withClause The criteria to be added to the join condition (<tt>ON</tt> clause) |
||||
* |
||||
* @return this (for method chaining) |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createAlias(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException; |
||||
|
||||
/** |
||||
* Join an association using the specified join-type, assigning an alias |
||||
* to the joined association. |
||||
* <p/> |
||||
* The joinType is expected to be one of {@link #INNER_JOIN} (the default), |
||||
* {@link #FULL_JOIN}, or {@link #LEFT_JOIN}. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* @param withClause The criteria to be added to the join condition (<tt>ON</tt> clause) |
||||
* |
||||
* @return this (for method chaining) |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
* @deprecated use {@link #createAlias(String, String, JoinType, Criterion)} |
||||
*/ |
||||
@Deprecated |
||||
public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException; |
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity. |
||||
* <p/> |
||||
* Functionally equivalent to {@link #createCriteria(String, com.fr.third.org.hibernate.sql.JoinType)} using |
||||
* {@link JoinType#INNER_JOIN} for the joinType. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createCriteria(String associationPath) throws HibernateException; |
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, using the |
||||
* specified join type. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param joinType The type of join to use. |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createCriteria(String associationPath, JoinType joinType) throws HibernateException; |
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, using the |
||||
* specified join type. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param joinType The type of join to use. |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
* @deprecated use {@link #createAlias(String, String, com.fr.third.org.hibernate.sql.JoinType)} |
||||
*/ |
||||
@Deprecated |
||||
public Criteria createCriteria(String associationPath, int joinType) throws HibernateException; |
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, |
||||
* assigning the given alias. |
||||
* <p/> |
||||
* Functionally equivalent to {@link #createCriteria(String, String, com.fr.third.org.hibernate.sql.JoinType)} using |
||||
* {@link JoinType#INNER_JOIN} for the joinType. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createCriteria(String associationPath, String alias) throws HibernateException; |
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, |
||||
* assigning the given alias and using the specified join type. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createCriteria(String associationPath, String alias, JoinType joinType) throws HibernateException; |
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, |
||||
* assigning the given alias and using the specified join type. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
* @deprecated use {@link #createCriteria(String, com.fr.third.org.hibernate.sql.JoinType)} |
||||
*/ |
||||
@Deprecated |
||||
public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException; |
||||
|
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, |
||||
* assigning the given alias and using the specified join type. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* @param withClause The criteria to be added to the join condition (<tt>ON</tt> clause) |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
*/ |
||||
public Criteria createCriteria(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException; |
||||
|
||||
/** |
||||
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, |
||||
* assigning the given alias and using the specified join type. |
||||
* |
||||
* @param associationPath A dot-separated property path |
||||
* @param alias The alias to assign to the joined association (for later reference). |
||||
* @param joinType The type of join to use. |
||||
* @param withClause The criteria to be added to the join condition (<tt>ON</tt> clause) |
||||
* |
||||
* @return the created "sub criteria" |
||||
* |
||||
* @throws HibernateException Indicates a problem creating the sub criteria |
||||
* @deprecated use {@link #createCriteria(String, String, com.fr.third.org.hibernate.sql.JoinType, com.fr.third.org.hibernate.criterion.Criterion)} |
||||
*/ |
||||
@Deprecated |
||||
public Criteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException; |
||||
|
||||
/** |
||||
* Set a strategy for handling the query results. This determines the |
||||
* "shape" of the query result. |
||||
* |
||||
* @param resultTransformer The transformer to apply |
||||
* @return this (for method chaining) |
||||
* |
||||
* @see #ROOT_ENTITY |
||||
* @see #DISTINCT_ROOT_ENTITY |
||||
* @see #ALIAS_TO_ENTITY_MAP |
||||
* @see #PROJECTION |
||||
*/ |
||||
public Criteria setResultTransformer(ResultTransformer resultTransformer); |
||||
|
||||
/** |
||||
* Set a limit upon the number of objects to be retrieved. |
||||
* |
||||
* @param maxResults the maximum number of results |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setMaxResults(int maxResults); |
||||
|
||||
/** |
||||
* Set the first result to be retrieved. |
||||
* |
||||
* @param firstResult the first result to retrieve, numbered from <tt>0</tt> |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setFirstResult(int firstResult); |
||||
|
||||
/** |
||||
* Was the read-only/modifiable mode explicitly initialized? |
||||
* |
||||
* @return true, the read-only/modifiable mode was explicitly initialized; false, otherwise. |
||||
* |
||||
* @see Criteria#setReadOnly(boolean) |
||||
*/ |
||||
public boolean isReadOnlyInitialized(); |
||||
|
||||
/** |
||||
* Should entities and proxies loaded by this Criteria be put in read-only mode? If the |
||||
* read-only/modifiable setting was not initialized, then the default |
||||
* read-only/modifiable setting for the persistence context is returned instead. |
||||
* @see Criteria#setReadOnly(boolean) |
||||
* @see com.fr.third.org.hibernate.engine.spi.PersistenceContext#isDefaultReadOnly() |
||||
* |
||||
* The read-only/modifiable setting has no impact on entities/proxies returned by the |
||||
* Criteria that existed in the session before the Criteria was executed. |
||||
* |
||||
* @return true, entities and proxies loaded by the criteria will be put in read-only mode |
||||
* false, entities and proxies loaded by the criteria will be put in modifiable mode |
||||
* @throws IllegalStateException if <code>isReadOnlyInitialized()</code> returns <code>false</code> |
||||
* and this Criteria is not associated with a session. |
||||
* @see Criteria#isReadOnlyInitialized() |
||||
*/ |
||||
public boolean isReadOnly(); |
||||
|
||||
/** |
||||
* Set the read-only/modifiable mode for entities and proxies |
||||
* loaded by this Criteria. This setting overrides the default setting |
||||
* for the persistence context. |
||||
* @see com.fr.third.org.hibernate.engine.spi.PersistenceContext#isDefaultReadOnly() |
||||
* |
||||
* To set the default read-only/modifiable setting used for |
||||
* entities and proxies that are loaded into the session: |
||||
* @see com.fr.third.org.hibernate.engine.spi.PersistenceContext#setDefaultReadOnly(boolean) |
||||
* @see com.fr.third.org.hibernate.Session#setDefaultReadOnly(boolean) |
||||
* |
||||
* Read-only entities are not dirty-checked and snapshots of persistent |
||||
* state are not maintained. Read-only entities can be modified, but |
||||
* changes are not persisted. |
||||
* |
||||
* When a proxy is initialized, the loaded entity will have the same |
||||
* read-only/modifiable setting as the uninitialized |
||||
* proxy has, regardless of the session's current setting. |
||||
* |
||||
* The read-only/modifiable setting has no impact on entities/proxies |
||||
* returned by the criteria that existed in the session before the criteria was executed. |
||||
* |
||||
* @param readOnly true, entities and proxies loaded by the criteria will be put in read-only mode |
||||
* false, entities and proxies loaded by the criteria will be put in modifiable mode |
||||
* @return {@code this}, for method chaining |
||||
*/ |
||||
public Criteria setReadOnly(boolean readOnly); |
||||
|
||||
/** |
||||
* Set a fetch size for the underlying JDBC query. |
||||
* |
||||
* @param fetchSize the fetch size |
||||
* @return this (for method chaining) |
||||
* |
||||
* @see java.sql.Statement#setFetchSize |
||||
*/ |
||||
public Criteria setFetchSize(int fetchSize); |
||||
|
||||
/** |
||||
* Set a timeout for the underlying JDBC query. |
||||
* |
||||
* @param timeout The timeout value to apply. |
||||
* @return this (for method chaining) |
||||
* |
||||
* @see java.sql.Statement#setQueryTimeout |
||||
*/ |
||||
public Criteria setTimeout(int timeout); |
||||
|
||||
/** |
||||
* Enable caching of this query result, provided query caching is enabled |
||||
* for the underlying session factory. |
||||
* |
||||
* @param cacheable Should the result be considered cacheable; default is |
||||
* to not cache (false). |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setCacheable(boolean cacheable); |
||||
|
||||
/** |
||||
* Set the name of the cache region to use for query result caching. |
||||
* |
||||
* @param cacheRegion the name of a query cache region, or <tt>null</tt> |
||||
* for the default query cache |
||||
* @return this (for method chaining) |
||||
* |
||||
* @see #setCacheable |
||||
*/ |
||||
public Criteria setCacheRegion(String cacheRegion); |
||||
|
||||
/** |
||||
* Add a comment to the generated SQL. |
||||
* |
||||
* @param comment a human-readable string |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setComment(String comment); |
||||
|
||||
|
||||
/** |
||||
* Add a DB query hint to the SQL. These differ from JPA's {@link com.fr.third.javax.persistence.QueryHint}, which is specific |
||||
* to the JPA implementation and ignores DB vendor-specific hints. Instead, these are intended solely for the |
||||
* vendor-specific hints, such as Oracle's optimizers. Multiple query hints are supported; the Dialect will |
||||
* determine concatenation and placement. |
||||
* |
||||
* @param hint The database specific query hint to add. |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria addQueryHint(String hint); |
||||
|
||||
/** |
||||
* Override the flush mode for this particular query. |
||||
* |
||||
* @param flushMode The flush mode to use. |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setFlushMode(FlushMode flushMode); |
||||
|
||||
/** |
||||
* Override the cache mode for this particular query. |
||||
* |
||||
* @param cacheMode The cache mode to use. |
||||
* @return this (for method chaining) |
||||
*/ |
||||
public Criteria setCacheMode(CacheMode cacheMode); |
||||
|
||||
/** |
||||
* Get the results. |
||||
* |
||||
* @return The list of matched query results. |
||||
* |
||||
* @throws HibernateException Indicates a problem either translating the criteria to SQL, |
||||
* exeucting the SQL or processing the SQL results. |
||||
*/ |
||||
public List list() throws HibernateException; |
||||
|
||||
/** |
||||
* Get the results as an instance of {@link ScrollableResults}. |
||||
* |
||||
* @return The {@link ScrollableResults} representing the matched |
||||
* query results. |
||||
* |
||||
* @throws HibernateException Indicates a problem either translating the criteria to SQL, |
||||
* exeucting the SQL or processing the SQL results. |
||||
*/ |
||||
public ScrollableResults scroll() throws HibernateException; |
||||
|
||||
/** |
||||
* Get the results as an instance of {@link ScrollableResults} based on the |
||||
* given scroll mode. |
||||
* |
||||
* @param scrollMode Indicates the type of underlying database cursor to |
||||
* request. |
||||
* |
||||
* @return The {@link ScrollableResults} representing the matched |
||||
* query results. |
||||
* |
||||
* @throws HibernateException Indicates a problem either translating the criteria to SQL, |
||||
* exeucting the SQL or processing the SQL results. |
||||
*/ |
||||
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException; |
||||
|
||||
/** |
||||
* Convenience method to return a single instance that matches |
||||
* the query, or null if the query returns no results. |
||||
* |
||||
* @return the single result or <tt>null</tt> |
||||
* @throws HibernateException if there is more than one matching result |
||||
*/ |
||||
public Object uniqueResult() throws HibernateException; |
||||
|
||||
} |
@ -0,0 +1,157 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import com.fr.third.org.hibernate.persister.entity.EntityPersister; |
||||
import com.fr.third.org.hibernate.type.Type; |
||||
|
||||
/** |
||||
* During a flush cycle, Hibernate needs to determine which of the entities associated with a {@link Session}. |
||||
* Dirty entities are the ones that get {@literal UPDATE}ed to the database. |
||||
* <p/> |
||||
* In some circumstances, that process of determining whether an entity is dirty can take a significant time as |
||||
* by default Hibernate must check each of the entity's attribute values one-by-one. Oftentimes applications |
||||
* already have knowledge of an entity's dirtiness and using that information instead would be more performant. |
||||
* The purpose of this contract then is to allow applications such a plug-in point. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public interface CustomEntityDirtinessStrategy { |
||||
/** |
||||
* Is this strategy capable of telling whether the given entity is dirty? A return of {@code true} means that |
||||
* {@link #isDirty} will be called next as the definitive means to determine whether the entity is dirty. |
||||
* |
||||
* @param entity The entity to be check. |
||||
* @param persister The persister corresponding to the given entity |
||||
* @param session The session from which this check originates. |
||||
* |
||||
* @return {@code true} indicates the dirty check can be done; {@code false} indicates it cannot. |
||||
*/ |
||||
public boolean canDirtyCheck(Object entity, EntityPersister persister, Session session); |
||||
|
||||
/** |
||||
* The callback used by Hibernate to determine if the given entity is dirty. Only called if the previous |
||||
* {@link #canDirtyCheck} returned {@code true} |
||||
* |
||||
* @param entity The entity to check. |
||||
* @param persister The persister corresponding to the given entity |
||||
* @param session The session from which this check originates. |
||||
* |
||||
* @return {@code true} indicates the entity is dirty; {@link false} indicates the entity is not dirty. |
||||
*/ |
||||
public boolean isDirty(Object entity, EntityPersister persister, Session session); |
||||
|
||||
/** |
||||
* Callback used by Hibernate to signal that the entity dirty flag should be cleared. Generally this |
||||
* happens after previous dirty changes were written to the database. |
||||
* |
||||
* @param entity The entity to reset |
||||
* @param persister The persister corresponding to the given entity |
||||
* @param session The session from which this call originates. |
||||
*/ |
||||
public void resetDirty(Object entity, EntityPersister persister, Session session); |
||||
|
||||
/** |
||||
* Callback used to hook into Hibernate algorithm for determination of which attributes have changed. Applications |
||||
* wanting to hook in to this would call back into the given {@link DirtyCheckContext#doDirtyChecking} |
||||
* method passing along an appropriate {@link AttributeChecker} implementation. |
||||
* |
||||
* @param entity The entity being checked |
||||
* @param persister The persister corresponding to the given entity |
||||
* @param session The session from which this call originates. |
||||
* @param dirtyCheckContext The callback context |
||||
*/ |
||||
public void findDirty(Object entity, EntityPersister persister, Session session, DirtyCheckContext dirtyCheckContext); |
||||
|
||||
/** |
||||
* A callback to drive dirty checking. Handed to the {@link CustomEntityDirtinessStrategy#findDirty} method |
||||
* so that it can callback on to it if it wants to handle dirty checking rather than using Hibernate's default |
||||
* checking |
||||
* |
||||
* @see CustomEntityDirtinessStrategy#findDirty |
||||
*/ |
||||
public static interface DirtyCheckContext { |
||||
/** |
||||
* The callback to indicate that dirty checking (the dirty attribute determination phase) should be handled |
||||
* by the calling {@link CustomEntityDirtinessStrategy} using the given {@link AttributeChecker}. |
||||
* |
||||
* @param attributeChecker The delegate usable by the context for determining which attributes are dirty. |
||||
*/ |
||||
public void doDirtyChecking(AttributeChecker attributeChecker); |
||||
} |
||||
|
||||
/** |
||||
* Responsible for identifying when attributes are dirty. |
||||
*/ |
||||
public static interface AttributeChecker { |
||||
/** |
||||
* Do the attribute dirty check. |
||||
* |
||||
* @param attributeInformation Information about the attribute which is useful to help determine if it is |
||||
* dirty. |
||||
* |
||||
* @return {@code true} indicates the attribute value has changed; {@code false} indicates it has not. |
||||
*/ |
||||
public boolean isDirty(AttributeInformation attributeInformation); |
||||
} |
||||
|
||||
/** |
||||
* Provides {@link AttributeChecker} with meta information about the attributes being checked. |
||||
*/ |
||||
@SuppressWarnings( {"UnusedDeclaration"}) |
||||
public static interface AttributeInformation { |
||||
/** |
||||
* Get a reference to the persister for the entity containing this attribute. |
||||
* |
||||
* @return The entity persister. |
||||
*/ |
||||
public EntityPersister getContainingPersister(); |
||||
|
||||
/** |
||||
* Many of Hibernate internals use arrays to define information about attributes. This value |
||||
* provides this index into those arrays for this particular attribute. |
||||
* <p/> |
||||
* It can be useful if needing to leverage those Hibernate internals. |
||||
* |
||||
* @return The attribute index. |
||||
*/ |
||||
public int getAttributeIndex(); |
||||
|
||||
/** |
||||
* Get the name of this attribute. |
||||
* |
||||
* @return The attribute name |
||||
*/ |
||||
public String getName(); |
||||
|
||||
/** |
||||
* Get the mapping type of this attribute. |
||||
* |
||||
* @return The mapping type. |
||||
*/ |
||||
public Type getType(); |
||||
|
||||
/** |
||||
* Get the current value of this attribute. |
||||
* |
||||
* @return The attributes current value |
||||
*/ |
||||
public Object getCurrentValue(); |
||||
|
||||
/** |
||||
* Get the loaded value of this attribute. |
||||
* <p/> |
||||
* <b>NOTE : A call to this method may require hitting the database in cases where the loaded state is |
||||
* not known. In those cases the db hit is incurred only once per entity, not for each attribute.</b> |
||||
* |
||||
* @return The attributes loaded value |
||||
*/ |
||||
public Object getLoadedValue(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,128 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* Raised whenever a duplicate for a certain type occurs. Duplicate class, table, property name etc. |
||||
* |
||||
* @author Max Rydahl Andersen |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public class DuplicateMappingException extends MappingException { |
||||
/** |
||||
* Enumeration of the types of things that can be duplicated. |
||||
*/ |
||||
public static enum Type { |
||||
/** |
||||
* A duplicate entity definition was encountered. |
||||
*/ |
||||
ENTITY( "entity" ), |
||||
/** |
||||
* A duplicate collection role was encountered |
||||
*/ |
||||
COLLECTION( "collection" ), |
||||
/** |
||||
* A duplicate table definition was encountered. |
||||
*/ |
||||
TABLE( "table" ), |
||||
/** |
||||
* A duplicate property/attribute definition was encountered. |
||||
*/ |
||||
PROPERTY( "property" ), |
||||
/** |
||||
* A duplicate column definition was encountered. |
||||
*/ |
||||
COLUMN( "column" ), |
||||
/** |
||||
* A duplicate column definition was encountered. |
||||
*/ |
||||
COLUMN_BINDING( "column-binding" ), |
||||
/** |
||||
* A duplicate named entity graph was encountered |
||||
*/ |
||||
NAMED_ENTITY_GRAPH( "NamedEntityGraph" ), |
||||
/** |
||||
* A duplicate named query (ql or native) was encountered |
||||
*/ |
||||
QUERY( "query" ), |
||||
/** |
||||
* A duplicate ResultSetMapping was encountered |
||||
*/ |
||||
RESULT_SET_MAPPING( "ResultSetMapping" ), |
||||
/** |
||||
* A duplicate NamedStoredProcedureQuery was encountered |
||||
*/ |
||||
PROCEDURE( "NamedStoredProcedureQuery" ); |
||||
|
||||
private final String text; |
||||
|
||||
Type(String text) { |
||||
this.text = text; |
||||
} |
||||
} |
||||
|
||||
private final String name; |
||||
private final String type; |
||||
|
||||
/** |
||||
* Creates a DuplicateMappingException using the given type and name. |
||||
* |
||||
* @param type The type of the duplicated thing. |
||||
* @param name The name of the duplicated thing. |
||||
*/ |
||||
public DuplicateMappingException(Type type, String name) { |
||||
this( type.text, name ); |
||||
} |
||||
|
||||
/** |
||||
* Creates a DuplicateMappingException using the given type and name. |
||||
* |
||||
* @param type The type of the duplicated thing. |
||||
* @param name The name of the duplicated thing. |
||||
* |
||||
* @deprecated Use the for taking {@link Type} instead. |
||||
*/ |
||||
@Deprecated |
||||
public DuplicateMappingException(String type, String name) { |
||||
this( "Duplicate " + type + " mapping " + name, type, name ); |
||||
} |
||||
|
||||
/** |
||||
* Creates a DuplicateMappingException using the given customMessage, type and name. |
||||
* |
||||
* @param customMessage A custom exception message explaining the exception condition |
||||
* @param type The type of the duplicated thing. |
||||
* @param name The name of the duplicated thing. |
||||
*/ |
||||
public DuplicateMappingException(String customMessage, Type type, String name) { |
||||
this( customMessage, type.name(), name ); |
||||
} |
||||
|
||||
/** |
||||
* Creates a DuplicateMappingException using the given customMessage, type and name. |
||||
* |
||||
* @param customMessage A custom exception message explaining the exception condition |
||||
* @param type The type of the duplicated thing. |
||||
* @param name The name of the duplicated thing. |
||||
* |
||||
* @deprecated Use the for taking {@link Type} instead. |
||||
*/ |
||||
@Deprecated |
||||
public DuplicateMappingException(String customMessage, String type, String name) { |
||||
super( customMessage ); |
||||
this.type=type; |
||||
this.name=name; |
||||
} |
||||
|
||||
public String getType() { |
||||
return type; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
} |
@ -0,0 +1,134 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Iterator; |
||||
|
||||
import com.fr.third.org.hibernate.type.Type; |
||||
|
||||
/** |
||||
* An interceptor that does nothing. May be used as a base class for application-defined custom interceptors. |
||||
* |
||||
* @author Gavin King |
||||
*/ |
||||
public class EmptyInterceptor implements Interceptor, Serializable { |
||||
/** |
||||
* The singleton reference. |
||||
*/ |
||||
public static final Interceptor INSTANCE = new EmptyInterceptor(); |
||||
|
||||
protected EmptyInterceptor() { |
||||
} |
||||
|
||||
@Override |
||||
public void onDelete( |
||||
Object entity, |
||||
Serializable id, |
||||
Object[] state, |
||||
String[] propertyNames, |
||||
Type[] types) {} |
||||
|
||||
@Override |
||||
public boolean onFlushDirty( |
||||
Object entity, |
||||
Serializable id, |
||||
Object[] currentState, |
||||
Object[] previousState, |
||||
String[] propertyNames, |
||||
Type[] types) { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public boolean onLoad( |
||||
Object entity, |
||||
Serializable id, |
||||
Object[] state, |
||||
String[] propertyNames, |
||||
Type[] types) { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public boolean onSave( |
||||
Object entity, |
||||
Serializable id, |
||||
Object[] state, |
||||
String[] propertyNames, |
||||
Type[] types) { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public void postFlush(Iterator entities) { |
||||
} |
||||
|
||||
@Override |
||||
public void preFlush(Iterator entities) { |
||||
} |
||||
|
||||
@Override |
||||
public Boolean isTransient(Object entity) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Object instantiate(String entityName, EntityMode entityMode, Serializable id) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public int[] findDirty( |
||||
Object entity, |
||||
Serializable id, |
||||
Object[] currentState, |
||||
Object[] previousState, |
||||
String[] propertyNames, |
||||
Type[] types) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String getEntityName(Object object) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Object getEntity(String entityName, Serializable id) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void afterTransactionBegin(Transaction tx) { |
||||
} |
||||
|
||||
@Override |
||||
public void afterTransactionCompletion(Transaction tx) { |
||||
} |
||||
|
||||
@Override |
||||
public void beforeTransactionCompletion(Transaction tx) { |
||||
} |
||||
|
||||
@Override |
||||
public String onPrepareStatement(String sql) { |
||||
return sql; |
||||
} |
||||
|
||||
@Override |
||||
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException { |
||||
} |
||||
|
||||
@Override |
||||
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException { |
||||
} |
||||
|
||||
@Override |
||||
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException { |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* Defines the representation modes available for entities. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public enum EntityMode { |
||||
/** |
||||
* The {@code pojo} entity mode describes an entity model made up of entity classes (loosely) following |
||||
* the java bean convention. |
||||
*/ |
||||
POJO( "pojo" ), |
||||
|
||||
/** |
||||
* The {@code dynamic-map} entity mode describes an entity model defined using {@link java.util.Map} references. |
||||
*/ |
||||
MAP( "dynamic-map" ); |
||||
|
||||
private final String externalName; |
||||
|
||||
private EntityMode(String externalName) { |
||||
this.externalName = externalName; |
||||
} |
||||
|
||||
public String getExternalName() { |
||||
return externalName; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return externalName; |
||||
} |
||||
|
||||
/** |
||||
* Legacy-style entity-mode name parsing. <b>Case insensitive</b> |
||||
* |
||||
* @param entityMode The entity mode name to evaluate |
||||
* |
||||
* @return The appropriate entity mode; {@code null} for incoming {@code entityMode} param is treated by returning |
||||
* {@link #POJO}. |
||||
*/ |
||||
public static EntityMode parse(String entityMode) { |
||||
if ( entityMode == null ) { |
||||
return POJO; |
||||
} |
||||
if ( MAP.externalName.equalsIgnoreCase( entityMode ) ) { |
||||
return MAP; |
||||
} |
||||
return valueOf( entityMode.toUpperCase( Locale.ENGLISH ) ); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,24 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* Contract for resolving an entity-name from a given entity instance. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public interface EntityNameResolver { |
||||
/** |
||||
* Given an entity instance, determine its entity-name. |
||||
* |
||||
* @param entity The entity instance. |
||||
* |
||||
* @return The corresponding entity-name, or null if this impl does not know how to perform resolution |
||||
* for the given entity instance. |
||||
*/ |
||||
public String resolveEntityName(Object entity); |
||||
} |
@ -0,0 +1,50 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* Represents an association fetching strategy. This is used |
||||
* together with the <tt>Criteria</tt> API to specify runtime |
||||
* fetching strategies.<br> |
||||
* <br> |
||||
* For HQL queries, use the <tt>FETCH</tt> keyword instead. |
||||
* |
||||
* @see Criteria#setFetchMode(java.lang.String, FetchMode) |
||||
* |
||||
* @author Gavin King |
||||
*/ |
||||
public enum FetchMode { |
||||
/** |
||||
* Default to the setting configured in the mapping file. |
||||
*/ |
||||
DEFAULT, |
||||
|
||||
/** |
||||
* Fetch using an outer join. Equivalent to <tt>fetch="join"</tt>. |
||||
*/ |
||||
JOIN, |
||||
/** |
||||
* Fetch eagerly, using a separate select. Equivalent to |
||||
* <tt>fetch="select"</tt>. |
||||
*/ |
||||
SELECT; |
||||
|
||||
/** |
||||
* Fetch lazily. Equivalent to <tt>outer-join="false"</tt>. |
||||
* |
||||
* @deprecated use <tt>FetchMode.SELECT</tt> |
||||
*/ |
||||
@Deprecated |
||||
public static final FetchMode LAZY = SELECT; |
||||
/** |
||||
* Fetch eagerly, using an outer join. Equivalent to <tt>outer-join="true"</tt>. |
||||
* |
||||
* @deprecated use <tt>FetchMode.JOIN</tt> |
||||
*/ |
||||
@Deprecated |
||||
public static final FetchMode EAGER = JOIN; |
||||
} |
@ -0,0 +1,72 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
import java.util.Collection; |
||||
|
||||
import com.fr.third.org.hibernate.engine.spi.FilterDefinition; |
||||
|
||||
/** |
||||
* Type definition of Filter. Filter defines the user's view into enabled dynamic filters, |
||||
* allowing them to set filter parameter values. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public interface Filter { |
||||
|
||||
/** |
||||
* Get the name of this filter. |
||||
* |
||||
* @return This filter's name. |
||||
*/ |
||||
public String getName(); |
||||
|
||||
/** |
||||
* Get the filter definition containing additional information about the |
||||
* filter (such as default-condition and expected parameter names/types). |
||||
* |
||||
* @return The filter definition |
||||
*/ |
||||
public FilterDefinition getFilterDefinition(); |
||||
|
||||
|
||||
/** |
||||
* Set the named parameter's value for this filter. |
||||
* |
||||
* @param name The parameter's name. |
||||
* @param value The value to be applied. |
||||
* @return This FilterImpl instance (for method chaining). |
||||
*/ |
||||
public Filter setParameter(String name, Object value); |
||||
|
||||
/** |
||||
* Set the named parameter's value list for this filter. Used |
||||
* in conjunction with IN-style filter criteria. |
||||
* |
||||
* @param name The parameter's name. |
||||
* @param values The values to be expanded into an SQL IN list. |
||||
* @return This FilterImpl instance (for method chaining). |
||||
*/ |
||||
public Filter setParameterList(String name, Collection values); |
||||
|
||||
/** |
||||
* Set the named parameter's value list for this filter. Used |
||||
* in conjunction with IN-style filter criteria. |
||||
* |
||||
* @param name The parameter's name. |
||||
* @param values The values to be expanded into an SQL IN list. |
||||
* @return This FilterImpl instance (for method chaining). |
||||
*/ |
||||
public Filter setParameterList(String name, Object[] values); |
||||
|
||||
/** |
||||
* Perform validation of the filter state. This is used to verify the |
||||
* state of the filter after its enablement and before its use. |
||||
* |
||||
* @throws HibernateException If the state is not currently valid. |
||||
*/ |
||||
public void validate() throws HibernateException; |
||||
} |
@ -0,0 +1,113 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* Represents a flushing strategy. The flush process synchronizes |
||||
* database state with session state by detecting state changes |
||||
* and executing SQL statements. |
||||
* |
||||
* @see Session#setFlushMode(FlushMode) |
||||
* @see Query#setFlushMode(FlushMode) |
||||
* @see Criteria#setFlushMode(FlushMode) |
||||
* |
||||
* @author Gavin King |
||||
*/ |
||||
public enum FlushMode { |
||||
/** |
||||
* The {@link Session} is never flushed unless {@link Session#flush} |
||||
* is explicitly called by the application. This mode is very |
||||
* efficient for read only transactions. |
||||
* |
||||
* @deprecated use {@link #MANUAL} instead. |
||||
*/ |
||||
@Deprecated |
||||
NEVER ( 0 ), |
||||
|
||||
/** |
||||
* The {@link Session} is only ever flushed when {@link Session#flush} |
||||
* is explicitly called by the application. This mode is very |
||||
* efficient for read only transactions. |
||||
*/ |
||||
MANUAL( 0 ), |
||||
|
||||
/** |
||||
* The {@link Session} is flushed when {@link Transaction#commit} |
||||
* is called. |
||||
*/ |
||||
COMMIT(5 ), |
||||
|
||||
/** |
||||
* The {@link Session} is sometimes flushed before query execution |
||||
* in order to ensure that queries never return stale state. This |
||||
* is the default flush mode. |
||||
*/ |
||||
AUTO(10 ), |
||||
|
||||
/** |
||||
* The {@link Session} is flushed before every query. This is |
||||
* almost always unnecessary and inefficient. |
||||
*/ |
||||
ALWAYS(20 ); |
||||
|
||||
private final int level; |
||||
|
||||
private FlushMode(int level) { |
||||
this.level = level; |
||||
} |
||||
|
||||
/** |
||||
* Checks to see if {@code this} flush mode is less than the given flush mode. |
||||
* |
||||
* @param other THe flush mode value to be checked against {@code this} |
||||
* |
||||
* @return {@code true} indicates {@code other} is less than {@code this}; {@code false} otherwise |
||||
*/ |
||||
public boolean lessThan(FlushMode other) { |
||||
return this.level < other.level; |
||||
} |
||||
|
||||
/** |
||||
* Checks to see if the given mode is the same as {@link #MANUAL}. |
||||
* |
||||
* @param mode The mode to check |
||||
* |
||||
* @return true/false |
||||
* |
||||
* @deprecated Just use equality check against {@link #MANUAL}. Legacy from before this was an enum |
||||
*/ |
||||
@Deprecated |
||||
public static boolean isManualFlushMode(FlushMode mode) { |
||||
return MANUAL.level == mode.level; |
||||
} |
||||
|
||||
/** |
||||
* Interprets an external representation of the flush mode. {@code null} is returned as {@code null}, otherwise |
||||
* {@link FlushMode#valueOf(String)} is used with the upper-case version of the incoming value. An unknown, |
||||
* non-null value results in a MappingException being thrown. |
||||
* |
||||
* @param externalName The external representation |
||||
* |
||||
* @return The interpreted FlushMode value. |
||||
* |
||||
* @throws MappingException Indicates an unrecognized external representation |
||||
*/ |
||||
public static FlushMode interpretExternalSetting(String externalName) { |
||||
if ( externalName == null ) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return FlushMode.valueOf( externalName.toUpperCase(Locale.ROOT) ); |
||||
} |
||||
catch ( IllegalArgumentException e ) { |
||||
throw new MappingException( "unknown FlushMode : " + externalName ); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,183 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.util.Iterator; |
||||
|
||||
import com.fr.third.org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor; |
||||
import com.fr.third.org.hibernate.collection.spi.PersistentCollection; |
||||
import com.fr.third.org.hibernate.engine.HibernateIterator; |
||||
import com.fr.third.org.hibernate.engine.jdbc.LobCreator; |
||||
import com.fr.third.org.hibernate.engine.jdbc.spi.JdbcServices; |
||||
import com.fr.third.org.hibernate.engine.spi.PersistentAttributeInterceptable; |
||||
import com.fr.third.org.hibernate.engine.spi.PersistentAttributeInterceptor; |
||||
import com.fr.third.org.hibernate.engine.spi.SessionImplementor; |
||||
import com.fr.third.org.hibernate.proxy.HibernateProxy; |
||||
import com.fr.third.org.hibernate.proxy.LazyInitializer; |
||||
|
||||
/** |
||||
* <ul> |
||||
* <li>Provides access to the full range of Hibernate built-in types. <tt>Type</tt> |
||||
* instances may be used to bind values to query parameters. |
||||
* <li>A factory for new <tt>Blob</tt>s and <tt>Clob</tt>s. |
||||
* <li>Defines static methods for manipulation of proxies. |
||||
* </ul> |
||||
* |
||||
* @author Gavin King |
||||
* @see java.sql.Clob |
||||
* @see java.sql.Blob |
||||
* @see com.fr.third.org.hibernate.type.Type |
||||
*/ |
||||
|
||||
public final class Hibernate { |
||||
/** |
||||
* Cannot be instantiated. |
||||
*/ |
||||
private Hibernate() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Force initialization of a proxy or persistent collection. |
||||
* <p/> |
||||
* Note: This only ensures intialization of a proxy object or collection; |
||||
* it is not guaranteed that the elements INSIDE the collection will be initialized/materialized. |
||||
* |
||||
* @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> |
||||
* @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed |
||||
*/ |
||||
public static void initialize(Object proxy) throws HibernateException { |
||||
if ( proxy == null ) { |
||||
return; |
||||
} |
||||
|
||||
if ( proxy instanceof HibernateProxy ) { |
||||
( (HibernateProxy) proxy ).getHibernateLazyInitializer().initialize(); |
||||
} |
||||
else if ( proxy instanceof PersistentCollection ) { |
||||
( (PersistentCollection) proxy ).forceInitialization(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Check if the proxy or persistent collection is initialized. |
||||
* |
||||
* @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> |
||||
* @return true if the argument is already initialized, or is not a proxy or collection |
||||
*/ |
||||
@SuppressWarnings("SimplifiableIfStatement") |
||||
public static boolean isInitialized(Object proxy) { |
||||
if ( proxy instanceof HibernateProxy ) { |
||||
return !( (HibernateProxy) proxy ).getHibernateLazyInitializer().isUninitialized(); |
||||
} |
||||
else if ( proxy instanceof PersistentCollection ) { |
||||
return ( (PersistentCollection) proxy ).wasInitialized(); |
||||
} |
||||
else { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Get the true, underlying class of a proxied persistent class. This operation |
||||
* will initialize a proxy by side-effect. |
||||
* |
||||
* @param proxy a persistable object or proxy |
||||
* @return the true class of the instance |
||||
* @throws HibernateException |
||||
*/ |
||||
public static Class getClass(Object proxy) { |
||||
if ( proxy instanceof HibernateProxy ) { |
||||
return ( (HibernateProxy) proxy ).getHibernateLazyInitializer() |
||||
.getImplementation() |
||||
.getClass(); |
||||
} |
||||
else { |
||||
return proxy.getClass(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Obtain a lob creator for the given session. |
||||
* |
||||
* @param session The session for which to obtain a lob creator |
||||
* |
||||
* @return The log creator reference |
||||
*/ |
||||
public static LobCreator getLobCreator(Session session) { |
||||
return getLobCreator( (SessionImplementor) session ); |
||||
} |
||||
|
||||
/** |
||||
* Obtain a lob creator for the given session. |
||||
* |
||||
* @param session The session for which to obtain a lob creator |
||||
* |
||||
* @return The log creator reference |
||||
*/ |
||||
public static LobCreator getLobCreator(SessionImplementor session) { |
||||
return session.getFactory() |
||||
.getServiceRegistry() |
||||
.getService( JdbcServices.class ) |
||||
.getLobCreator( session ); |
||||
} |
||||
|
||||
/** |
||||
* Close an {@link Iterator} instances obtained from {@link com.fr.third.org.hibernate.Query#iterate()} immediately |
||||
* instead of waiting until the session is closed or disconnected. |
||||
* |
||||
* @param iterator an Iterator created by iterate() |
||||
* |
||||
* @throws HibernateException Indicates a problem closing the Hibernate iterator. |
||||
* @throws IllegalArgumentException If the Iterator is not a "Hibernate Iterator". |
||||
* |
||||
* @see Query#iterate() |
||||
*/ |
||||
public static void close(Iterator iterator) throws HibernateException { |
||||
if ( iterator instanceof HibernateIterator ) { |
||||
( (HibernateIterator) iterator ).close(); |
||||
} |
||||
else { |
||||
throw new IllegalArgumentException( "not a Hibernate iterator" ); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Check if the property is initialized. If the named property does not exist |
||||
* or is not persistent, this method always returns <tt>true</tt>. |
||||
* |
||||
* @param proxy The potential proxy |
||||
* @param propertyName the name of a persistent attribute of the object |
||||
* @return true if the named property of the object is not listed as uninitialized; false otherwise |
||||
*/ |
||||
public static boolean isPropertyInitialized(Object proxy, String propertyName) { |
||||
final Object entity; |
||||
if ( proxy instanceof HibernateProxy ) { |
||||
final LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer(); |
||||
if ( li.isUninitialized() ) { |
||||
return false; |
||||
} |
||||
else { |
||||
entity = li.getImplementation(); |
||||
} |
||||
} |
||||
else { |
||||
entity = proxy; |
||||
} |
||||
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) { |
||||
PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) entity ).$$_hibernate_getInterceptor(); |
||||
if ( interceptor != null && interceptor instanceof LazyAttributeLoadingInterceptor ) { |
||||
return ( (LazyAttributeLoadingInterceptor) interceptor ).isAttributeLoaded( propertyName ); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* Marks a group of exceptions that generally indicate an internal Hibernate error or bug. |
||||
* |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public class HibernateError extends HibernateException { |
||||
/** |
||||
* Constructs HibernateError with the condition message. |
||||
* |
||||
* @param message Message explaining the exception/error condition |
||||
*/ |
||||
public HibernateError(String message) { |
||||
super( message ); |
||||
} |
||||
|
||||
/** |
||||
* Constructs HibernateError with the condition message and cause. |
||||
* |
||||
* @param message Message explaining the exception/error condition |
||||
* @param cause The underlying cause. |
||||
*/ |
||||
public HibernateError(String message, Throwable cause) { |
||||
super( message, cause ); |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
/** |
||||
* The base exception type for Hibernate exceptions. |
||||
* <p/> |
||||
* Note that all {@link java.sql.SQLException SQLExceptions} will be wrapped in some form of |
||||
* {@link JDBCException}. |
||||
* |
||||
* @see JDBCException |
||||
* |
||||
* @author Gavin King |
||||
*/ |
||||
public class HibernateException extends RuntimeException { |
||||
/** |
||||
* Constructs a HibernateException using the given exception message. |
||||
* |
||||
* @param message The message explaining the reason for the exception |
||||
*/ |
||||
public HibernateException(String message) { |
||||
super( message ); |
||||
} |
||||
|
||||
/** |
||||
* Constructs a HibernateException using the given message and underlying cause. |
||||
* |
||||
* @param cause The underlying cause. |
||||
*/ |
||||
public HibernateException(Throwable cause) { |
||||
super( cause ); |
||||
} |
||||
|
||||
/** |
||||
* Constructs a HibernateException using the given message and underlying cause. |
||||
* |
||||
* @param message The message explaining the reason for the exception. |
||||
* @param cause The underlying cause. |
||||
*/ |
||||
public HibernateException(String message, Throwable cause) { |
||||
super( message, cause ); |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* Loads an entity by its primary identifier. |
||||
* |
||||
* @author Eric Dalquist |
||||
* @author Steve Ebersole |
||||
*/ |
||||
public interface IdentifierLoadAccess<T> { |
||||
/** |
||||
* Specify the {@link LockOptions} to use when retrieving the entity. |
||||
* |
||||
* @param lockOptions The lock options to use. |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
*/ |
||||
IdentifierLoadAccess<T> with(LockOptions lockOptions); |
||||
|
||||
/** |
||||
* Specify the {@link CacheMode} to use when retrieving the entity. |
||||
* |
||||
* @param cacheMode The CacheMode to use. |
||||
* |
||||
* @return {@code this}, for method chaining |
||||
*/ |
||||
IdentifierLoadAccess<T> with(CacheMode cacheMode); |
||||
|
||||
/** |
||||
* Return the persistent instance with the given identifier, assuming that the instance exists. This method |
||||
* might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed. |
||||
* |
||||
* You should not use this method to determine if an instance exists; to check for existence, use {@link #load} |
||||
* instead. Use this only to retrieve an instance that you assume exists, where non-existence would be an |
||||
* actual error. |
||||
* |
||||
* @param id The identifier for which to obtain a reference |
||||
* |
||||
* @return the persistent instance or proxy |
||||
*/ |
||||
T getReference(Serializable id); |
||||
|
||||
/** |
||||
* Return the persistent instance with the given identifier, or null if there is no such persistent instance. |
||||
* If the instance is already associated with the session, return that instance, initializing it if needed. This |
||||
* method never returns an uninitialized instance. |
||||
* |
||||
* @param id The identifier |
||||
* |
||||
* @return The persistent instance or {@code null} |
||||
*/ |
||||
T load(Serializable id); |
||||
} |
@ -0,0 +1,23 @@
|
||||
/* |
||||
* Hibernate, Relational Persistence for Idiomatic Java |
||||
* |
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/ |
||||
package com.fr.third.org.hibernate; |
||||
|
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.Target; |
||||
|
||||
import static java.lang.annotation.ElementType.PACKAGE; |
||||
import static java.lang.annotation.ElementType.METHOD; |
||||
import static java.lang.annotation.ElementType.TYPE; |
||||
import static java.lang.annotation.RetentionPolicy.CLASS; |
||||
|
||||
/** |
||||
* @author Steve Ebersole |
||||
*/ |
||||
@Target({PACKAGE, TYPE, METHOD}) |
||||
@Retention(CLASS) |
||||
public @interface Incubating { |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue