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

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

源代码1 项目: Knowage-Server   文件: Table.java
public String sqlTemporaryTableCreateString(Dialect dialect, Mapping mapping) throws HibernateException {
	StringBuffer buffer = new StringBuffer( dialect.getCreateTemporaryTableString() )
			.append( ' ' )
			.append( name )
			.append( " (" );
	Iterator itr = getColumnIterator();
	while ( itr.hasNext() ) {
		final Column column = (Column) itr.next();
		buffer.append( column.getQuotedName( dialect ) ).append( ' ' );
		buffer.append( column.getSqlType( dialect, mapping ) );
		if ( column.isNullable() ) {
			buffer.append( dialect.getNullColumnString() );
		}
		else {
			buffer.append( " not null" );
		}
		if ( itr.hasNext() ) {
			buffer.append( ", " );
		}
	}
	buffer.append( ") " );
	buffer.append( dialect.getCreateTemporaryTablePostfix() );
	return buffer.toString();
}
 
源代码2 项目: Knowage-Server   文件: Table.java
public String sqlTemporaryTableCreateString(Dialect dialect, Mapping mapping) throws HibernateException {
	StringBuffer buffer = new StringBuffer( dialect.getCreateTemporaryTableString() )
			.append( ' ' )
			.append( name )
			.append( " (" );
	Iterator itr = getColumnIterator();
	while ( itr.hasNext() ) {
		final Column column = (Column) itr.next();
		buffer.append( column.getQuotedName( dialect ) ).append( ' ' );
		buffer.append( column.getSqlType( dialect, mapping ) );
		if ( column.isNullable() ) {
			buffer.append( dialect.getNullColumnString() );
		}
		else {
			buffer.append( " not null" );
		}
		if ( itr.hasNext() ) {
			buffer.append( ", " );
		}
	}
	buffer.append( ") " );
	buffer.append( dialect.getCreateTemporaryTablePostfix() );
	return buffer.toString();
}
 
源代码3 项目: Knowage-Server   文件: Table.java
public String sqlTemporaryTableCreateString(Dialect dialect, Mapping mapping) throws HibernateException {
	StringBuffer buffer = new StringBuffer( dialect.getCreateTemporaryTableString() )
			.append( ' ' )
			.append( name )
			.append( " (" );
	Iterator itr = getColumnIterator();
	while ( itr.hasNext() ) {
		final Column column = (Column) itr.next();
		buffer.append( column.getQuotedName( dialect ) ).append( ' ' );
		buffer.append( column.getSqlType( dialect, mapping ) );
		if ( column.isNullable() ) {
			buffer.append( dialect.getNullColumnString() );
		}
		else {
			buffer.append( " not null" );
		}
		if ( itr.hasNext() ) {
			buffer.append( ", " );
		}
	}
	buffer.append( ") " );
	buffer.append( dialect.getCreateTemporaryTablePostfix() );
	return buffer.toString();
}
 
源代码4 项目: cacheonix-core   文件: 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 )
					.startsWith( columnInfo.getTypeName().toLowerCase() )
					|| columnInfo.getTypeCode() == col.getSqlTypeCode( mapping );
			if ( !typesMatch ) {
				throw new HibernateException(
						"Wrong column type: " + col.getName() +
								", expected: " + col.getSqlType( dialect, mapping )
				);
			}
		}
	}

}
 
源代码5 项目: cacheonix-core   文件: Table.java
public String sqlTemporaryTableCreateString(Dialect dialect, Mapping mapping) throws HibernateException {
	StringBuffer buffer = new StringBuffer( dialect.getCreateTemporaryTableString() )
			.append( ' ' )
			.append( name )
			.append( " (" );
	Iterator itr = getColumnIterator();
	while ( itr.hasNext() ) {
		final Column column = (Column) itr.next();
		buffer.append( column.getQuotedName( dialect ) ).append( ' ' );
		buffer.append( column.getSqlType( dialect, mapping ) );
		if ( column.isNullable() ) {
			buffer.append( dialect.getNullColumnString() );
		}
		else {
			buffer.append( " not null" );
		}
		if ( itr.hasNext() ) {
			buffer.append( ", " );
		}
	}
	buffer.append( ") " );
	buffer.append( dialect.getCreateTemporaryTablePostfix() );
	return buffer.toString();
}
 
源代码6 项目: cacheonix-core   文件: 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();
}
 
源代码7 项目: cacheonix-core   文件: PersisterFactory.java
public static EntityPersister createClassPersister(
		PersistentClass model, 
		CacheConcurrencyStrategy cache, 
		SessionFactoryImplementor factory,
		Mapping cfg)
throws HibernateException {
	Class persisterClass = model.getEntityPersisterClass();
	if (persisterClass==null || persisterClass==SingleTableEntityPersister.class) {
		return new SingleTableEntityPersister(model, cache, factory, cfg);
	}
	else if (persisterClass==JoinedSubclassEntityPersister.class) {
		return new JoinedSubclassEntityPersister(model, cache, factory, cfg);
	}
	else if (persisterClass==UnionSubclassEntityPersister.class) {
		return new UnionSubclassEntityPersister(model, cache, factory, cfg);
	}
	else {
		return create(persisterClass, model, cache, factory, cfg);
	}
}
 
源代码8 项目: Knowage-Server   文件: 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()
					.startsWith( columnInfo.getTypeName().toLowerCase() )
					|| 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() +
						", expected: " + col.getSqlType( dialect, mapping )
				);
			}
		}
	}

}
 
源代码9 项目: Knowage-Server   文件: 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()
					.startsWith( columnInfo.getTypeName().toLowerCase() )
					|| 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() +
						", expected: " + col.getSqlType( dialect, mapping )
				);
			}
		}
	}

}
 
源代码10 项目: Knowage-Server   文件: 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()
					.startsWith( columnInfo.getTypeName().toLowerCase() )
					|| 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() +
						", expected: " + col.getSqlType( dialect, mapping )
				);
			}
		}
	}

}
 
源代码11 项目: cacheonix-core   文件: EntityType.java
/**
 * The name of the property on the associated entity to which our FK
 * refers
 *
 * @param factory The mappings...
 * @return The appropriate property name.
 * @throws MappingException Generally, if unable to resolve the associated entity name
 */
public final String getIdentifierOrUniqueKeyPropertyName(Mapping factory)
throws MappingException {
	if ( isReferenceToPrimaryKey() ) {
		return factory.getIdentifierPropertyName( getAssociatedEntityName() );
	}
	else {
		return uniqueKeyPropertyName;
	}
}
 
源代码12 项目: Knowage-Server   文件: 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()
					.startsWith( columnInfo.getTypeName().toLowerCase() )
					|| 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() +
						", expected: " + col.getSqlType( dialect, mapping )
				);
			}
		}
	}

}
 
源代码13 项目: cacheonix-core   文件: Constraint.java
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
	if ( isGenerated( dialect ) ) {
		String constraintString = sqlConstraintString( dialect, getName(), defaultCatalog, defaultSchema );
		StringBuffer buf = new StringBuffer( "alter table " )
				.append( getTable().getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
				.append( constraintString );
		return buf.toString();
	}
	else {
		return null;
	}
}
 
源代码14 项目: cacheonix-core   文件: Collection.java
public void validate(Mapping mapping) throws MappingException {
	if ( getKey().isCascadeDeleteEnabled() && ( !isInverse() || !isOneToMany() ) ) {
		throw new MappingException(
			"only inverse one-to-many associations may use on-delete=\"cascade\": " 
			+ getRole() );
	}
	if ( !getKey().isValid( mapping ) ) {
		throw new MappingException(
			"collection foreign key mapping has wrong number of columns: "
			+ getRole()
			+ " type: "
			+ getKey().getType().getName() );
	}
	if ( !getElement().isValid( mapping ) ) {
		throw new MappingException( 
			"collection element mapping has wrong number of columns: "
			+ getRole()
			+ " type: "
			+ getElement().getType().getName() );
	}

	checkColumnDuplication();
	
	if ( elementNodeName!=null && elementNodeName.startsWith("@") ) {
		throw new MappingException("element node must not be an attribute: " + elementNodeName );
	}
	if ( elementNodeName!=null && elementNodeName.equals(".") ) {
		throw new MappingException("element node must not be the parent: " + elementNodeName );
	}
	if ( nodeName!=null && nodeName.indexOf('@')>-1 ) {
		throw new MappingException("collection node must not be an attribute: " + elementNodeName );
	}
}
 
源代码15 项目: cacheonix-core   文件: CompositeCustomType.java
public int getColumnSpan(Mapping mapping) throws MappingException {
	Type[] types = userType.getPropertyTypes();
	int n=0;
	for (int i=0; i<types.length; i++) {
		n+=types[i].getColumnSpan(mapping);
	}
	return n;
}
 
源代码16 项目: cacheonix-core   文件: RootClass.java
public void validate(Mapping mapping) throws MappingException {
	super.validate(mapping);
	if ( !getIdentifier().isValid(mapping) ) {
		throw new MappingException(
			"identifier mapping has wrong number of columns: " +
			getEntityName() +
			" type: " +
			getIdentifier().getType().getName()
		);
	}
	checkCompositeIdentifier();
}
 
源代码17 项目: cacheonix-core   文件: Index.java
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema)
		throws HibernateException {
	return buildSqlCreateIndexString(
			dialect,
			getName(),
			getTable(),
			getColumnIterator(),
			false,
			defaultCatalog,
			defaultSchema
	);
}
 
源代码18 项目: cacheonix-core   文件: 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()
		);
	}
}
 
public String sqlCreateString(
        Dialect dialect,
        Mapping p,
        String defaultCatalog,
        String defaultSchema) throws HibernateException {
	return injectCatalogAndSchema( sqlCreateString, defaultCatalog, defaultSchema );
}
 
源代码20 项目: cacheonix-core   文件: 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() ) {
		return getIdentifierType(factory);
	}
	else {
		Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
		if ( type.isEntityType() ) {
			type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory );
		}
		return type;
	}
}
 
源代码21 项目: cacheonix-core   文件: PersistentClass.java
public void prepareTemporaryTables(Mapping mapping, Dialect dialect) {
	if ( dialect.supportsTemporaryTables() ) {
		temporaryIdTableName = dialect.generateTemporaryTableName( getTable().getName() );
		Table table = new Table();
		table.setName( temporaryIdTableName );
		Iterator itr = getTable().getPrimaryKey().getColumnIterator();
		while( itr.hasNext() ) {
			Column column = (Column) itr.next();
			table.addColumn( (Column) column.clone()  );
		}
		temporaryIdTableDDL = table.sqlTemporaryTableCreateString( dialect, mapping );
	}
}
 
源代码22 项目: webdsl   文件: SingleTableEntityPersister.java
public SingleTableEntityPersister(PersistentClass persistentClass,
		EntityRegionAccessStrategy cacheAccessStrategy,
		SessionFactoryImplementor factory,
		Mapping mapping) throws HibernateException {
	super(persistentClass, cacheAccessStrategy, factory, mapping);
	this.hasSubselectLoadableCollections = persistentClass.hasSubselectLoadableCollections();
	java.util.Iterator i = persistentClass.getSubclassIterator();
	while(!this.hasSubselectLoadableCollections && i.hasNext()) {
		this.hasSubselectLoadableCollections = ((org.hibernate.mapping.PersistentClass) i.next()).hasSubselectLoadableCollections();
	}
}
 
源代码23 项目: cacheonix-core   文件: UniqueKey.java
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
	if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
		return super.sqlCreateString( dialect, p, defaultCatalog, defaultSchema );
	}
	else {
		return Index.buildSqlCreateIndexString( dialect, getName(), getTable(), getColumnIterator(), true,
				defaultCatalog, defaultSchema );
	}
}
 
源代码24 项目: cacheonix-core   文件: AbstractEntityPersister.java
private void initIdentifierPropertyPaths(Mapping mapping) throws MappingException {
	String idProp = getIdentifierPropertyName();
	if ( idProp != null ) {
		propertyMapping.initPropertyPaths( idProp, getIdentifierType(), getIdentifierColumnNames(), null, mapping );
	}
	if ( entityMetamodel.getIdentifierProperty().isEmbedded() ) {
		propertyMapping.initPropertyPaths( null, getIdentifierType(), getIdentifierColumnNames(), null, mapping );
	}
	if ( ! entityMetamodel.hasNonIdentifierPropertyNamedId() ) {
		propertyMapping.initPropertyPaths( ENTITY_ID, getIdentifierType(), getIdentifierColumnNames(), null, mapping );
	}
}
 
源代码25 项目: cacheonix-core   文件: AbstractEntityPersister.java
private void initDiscriminatorPropertyPath(Mapping mapping) throws MappingException {
	propertyMapping.initPropertyPaths( ENTITY_CLASS,
			getDiscriminatorType(),
			new String[]{getDiscriminatorColumnName()},
			new String[]{getDiscriminatorFormulaTemplate()},
			getFactory() );
}
 
源代码26 项目: cacheonix-core   文件: AbstractPropertyMapping.java
private boolean hasNonIdentifierPropertyNamedId(final EntityType entityType, final Mapping factory) {
	// TODO : would be great to have a Mapping#hasNonIdentifierPropertyNamedId method
	// I don't believe that Mapping#getReferencedPropertyType accounts for the identifier property; so
	// if it returns for a property named 'id', then we should have a non-id field named id
	try {
		return factory.getReferencedPropertyType( entityType.getAssociatedEntityName(), EntityPersister.ENTITY_ID ) != null;
	}
	catch( MappingException e ) {
		return false;
	}
}
 
public CompositeElementPropertyMapping(
		String[] elementColumns, 
		String[] elementFormulaTemplates, 
		AbstractComponentType compositeType, 
		Mapping factory)
throws MappingException {

	this.compositeType = compositeType;

	initComponentPropertyPaths(null, compositeType, elementColumns, elementFormulaTemplates, factory);

}
 
源代码28 项目: cacheonix-core   文件: EntityType.java
/**
 * {@inheritDoc}
 */
public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException {
	if ( !isEmbeddedInXML ) {
		return getIdentifierType(factory).fromXMLNode(xml, factory);
	}
	else {
		return xml;
	}
}
 
源代码29 项目: cacheonix-core   文件: Dialect.java
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
	int[] sqlTypes;
	try {
		sqlTypes = columnType.sqlTypes( mapping );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
	if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in avg()" );
	return Hibernate.DOUBLE;
}
 
源代码30 项目: cacheonix-core   文件: Dialect.java
public Type getReturnType(Type columnType, Mapping mapping) {
	//pre H3.2 behavior: super.getReturnType(ct, m);
	int[] sqlTypes;
	try {
		sqlTypes = columnType.sqlTypes( mapping );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
	if ( sqlTypes.length != 1 ) throw new QueryException( "multi-column type in sum()" );
	int sqlType = sqlTypes[0];

	// First allow the actual type to control the return value. (the actual underlying sqltype could actually be different)
	if ( columnType == Hibernate.BIG_INTEGER ) {
		return Hibernate.BIG_INTEGER;
	}
	else if ( columnType == Hibernate.BIG_DECIMAL ) {
		return Hibernate.BIG_DECIMAL;
	}
	else if ( columnType == Hibernate.LONG || columnType == Hibernate.SHORT || columnType == Hibernate.INTEGER) {
		return Hibernate.LONG;
	}
	else if ( columnType == Hibernate.FLOAT || columnType == Hibernate.DOUBLE) {
		return Hibernate.DOUBLE;
	}

	// finally use the sqltype if == on Hibernate types did not find a match.
	if ( sqlType == Types.NUMERIC ) {
		return columnType; //because numeric can be anything
	}
	else if ( sqlType == Types.FLOAT || sqlType == Types.DOUBLE || sqlType == Types.DECIMAL || sqlType == Types.REAL) {
		return Hibernate.DOUBLE;
	}
	else if ( sqlType == Types.BIGINT || sqlType == Types.INTEGER || sqlType == Types.SMALLINT || sqlType == Types.TINYINT ) {
		return Hibernate.LONG;
	}
	else {
		return columnType;
	}
}
 
 类所在包
 类方法
 同包方法