Java 类org.hibernate.mapping.Property 实例源码
项目:lams
文件:ClassPropertyHolder.java
public void addProperty(Property prop, XClass declaringClass) {
if ( prop.getValue() instanceof Component ) {
//TODO handle quote and non quote table comparison
String tableName = prop.getValue().getTable().getName();
if ( getJoinsPerRealTableName().containsKey( tableName ) ) {
final Join join = getJoinsPerRealTableName().get( tableName );
addPropertyToJoin( prop, declaringClass, join );
}
else {
addPropertyToPersistentClass( prop, declaringClass );
}
}
else {
addPropertyToPersistentClass( prop, declaringClass );
}
}
项目:lams
文件:ClassPropertyHolder.java
private void addPropertyToPersistentClass(Property prop, XClass declaringClass) {
if ( declaringClass != null ) {
final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
if ( inheritanceState == null ) {
throw new AssertionFailure(
"Declaring class is not found in the inheritance state hierarchy: " + declaringClass
);
}
if ( inheritanceState.isEmbeddableSuperclass() ) {
persistentClass.addMappedsuperclassProperty(prop);
addPropertyToMappedSuperclass( prop, declaringClass );
}
else {
persistentClass.addProperty( prop );
}
}
else {
persistentClass.addProperty( prop );
}
}
项目:lams
文件:ClassPropertyHolder.java
private void addPropertyToJoin(Property prop, XClass declaringClass, Join join) {
if ( declaringClass != null ) {
final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
if ( inheritanceState == null ) {
throw new AssertionFailure(
"Declaring class is not found in the inheritance state hierarchy: " + declaringClass
);
}
if ( inheritanceState.isEmbeddableSuperclass() ) {
join.addMappedsuperclassProperty(prop);
addPropertyToMappedSuperclass( prop, declaringClass );
}
else {
join.addProperty( prop );
}
}
else {
join.addProperty( prop );
}
}
项目:lams
文件:BinderHelper.java
/**
* create a property copy reusing the same value
*/
public static Property shallowCopy(Property property) {
Property clone = new Property();
clone.setCascade( property.getCascade() );
clone.setInsertable( property.isInsertable() );
clone.setLazy( property.isLazy() );
clone.setName( property.getName() );
clone.setNodeName( property.getNodeName() );
clone.setNaturalIdentifier( property.isNaturalIdentifier() );
clone.setOptimisticLocked( property.isOptimisticLocked() );
clone.setOptional( property.isOptional() );
clone.setPersistentClass( property.getPersistentClass() );
clone.setPropertyAccessorName( property.getPropertyAccessorName() );
clone.setSelectable( property.isSelectable() );
clone.setUpdateable( property.isUpdateable() );
clone.setValue( property.getValue() );
return clone;
}
项目:lams
文件:BinderHelper.java
private static void matchColumnsByProperty(Property property, Map<Column, Set<Property>> columnsToProperty) {
if ( property == null ) return;
if ( "noop".equals( property.getPropertyAccessorName() )
|| "embedded".equals( property.getPropertyAccessorName() ) ) {
return;
}
// FIXME cannot use subproperties becasue the caller needs top level properties
// if ( property.isComposite() ) {
// Iterator subProperties = ( (Component) property.getValue() ).getPropertyIterator();
// while ( subProperties.hasNext() ) {
// matchColumnsByProperty( (Property) subProperties.next(), columnsToProperty );
// }
// }
else {
Iterator columnIt = property.getColumnIterator();
while ( columnIt.hasNext() ) {
Object column = columnIt.next(); //can be a Formula so we don't cast
//noinspection SuspiciousMethodCalls
if ( columnsToProperty.containsKey( column ) ) {
columnsToProperty.get( column ).add( property );
}
}
}
}
项目:lams
文件:ComponentPropertyHolder.java
public void addProperty(Property prop, Ejb3Column[] columns, XClass declaringClass) {
//Ejb3Column.checkPropertyConsistency( ); //already called earlier
/*
* Check table matches between the component and the columns
* if not, change the component table if no properties are set
* if a property is set already the core cannot support that
*/
if (columns != null) {
Table table = columns[0].getTable();
if ( !table.equals( component.getTable() ) ) {
if ( component.getPropertySpan() == 0 ) {
component.setTable( table );
}
else {
throw new AnnotationException(
"A component cannot hold properties split into 2 different tables: "
+ this.getPath()
);
}
}
}
addProperty( prop, declaringClass );
}
项目:lams
文件:PropertyBinder.java
private Property makePropertyAndValue() {
validateBind();
LOG.debugf( "MetadataSourceProcessor property %s with lazy=%s", name, lazy );
final String containerClassName = holder.getClassName();
holder.startingProperty( property );
simpleValueBinder = new SimpleValueBinder();
simpleValueBinder.setMappings( mappings );
simpleValueBinder.setPropertyName( name );
simpleValueBinder.setReturnedClassName( returnedClassName );
simpleValueBinder.setColumns( columns );
simpleValueBinder.setPersistentClassName( containerClassName );
simpleValueBinder.setType(
property,
returnedClass,
containerClassName,
holder.resolveAttributeConverterDefinition( property )
);
simpleValueBinder.setMappings( mappings );
simpleValueBinder.setReferencedEntityName( referencedEntityName );
simpleValueBinder.setAccessType( accessType );
SimpleValue propertyValue = simpleValueBinder.make();
setValue( propertyValue );
return makeProperty();
}
项目:lams
文件:AbstractComponentTuplizer.java
protected AbstractComponentTuplizer(Component component) {
propertySpan = component.getPropertySpan();
getters = new Getter[propertySpan];
setters = new Setter[propertySpan];
Iterator iter = component.getPropertyIterator();
boolean foundCustomAccessor=false;
int i = 0;
while ( iter.hasNext() ) {
Property prop = ( Property ) iter.next();
getters[i] = buildGetter( component, prop );
setters[i] = buildSetter( component, prop );
if ( !prop.isBasicPropertyAccessor() ) {
foundCustomAccessor = true;
}
i++;
}
hasCustomAccessors = foundCustomAccessor;
instantiator = buildInstantiator( component );
}
项目:lams
文件:ComponentMetamodel.java
public ComponentMetamodel(Component component) {
// this.sessionFactory = sessionFactory;
this.role = component.getRoleName();
this.isKey = component.isKey();
propertySpan = component.getPropertySpan();
properties = new StandardProperty[propertySpan];
Iterator itr = component.getPropertyIterator();
int i = 0;
while ( itr.hasNext() ) {
Property property = ( Property ) itr.next();
properties[i] = PropertyFactory.buildStandardProperty( property, false );
propertyIndexes.put( property.getName(), i );
i++;
}
entityMode = component.hasPojoRepresentation() ? EntityMode.POJO : EntityMode.MAP;
// todo : move this to SF per HHH-3517; also see HHH-1907 and ComponentMetamodel
final ComponentTuplizerFactory componentTuplizerFactory = new ComponentTuplizerFactory();
final String tuplizerClassName = component.getTuplizerImplClassName( entityMode );
this.componentTuplizer = tuplizerClassName == null ? componentTuplizerFactory.constructDefaultTuplizer(
entityMode,
component
) : componentTuplizerFactory.constructTuplizer( tuplizerClassName, component );
}
项目:unitimes
文件:HibernateUtil.java
public static void fixSchemaInFormulas(Configuration cfg) {
cfg.buildMappings();
String schema = cfg.getProperty("default_schema");
if (schema!=null) {
for (Iterator i=cfg.getClassMappings();i.hasNext();) {
PersistentClass pc = (PersistentClass)i.next();
for (Iterator j=pc.getPropertyIterator();j.hasNext();) {
Property p = (Property)j.next();
for (Iterator k=p.getColumnIterator();k.hasNext();) {
Selectable c = (Selectable)k.next();
if (c instanceof Formula) {
Formula f = (Formula)c;
if (f.getFormula()!=null && f.getFormula().indexOf("%SCHEMA%")>=0) {
f.setFormula(f.getFormula().replaceAll("%SCHEMA%", schema));
sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula());
}
}
}
}
}
}
}
项目:cacheonix-core
文件:PropertyAccessorFactory.java
/**
* Retrieves a PropertyAccessor instance based on the given property definition and
* entity mode.
*
* @param property The property for which to retrieve an accessor.
* @param mode The mode for the resulting entity.
* @return An appropriate accessor.
* @throws MappingException
*/
public static PropertyAccessor getPropertyAccessor(Property property, EntityMode mode) throws MappingException {
//TODO: this is temporary in that the end result will probably not take a Property reference per-se.
if ( null == mode || EntityMode.POJO.equals( mode ) ) {
return getPojoPropertyAccessor( property.getPropertyAccessorName() );
}
else if ( EntityMode.MAP.equals( mode ) ) {
return getDynamicMapPropertyAccessor();
}
else if ( EntityMode.DOM4J.equals( mode ) ) {
//TODO: passing null here, because this method is not really used for DOM4J at the moment
// but it is still a bug, if we don't get rid of this!
return getDom4jPropertyAccessor( property.getAccessorPropertyName( mode ), property.getType(), null );
}
else {
throw new MappingException( "Unknown entity mode [" + mode + "]" );
}
}
项目:cacheonix-core
文件:ComponentMetamodel.java
public ComponentMetamodel(Component component) {
// this.sessionFactory = sessionFactory;
this.role = component.getRoleName();
this.isKey = component.isKey();
propertySpan = component.getPropertySpan();
properties = new StandardProperty[propertySpan];
Iterator itr = component.getPropertyIterator();
int i = 0;
while ( itr.hasNext() ) {
Property property = ( Property ) itr.next();
properties[i] = PropertyFactory.buildStandardProperty( property, false );
propertyIndexes.put( property.getName(), new Integer( i ) );
i++;
}
tuplizerMapping = new ComponentEntityModeToTuplizerMapping( component );
}
项目:greenpepper
文件:AbstractDBUnitHibernateMemoryTest.java
@SuppressWarnings("unchecked")
protected String[] getColumnNames( Class peristentClass, String[] includedFields )
throws MappingException
{
Collection columns = new ArrayList();
for ( int i = 0; i < includedFields.length; i++ )
{
String propertyName = includedFields[i];
Property property = getMapping( peristentClass ).getProperty( propertyName );
for ( Iterator it = property.getColumnIterator(); it.hasNext(); )
{
Column col = ( Column ) it.next();
columns.add( col.getName() );
}
}
return ( String[] ) columns.toArray( new String[columns.size()] );
}
项目:high-performance-java-persistence
文件:MetadataTest.java
@Test
public void testEntityToDatabaseBindingMetadata() {
Metadata metadata = MetadataExtractorIntegrator.INSTANCE.getMetadata();
for ( PersistentClass persistentClass : metadata.getEntityBindings()) {
Table table = persistentClass.getTable();
LOGGER.info( "Entity: {} is mapped to table: {}",
persistentClass.getClassName(),
table.getName()
);
for(Iterator propertyIterator =
persistentClass.getPropertyIterator(); propertyIterator.hasNext(); ) {
Property property = (Property) propertyIterator.next();
for(Iterator columnIterator =
property.getColumnIterator(); columnIterator.hasNext(); ) {
Column column = (Column) columnIterator.next();
LOGGER.info( "Property: {} is mapped on table column: {} of type: {}",
property.getName(),
column.getName(),
column.getSqlType()
);
}
}
}
}
项目:unitime
文件:HibernateUtil.java
public static void fixSchemaInFormulas(Configuration cfg) {
cfg.buildMappings();
String schema = cfg.getProperty("default_schema");
if (schema!=null) {
for (Iterator i=cfg.getClassMappings();i.hasNext();) {
PersistentClass pc = (PersistentClass)i.next();
for (Iterator j=pc.getPropertyIterator();j.hasNext();) {
Property p = (Property)j.next();
for (Iterator k=p.getColumnIterator();k.hasNext();) {
Selectable c = (Selectable)k.next();
if (c instanceof Formula) {
Formula f = (Formula)c;
if (f.getFormula()!=null && f.getFormula().indexOf("%SCHEMA%")>=0) {
f.setFormula(f.getFormula().replaceAll("%SCHEMA%", schema));
sLog.debug("Schema updated in "+pc.getClassName()+"."+p.getName()+" to "+f.getFormula());
}
}
}
}
}
}
}
项目:greenpepper3
文件:AbstractDBUnitHibernateMemoryTest.java
@SuppressWarnings("unchecked")
protected String[] getColumnNames( Class peristentClass, String[] includedFields )
throws MappingException
{
Collection columns = new ArrayList();
for ( int i = 0; i < includedFields.length; i++ )
{
String propertyName = includedFields[i];
Property property = getMapping( peristentClass ).getProperty( propertyName );
for ( Iterator it = property.getColumnIterator(); it.hasNext(); )
{
Column col = ( Column ) it.next();
columns.add( col.getName() );
}
}
return ( String[] ) columns.toArray( new String[columns.size()] );
}
项目:cagrid-core
文件:HibernateConfigTypesInformationResolver.java
public List<String> getNestedInnerComponentNames(String parentClassname, String topLevelComponentName,
String nestedComponentName, String innerComponentNamePrefix) {
List<String> names = new ArrayList<String>();
PersistentClass parent = configuration.getClassMapping(parentClassname);
Property topLevelProperty = parent.getProperty(topLevelComponentName);
Component topLevelComponent = (Component) topLevelProperty.getValue();
Property nestedProperty = topLevelComponent.getProperty(nestedComponentName);
Set nestedSet = (Set) nestedProperty.getValue();
Component nestedComponent = (Component) nestedSet.getElement();
Iterator<?> propertyIter = nestedComponent.getPropertyIterator();
while (propertyIter.hasNext()) {
Property prop = (Property) propertyIter.next();
if (prop.getName().startsWith(innerComponentNamePrefix)) {
names.add(prop.getName());
}
}
return names;
}
项目:cagrid-core
文件:HibernateConfigTypesInformationResolver.java
public Class<?> getJavaDataType(String classname, String field) throws TypesInformationException {
LOG.debug("Getting java type of " + classname + "." + field);
String fqName = classname + "." + field;
Class<?> type = fieldDataTypes.get(fqName);
if (type == null) {
PersistentClass clazz = findPersistentClass(classname);
if (clazz != null) {
// TODO: test that this barks up the inheritance tree for properties
Property property = clazz.getRecursiveProperty(field);
if (property != null) {
type = property.getType().getReturnedClass();
} else {
throw new TypesInformationException("Field " + fqName + " not found in hibernate configuration");
}
} else {
throw new TypesInformationException("Class " + classname + " not found in hibernate configuration");
}
fieldDataTypes.put(fqName, type);
}
return type;
}
项目:cagrid-core
文件:HibernateConfigTypesInformationResolver.java
public List<String> getNestedInnerComponentNames(String parentClassname, String topLevelComponentName,
String nestedComponentName, String innerComponentNamePrefix) {
List<String> names = new ArrayList<String>();
PersistentClass parent = configuration.getClassMapping(parentClassname);
Property topLevelProperty = parent.getProperty(topLevelComponentName);
Component topLevelComponent = (Component) topLevelProperty.getValue();
Property nestedProperty = topLevelComponent.getProperty(nestedComponentName);
Set nestedSet = (Set) nestedProperty.getValue();
Component nestedComponent = (Component) nestedSet.getElement();
Iterator<?> propertyIter = nestedComponent.getPropertyIterator();
while (propertyIter.hasNext()) {
Property prop = (Property) propertyIter.next();
if (prop.getName().startsWith(innerComponentNamePrefix)) {
names.add(prop.getName());
}
}
return names;
}
项目:caarray
文件:AbstractCaArrayDaoImpl.java
/**
* Update the provided criteria object with values from the associated entites. For collection-valued
* associations, the criteria will contain a disjunction using collection members as examples.
*
* @param entityToMatch the entity to match
*/
@SuppressWarnings("unchecked")
public void addCriteriaForAssociations() {
try {
final PersistentClass pclass = getClassMapping(this.exampleCriteria.getExample().getClass());
if (pclass == null) {
throw new DAOException("Could not find hibernate class mapping in hierarchy of class "
+ this.exampleCriteria.getExample().getClass().getName());
}
final Iterator<Property> properties = pclass.getPropertyClosureIterator();
while (properties.hasNext()) {
final Property prop = properties.next();
if (prop.getType().isAssociationType()) {
addCriterionForAssociation(prop);
}
}
} catch (final IllegalAccessException iae) {
LOG.error(UNABLE_TO_GET_ASSOCIATION_VAL, iae);
throw new DAOException(UNABLE_TO_GET_ASSOCIATION_VAL, iae);
} catch (final InvocationTargetException ite) {
LOG.error(UNABLE_TO_GET_ASSOCIATION_VAL, ite);
throw new DAOException(UNABLE_TO_GET_ASSOCIATION_VAL, ite);
}
}
项目:lams
文件:HbmBinder.java
private static void bindCompositeId(Element idNode, RootClass entity, Mappings mappings,
java.util.Map inheritedMetas) throws MappingException {
String propertyName = idNode.attributeValue( "name" );
Component id = new Component( mappings, entity );
entity.setIdentifier( id );
bindCompositeId( idNode, id, entity, propertyName, mappings, inheritedMetas );
if ( propertyName == null ) {
entity.setEmbeddedIdentifier( id.isEmbedded() );
if ( id.isEmbedded() ) {
// todo : what is the implication of this?
id.setDynamic( !entity.hasPojoRepresentation() );
/*
* Property prop = new Property(); prop.setName("id");
* prop.setPropertyAccessorName("embedded"); prop.setValue(id);
* entity.setIdentifierProperty(prop);
*/
}
}
else {
Property prop = new Property();
prop.setValue( id );
bindProperty( idNode, prop, mappings, inheritedMetas );
entity.setIdentifierProperty( prop );
entity.setDeclaredIdentifierProperty( prop );
}
makeIdentifier( idNode, id, mappings );
}
项目:lams
文件:HbmBinder.java
private static void bindVersioningProperty(Table table, Element subnode, Mappings mappings,
String name, RootClass entity, java.util.Map inheritedMetas) {
String propertyName = subnode.attributeValue( "name" );
SimpleValue val = new SimpleValue( mappings, table );
bindSimpleValue( subnode, val, false, propertyName, mappings );
if ( !val.isTypeSpecified() ) {
// this is either a <version/> tag with no type attribute,
// or a <timestamp/> tag
if ( "version".equals( name ) ) {
val.setTypeName( "integer" );
}
else {
if ( "db".equals( subnode.attributeValue( "source" ) ) ) {
val.setTypeName( "dbtimestamp" );
}
else {
val.setTypeName( "timestamp" );
}
}
}
Property prop = new Property();
prop.setValue( val );
bindProperty( subnode, prop, mappings, inheritedMetas );
// for version properties marked as being generated, make sure they are "always"
// generated; aka, "insert" is invalid; this is dis-allowed by the DTD,
// but just to make sure...
if ( prop.getValueGenerationStrategy() != null ) {
if ( prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT ) {
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
}
}
makeVersion( subnode, val );
entity.setVersion( prop );
entity.addProperty( prop );
}
项目:lams
文件:ClassPropertyHolder.java
public void addProperty(Property prop, Ejb3Column[] columns, XClass declaringClass) {
//Ejb3Column.checkPropertyConsistency( ); //already called earlier
if ( columns != null && columns[0].isSecondary() ) {
//TODO move the getJoin() code here?
final Join join = columns[0].getJoin();
addPropertyToJoin( prop, declaringClass, join );
}
else {
addProperty( prop, declaringClass );
}
}
项目:lams
文件:ToOneFkSecondPass.java
@Override
public boolean isInPrimaryKey() {
if ( entityClassName == null ) return false;
final PersistentClass persistentClass = mappings.getClass( entityClassName );
Property property = persistentClass.getIdentifierProperty();
if ( path == null ) {
return false;
}
else if ( property != null) {
//try explicit identifier property
return path.startsWith( property.getName() + "." );
}
else {
//try the embedded property
//embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
if ( path.startsWith( "id." ) ) {
KeyValue valueIdentifier = persistentClass.getIdentifier();
String localPath = path.substring( 3 );
if ( valueIdentifier instanceof Component ) {
Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
while ( it.hasNext() ) {
Property idProperty = (Property) it.next();
if ( localPath.startsWith( idProperty.getName() ) ) return true;
}
}
}
}
return false;
}
项目:lams
文件:TypeSafeActivator.java
private static void applyDDL(
String prefix,
PersistentClass persistentClass,
Class<?> clazz,
ValidatorFactory factory,
Set<Class<?>> groups,
boolean activateNotNull,
Dialect dialect) {
final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass( clazz );
//no bean level constraints can be applied, go to the properties
for ( PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties() ) {
Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() );
boolean hasNotNull;
if ( property != null ) {
hasNotNull = applyConstraints(
propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect
);
if ( property.isComposite() && propertyDesc.isCascaded() ) {
Class<?> componentClass = ( (Component) property.getValue() ).getComponentClass();
/*
* we can apply not null if the upper component let's us activate not null
* and if the property is not null.
* Otherwise, all sub columns should be left nullable
*/
final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull;
applyDDL(
prefix + propertyDesc.getPropertyName() + ".",
persistentClass, componentClass, factory, groups,
canSetNotNullOnColumns,
dialect
);
}
//FIXME add collection of components
}
}
}
项目:lams
文件:TypeSafeActivator.java
private static boolean applyConstraints(
Set<ConstraintDescriptor<?>> constraintDescriptors,
Property property,
PropertyDescriptor propertyDesc,
Set<Class<?>> groups,
boolean canApplyNotNull,
Dialect dialect) {
boolean hasNotNull = false;
for ( ConstraintDescriptor<?> descriptor : constraintDescriptors ) {
if ( groups != null && Collections.disjoint( descriptor.getGroups(), groups ) ) {
continue;
}
if ( canApplyNotNull ) {
hasNotNull = hasNotNull || applyNotNull( property, descriptor );
}
// apply bean validation specific constraints
applyDigits( property, descriptor );
applySize( property, descriptor, propertyDesc );
applyMin( property, descriptor, dialect );
applyMax( property, descriptor, dialect );
// apply hibernate validator specific constraints - we cannot import any HV specific classes though!
// no need to check explicitly for @Range. @Range is a composed constraint using @Min and @Max which
// will be taken care later
applyLength( property, descriptor, propertyDesc );
// pass an empty set as composing constraints inherit the main constraint and thus are matching already
hasNotNull = hasNotNull || applyConstraints(
descriptor.getComposingConstraints(),
property, propertyDesc, null,
canApplyNotNull,
dialect
);
}
return hasNotNull;
}
项目:lams
文件:TypeSafeActivator.java
private static void applyMin(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
if ( Min.class.equals( descriptor.getAnnotation().annotationType() ) ) {
@SuppressWarnings("unchecked")
ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor;
long min = minConstraint.getAnnotation().value();
Column col = (Column) property.getColumnIterator().next();
String checkConstraint = col.getQuotedName(dialect) + ">=" + min;
applySQLCheck( col, checkConstraint );
}
}
项目:lams
文件:TypeSafeActivator.java
private static void applyMax(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
if ( Max.class.equals( descriptor.getAnnotation().annotationType() ) ) {
@SuppressWarnings("unchecked")
ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor;
long max = maxConstraint.getAnnotation().value();
Column col = (Column) property.getColumnIterator().next();
String checkConstraint = col.getQuotedName(dialect) + "<=" + max;
applySQLCheck( col, checkConstraint );
}
}
项目:lams
文件:TypeSafeActivator.java
private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) {
boolean hasNotNull = false;
if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) {
// single table inheritance should not be forced to null due to shared state
if ( !( property.getPersistentClass() instanceof SingleTableSubclass ) ) {
//composite should not add not-null on all columns
if ( !property.isComposite() ) {
final Iterator<Selectable> iter = property.getColumnIterator();
while ( iter.hasNext() ) {
final Selectable selectable = iter.next();
if ( Column.class.isInstance( selectable ) ) {
Column.class.cast( selectable ).setNullable( false );
}
else {
LOG.debugf(
"@NotNull was applied to attribute [%s] which is defined (at least partially) " +
"by formula(s); formula portions will be skipped",
property.getName()
);
}
}
}
}
hasNotNull = true;
}
return hasNotNull;
}
项目:lams
文件:TypeSafeActivator.java
private static void applyDigits(Property property, ConstraintDescriptor<?> descriptor) {
if ( Digits.class.equals( descriptor.getAnnotation().annotationType() ) ) {
@SuppressWarnings("unchecked")
ConstraintDescriptor<Digits> digitsConstraint = (ConstraintDescriptor<Digits>) descriptor;
int integerDigits = digitsConstraint.getAnnotation().integer();
int fractionalDigits = digitsConstraint.getAnnotation().fraction();
Column col = (Column) property.getColumnIterator().next();
col.setPrecision( integerDigits + fractionalDigits );
col.setScale( fractionalDigits );
}
}
项目:lams
文件:TypeSafeActivator.java
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
if ( Size.class.equals( descriptor.getAnnotation().annotationType() )
&& String.class.equals( propertyDescriptor.getElementClass() ) ) {
@SuppressWarnings("unchecked")
ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
int max = sizeConstraint.getAnnotation().max();
Column col = (Column) property.getColumnIterator().next();
if ( max < Integer.MAX_VALUE ) {
col.setLength( max );
}
}
}
项目:lams
文件:TypeSafeActivator.java
private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
if ( "org.hibernate.validator.constraints.Length".equals(
descriptor.getAnnotation().annotationType().getName()
)
&& String.class.equals( propertyDescriptor.getElementClass() ) ) {
@SuppressWarnings("unchecked")
int max = (Integer) descriptor.getAttributes().get( "max" );
Column col = (Column) property.getColumnIterator().next();
if ( max < Integer.MAX_VALUE ) {
col.setLength( max );
}
}
}
项目:lams
文件:OneToOneSecondPass.java
/**
* Builds the <code>Join</code> instance for the mapped by side of a <i>OneToOne</i> association using
* a join tables.
* <p>
* Note:<br/>
* <ul>
* <li>From the mappedBy side we should not create the PK nor the FK, this is handled from the other side.</li>
* <li>This method is a dirty dupe of EntityBinder.bindSecondaryTable</i>.
* </p>
*/
private Join buildJoinFromMappedBySide(PersistentClass persistentClass, Property otherSideProperty, Join originalJoin) {
Join join = new Join();
join.setPersistentClass( persistentClass );
//no check constraints available on joins
join.setTable( originalJoin.getTable() );
join.setInverse( true );
SimpleValue key = new DependantValue( mappings, join.getTable(), persistentClass.getIdentifier() );
//TODO support @ForeignKey
join.setKey( key );
join.setSequentialSelect( false );
//TODO support for inverse and optional
join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway
key.setCascadeDeleteEnabled( false );
Iterator mappedByColumns = otherSideProperty.getValue().getColumnIterator();
while ( mappedByColumns.hasNext() ) {
Column column = (Column) mappedByColumns.next();
Column copy = new Column();
copy.setLength( column.getLength() );
copy.setScale( column.getScale() );
copy.setValue( key );
copy.setName( column.getQuotedName() );
copy.setNullable( column.isNullable() );
copy.setPrecision( column.getPrecision() );
copy.setUnique( column.isUnique() );
copy.setSqlType( column.getSqlType() );
copy.setCheckConstraint( column.getCheckConstraint() );
copy.setComment( column.getComment() );
copy.setDefaultValue( column.getDefaultValue() );
key.addColumn( copy );
}
persistentClass.addJoin( join );
return join;
}
项目:lams
文件:ResultsetMappingSecondPass.java
@SuppressWarnings({ "unchecked" })
private List getFollowers(Iterator parentPropIter, String reducedName, String name) {
boolean hasFollowers = false;
List followers = new ArrayList();
while ( parentPropIter.hasNext() ) {
String currentPropertyName = ( (Property) parentPropIter.next() ).getName();
String currentName = reducedName + '.' + currentPropertyName;
if ( hasFollowers ) {
followers.add( currentName );
}
if ( name.equals( currentName ) ) hasFollowers = true;
}
return followers;
}
项目:lams
文件:PropertyAccessorFactory.java
/**
* Retrieves a PropertyAccessor instance based on the given property definition and
* entity mode.
*
* @param property The property for which to retrieve an accessor.
* @param mode The mode for the resulting entity.
* @return An appropriate accessor.
* @throws MappingException
*/
public static PropertyAccessor getPropertyAccessor(Property property, EntityMode mode) throws MappingException {
//TODO: this is temporary in that the end result will probably not take a Property reference per-se.
if ( null == mode || EntityMode.POJO.equals( mode ) ) {
return getPojoPropertyAccessor( property.getPropertyAccessorName() );
}
else if ( EntityMode.MAP.equals( mode ) ) {
return getDynamicMapPropertyAccessor();
}
else {
throw new MappingException( "Unknown entity mode [" + mode + "]" );
}
}
项目:lams
文件:AbstractEntityPersister.java
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
while ( propertyIterator.hasNext() ) {
Property prop = ( Property ) propertyIterator.next();
String propname = path == null ? prop.getName() : path + "." + prop.getName();
if ( prop.isComposite() ) {
Component component = ( Component ) prop.getValue();
Iterator compProps = component.getPropertyIterator();
internalInitSubclassPropertyAliasesMap( propname, compProps );
}
else {
String[] aliases = new String[prop.getColumnSpan()];
String[] cols = new String[prop.getColumnSpan()];
Iterator colIter = prop.getColumnIterator();
int l = 0;
while ( colIter.hasNext() ) {
Selectable thing = ( Selectable ) colIter.next();
aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
l++;
}
subclassPropertyAliases.put( propname, aliases );
subclassPropertyColumnNames.put( propname, cols );
}
}
}
项目:lams
文件:EntityMetamodel.java
private static GenerationStrategyPair buildGenerationStrategyPair(
final SessionFactoryImplementor sessionFactory,
final Property mappingProperty) {
final ValueGeneration valueGeneration = mappingProperty.getValueGenerationStrategy();
if ( valueGeneration != null && valueGeneration.getGenerationTiming() != GenerationTiming.NEVER ) {
// the property is generated in full. build the generation strategy pair.
if ( valueGeneration.getValueGenerator() != null ) {
// in-memory generation
return new GenerationStrategyPair(
FullInMemoryValueGenerationStrategy.create( valueGeneration )
);
}
else {
// in-db generation
return new GenerationStrategyPair(
create(
sessionFactory,
mappingProperty,
valueGeneration
)
);
}
}
else if ( mappingProperty.getValue() instanceof Component ) {
final CompositeGenerationStrategyPairBuilder builder = new CompositeGenerationStrategyPairBuilder( mappingProperty );
interpretPartialCompositeValueGeneration( sessionFactory, (Component) mappingProperty.getValue(), builder );
return builder.buildPair();
}
return NO_GEN_PAIR;
}
项目:lams
文件:EntityMetamodel.java
private static void interpretPartialCompositeValueGeneration(
SessionFactoryImplementor sessionFactory,
Component composite,
CompositeGenerationStrategyPairBuilder builder) {
Iterator subProperties = composite.getPropertyIterator();
while ( subProperties.hasNext() ) {
final Property subProperty = (Property) subProperties.next();
builder.addPair( buildGenerationStrategyPair( sessionFactory, subProperty ) );
}
}
项目:lams
文件:EntityMetamodel.java
public static InDatabaseValueGenerationStrategyImpl create(
SessionFactoryImplementor sessionFactoryImplementor,
Property mappingProperty,
ValueGeneration valueGeneration) {
final int numberOfMappedColumns = mappingProperty.getType().getColumnSpan( sessionFactoryImplementor );
if ( numberOfMappedColumns == 1 ) {
return new InDatabaseValueGenerationStrategyImpl(
valueGeneration.getGenerationTiming(),
valueGeneration.referenceColumnInSql(),
new String[] { valueGeneration.getDatabaseGeneratedReferencedColumnValue() }
);
}
else {
if ( valueGeneration.getDatabaseGeneratedReferencedColumnValue() != null ) {
LOG.debugf(
"Value generator specified column value in reference to multi-column attribute [%s -> %s]; ignoring",
mappingProperty.getPersistentClass(),
mappingProperty.getName()
);
}
return new InDatabaseValueGenerationStrategyImpl(
valueGeneration.getGenerationTiming(),
valueGeneration.referenceColumnInSql(),
new String[numberOfMappedColumns]
);
}
}
项目:lams
文件:EntityMetamodel.java
private ValueInclusion determineInsertValueGenerationType(Property mappingProperty, NonIdentifierAttribute runtimeProperty) {
if ( isInsertGenerated( runtimeProperty ) ) {
return ValueInclusion.FULL;
}
else if ( mappingProperty.getValue() instanceof Component ) {
if ( hasPartialInsertComponentGeneration( ( Component ) mappingProperty.getValue() ) ) {
return ValueInclusion.PARTIAL;
}
}
return ValueInclusion.NONE;
}