org.hibernate.mapping.SimpleValue#isTypeSpecified ( )源码实例Demo

下面列出了org.hibernate.mapping.SimpleValue#isTypeSpecified ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cacheonix-core   文件: HbmBinder.java
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 );
}
 
源代码2 项目: cacheonix-core   文件: 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( 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 );
}
 
源代码3 项目: lams   文件: ModelBinder.java
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
	);
}
 
源代码4 项目: cacheonix-core   文件: HbmBinder.java
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 );
}
 
源代码5 项目: cacheonix-core   文件: HbmBinder.java
/**
 * 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 );
	}
}