Java Code Examples for org.hibernate.mapping.Property#setValue()
The following examples show how to use
org.hibernate.mapping.Property#setValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinderHelper.java From lams with GNU General Public License v2.0 | 6 votes |
/** * 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.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; }
Example 2
Source File: HibernatePropertyParser.java From mPaaS with Apache License 2.0 | 6 votes |
/** * 将数据字典解析成Hibernate的字段,不支持级联,不支持一对多 */ public void parse(MetaProperty property, PersistentClass pclazz) { // feature HibernatePropertyFeature feature = property .getFeature(HibernatePropertyFeature.class); if (feature == null) { feature = new HibernatePropertyFeature(); } // value Value value; if (property.isCollection()) { value = buildCollectionValue(property, feature, pclazz); } else { value = buildElement(pclazz, property, feature, pclazz.getTable()); } // property Property prop = buildProperty(property, feature, pclazz); prop.setValue(value); pclazz.addProperty(prop); // version if (feature.isVersion()) { handleVersion(prop, pclazz); } }
Example 3
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 6 votes |
private Property createAnyAssociationAttribute( MappingDocument sourceDocument, SingularAttributeSourceAny anyMapping, Any anyBinding, String entityName) { final String attributeName = anyMapping.getName(); bindAny( sourceDocument, anyMapping, anyBinding, anyMapping.getAttributeRole(), anyMapping.getAttributePath() ); prepareValueTypeViaReflection( sourceDocument, anyBinding, entityName, attributeName, anyMapping.getAttributeRole() ); anyBinding.createForeignKey(); Property prop = new Property(); prop.setValue( anyBinding ); bindProperty( sourceDocument, anyMapping, prop ); return prop; }
Example 4
Source File: Dom4jAccessorTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private Property generateNameProperty() { SimpleValue value = new SimpleValue(); value.setTypeName( "string" ); Property property = new Property(); property.setName( "name" ); property.setNodeName( "name" ); property.setValue( value ); return property; }
Example 5
Source File: Dom4jAccessorTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private Property generateAccountIdProperty() { SimpleValue value = new SimpleValue(); value.setTypeName( "long" ); Property property = new Property(); property.setName( "number" ); property.setNodeName( "account/@num" ); property.setValue( value ); return property; }
Example 6
Source File: Dom4jAccessorTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private Property generateTextProperty() { SimpleValue value = new SimpleValue(); value.setTypeName( "string" ); Property property = new Property(); property.setName( "text" ); property.setNodeName( "." ); property.setValue( value ); return property; }
Example 7
Source File: Dom4jAccessorTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private Property generateIdProperty() { SimpleValue value = new SimpleValue(); value.setTypeName( "long" ); Property property = new Property(); property.setName( "id" ); property.setNodeName( "@id" ); property.setValue( value ); return property; }
Example 8
Source File: HbmBinder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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( 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.getGeneration() == PropertyGeneration.INSERT ) { throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" ); } makeVersion( subnode, val ); entity.setVersion( prop ); entity.addProperty( prop ); }
Example 9
Source File: HbmBinder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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( 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 ); } makeIdentifier( idNode, id, mappings ); }
Example 10
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 5 votes |
private Property createOneToOneAttribute( MappingDocument sourceDocument, SingularAttributeSourceOneToOne oneToOneSource, OneToOne oneToOneBinding, String containingClassName) { bindOneToOne( sourceDocument, oneToOneSource, oneToOneBinding ); prepareValueTypeViaReflection( sourceDocument, oneToOneBinding, containingClassName, oneToOneSource.getName(), oneToOneSource.getAttributeRole() ); final String propertyRef = oneToOneBinding.getReferencedPropertyName(); if ( propertyRef != null ) { handlePropertyReference( sourceDocument, oneToOneBinding.getReferencedEntityName(), propertyRef, true, "<one-to-one name=\"" + oneToOneSource.getName() + "\"/>" ); } oneToOneBinding.createForeignKey(); Property prop = new Property(); prop.setValue( oneToOneBinding ); bindProperty( sourceDocument, oneToOneSource, prop ); return prop; }
Example 11
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 5 votes |
private void finishBindingCompositeIdentifier( MappingDocument sourceDocument, RootClass rootEntityDescriptor, CompositeIdentifierSource identifierSource, Component cid, String propertyName) { if ( propertyName == null ) { rootEntityDescriptor.setEmbeddedIdentifier( cid.isEmbedded() ); if ( cid.isEmbedded() ) { // todo : what is the implication of this? cid.setDynamic( !rootEntityDescriptor.hasPojoRepresentation() ); /* * Property prop = new Property(); prop.setName("id"); * prop.setPropertyAccessorName("embedded"); prop.setValue(id); * entity.setIdentifierProperty(prop); */ } } else { Property prop = new Property(); prop.setValue( cid ); bindProperty( sourceDocument, ( (IdentifierSourceAggregatedComposite) identifierSource ).getIdentifierAttributeSource(), prop ); rootEntityDescriptor.setIdentifierProperty( prop ); rootEntityDescriptor.setDeclaredIdentifierProperty( prop ); } makeIdentifier( sourceDocument, identifierSource.getIdentifierGeneratorDescriptor(), null, cid ); }
Example 12
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
private Property createManyToOneAttribute( MappingDocument sourceDocument, SingularAttributeSourceManyToOne manyToOneSource, ManyToOne manyToOneBinding, String containingClassName) { final String attributeName = manyToOneSource.getName(); final String referencedEntityName; if ( manyToOneSource.getReferencedEntityName() != null ) { referencedEntityName = manyToOneSource.getReferencedEntityName(); } else { Class reflectedPropertyClass = Helper.reflectedPropertyClass( sourceDocument, containingClassName, attributeName ); if ( reflectedPropertyClass != null ) { referencedEntityName = reflectedPropertyClass.getName(); } else { prepareValueTypeViaReflection( sourceDocument, manyToOneBinding, containingClassName, attributeName, manyToOneSource.getAttributeRole() ); referencedEntityName = manyToOneBinding.getTypeName(); } } if ( manyToOneSource.isUnique() ) { manyToOneBinding.markAsLogicalOneToOne(); } bindManyToOneAttribute( sourceDocument, manyToOneSource, manyToOneBinding, referencedEntityName ); final String propertyRef = manyToOneBinding.getReferencedPropertyName(); if ( propertyRef != null ) { handlePropertyReference( sourceDocument, manyToOneBinding.getReferencedEntityName(), propertyRef, true, "<many-to-one name=\"" + manyToOneSource.getName() + "\"/>" ); } Property prop = new Property(); prop.setValue( manyToOneBinding ); bindProperty( sourceDocument, manyToOneSource, prop ); if ( StringHelper.isNotEmpty( manyToOneSource.getCascadeStyleName() ) ) { // todo : would be better to delay this the end of binding (second pass, etc) // in order to properly allow for a singular unique column for a many-to-one to // also trigger a "logical one-to-one". As-is, this can occasionally lead to // false exceptions if the many-to-one column binding is delayed and the // uniqueness is indicated on the <column/> rather than on the <many-to-one/> // // Ideally, would love to see a SimpleValue#validate approach, rather than a // SimpleValue#isValid that is then handled at a higher level (Property, etc). // The reason being that the current approach misses the exact reason // a "validation" fails since it loses "context" if ( manyToOneSource.getCascadeStyleName().contains( "delete-orphan" ) ) { if ( !manyToOneBinding.isLogicalOneToOne() ) { throw new MappingException( String.format( Locale.ENGLISH, "many-to-one attribute [%s] specified delete-orphan but is not specified as unique; " + "remove delete-orphan cascading or specify unique=\"true\"", manyToOneSource.getAttributeRole().getFullPath() ), sourceDocument.getOrigin() ); } } } return prop; }
Example 13
Source File: HbmBinder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
private static void bindSimpleId(Element idNode, RootClass entity, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { String propertyName = idNode.attributeValue( "name" ); SimpleValue id = new SimpleValue( entity.getTable() ); entity.setIdentifier( id ); // if ( propertyName == null || entity.getPojoRepresentation() == null ) { // bindSimpleValue( idNode, id, false, RootClass.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings ); // if ( !id.isTypeSpecified() ) { // throw new MappingException( "must specify an identifier type: " + entity.getEntityName() // ); // } // } // else { // bindSimpleValue( idNode, id, false, propertyName, mappings ); // PojoRepresentation pojo = entity.getPojoRepresentation(); // id.setTypeUsingReflection( pojo.getClassName(), propertyName ); // // Property prop = new Property(); // prop.setValue( id ); // bindProperty( idNode, prop, mappings, inheritedMetas ); // entity.setIdentifierProperty( prop ); // } if ( propertyName == null ) { bindSimpleValue( idNode, id, false, RootClass.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings ); } else { bindSimpleValue( idNode, id, false, propertyName, mappings ); } if ( propertyName == null || !entity.hasPojoRepresentation() ) { if ( !id.isTypeSpecified() ) { throw new MappingException( "must specify an identifier type: " + entity.getEntityName() ); } } else { id.setTypeUsingReflection( entity.getClassName(), propertyName ); } if ( propertyName != null ) { Property prop = new Property(); prop.setValue( id ); bindProperty( idNode, prop, mappings, inheritedMetas ); entity.setIdentifierProperty( prop ); } // TODO: /* * if ( id.getHibernateType().getReturnedClass().isArray() ) throw new MappingException( * "illegal use of an array as an identifier (arrays don't reimplement equals)" ); */ makeIdentifier( idNode, id, mappings ); }
Example 14
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
private Property createBasicAttribute( MappingDocument sourceDocument, final SingularAttributeSourceBasic attributeSource, SimpleValue value, String containingClassName) { final String attributeName = attributeSource.getName(); bindSimpleValueType( sourceDocument, attributeSource.getTypeInformation(), value ); relationalObjectBinder.bindColumnsAndFormulas( sourceDocument, attributeSource.getRelationalValueSources(), value, attributeSource.areValuesNullableByDefault(), new RelationalObjectBinder.ColumnNamingDelegate() { @Override public Identifier determineImplicitName(LocalMetadataBuildingContext context) { return implicitNamingStrategy.determineBasicColumnName( attributeSource ); } } ); prepareValueTypeViaReflection( sourceDocument, value, containingClassName, attributeName, attributeSource.getAttributeRole() ); resolveLob( attributeSource, value ); // // this is done here 'cos we might only know the type here (ugly!) // // TODO: improve this a lot: // if ( value instanceof ToOne ) { // ToOne toOne = (ToOne) value; // String propertyRef = toOne.getReferencedEntityAttributeName(); // if ( propertyRef != null ) { // mappings.addUniquePropertyReference( toOne.getReferencedEntityName(), propertyRef ); // } // toOne.setCascadeDeleteEnabled( "cascade".equals( subnode.attributeValue( "on-delete" ) ) ); // } // else if ( value instanceof Collection ) { // Collection coll = (Collection) value; // String propertyRef = coll.getReferencedEntityAttributeName(); // // not necessarily a *unique* property reference // if ( propertyRef != null ) { // mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef ); // } // } value.createForeignKey(); Property property = new Property(); property.setValue( value ); property.setLob( value.isLob() ); bindProperty( sourceDocument, attributeSource, property ); return property; }
Example 15
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
private void bindEntityVersion( MappingDocument sourceDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) { final VersionAttributeSource versionAttributeSource = hierarchySource.getVersionAttributeSource(); final SimpleValue versionValue = new SimpleValue( sourceDocument, rootEntityDescriptor.getTable() ); versionValue.makeVersion(); bindSimpleValueType( sourceDocument, versionAttributeSource.getTypeInformation(), versionValue ); relationalObjectBinder.bindColumnsAndFormulas( sourceDocument, versionAttributeSource.getRelationalValueSources(), versionValue, false, new RelationalObjectBinder.ColumnNamingDelegate() { @Override public Identifier determineImplicitName(LocalMetadataBuildingContext context) { return implicitNamingStrategy.determineBasicColumnName( versionAttributeSource ); } } ); Property prop = new Property(); prop.setValue( versionValue ); bindProperty( sourceDocument, versionAttributeSource, prop ); // 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 version/timestamp property", sourceDocument.getOrigin() ); } } if ( versionAttributeSource.getUnsavedValue() != null ) { versionValue.setNullValue( versionAttributeSource.getUnsavedValue() ); } else { versionValue.setNullValue( "undefined" ); } rootEntityDescriptor.setVersion( prop ); rootEntityDescriptor.setDeclaredVersion( prop ); rootEntityDescriptor.addProperty( prop ); }
Example 16
Source File: HbmBinder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public static void bindCompositeId(Element node, Component component, PersistentClass persistentClass, String propertyName, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { component.setKey( true ); String path = StringHelper.qualify( persistentClass.getEntityName(), propertyName == null ? "id" : propertyName ); bindComponent( node, component, persistentClass.getClassName(), propertyName, path, false, node.attribute( "class" ) == null && propertyName == null, mappings, inheritedMetas, false ); if ( "true".equals( node.attributeValue("mapped") ) ) { if ( propertyName!=null ) { throw new MappingException("cannot combine mapped=\"true\" with specified name"); } Component mapper = new Component(persistentClass); bindComponent( node, mapper, persistentClass.getClassName(), null, path, false, true, mappings, inheritedMetas, true ); persistentClass.setIdentifierMapper(mapper); Property property = new Property(); property.setName("_identifierMapper"); property.setNodeName("id"); property.setUpdateable(false); property.setInsertable(false); property.setValue(mapper); property.setPropertyAccessorName( "embedded" ); persistentClass.addProperty(property); } }
Example 17
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
private void bindNonAggregatedCompositeEntityIdentifier( MappingDocument mappingDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) { final IdentifierSourceNonAggregatedComposite identifierSource = (IdentifierSourceNonAggregatedComposite) hierarchySource.getIdentifierSource(); final Component cid = new Component( mappingDocument, rootEntityDescriptor ); cid.setKey( true ); rootEntityDescriptor.setIdentifier( cid ); final String idClassName = extractIdClassName( identifierSource ); bindComponent( mappingDocument, hierarchySource.getRoot().getAttributeRoleBase().append( "<id>" ).getFullPath(), identifierSource.getEmbeddableSource(), cid, idClassName, rootEntityDescriptor.getClassName(), null, idClassName == null, false, null ); if ( idClassName != null ) { // we also need to bind the "id mapper". ugh, terrible name. Basically we need to // create a virtual (embedded) composite for the non-aggregated attributes on the entity // itself. final Component mapper = new Component( mappingDocument, rootEntityDescriptor ); bindComponent( mappingDocument, hierarchySource.getRoot().getAttributeRoleBase().append( ID_MAPPER_PATH_PART ).getFullPath(), identifierSource.getEmbeddableSource(), mapper, rootEntityDescriptor.getClassName(), null, null, true, false, null ); rootEntityDescriptor.setIdentifierMapper(mapper); Property property = new Property(); property.setName( PropertyPath.IDENTIFIER_MAPPER_PROPERTY ); property.setUpdateable( false ); property.setInsertable( false ); property.setValue( mapper ); property.setPropertyAccessorName( "embedded" ); rootEntityDescriptor.addProperty( property ); } finishBindingCompositeIdentifier( mappingDocument, rootEntityDescriptor, identifierSource, cid, null ); }
Example 18
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
private void bindSimpleEntityIdentifier( MappingDocument sourceDocument, final EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) { final IdentifierSourceSimple idSource = (IdentifierSourceSimple) hierarchySource.getIdentifierSource(); final SimpleValue idValue = new SimpleValue( sourceDocument, rootEntityDescriptor.getTable() ); rootEntityDescriptor.setIdentifier( idValue ); bindSimpleValueType( sourceDocument, idSource.getIdentifierAttributeSource().getTypeInformation(), idValue ); final String propertyName = idSource.getIdentifierAttributeSource().getName(); if ( propertyName == null || !rootEntityDescriptor.hasPojoRepresentation() ) { if ( !idValue.isTypeSpecified() ) { throw new MappingException( "must specify an identifier type: " + rootEntityDescriptor.getEntityName(), sourceDocument.getOrigin() ); } } else { idValue.setTypeUsingReflection( rootEntityDescriptor.getClassName(), propertyName ); } relationalObjectBinder.bindColumnsAndFormulas( sourceDocument, ( (RelationalValueSourceContainer) idSource.getIdentifierAttributeSource() ).getRelationalValueSources(), idValue, false, new RelationalObjectBinder.ColumnNamingDelegate() { @Override public Identifier determineImplicitName(final LocalMetadataBuildingContext context) { context.getBuildingOptions().getImplicitNamingStrategy().determineIdentifierColumnName( new ImplicitIdentifierColumnNameSource() { @Override public EntityNaming getEntityNaming() { return hierarchySource.getRoot().getEntityNamingSource(); } @Override public AttributePath getIdentifierAttributePath() { return idSource.getIdentifierAttributeSource().getAttributePath(); } @Override public MetadataBuildingContext getBuildingContext() { return context; } } ); return database.toIdentifier( propertyName ); } } ); if ( propertyName != null ) { Property prop = new Property(); prop.setValue( idValue ); bindProperty( sourceDocument, idSource.getIdentifierAttributeSource(), prop ); rootEntityDescriptor.setIdentifierProperty( prop ); rootEntityDescriptor.setDeclaredIdentifierProperty( prop ); } makeIdentifier( sourceDocument, idSource.getIdentifierGeneratorDescriptor(), idSource.getUnsavedValue(), idValue ); }
Example 19
Source File: PropertyBinder.java From lams with GNU General Public License v2.0 | 4 votes |
public Property makeProperty() { validateMake(); LOG.debugf( "Building property %s", name ); Property prop = new Property(); prop.setName( name ); prop.setValue( value ); prop.setLazy( lazy ); prop.setLazyGroup( lazyGroup ); prop.setCascade( cascade ); prop.setPropertyAccessorName( accessType.getType() ); if ( property != null ) { prop.setValueGenerationStrategy( determineValueGenerationStrategy( property ) ); if ( property.isAnnotationPresent( AttributeAccessor.class ) ) { final AttributeAccessor accessor = property.getAnnotation( AttributeAccessor.class ); prop.setPropertyAccessorName( accessor.value() ); } } NaturalId naturalId = property != null ? property.getAnnotation( NaturalId.class ) : null; if ( naturalId != null ) { if ( ! entityBinder.isRootEntity() ) { throw new AnnotationException( "@NaturalId only valid on root entity (or its @MappedSuperclasses)" ); } if ( ! naturalId.mutable() ) { updatable = false; } prop.setNaturalIdentifier( true ); } // HHH-4635 -- needed for dialect-specific property ordering Lob lob = property != null ? property.getAnnotation( Lob.class ) : null; prop.setLob( lob != null ); prop.setInsertable( insertable ); prop.setUpdateable( updatable ); // this is already handled for collections in CollectionBinder... if ( Collection.class.isInstance( value ) ) { prop.setOptimisticLocked( ( (Collection) value ).isOptimisticLocked() ); } else { final OptimisticLock lockAnn = property != null ? property.getAnnotation( OptimisticLock.class ) : null; if ( lockAnn != null ) { //TODO this should go to the core as a mapping validation checking if ( lockAnn.excluded() && ( property.isAnnotationPresent( javax.persistence.Version.class ) || property.isAnnotationPresent( Id.class ) || property.isAnnotationPresent( EmbeddedId.class ) ) ) { throw new AnnotationException( "@OptimisticLock.exclude=true incompatible with @Id, @EmbeddedId and @Version: " + StringHelper.qualify( holder.getPath(), name ) ); } } final boolean isOwnedValue = !isToOneValue( value ) || insertable; // && updatable as well??? final boolean includeInOptimisticLockChecks = ( lockAnn != null ) ? ! lockAnn.excluded() : isOwnedValue; prop.setOptimisticLocked( includeInOptimisticLockChecks ); } LOG.tracev( "Cascading {0} with {1}", name, cascade ); this.mappingProperty = prop; return prop; }