org.hibernate.engine.Mapping Java Examples

The following examples show how to use org.hibernate.engine.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: PersistentClass.java    From cacheonix-core with GNU Lesser General Public License v2.1 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 #2
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #3
Source File: Table.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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();
}
 
Example #4
Source File: Table.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 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 )
					.startsWith( columnInfo.getTypeName().toLowerCase() )
					|| columnInfo.getTypeCode() == col.getSqlTypeCode( mapping );
			if ( !typesMatch ) {
				throw new HibernateException(
						"Wrong column type: " + col.getName() +
								", expected: " + col.getSqlType( dialect, mapping )
				);
			}
		}
	}

}
 
Example #5
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: PersisterFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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);
	}
}
 
Example #7
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #8
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.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()
					.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 )
				);
			}
		}
	}

}
 
Example #9
Source File: CompositeCustomType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example #10
Source File: AbstractPropertyMapping.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
	}
}
 
Example #11
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.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()
					.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 )
				);
			}
		}
	}

}
 
Example #12
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.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()
					.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 )
				);
			}
		}
	}

}
 
Example #13
Source File: CompositeElementPropertyMapping.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public CompositeElementPropertyMapping(
		String[] elementColumns, 
		String[] elementFormulaTemplates, 
		AbstractComponentType compositeType, 
		Mapping factory)
throws MappingException {

	this.compositeType = compositeType;

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

}
 
Example #14
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.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()
					.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 )
				);
			}
		}
	}

}
 
Example #15
Source File: EntityType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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;
	}
}
 
Example #16
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
	}
}
 
Example #17
Source File: EntityType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException {
	if ( !isEmbeddedInXML ) {
		return getIdentifierType(factory).fromXMLNode(xml, factory);
	}
	else {
		return xml;
	}
}
 
Example #18
Source File: Constraint.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
	}
}
 
Example #19
Source File: ComponentType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
	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 #20
Source File: Dialect.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example #21
Source File: RootClass.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
}
 
Example #22
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void initDiscriminatorPropertyPath(Mapping mapping) throws MappingException {
	propertyMapping.initPropertyPaths( ENTITY_CLASS,
			getDiscriminatorType(),
			new String[]{getDiscriminatorColumnName()},
			new String[]{getDiscriminatorFormulaTemplate()},
			getFactory() );
}
 
Example #23
Source File: Dialect.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
	}
}
 
Example #24
Source File: Index.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String sqlCreateString(Dialect dialect, Mapping mapping, String defaultCatalog, String defaultSchema)
		throws HibernateException {
	return buildSqlCreateIndexString(
			dialect,
			getName(),
			getTable(),
			getColumnIterator(),
			false,
			defaultCatalog,
			defaultSchema
	);
}
 
Example #25
Source File: UnionSubclass.java    From cacheonix-core with GNU Lesser General Public License v2.1 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 #26
Source File: SimpleAuxiliaryDatabaseObject.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String sqlCreateString(
        Dialect dialect,
        Mapping p,
        String defaultCatalog,
        String defaultSchema) throws HibernateException {
	return injectCatalogAndSchema( sqlCreateString, defaultCatalog, defaultSchema );
}
 
Example #27
Source File: EntityType.java    From cacheonix-core with GNU Lesser General Public License v2.1 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() ) {
		return getIdentifierType(factory);
	}
	else {
		Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
		if ( type.isEntityType() ) {
			type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory );
		}
		return type;
	}
}
 
Example #28
Source File: PersistentClass.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
	}
}
 
Example #29
Source File: SingleTableEntityPersister.java    From webdsl with Apache License 2.0 5 votes vote down vote up
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();
	}
}
 
Example #30
Source File: UniqueKey.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
	}
}