|
Hibernate example source code file (PropertyMocker.java)
The Hibernate PropertyMocker.java source code/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Inc.. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.metamodel.source.annotations.xml.mocker; import java.util.ArrayList; import java.util.List; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.hibernate.HibernateException; import org.hibernate.metamodel.source.annotation.jaxb.XMLAccessType; import org.hibernate.metamodel.source.annotation.jaxb.XMLEnumType; import org.hibernate.metamodel.source.annotation.jaxb.XMLMapKey; import org.hibernate.metamodel.source.annotation.jaxb.XMLMapKeyClass; import org.hibernate.metamodel.source.annotation.jaxb.XMLMapKeyColumn; import org.hibernate.metamodel.source.annotation.jaxb.XMLMapKeyJoinColumn; import org.hibernate.metamodel.source.annotation.jaxb.XMLTemporalType; /** * @author Strong Liu */ abstract class PropertyMocker extends AnnotationMocker { protected ClassInfo classInfo; private AnnotationTarget target; PropertyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults) { super( indexBuilder, defaults ); this.classInfo = classInfo; } protected abstract void processExtra(); protected abstract String getFieldName(); protected abstract XMLAccessType getAccessType(); protected abstract void setAccessType(XMLAccessType accessType); @Override protected DotName getTargetName() { return classInfo.name(); } protected void resolveTarget() { //attribute in orm.xml has access sub-element XMLAccessType accessType = getAccessType(); if ( accessType == null ) { //attribute in the entity class has @Access accessType = AccessHelper.getAccessFromAttributeAnnotation( getTargetName(), getFieldName(), indexBuilder ); if ( accessType == null ) { accessType = AccessHelper.getEntityAccess( getTargetName(), indexBuilder ); } if ( accessType == null ) { accessType = AccessHelper.getAccessFromIdPosition( getTargetName(), indexBuilder ); } if (accessType == null ) { //this should only for determin @Id position accessType = AccessHelper.getAccessFromDefault( indexBuilder ); } if ( accessType == null ) { accessType = XMLAccessType.PROPERTY; } setAccessType( accessType ); } } @Override protected AnnotationTarget getTarget() { if ( target == null ) { target = getTargetFromAttributeAccessType( getAccessType() ); } return target; } protected AnnotationTarget getTargetFromAttributeAccessType(XMLAccessType accessType) { if ( accessType == null ) { throw new IllegalArgumentException( "access type can't be null." ); } switch ( accessType ) { case FIELD: return MockHelper.getTarget( indexBuilder.getServiceRegistry(), classInfo, getFieldName(), MockHelper.TargetType.FIELD ); case PROPERTY: return MockHelper.getTarget( indexBuilder.getServiceRegistry(), classInfo, getFieldName(), MockHelper.TargetType.PROPERTY ); default: throw new HibernateException( "can't determin access type [" + accessType + "]" ); } } @Override final void process() { resolveTarget(); processExtra(); } protected AnnotationInstance parserMapKeyColumn(XMLMapKeyColumn mapKeyColumn, AnnotationTarget target) { if ( mapKeyColumn == null ) { return null; } List<AnnotationValue> annotationValueList = new ArrayList Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate PropertyMocker.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.