本文整理匯總了Java中javax.persistence.MappedSuperclass類的典型用法代碼示例。如果您正苦於以下問題:Java MappedSuperclass類的具體用法?Java MappedSuperclass怎麽用?Java MappedSuperclass使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MappedSuperclass類屬於javax.persistence包,在下文中一共展示了MappedSuperclass類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: build
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public ResourceInformation build(final Class<?> resourceClass) {
String resourceType = getResourceType(resourceClass);
MetaDataObject meta = metaProvider.discoverMeta(resourceClass).asDataObject();
DefaultResourceInstanceBuilder instanceBuilder = new DefaultResourceInstanceBuilder(resourceClass);
List<ResourceField> fields = getResourceFields(resourceClass);
Class<?> superclass = resourceClass.getSuperclass();
String superResourceType = superclass != Object.class
&& superclass.getAnnotation(MappedSuperclass.class) == null ? context.getResourceType(superclass)
: null;
TypeParser typeParser = context.getTypeParser();
return new JpaResourceInformation(typeParser, meta, resourceClass, resourceType, superResourceType,
instanceBuilder, fields);
}
示例2: getResourceType
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
@Override
public String getResourceType(Class<?> entityClass) {
JpaResource annotation = entityClass.getAnnotation(JpaResource.class);
if (annotation != null) {
return annotation.type();
}
if (entityClass.getAnnotation(MappedSuperclass.class) != null) {
return null; // super classes do not have a document type
}
String name = entityClass.getSimpleName();
if (name.endsWith(ENTITY_NAME_SUFFIX)) {
name = name.substring(0, name.length() - ENTITY_NAME_SUFFIX.length());
}
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
}
示例3: buildHierarchyColumnOverride
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
private void buildHierarchyColumnOverride(XClass element) {
XClass current = element;
Map<String, Column[]> columnOverride = new HashMap<String, Column[]>();
Map<String, JoinColumn[]> joinColumnOverride = new HashMap<String, JoinColumn[]>();
Map<String, JoinTable> joinTableOverride = new HashMap<String, JoinTable>();
while ( current != null && !mappings.getReflectionManager().toXClass( Object.class ).equals( current ) ) {
if ( current.isAnnotationPresent( Entity.class ) || current.isAnnotationPresent( MappedSuperclass.class )
|| current.isAnnotationPresent( Embeddable.class ) ) {
//FIXME is embeddable override?
Map<String, Column[]> currentOverride = buildColumnOverride( current, getPath() );
Map<String, JoinColumn[]> currentJoinOverride = buildJoinColumnOverride( current, getPath() );
Map<String, JoinTable> currentJoinTableOverride = buildJoinTableOverride( current, getPath() );
currentOverride.putAll( columnOverride ); //subclasses have precedence over superclasses
currentJoinOverride.putAll( joinColumnOverride ); //subclasses have precedence over superclasses
currentJoinTableOverride.putAll( joinTableOverride ); //subclasses have precedence over superclasses
columnOverride = currentOverride;
joinColumnOverride = currentJoinOverride;
joinTableOverride = currentJoinTableOverride;
}
current = current.getSuperclass();
}
holderColumnOverride = columnOverride.size() > 0 ? columnOverride : null;
holderJoinColumnOverride = joinColumnOverride.size() > 0 ? joinColumnOverride : null;
holderJoinTableOverride = joinTableOverride.size() > 0 ? joinTableOverride : null;
}
示例4: getClasses
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
protected List<String> getClasses(Resource[] resources) {
List<String> classNames = new ArrayList<>();
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader metadataReader;
try {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
} catch (IOException e) {
throw new RuntimeException("Unable to read metadata resource", e);
}
AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
if (annotationMetadata.isAnnotated(com.haulmont.chile.core.annotations.MetaClass.class.getName())
|| annotationMetadata.isAnnotated(MappedSuperclass.class.getName())
|| annotationMetadata.isAnnotated(Entity.class.getName())) {
ClassMetadata classMetadata = metadataReader.getClassMetadata();
classNames.add(classMetadata.getClassName());
}
}
}
return classNames;
}
示例5: buildProperties
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
/**
* Fills the {@link #properties}.
*
* @param c
* the currently inspected class
* @param stopClass
* the class in the hierarchy to stop inspecting
*/
private void buildProperties(final Class<? super E> c, final Class<? super E> stopClass) {
// Fill properties of super classes (at least until we find the joined parent class)
if (c.getSuperclass() != null && c.getSuperclass() != stopClass) {
buildProperties(c.getSuperclass(), stopClass);
}
// And now fill the properties of this class
if (c.isAnnotationPresent(MappedSuperclass.class) || c.isAnnotationPresent(Entity.class)) {
for (final AttributeAccessor field : this.accessStyle.getDeclaredAttributes(c, this.entityClass)) {
if (!field.isAnnotationPresent(EmbeddedId.class) && !field.isAnnotationPresent(Id.class)) {
final Property<E, ?> property = buildProperty(field, getColumnAnnotation(field),
this.associationOverrides.get(field.getName()));
if (property != null) {
this.properties.put(field.getName(), property);
this.allProperties.add(property);
if (property instanceof SingularProperty) {
buildUniqueProperty((SingularProperty<E, ?>) property);
}
}
}
}
}
}
示例6: testStaticWeaving
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
@Test
public void testStaticWeaving() {
// first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation
Reflections reflections = new Reflections(
DocumentAttachment.class.getPackage().getName(),
DocumentBase.class.getPackage().getName(),
MaintenanceLock.class.getPackage().getName(),
Message.class.getPackage().getName());
Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class);
Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class);
Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class);
// next, let's assert that they have been statically weaved
assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
示例7: getField
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
/**
* A partir du nom du fieldname, retorune le field
* @param cl
* @param fieldName
* @return
* @throws FieldNotFound
*/
private static Field getField(final Class cl, final String fieldName) throws FieldNotFound {
Class tClass = cl;
boolean found = false;
while (!found && (tClass.isAnnotationPresent(Entity.class) || tClass.isAnnotationPresent(MappedSuperclass.class))) {
try {
Field field = tClass.getDeclaredField(fieldName);
if (field.isAnnotationPresent(Lob.class)) {
throw new FieldNotFound();
}
return field;
} catch (NoSuchFieldException ex) { // on verifie dans la hierarchie aussi
tClass = tClass.getSuperclass();
}
}
throw new FieldNotFound();
}
示例8: isJpaAnnotated
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
public static boolean isJpaAnnotated(Class<?> clazz) {
if (clazz == null) {
return false;
}
if (!cache.containsKey(clazz.getName())) {
if (clazz.getName().contains("EnhancerByCGLIB")) {
try {
// Strip a proxy if found
clazz = Class.forName(clazz.getName().substring(0, clazz.getName().indexOf("$$EnhancerByCGLIB")));
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
synchronized (cache) {
cache.put(clazz.getName(), new Boolean(clazz.isAnnotationPresent(Entity.class) || clazz.isAnnotationPresent(MappedSuperclass.class)));
}
}
return cache.get(clazz.getName()).booleanValue();
}
示例9: hasOnlyValidJpaEntities
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
/**
* Verifies that all class that are annotated with {@link Entity} observe the rules for JPA entities.
*
* <ul>
* <li>The class must have a public or protected, no-argument constructor. The class may have other
* constructors.</li>
* <li>The class must not be declared final.</li>
* <li>No methods or persistent instance variables must be declared final.</li>
* <li>Persistent instance variables must be declared private, protected, or package-private.</li>
* </ul>
*
* @return Self.
*/
public JandexAssert hasOnlyValidJpaEntities() {
// Precondition
isNotNull();
final List<AnnotationInstance> annotations = new ArrayList<>();
annotations.addAll(actual.getAnnotations(DotName.createSimple(Entity.class.getName())));
annotations.addAll(actual.getAnnotations(DotName.createSimple(MappedSuperclass.class.getName())));
for (final AnnotationInstance ai : annotations) {
final AnnotationTarget target = ai.target();
final ClassInfo info = target.asClass();
final AssertionRules<ClassInfo> rules = new AssertionRules<ClassInfo>(
new RulePublicOrProtectedNoArgConstructor(), new RuleClassNotFinal(),
new RuleClassHasNoFinalMethods(), new RulePersistentInstanceFieldVisibility());
final AssertionResult result = rules.verify(info);
if (!result.isValid()) {
failWithMessage(result.getErrorMessage());
}
}
return this;
}
示例10: extractInheritanceType
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
private void extractInheritanceType() {
XAnnotatedElement element = getClazz();
Inheritance inhAnn = element.getAnnotation( Inheritance.class );
MappedSuperclass mappedSuperClass = element.getAnnotation( MappedSuperclass.class );
if ( mappedSuperClass != null ) {
setEmbeddableSuperclass( true );
setType( inhAnn == null ? null : inhAnn.strategy() );
}
else {
setType( inhAnn == null ? InheritanceType.SINGLE_TABLE : inhAnn.strategy() );
}
}
示例11: addMappedSuperClassInMetadata
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
private void addMappedSuperClassInMetadata(PersistentClass persistentClass) {
//add @MappedSuperclass in the metadata
// classes from 0 to n-1 are @MappedSuperclass and should be linked
org.hibernate.mapping.MappedSuperclass mappedSuperclass = null;
final InheritanceState superEntityState =
InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass );
PersistentClass superEntity =
superEntityState != null ?
mappings.getClass( superEntityState.getClazz().getName() ) :
null;
final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1;
for ( int index = 0; index < lastMappedSuperclass; index++ ) {
org.hibernate.mapping.MappedSuperclass parentSuperclass = mappedSuperclass;
final Class<?> type = mappings.getReflectionManager()
.toClass( classesToProcessForMappedSuperclass.get( index ) );
//add MAppedSuperclass if not already there
mappedSuperclass = mappings.getMappedSuperclass( type );
if ( mappedSuperclass == null ) {
mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity );
mappedSuperclass.setMappedClass( type );
mappings.addMappedSuperclass( type, mappedSuperclass );
}
}
if ( mappedSuperclass != null ) {
persistentClass.setSuperMappedSuperclass( mappedSuperclass );
}
}
示例12: getMappedSuperclass
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
private MappedSuperclass getMappedSuperclass(Element tree, XMLContext.Default defaults) {
if ( tree == null ) {
return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation( MappedSuperclass.class ) : null;
}
else {
if ( "mapped-superclass".equals( tree.getName() ) ) {
AnnotationDescriptor entity = new AnnotationDescriptor( MappedSuperclass.class );
return AnnotationFactory.create( entity );
}
else {
return null; //this is not an entity
}
}
}
示例13: getManagedJpaClasses
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
@Nonnull
@SuppressWarnings("unchecked")
public static Set<Class<?>> getManagedJpaClasses() {
return getMainClasses(Predicates.or(
withAnnotation(Entity.class),
withAnnotation(Embeddable.class),
withAnnotation(MappedSuperclass.class)));
}
示例14: getJpaSuperclass
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
private Class<?> getJpaSuperclass(Class<?> resourceClass) {
Class<?> superclass = resourceClass.getSuperclass();
while(superclass != Object.class){
if(superclass.getAnnotation(Entity.class) != null || superclass.getAnnotation(MappedSuperclass.class) != null){
return superclass;
}
superclass = superclass.getSuperclass();
}
return null;
}
示例15: getParent
import javax.persistence.MappedSuperclass; //導入依賴的package包/類
public String getParent() {
MetaClass ancestor = meta.getAncestor();
if (ancestor == null || !ancestor.getName().contains("$") ||
ancestor.getJavaClass().isAnnotationPresent(MappedSuperclass.class))
return "";
if (!readPermitted(ancestor)) {
return null;
}
return "Parent is " + asHref(ancestor.getName());
}