private static void bindDiscriminatorProperty(Table table, RootClass entity, Element subnode, Mappings mappings) { SimpleValue discrim = new SimpleValue( mappings, 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 ); final String explicitForceValue = subnode.attributeValue( "force" ); boolean forceDiscriminatorInSelects = explicitForceValue == null ? mappings.forceDiscriminatorInSelectsByDefault() : "true".equals( explicitForceValue ); entity.setForceDiscriminator( forceDiscriminatorInSelects ); if ( "false".equals( subnode.attributeValue( "insert" ) ) ) { entity.setDiscriminatorInsertable( false ); } }
public static void bindIdentifierCollectionSecondPass(Element node, IdentifierCollection collection, java.util.Map persistentClasses, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindCollectionSecondPass( node, collection, persistentClasses, mappings, inheritedMetas ); Element subnode = node.element( "collection-id" ); SimpleValue id = new SimpleValue( mappings, collection.getCollectionTable() ); bindSimpleValue( subnode, id, false, IdentifierCollection.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings ); collection.setIdentifier( id ); makeIdentifier( subnode, id, mappings ); }
private static void bindDiscriminatorColumnToRootPersistentClass( RootClass rootClass, Ejb3DiscriminatorColumn discriminatorColumn, Map<String, Join> secondaryTables, PropertyHolder propertyHolder, Mappings mappings) { if ( rootClass.getDiscriminator() == null ) { if ( discriminatorColumn == null ) { throw new AssertionFailure( "discriminator column should have been built" ); } discriminatorColumn.setJoins( secondaryTables ); discriminatorColumn.setPropertyHolder( propertyHolder ); SimpleValue discriminatorColumnBinding = new SimpleValue( mappings, rootClass.getTable() ); rootClass.setDiscriminator( discriminatorColumnBinding ); discriminatorColumn.linkWithValue( discriminatorColumnBinding ); discriminatorColumnBinding.setTypeName( discriminatorColumn.getDiscriminatorTypeName() ); rootClass.setPolymorphic( true ); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Setting discriminator for entity {0}", rootClass.getEntityName() ); } } }
public void linkValueUsingDefaultColumnNaming( Column referencedColumn, PersistentClass referencedEntity, SimpleValue value) { String columnName; String logicalReferencedColumn = getMappings().getLogicalColumnName( referencedColumn.getQuotedName(), referencedEntity.getTable() ); columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn ); //yuk side effect on an implicit column setLogicalColumnName( columnName ); setReferencedColumn( logicalReferencedColumn ); initMappingColumn( columnName, null, referencedColumn.getLength(), referencedColumn.getPrecision(), referencedColumn.getScale(), getMappingColumn() != null ? getMappingColumn().isNullable() : false, referencedColumn.getSqlType(), getMappingColumn() != null ? getMappingColumn().isUnique() : false, false ); linkWithValue( value ); }
@Override protected void addColumnBinding(SimpleValue value) { if ( StringHelper.isEmpty( mappedBy ) ) { // was the column explicitly quoted in the mapping/annotation // TODO: in metamodel, we need to better split global quoting and explicit quoting w/ respect to logical names boolean isLogicalColumnQuoted = StringHelper.isQuoted( getLogicalColumnName() ); final ObjectNameNormalizer nameNormalizer = getMappings().getObjectNameNormalizer(); final String logicalColumnName = nameNormalizer.normalizeIdentifierQuoting( getLogicalColumnName() ); final String referencedColumn = nameNormalizer.normalizeIdentifierQuoting( getReferencedColumn() ); final String unquotedLogColName = StringHelper.unquote( logicalColumnName ); final String unquotedRefColumn = StringHelper.unquote( referencedColumn ); String logicalCollectionColumnName = getNamingStrategyDelegate().determineLogicalCollectionColumnName( unquotedLogColName, getPropertyName(), unquotedRefColumn ); if ( isLogicalColumnQuoted ) { logicalCollectionColumnName = StringHelper.quote( logicalCollectionColumnName ); } getMappings().addColumnBinding( logicalCollectionColumnName, getMappingColumn(), value.getTable() ); } }
private static void bindCollectionSecondPass( Collection collValue, PersistentClass collectionEntity, Ejb3JoinColumn[] joinColumns, boolean cascadeDeleteEnabled, XProperty property, Mappings mappings) { try { BinderHelper.createSyntheticPropertyReference( joinColumns, collValue.getOwner(), collectionEntity, collValue, false, mappings ); } catch (AnnotationException ex) { throw new AnnotationException( "Unable to map collection " + collectionEntity.getClassName() + "." + property.getName(), ex ); } SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, mappings ); if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) { joinColumns[0].setJPA2ElementCollection( true ); } TableBinder.bindFk( collValue.getOwner(), collectionEntity, joinColumns, key, false, mappings ); }
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(); }
public SimpleValue make() { validate(); LOG.debugf( "building SimpleValue for %s", propertyName ); if ( table == null ) { table = columns[0].getTable(); } simpleValue = new SimpleValue( mappings, table ); linkWithValue(); boolean isInSecondPass = mappings.isInSecondPass(); SetSimpleValueTypeSecondPass secondPass = new SetSimpleValueTypeSecondPass( this ); if ( !isInSecondPass ) { //Defer this to the second pass mappings.addSecondPass( secondPass ); } else { //We are already in second pass fillSimpleValue(); } return simpleValue; }
public static void linkJoinColumnWithValueOverridingNameIfImplicit( PersistentClass referencedEntity, Iterator columnIterator, Ejb3JoinColumn[] columns, SimpleValue value) { for (Ejb3JoinColumn joinCol : columns) { Column synthCol = (Column) columnIterator.next(); if ( joinCol.isNameDeferred() ) { //this has to be the default value joinCol.linkValueUsingDefaultColumnNaming( synthCol, referencedEntity, value ); } else { joinCol.linkWithValue( value ); joinCol.overrideFromReferencedColumnIfNecessary( synthCol ); } } }
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 ); }
public static void bindIdentifierCollectionSecondPass(Element node, IdentifierCollection collection, java.util.Map persistentClasses, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindCollectionSecondPass( node, collection, persistentClasses, mappings, inheritedMetas ); Element subnode = node.element( "collection-id" ); SimpleValue id = new SimpleValue( collection.getCollectionTable() ); bindSimpleValue( subnode, id, false, IdentifierCollection.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings ); collection.setIdentifier( id ); makeIdentifier( subnode, id, mappings ); }
public void testProperCallbacks() { ValueVisitor vv = new ValueVisitorValidator(); new Any(new Table()).accept(vv); new Array(new RootClass()).accept(vv); new Bag(new RootClass()).accept(vv); new Component(new RootClass()).accept(vv); new DependantValue(null,null).accept(vv); new IdentifierBag(null).accept(vv); new List(null).accept(vv); new ManyToOne(null).accept(vv); new Map(null).accept(vv); new OneToMany(null).accept(vv); new OneToOne(null, new RootClass() ).accept(vv); new PrimitiveArray(null).accept(vv); new Set(null).accept(vv); new SimpleValue().accept(vv); }
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 ); }
public static void bindSimpleValue(Element node, SimpleValue simpleValue, boolean isNullable, String path, Mappings mappings) throws MappingException { bindSimpleValueType( node, simpleValue, mappings ); bindColumnsOrFormula( node, simpleValue, path, isNullable, mappings ); Attribute fkNode = node.attribute( "foreign-key" ); if ( fkNode != null ) simpleValue.setForeignKeyName( fkNode.getValue() ); }
private static void bindSimpleValueType(Element node, SimpleValue simpleValue, Mappings mappings) throws MappingException { String typeName = null; Properties parameters = new Properties(); Attribute typeNode = node.attribute( "type" ); if ( typeNode == null ) { typeNode = node.attribute( "id-type" ); // for an any } else { typeName = typeNode.getValue(); } Element typeChild = node.element( "type" ); if ( typeName == null && typeChild != null ) { typeName = typeChild.attribute( "name" ).getValue(); Iterator typeParameters = typeChild.elementIterator( "param" ); while ( typeParameters.hasNext() ) { Element paramElement = (Element) typeParameters.next(); parameters.setProperty( paramElement.attributeValue( "name" ), paramElement.getTextTrim() ); } } resolveAndBindTypeDef(simpleValue, mappings, typeName, parameters); }
private static void resolveAndBindTypeDef(SimpleValue simpleValue, Mappings mappings, String typeName, Properties parameters) { TypeDef typeDef = mappings.getTypeDef( typeName ); if ( typeDef != null ) { typeName = typeDef.getTypeClass(); // parameters on the property mapping should // override parameters in the typedef Properties allParameters = new Properties(); allParameters.putAll( typeDef.getParameters() ); allParameters.putAll( parameters ); parameters = allParameters; }else if (typeName!=null && !mappings.isInSecondPass()){ BasicType basicType=mappings.getTypeResolver().basic(typeName); if (basicType==null) { /* * If the referenced typeName isn't a basic-type, it's probably a typedef defined * in a mapping file not read yet. * It should be solved by deferring the resolution and binding of this type until * all mapping files are read - the second passes. * Fixes issue HHH-7300 */ SecondPass resolveUserTypeMappingSecondPass=new ResolveUserTypeMappingSecondPass(simpleValue,typeName,mappings,parameters); mappings.addSecondPass(resolveUserTypeMappingSecondPass); } } if ( !parameters.isEmpty() ) simpleValue.setTypeParameters( parameters ); if ( typeName != null ) simpleValue.setTypeName( typeName ); }
private static void bindColumnsOrFormula(Element node, SimpleValue simpleValue, String path, boolean isNullable, Mappings mappings) { Attribute formulaNode = node.attribute( "formula" ); if ( formulaNode != null ) { Formula f = new Formula(); f.setFormula( formulaNode.getText() ); simpleValue.addFormula( f ); } else { bindColumns( node, simpleValue, isNullable, true, path, mappings ); } }
private static final void makeVersion(Element node, SimpleValue model) { // VERSION UNSAVED-VALUE Attribute nullValueNode = node.attribute( "unsaved-value" ); if ( nullValueNode != null ) { model.setNullValue( nullValueNode.getValue() ); } else { model.setNullValue( "undefined" ); } }
/** * Called for Lists, arrays, primitive arrays */ public static void bindListSecondPass(Element node, List list, java.util.Map classes, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindCollectionSecondPass( node, list, classes, mappings, inheritedMetas ); Element subnode = node.element( "list-index" ); if ( subnode == null ) subnode = node.element( "index" ); SimpleValue iv = new SimpleValue( mappings, list.getCollectionTable() ); bindSimpleValue( subnode, iv, list.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings ); iv.setTypeName( "integer" ); list.setIndex( iv ); String baseIndex = subnode.attributeValue( "base" ); if ( baseIndex != null ) list.setBaseIndex( Integer.parseInt( baseIndex ) ); list.setIndexNodeName( subnode.attributeValue("node") ); if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) { String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName ); IndexBackref ib = new IndexBackref(); ib.setName( '_' + list.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( list.getRole() ); ib.setEntityName( list.getOwner().getEntityName() ); ib.setValue( list.getIndex() ); // ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next() // ).setNullable(false); referenced.addProperty( ib ); } }
public ResolveUserTypeMappingSecondPass(SimpleValue simpleValue, String typeName, Mappings mappings, Properties parameters) { this.simpleValue=simpleValue; this.typeName=typeName; this.parameters=parameters; this.mappings=mappings; }
/** * 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; }
public JoinedSubclassFkSecondPass( JoinedSubclass entity, Ejb3JoinColumn[] inheritanceJoinedColumns, SimpleValue key, Mappings mappings) { super( key, inheritanceJoinedColumns ); this.entity = entity; this.mappings = mappings; }
private static void processId( PropertyHolder propertyHolder, PropertyData inferredData, SimpleValue idValue, HashMap<String, IdGenerator> classGenerators, boolean isIdentifierMapper, Mappings mappings) { if ( isIdentifierMapper ) { throw new AnnotationException( "@IdClass class should not have @Id nor @EmbeddedId properties: " + BinderHelper.getPath( propertyHolder, inferredData ) ); } XClass returnedClass = inferredData.getClassOrElement(); XProperty property = inferredData.getProperty(); //clone classGenerator and override with local values HashMap<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone(); localGenerators.putAll( buildLocalGenerators( property, mappings ) ); //manage composite related metadata //guess if its a component and find id data access (property, field etc) final boolean isComponent = returnedClass.isAnnotationPresent( Embeddable.class ) || property.isAnnotationPresent( EmbeddedId.class ); GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class ); String generatorType = generatedValue != null ? generatorType( generatedValue.strategy(), mappings ) : "assigned"; String generatorName = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT; if ( isComponent ) { generatorType = "assigned"; } //a component must not have any generator BinderHelper.makeIdGenerator( idValue, generatorType, generatorName, mappings, localGenerators ); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() ); } }
public void copyReferencedStructureAndCreateDefaultJoinColumns( PersistentClass referencedEntity, Iterator columnIterator, SimpleValue value) { if ( !isNameDeferred() ) { throw new AssertionFailure( "Building implicit column but the column is not implicit" ); } while ( columnIterator.hasNext() ) { Column synthCol = (Column) columnIterator.next(); this.linkValueUsingDefaultColumnNaming( synthCol, referencedEntity, value ); } //reset for the future setMappingColumn( null ); }
/** * used for mappedBy cases */ public void linkValueUsingAColumnCopy(Column column, SimpleValue value) { initMappingColumn( //column.getName(), column.getQuotedName(), null, column.getLength(), column.getPrecision(), column.getScale(), getMappingColumn().isNullable(), column.getSqlType(), getMappingColumn().isUnique(), false //We do copy no strategy here ); linkWithValue( value ); }
private static void checkFilterConditions(Collection collValue) { //for now it can't happen, but sometime soon... if ( ( collValue.getFilters().size() != 0 || StringHelper.isNotEmpty( collValue.getWhere() ) ) && collValue.getFetchMode() == FetchMode.JOIN && !( collValue.getElement() instanceof SimpleValue ) && //SimpleValue (CollectionOfElements) are always SELECT but it does not matter collValue.getElement().getFetchMode() != FetchMode.JOIN ) { throw new MappingException( "@ManyToMany or @CollectionOfElements defining filter or where without join fetching " + "not valid within collection using join fetching[" + collValue.getRole() + "]" ); } }
private void bindIndex(final Mappings mappings) { if ( !indexColumn.isImplicit() ) { PropertyHolder valueHolder = PropertyHolderBuilder.buildPropertyHolder( this.collection, StringHelper.qualify( this.collection.getRole(), "key" ), null, null, propertyHolder, mappings ); List list = (List) this.collection; if ( !list.isOneToMany() ) indexColumn.forceNotNull(); indexColumn.setPropertyHolder( valueHolder ); SimpleValueBinder value = new SimpleValueBinder(); value.setColumns( new Ejb3Column[] { indexColumn } ); value.setExplicitType( "integer" ); value.setMappings( mappings ); SimpleValue indexValue = value.make(); indexColumn.linkWithValue( indexValue ); list.setIndex( indexValue ); list.setBaseIndex( indexColumn.getBase() ); if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) { String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName ); IndexBackref ib = new IndexBackref(); ib.setName( '_' + propertyName + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( list.getRole() ); ib.setEntityName( list.getOwner().getEntityName() ); ib.setValue( list.getIndex() ); referenced.addProperty( ib ); } } else { Collection coll = this.collection; throw new AnnotationException( "List/array has to be annotated with an @OrderColumn (or @IndexColumn): " + coll.getRole() ); } }
private void bindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns, Mappings mappings) { SimpleValue key = new DependantValue( mappings, join.getTable(), persistentClass.getIdentifier() ); join.setKey( key ); setFKNameIfDefined( join ); key.setCascadeDeleteEnabled( false ); TableBinder.bindFk( persistentClass, null, ejb3JoinColumns, key, false, mappings ); join.createPrimaryKey(); join.createForeignKey(); persistentClass.addJoin( join ); }
public void linkWithValue(SimpleValue value) { if ( formula != null ) { value.addFormula( formula ); } else { getMappingColumn().setValue( value ); value.addColumn( getMappingColumn() ); value.getTable().addColumn( getMappingColumn() ); addColumnBinding( value ); table = value.getTable(); } }
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 ); }
private static void bindSimpleValueType(Element node, SimpleValue simpleValue, Mappings mappings) throws MappingException { String typeName = null; Properties parameters = new Properties(); Attribute typeNode = node.attribute( "type" ); if ( typeNode == null ) typeNode = node.attribute( "id-type" ); // for an any if ( typeNode != null ) typeName = typeNode.getValue(); Element typeChild = node.element( "type" ); if ( typeName == null && typeChild != null ) { typeName = typeChild.attribute( "name" ).getValue(); Iterator typeParameters = typeChild.elementIterator( "param" ); while ( typeParameters.hasNext() ) { Element paramElement = (Element) typeParameters.next(); parameters.setProperty( paramElement.attributeValue( "name" ), paramElement.getTextTrim() ); } } TypeDef typeDef = mappings.getTypeDef( typeName ); if ( typeDef != null ) { typeName = typeDef.getTypeClass(); // parameters on the property mapping should // override parameters in the typedef Properties allParameters = new Properties(); allParameters.putAll( typeDef.getParameters() ); allParameters.putAll( parameters ); parameters = allParameters; } if ( !parameters.isEmpty() ) simpleValue.setTypeParameters( parameters ); if ( typeName != null ) simpleValue.setTypeName( typeName ); }
/** * Called for Lists, arrays, primitive arrays */ public static void bindListSecondPass(Element node, List list, java.util.Map classes, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindCollectionSecondPass( node, list, classes, mappings, inheritedMetas ); Element subnode = node.element( "list-index" ); if ( subnode == null ) subnode = node.element( "index" ); SimpleValue iv = new SimpleValue( list.getCollectionTable() ); bindSimpleValue( subnode, iv, list.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings ); iv.setTypeName( "integer" ); list.setIndex( iv ); String baseIndex = subnode.attributeValue( "base" ); if ( baseIndex != null ) list.setBaseIndex( Integer.parseInt( baseIndex ) ); list.setIndexNodeName( subnode.attributeValue("node") ); if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) { String entityName = ( (OneToMany) list.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( list.getRole() ); ib.setEntityName( list.getOwner().getEntityName() ); ib.setValue( list.getIndex() ); // ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next() // ).setNullable(false); referenced.addProperty( ib ); } }
private void applyCacheSettings(Configuration configuration) { if ( settings.getCacheConcurrencyStrategy() != null ) { Iterator iter = configuration.getClassMappings(); while ( iter.hasNext() ) { PersistentClass clazz = (PersistentClass) iter.next(); Iterator props = clazz.getPropertyClosureIterator(); boolean hasLob = false; while ( props.hasNext() ) { Property prop = (Property) props.next(); if ( prop.getValue().isSimpleValue() ) { String type = ( ( SimpleValue ) prop.getValue() ).getTypeName(); if ( "blob".equals(type) || "clob".equals(type) ) { hasLob = true; } if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) { hasLob = true; } } } if ( !hasLob && !clazz.isInherited() && settings.overrideCacheStrategy() ) { configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), settings.getCacheConcurrencyStrategy() ); } } iter = configuration.getCollectionMappings(); while ( iter.hasNext() ) { Collection coll = (Collection) iter.next(); configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), settings.getCacheConcurrencyStrategy() ); } } }
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; }
private Property generateTextProperty() { SimpleValue value = new SimpleValue(); value.setTypeName( "string" ); Property property = new Property(); property.setName( "text" ); property.setNodeName( "." ); property.setValue( value ); return property; }
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; }
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; }