Java Code Examples for org.hibernate.mapping.SimpleValue#isTypeSpecified()
The following examples show how to use
org.hibernate.mapping.SimpleValue#isTypeSpecified() .
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: HbmBinder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
private static void bindDiscriminatorProperty(Table table, RootClass entity, Element subnode, Mappings mappings) { SimpleValue discrim = new SimpleValue( table ); entity.setDiscriminator( discrim ); bindSimpleValue( subnode, discrim, false, RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings ); if ( !discrim.isTypeSpecified() ) { discrim.setTypeName( "string" ); // ( (Column) discrim.getColumnIterator().next() ).setType(type); } entity.setPolymorphic( true ); if ( "true".equals( subnode.attributeValue( "force" ) ) ) entity.setForceDiscriminator( true ); if ( "false".equals( subnode.attributeValue( "insert" ) ) ) entity.setDiscriminatorInsertable( false ); }
Example 2
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 3
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 4
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 5
Source File: HbmBinder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Called for Maps */ public static void bindMapSecondPass(Element node, Map map, java.util.Map classes, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindCollectionSecondPass( node, map, classes, mappings, inheritedMetas ); Iterator iter = node.elementIterator(); while ( iter.hasNext() ) { Element subnode = (Element) iter.next(); String name = subnode.getName(); if ( "index".equals( name ) || "map-key".equals( name ) ) { SimpleValue value = new SimpleValue( map.getCollectionTable() ); bindSimpleValue( subnode, value, map.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings ); if ( !value.isTypeSpecified() ) { throw new MappingException( "map index element must specify a type: " + map.getRole() ); } map.setIndex( value ); map.setIndexNodeName( subnode.attributeValue("node") ); } else if ( "index-many-to-many".equals( name ) || "map-key-many-to-many".equals( name ) ) { ManyToOne mto = new ManyToOne( map.getCollectionTable() ); bindManyToOne( subnode, mto, IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, map.isOneToMany(), mappings ); map.setIndex( mto ); } else if ( "composite-index".equals( name ) || "composite-map-key".equals( name ) ) { Component component = new Component( map ); bindComposite( subnode, component, map.getRole() + ".index", map.isOneToMany(), mappings, inheritedMetas ); map.setIndex( component ); } else if ( "index-many-to-any".equals( name ) ) { Any any = new Any( map.getCollectionTable() ); bindAny( subnode, any, map.isOneToMany(), mappings ); map.setIndex( any ); } } // TODO: this is a bit of copy/paste from IndexedCollection.createPrimaryKey() boolean indexIsFormula = false; Iterator colIter = map.getIndex().getColumnIterator(); while ( colIter.hasNext() ) { if ( ( (Selectable) colIter.next() ).isFormula() ) indexIsFormula = true; } if ( map.isOneToMany() && !map.getKey().isNullable() && !map.isInverse() && !indexIsFormula ) { String entityName = ( (OneToMany) map.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName ); IndexBackref ib = new IndexBackref(); ib.setName( '_' + node.attributeValue( "name" ) + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( map.getRole() ); ib.setEntityName( map.getOwner().getEntityName() ); ib.setValue( map.getIndex() ); // ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next() // ).setNullable(false); referenced.addProperty( ib ); } }