Java Code Examples for org.hibernate.mapping.SimpleValue#setTypeName()

The following examples show how to use org.hibernate.mapping.SimpleValue#setTypeName() . 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: AnnotationBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void bindDiscriminatorColumnToRootPersistentClass(
		RootClass rootClass,
		Ejb3DiscriminatorColumn discriminatorColumn,
		Map<String, Join> secondaryTables,
		PropertyHolder propertyHolder,
		MetadataBuildingContext context) {
	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( context, 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() );
		}
	}
}
 
Example 2
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void bindSimpleValueType(
		MappingDocument mappingDocument,
		HibernateTypeSource typeSource,
		SimpleValue simpleValue) {
	if ( mappingDocument.getBuildingOptions().useNationalizedCharacterData() ) {
		simpleValue.makeNationalized();
	}

	final TypeResolution typeResolution = resolveType( mappingDocument, typeSource );
	if ( typeResolution == null ) {
		// no explicit type info was found
		return;
	}

	if ( CollectionHelper.isNotEmpty( typeResolution.parameters ) ) {
		simpleValue.setTypeParameters( typeResolution.parameters );
	}

	if ( typeResolution.typeName != null ) {
		simpleValue.setTypeName( typeResolution.typeName );
	}
}
 
Example 3
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 4
Source File: HibernatePropertyParser.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/**
 * 构造SimpleValue
 */
private SimpleValue buildSimpleValue(Table table, PersistentClass pclazz,
									 MetaProperty property, String columnName) {
    // 是否枚举是枚举类型
	if (MetaConstant.isEnum(property)) {
		Class<?>[] inners = ReflectUtil
				.classForName(property.getEnumClass()).getClasses();
		if (inners != null) {
			for (Class<?> inner : inners) {
				if (!AttributeConverter.class.isAssignableFrom(inner)) {
					continue;
				}
				SimpleValue value = new SimpleValue(metadataCollector,
						table);
				value.setTypeName(StringHelper.join(
						AttributeConverterTypeAdapter.NAME_PREFIX,
						inner.getName()));
				value.setTypeUsingReflection(pclazz.getClassName(),
						property.getName());
				buildColumn(columnName, property.getLength(), value, table);
				return value;
			}
		}
	}
	return buildSimpleValue(table, property.getType(), columnName,
			property.getLength());
}
 
Example 5
Source File: HibernatePropertyParser.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/**
 * 构造SimpleValue
 */
private SimpleValue buildSimpleValue(Table table, String type,
									 String columnName, int len) {
	SimpleValue value = new SimpleValue(metadataCollector, table);
	String typeName = null;
	for (Entry<String, String> entry : HBMTYPES.entrySet()) {
		if (entry.getValue().equals(type)) {
			typeName = entry.getKey();
			break;
		}
	}
	value.setTypeName(typeName == null ? type.toLowerCase() : typeName);
	buildColumn(columnName, len, value, table);
	return value;
}
 
Example 6
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 7
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
}
 
Example 8
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 );
	}
}
 
Example 9
Source File: Dom4jAccessorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 10
Source File: Dom4jAccessorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 11
Source File: Dom4jAccessorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 12
Source File: Dom4jAccessorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}