Java Code Examples for org.hibernate.engine.spi.Mapping

The following examples show how to use org.hibernate.engine.spi.Mapping. These examples are extracted from open source projects. 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 Project: lams   Source File: CompositeCustomType.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean[] toColumnNullness(Object value, Mapping mapping) {
	boolean[] result = new boolean[getColumnSpan( mapping )];
	if ( value == null ) {
		return result;
	}
	Object[] values = getPropertyValues( value, EntityMode.POJO ); //TODO!!!!!!!
	int loc = 0;
	Type[] propertyTypes = getSubtypes();
	for ( int i = 0; i < propertyTypes.length; i++ ) {
		boolean[] propertyNullness = propertyTypes[i].toColumnNullness( values[i], mapping );
		System.arraycopy( propertyNullness, 0, result, loc, propertyNullness.length );
		loc += propertyNullness.length;
	}
	return result;
}
 
Example 2
Source Project: lams   Source File: PersistentClass.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void validate(Mapping mapping) throws MappingException {
	Iterator iter = getPropertyIterator();
	while ( iter.hasNext() ) {
		Property prop = (Property) iter.next();
		if ( !prop.isValid( mapping ) ) {
			throw new MappingException(
					"property mapping has wrong number of columns: " +
							StringHelper.qualify( getEntityName(), prop.getName() ) +
							" type: " +
							prop.getType().getName()
			);
		}
	}
	checkPropertyDuplication();
	checkColumnDuplication();
}
 
Example 3
Source Project: lams   Source File: Column.java    License: GNU General Public License v2.0 6 votes vote down vote up
public int getSqlTypeCode(Mapping mapping) throws MappingException {
	org.hibernate.type.Type type = getValue().getType();
	try {
		int sqlTypeCode = type.sqlTypes( mapping )[getTypeIndex()];
		if ( getSqlTypeCode() != null && getSqlTypeCode() != sqlTypeCode ) {
			throw new MappingException( "SQLType code's does not match. mapped as " + sqlTypeCode + " but is " + getSqlTypeCode() );
		}
		return sqlTypeCode;
	}
	catch (Exception e) {
		throw new MappingException(
				"Could not determine type for column " +
						name +
						" of type " +
						type.getClass().getName() +
						": " +
						e.getClass().getName(),
				e
		);
	}
}
 
Example 4
Source Project: lams   Source File: Constraint.java    License: GNU General Public License v2.0 5 votes vote down vote up
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
	if ( isGenerated( dialect ) ) {
		// Certain dialects (ex: HANA) don't support FKs as expected, but other constraints can still be created.
		// If that's the case, hasAlterTable() will be true, but getAddForeignKeyConstraintString will return
		// empty string.  Prevent blank "alter table" statements.
		String constraintString = sqlConstraintString( dialect, getName(), defaultCatalog, defaultSchema );
		if ( !StringHelper.isEmpty( constraintString ) ) {
			final String tableName = getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema );
			return dialect.getAlterTableString( tableName ) + " " + constraintString;
		}
	}
	return null;
}
 
Example 5
Source Project: lams   Source File: CompositeCustomType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getColumnSpan(Mapping mapping) throws MappingException {
	Type[] types = userType.getPropertyTypes();
	int n = 0;
	for ( Type type : types ) {
		n += type.getColumnSpan( mapping );
	}
	return n;
}
 
Example 6
Source Project: lams   Source File: IdentifierCollection.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void validate(Mapping mapping) throws MappingException {
	super.validate( mapping );

	assert getElement() != null : "IdentifierCollection identifier not bound : " + getRole();

	if ( !getIdentifier().isValid(mapping) ) {
		throw new MappingException(
			"collection id mapping has wrong number of columns: " +
			getRole() +
			" type: " +
			getIdentifier().getType().getName()
		);
	}
}
 
Example 7
Source Project: lams   Source File: Index.java    License: GNU General Public License v2.0 5 votes vote down vote up
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema)
		throws HibernateException {
	return buildSqlCreateIndexString(
			dialect,
			getQuotedName( dialect ),
			getTable(),
			getColumnIterator(),
			columnOrderMap,
			false,
			defaultCatalog,
			defaultSchema
	);
}
 
Example 8
Source Project: lams   Source File: UnionSubclass.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void validate(Mapping mapping) throws MappingException {
	super.validate(mapping);
	if ( key!=null && !key.isValid(mapping) ) {
		throw new MappingException(
			"subclass key mapping has wrong number of columns: " +
			getEntityName() +
			" type: " +
			key.getType().getName()
		);
	}
}
 
Example 9
Source Project: lams   Source File: Table.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void validateColumns(Dialect dialect, Mapping mapping, TableMetadata tableInfo) {
	Iterator iter = getColumnIterator();
	while ( iter.hasNext() ) {
		Column col = (Column) iter.next();

		ColumnMetadata columnInfo = tableInfo.getColumnMetadata( col.getName() );

		if ( columnInfo == null ) {
			throw new HibernateException( "Missing column: " + col.getName() + " in " + Table.qualify( tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()));
		}
		else {
			final boolean typesMatch = col.getSqlType( dialect, mapping ).toLowerCase(Locale.ROOT)
					.startsWith( columnInfo.getTypeName().toLowerCase(Locale.ROOT) )
					|| columnInfo.getTypeCode() == col.getSqlTypeCode( mapping );
			if ( !typesMatch ) {
				throw new HibernateException(
						"Wrong column type in " +
						Table.qualify( tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()) +
						" for column " + col.getName() +
						". Found: " + columnInfo.getTypeName().toLowerCase(Locale.ROOT) +
						", expected: " + col.getSqlType( dialect, mapping )
				);
			}
		}
	}

}
 
Example 10
Source Project: lams   Source File: UniqueKey.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
	public String sqlCreateString(
			Dialect dialect,
			Mapping p,
			String defaultCatalog,
			String defaultSchema) {
		return null;
//		return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
//				this, defaultCatalog, defaultSchema
//		);
	}
 
Example 11
Source Project: lams   Source File: AbstractEntityPersister.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void initOrdinaryPropertyPaths(Mapping mapping) throws MappingException {
	for ( int i = 0; i < getSubclassPropertyNameClosure().length; i++ ) {
		propertyMapping.initPropertyPaths(
				getSubclassPropertyNameClosure()[i],
				getSubclassPropertyTypeClosure()[i],
				getSubclassPropertyColumnNameClosure()[i],
				getSubclassPropertyColumnReaderClosure()[i],
				getSubclassPropertyColumnReaderTemplateClosure()[i],
				getSubclassPropertyFormulaTemplateClosure()[i],
				mapping
		);
	}
}
 
Example 12
Source Project: lams   Source File: EntityType.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected Type requireIdentifierOrUniqueKeyType(Mapping mapping) {
	final Type fkTargetType = getIdentifierOrUniqueKeyType( mapping );
	if ( fkTargetType == null ) {
		throw new MappingException(
				"Unable to determine FK target Type for many-to-one or one-to-one mapping: " +
						"referenced-entity-name=[" + getAssociatedEntityName() +
						"], referenced-entity-attribute-name=[" + getLHSPropertyName() + "]"
		);
	}
	return fkTargetType;
}
 
Example 13
Source Project: lams   Source File: JoinHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the columns of the owning entity which are to be used in the join
 *
 * @param type The type representing the join
 * @param property The property index for the association type
 * @param begin ?
 * @param lhsPersister The persister for the left-hand-side of the join
 * @param mapping The mapping object (typically the SessionFactory)
 *
 * @return The columns for the left-hand-side of the join
 */
public static String[] getLHSColumnNames(
		AssociationType type,
		int property,
		int begin,
		OuterJoinLoadable lhsPersister,
		Mapping mapping) {
	if ( type.useLHSPrimaryKey() ) {
		//return lhsPersister.getSubclassPropertyColumnNames(property);
		return lhsPersister.getIdentifierColumnNames();
	}
	else {
		final String propertyName = type.getLHSPropertyName();
		if ( propertyName == null ) {
			//slice, to get the columns for this component
			//property
			return ArrayHelper.slice(
					property < 0
							? lhsPersister.getIdentifierColumnNames()
							: lhsPersister.getSubclassPropertyColumnNames( property ),
					begin,
					type.getColumnSpan( mapping )
			);
		}
		else {
			//property-refs for associations defined on a
			//component are not supported, so no need to slice
			return lhsPersister.getPropertyColumnNames( propertyName );
		}
	}
}
 
Example 14
Source Project: lams   Source File: EntityType.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine the type of either (1) the identifier if we reference the
 * associated entity's PK or (2) the unique key to which we refer (i.e.
 * the property-ref).
 *
 * @param factory The mappings...
 *
 * @return The appropriate type.
 *
 * @throws MappingException Generally, if unable to resolve the associated entity name
 * or unique key property name.
 */
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException {
	if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
		return getIdentifierType( factory );
	}
	else {
		Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
		if ( type.isEntityType() ) {
			type = ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory );
		}
		return type;
	}
}
 
Example 15
protected final int determineJdbcTypeCode(Type type, Mapping mapping) throws QueryException {
	try {
		final int[] jdbcTypeCodes = type.sqlTypes( mapping );
		if ( jdbcTypeCodes.length != 1 ) {
			throw new QueryException( "multiple-column type in sum()" );
		}
		return jdbcTypeCodes[0];
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
}
 
Example 16
Source Project: lams   Source File: ComponentType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getColumnSpan(Mapping mapping) throws MappingException {
	int span = 0;
	for ( int i = 0; i < propertySpan; i++ ) {
		span += propertyTypes[i].getColumnSpan( mapping );
	}
	return span;
}
 
Example 17
Source Project: lams   Source File: ComponentType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Size[] defaultSizes(Mapping mapping) throws MappingException {
	//Not called at runtime so doesn't matter if its slow :)
	final Size[] sizes = new Size[getColumnSpan( mapping )];
	int soFar = 0;
	for ( Type propertyType : propertyTypes ) {
		final Size[] propertySizes = propertyType.defaultSizes( mapping );
		System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length );
		soFar += propertySizes.length;
	}
	return sizes;
}
 
Example 18
Source Project: lams   Source File: CompositeCustomType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Size[] defaultSizes(Mapping mapping) throws MappingException {
	//Not called at runtime so doesn't matter if its slow :)
	final Size[] sizes = new Size[getColumnSpan( mapping )];
	int soFar = 0;
	for ( Type propertyType : userType.getPropertyTypes() ) {
		final Size[] propertySizes = propertyType.defaultSizes( mapping );
		System.arraycopy( propertySizes, 0, sizes, soFar, propertySizes.length );
		soFar += propertySizes.length;
	}
	return sizes;
}
 
Example 19
Source Project: blog-tutorials   Source File: PostgreSQLFTSFunction.java    License: MIT License 4 votes vote down vote up
@Override
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
	return new BooleanType();
}
 
Example 20
Source Project: lams   Source File: ToOne.java    License: GNU General Public License v2.0 4 votes vote down vote up
public boolean isValid(Mapping mapping) throws MappingException {
	if (referencedEntityName==null) {
		throw new MappingException("association must specify the referenced entity");
	}
	return super.isValid( mapping );
}
 
Example 21
Source Project: lams   Source File: Collection.java    License: GNU General Public License v2.0 4 votes vote down vote up
public boolean isValid(Mapping mapping) throws MappingException {
	return true;
}
 
Example 22
Source Project: lams   Source File: AnyType.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getColumnSpan(Mapping session) {
	return 2;
}
 
Example 23
Source Project: lams   Source File: CollectionType.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size[] defaultSizes(Mapping mapping) throws MappingException {
	return new Size[] { LEGACY_DEFAULT_SIZE };
}
 
Example 24
@Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
	return columnMapper.getHibernateType().dictatedSizes(mapping);
}
 
Example 25
@Override
public Type getReturnType(Type columnType, Mapping mapping)
        throws QueryException {
    return FloatType.INSTANCE;
}
 
Example 26
Source Project: lams   Source File: CollectionType.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
	return new Size[] { LEGACY_DICTATED_SIZE };
}
 
Example 27
Source Project: lams   Source File: MetaType.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
	return baseType.dictatedSizes( mapping );
}
 
Example 28
@Override
public int getColumnSpan(Mapping mapping) throws MappingException {
	return 1;
}
 
Example 29
Source Project: hibernate-types   Source File: ImmutableType.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException {
    Method valueOfMethod = ReflectionUtils.getMethodOrNull(clazz, "valueOf", String.class);
    return valueOfMethod != null ? ReflectionUtils.invokeStaticMethod(valueOfMethod, xml.getText()) : null;
}
 
Example 30
Source Project: lams   Source File: MetaType.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size[] defaultSizes(Mapping mapping) throws MappingException {
	return baseType.defaultSizes( mapping );
}