org.hibernate.mapping.Value Java Examples

The following examples show how to use org.hibernate.mapping.Value. 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: HibernatePropertyParser.java    From mPaaS with Apache License 2.0 6 votes vote down vote up
/**
 * 将数据字典解析成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 #2
Source File: EntityBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void bindDiscriminatorValue() {
	if ( StringHelper.isEmpty( discriminatorValue ) ) {
		Value discriminator = persistentClass.getDiscriminator();
		if ( discriminator == null ) {
			persistentClass.setDiscriminatorValue( name );
		}
		else if ( "character".equals( discriminator.getType().getName() ) ) {
			throw new AnnotationException(
					"Using default @DiscriminatorValue for a discriminator of type CHAR is not safe"
			);
		}
		else if ( "integer".equals( discriminator.getType().getName() ) ) {
			persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
		}
		else {
			persistentClass.setDiscriminatorValue( name ); //Spec compliant
		}
	}
	else {
		//persistentClass.getDiscriminator()
		persistentClass.setDiscriminatorValue( discriminatorValue );
	}
}
 
Example #3
Source File: TableBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static void createUniqueConstraint(Value value) {
	Iterator iter = value.getColumnIterator();
	ArrayList cols = new ArrayList();
	while ( iter.hasNext() ) {
		cols.add( iter.next() );
	}
	value.getTable().createUniqueKey( cols );
}
 
Example #4
Source File: MapBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void makeOneToManyMapKeyColumnNullableIfNotInProperty(
		final XProperty property) {
	final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection;
	if ( map.isOneToMany() &&
			property.isAnnotationPresent( MapKeyColumn.class ) ) {
		final Value indexValue = map.getIndex();
		if ( indexValue.getColumnSpan() != 1 ) {
			throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" );
		}
		final Selectable selectable = indexValue.getColumnIterator().next();
		if ( selectable.isFormula() ) {
			throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" );
		}
		Column column = (Column) map.getIndex().getColumnIterator().next();
		if ( !column.isNullable() ) {
			final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass();
			// check if the index column has been mapped by the associated entity to a property;
			// @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only
			// need to check "un-joined" properties.
			if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) {
				// The index column is not mapped to an associated entity property so we can
				// safely make the index column nullable.
				column.setNullable( true );
			}
		}
	}
}
 
Example #5
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private SingularAttributeMetadataImpl(
		Property propertyMapping,
		AbstractManagedType<X> ownerType,
		Member member,
		Attribute.PersistentAttributeType persistentAttributeType) {
	super( propertyMapping, ownerType, member, persistentAttributeType );
	valueContext = new ValueContext() {
		public Value getValue() {
			return getPropertyMapping().getValue();
		}

		public Class getBindableType() {
			return getAttributeMetadata().getJavaType();
		}

		public ValueClassification getValueClassification() {
			switch ( getPersistentAttributeType() ) {
				case EMBEDDED: {
					return ValueClassification.EMBEDDABLE;
				}
				case BASIC: {
					return ValueClassification.BASIC;
				}
				default: {
					return ValueClassification.ENTITY;
				}
			}
		}

		public AttributeMetadata getAttributeMetadata() {
			return SingularAttributeMetadataImpl.this;
		}
	};
}
 
Example #6
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void prepareValueTypeViaReflection(
		MappingDocument sourceDocument,
		Value value,
		String containingClassName,
		String propertyName,
		AttributeRole attributeRole) {
	if ( StringHelper.isEmpty( propertyName ) ) {
		throw new MappingException(
				String.format(
						Locale.ENGLISH,
						"Attribute mapping must define a name attribute: containingClassName=[%s], propertyName=[%s], role=[%s]",
						containingClassName,
						propertyName,
						attributeRole.getFullPath()
				),
				sourceDocument.getOrigin()
		);
	}

	try {
		value.setTypeUsingReflection( containingClassName, propertyName );
	}
	catch (org.hibernate.MappingException ome) {
		throw new MappingException(
				String.format(
						Locale.ENGLISH,
						"Error calling Value#setTypeUsingReflection: containingClassName=[%s], propertyName=[%s], role=[%s]",
						containingClassName,
						propertyName,
						attributeRole.getFullPath()
				),
				ome,
				sourceDocument.getOrigin()
		);
	}
}
 
Example #7
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String columns(Value value) {
	final StringBuilder builder = new StringBuilder();
	final Iterator<Selectable> selectableItr = value.getColumnIterator();
	while ( selectableItr.hasNext() ) {
		builder.append( selectableItr.next().getText() );
		if ( selectableItr.hasNext() ) {
			builder.append( ", " );
		}
	}
	return builder.toString();
}
 
Example #8
Source File: IgniteCacheInitializer.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String fieldType(Column currentColumn) {
	Value value = currentColumn.getValue();
	Type type = value.getType();
	while ( type.isEntityType() || type.isComponentType() ) {
		if ( type.isEntityType() ) {
			type = ( (SimpleValue) value ).getMetadata().getIdentifierType( type.getName() );
		}
		if ( type.isComponentType() ) {
			int i = 0;
			boolean columnFound = false;
			// search which nested property is mapped to the given column
			for ( Iterator<Selectable> ci = value.getColumnIterator(); ci.hasNext(); ++i ) {
				if ( currentColumn.getName().equals( ci.next().getText() ) ) {
					type = ( (ComponentType) type ).getSubtypes()[i];
					columnFound = true;
					break;
				}
			}
			if ( !columnFound ) {
				throw new IllegalArgumentException( "Cannot determine type for column " + currentColumn );
			}
		}
	}
	GridType gridType = serviceRegistry.getService( TypeTranslator.class ).getType( type );
	if ( gridType instanceof EnumType ) {
		return enumFieldType( (EnumType) gridType );
	}
	if ( gridType instanceof YesNoType ) {
		return STRING_CLASS_NAME;
	}
	if ( gridType instanceof NumericBooleanType ) {
		return INTEGER_CLASS_NAME;
	}
	Class<?> returnedClass = type.getReturnedClass();
	if ( Character.class.equals( returnedClass ) ) {
		return STRING_CLASS_NAME;
	}
	return returnedClass.getName();
}
 
Example #9
Source File: FkSecondPass.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Value getValue() {
	return value;
}
 
Example #10
Source File: PropertyBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setValue(Value value) {
	this.value = value;
}
 
Example #11
Source File: PropertyBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private boolean isToOneValue(Value value) {
	return ToOne.class.isInstance( value );
}
 
Example #12
Source File: PropertyBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Value getValue() {
	return value;
}
 
Example #13
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private PluralAttributeMetadataImpl(
		Property propertyMapping,
		AbstractManagedType<X> ownerType,
		Member member,
		Attribute.PersistentAttributeType persistentAttributeType,
		Attribute.PersistentAttributeType elementPersistentAttributeType,
		Attribute.PersistentAttributeType keyPersistentAttributeType) {
	super( propertyMapping, ownerType, member, persistentAttributeType );
	this.attributeCollectionType = determineCollectionType( getJavaType() );
	this.elementPersistentAttributeType = elementPersistentAttributeType;
	this.keyPersistentAttributeType = keyPersistentAttributeType;

	ParameterizedType signatureType = getSignatureType( member );
	if ( keyPersistentAttributeType == null ) {
		elementJavaType = signatureType != null ?
				getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
				Object.class; //FIXME and honor targetEntity?
		keyJavaType = null;
	}
	else {
		keyJavaType = signatureType != null ?
				getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] ) :
				Object.class; //FIXME and honor targetEntity?
		elementJavaType = signatureType != null ?
				getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] ) :
				Object.class; //FIXME and honor targetEntity?
	}

	this.elementValueContext = new ValueContext() {
		public Value getValue() {
			return ( (Collection) getPropertyMapping().getValue() ).getElement();
		}

		public Class getBindableType() {
			return elementJavaType;
		}

		public ValueClassification getValueClassification() {
			switch ( PluralAttributeMetadataImpl.this.elementPersistentAttributeType ) {
				case EMBEDDED: {
					return ValueClassification.EMBEDDABLE;
				}
				case BASIC: {
					return ValueClassification.BASIC;
				}
				default: {
					return ValueClassification.ENTITY;
				}
			}
		}

		public AttributeMetadata getAttributeMetadata() {
			return PluralAttributeMetadataImpl.this;
		}
	};

	// interpret the key, if one
	if ( keyPersistentAttributeType != null ) {
		this.keyValueContext = new ValueContext() {
			public Value getValue() {
				return ( (Map) getPropertyMapping().getValue() ).getIndex();
			}

			public Class getBindableType() {
				return keyJavaType;
			}

			public ValueClassification getValueClassification() {
				switch ( PluralAttributeMetadataImpl.this.keyPersistentAttributeType ) {
					case EMBEDDED: {
						return ValueClassification.EMBEDDABLE;
					}
					case BASIC: {
						return ValueClassification.BASIC;
					}
					default: {
						return ValueClassification.ENTITY;
					}
				}
			}

			public AttributeMetadata getAttributeMetadata() {
				return PluralAttributeMetadataImpl.this;
			}
		};
	}
	else {
		keyValueContext = null;
	}
}
 
Example #14
Source File: ExportableColumn.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isSame(Value value) {
	return false;
}
 
Example #15
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieve the value itself
 *
 * @return The value
 */
public Value getValue();