org.hibernate.engine.spi.Mapping Java Examples

The following examples show how to use org.hibernate.engine.spi.Mapping. 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: CompositeCustomType.java    From lams with 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 File: Column.java    From lams with 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 #3
Source File: PersistentClass.java    From lams with 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 #4
Source File: EntityType.java    From lams with 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 #5
Source File: CompositeCustomType.java    From lams with 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 #6
Source File: IdentifierCollection.java    From lams with 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 File: Index.java    From lams with 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 File: CompositeCustomType.java    From lams with 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 #9
Source File: Constraint.java    From lams with 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 #10
Source File: UniqueKey.java    From lams with 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 File: UnionSubclass.java    From lams with 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 #12
Source File: Table.java    From lams with 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 #13
Source File: ComponentType.java    From lams with 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 #14
Source File: ComponentType.java    From lams with 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 #15
Source File: AbstractEntityPersister.java    From lams with 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 #16
Source File: EntityType.java    From lams with 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 #17
Source File: StandardAnsiSqlAggregationFunctions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #18
Source File: JoinHelper.java    From lams with 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 #19
Source File: PositionSubstringFunction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
	return StandardBasicTypes.INTEGER;
}
 
Example #20
Source File: SQLFunctionTemplate.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
	return type;
}
 
Example #21
Source File: CollectionType.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getColumnSpan(Mapping session) throws MappingException {
	return 0;
}
 
Example #22
Source File: PostgreSQLFTSFunction.java    From blog-tutorials with MIT License 4 votes vote down vote up
@Override
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
	return new BooleanType();
}
 
Example #23
Source File: NoArgSQLFunction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
	return returnType;
}
 
Example #24
Source File: AbstractStandardBasicType.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
	return new Size[] { getDictatedSize() };
}
 
Example #25
Source File: CharIndexFunction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
	return StandardBasicTypes.INTEGER;
}
 
Example #26
Source File: StandardSQLFunction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getReturnType(Type firstArgumentType, Mapping mapping) {
	return registeredType == null ? firstArgumentType : registeredType;
}
 
Example #27
Source File: AnyType.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Size[] defaultSizes(Mapping mapping) throws MappingException {
	return ArrayHelper.join( discriminatorType.defaultSizes( mapping ), identifierType.defaultSizes( mapping ) );
}
 
Example #28
Source File: ImmutableType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public int getColumnSpan(Mapping mapping) throws MappingException {
    return 1;
}
 
Example #29
Source File: NvlFunction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException {
	return argumentType;
}
 
Example #30
Source File: ImmutableType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
    return sqlTypes();
}