类org.hibernate.engine.spi.Mapping源码实例Demo

下面列出了怎么用org.hibernate.engine.spi.Mapping的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: CompositeCustomType.java
@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;
}
 
源代码2 项目: lams   文件: PersistentClass.java
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();
}
 
源代码3 项目: lams   文件: Column.java
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
		);
	}
}
 
源代码4 项目: lams   文件: Constraint.java
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;
}
 
源代码5 项目: lams   文件: CompositeCustomType.java
@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;
}
 
源代码6 项目: lams   文件: IdentifierCollection.java
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()
		);
	}
}
 
源代码7 项目: lams   文件: Index.java
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema)
		throws HibernateException {
	return buildSqlCreateIndexString(
			dialect,
			getQuotedName( dialect ),
			getTable(),
			getColumnIterator(),
			columnOrderMap,
			false,
			defaultCatalog,
			defaultSchema
	);
}
 
源代码8 项目: lams   文件: UnionSubclass.java
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()
		);
	}
}
 
源代码9 项目: lams   文件: Table.java
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 )
				);
			}
		}
	}

}
 
源代码10 项目: lams   文件: UniqueKey.java
@Override
	public String sqlCreateString(
			Dialect dialect,
			Mapping p,
			String defaultCatalog,
			String defaultSchema) {
		return null;
//		return dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
//				this, defaultCatalog, defaultSchema
//		);
	}
 
源代码11 项目: lams   文件: AbstractEntityPersister.java
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
		);
	}
}
 
源代码12 项目: lams   文件: EntityType.java
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;
}
 
源代码13 项目: lams   文件: JoinHelper.java
/**
 * 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 );
		}
	}
}
 
源代码14 项目: lams   文件: EntityType.java
/**
 * 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;
	}
}
 
源代码15 项目: lams   文件: StandardAnsiSqlAggregationFunctions.java
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 );
	}
}
 
源代码16 项目: lams   文件: ComponentType.java
@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;
}
 
源代码17 项目: lams   文件: ComponentType.java
@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;
}
 
源代码18 项目: lams   文件: CompositeCustomType.java
@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;
}
 
源代码19 项目: blog-tutorials   文件: PostgreSQLFTSFunction.java
@Override
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
	return new BooleanType();
}
 
源代码20 项目: lams   文件: ToOne.java
public boolean isValid(Mapping mapping) throws MappingException {
	if (referencedEntityName==null) {
		throw new MappingException("association must specify the referenced entity");
	}
	return super.isValid( mapping );
}
 
源代码21 项目: lams   文件: Collection.java
public boolean isValid(Mapping mapping) throws MappingException {
	return true;
}
 
源代码22 项目: lams   文件: AnyType.java
@Override
public int getColumnSpan(Mapping session) {
	return 2;
}
 
源代码23 项目: lams   文件: CollectionType.java
@Override
public Size[] defaultSizes(Mapping mapping) throws MappingException {
	return new Size[] { LEGACY_DEFAULT_SIZE };
}
 
@Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
	return columnMapper.getHibernateType().dictatedSizes(mapping);
}
 
源代码25 项目: JuniperBot   文件: PostgreSQLToRankCDFunction.java
@Override
public Type getReturnType(Type columnType, Mapping mapping)
        throws QueryException {
    return FloatType.INSTANCE;
}
 
源代码26 项目: lams   文件: CollectionType.java
@Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
	return new Size[] { LEGACY_DICTATED_SIZE };
}
 
源代码27 项目: lams   文件: MetaType.java
@Override
public Size[] dictatedSizes(Mapping mapping) throws MappingException {
	return baseType.dictatedSizes( mapping );
}
 
@Override
public int getColumnSpan(Mapping mapping) throws MappingException {
	return 1;
}
 
源代码29 项目: hibernate-types   文件: ImmutableType.java
@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;
}
 
源代码30 项目: lams   文件: MetaType.java
@Override
public Size[] defaultSizes(Mapping mapping) throws MappingException {
	return baseType.defaultSizes( mapping );
}
 
 类所在包
 同包方法