Java Code Examples for org.hibernate.type.Type.getReturnedClass()

The following are Jave code examples for showing how to use getReturnedClass() of the org.hibernate.type.Type class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: SequenceStyleGenerator.java   View Source Code Vote up 6 votes
/**
 * Build the database structure.
 *
 * @param type The Hibernate type of the identifier property
 * @param params The params supplied in the generator config (plus some standard useful extras).
 * @param dialect The dialect being used.
 * @param forceTableUse Should a table be used even if the dialect supports sequences?
 * @param sequenceName The name to use for the sequence or table.
 * @param initialValue The initial value.
 * @param incrementSize the increment size to use (after any adjustments).
 *
 * @return An abstraction for the actual database structure in use (table vs. sequence).
 */
protected DatabaseStructure buildDatabaseStructure(
		Type type,
		Properties params,
		Dialect dialect,
		boolean forceTableUse,
		String sequenceName,
		int initialValue,
		int incrementSize) {
	final boolean useSequence = dialect.supportsSequences() && !forceTableUse;
	if ( useSequence ) {
		return new SequenceStructure( dialect, sequenceName, initialValue, incrementSize, type.getReturnedClass() );
	}
	else {
		final String valueColumnName = determineValueColumnName( params, dialect );
		return new TableStructure( dialect, sequenceName, valueColumnName, initialValue, incrementSize, type.getReturnedClass() );
	}
}
 
Example 2
Project: hibernate-ogm-ignite   File: IgniteCacheInitializer.java   View Source Code Vote up 6 votes
private String fieldType(Column currentColumn) {
	TypeTranslator translator = serviceRegistry.getService( TypeTranslator.class );
	Type valueType = currentColumn.getValue().getType();
	GridType gridType = translator.getType( valueType );
	if ( gridType instanceof EnumType ) {
		return enumFieldType( (EnumType) gridType );
	}
	if ( gridType instanceof YesNoType ) {
		return STRING_CLASS_NAME;
	}
	if ( gridType instanceof NumericBooleanType ) {
		return INTEGER_CLASS_NAME;
	}
	Class<?> returnedClass = valueType.getReturnedClass();
	if ( Character.class.equals( returnedClass ) ) {
		return STRING_CLASS_NAME;
	}
	return returnedClass.getName();
}
 
Example 3
Project: lams   File: TableHiLoGenerator.java   View Source Code Vote up 5 votes
@Override
public void configure(Type type, Properties params, Dialect d) {
	super.configure( type, params, d );
	maxLo = ConfigurationHelper.getInt( MAX_LO, params, Short.MAX_VALUE );

	if ( maxLo >= 1 ) {
		hiloOptimizer = new LegacyHiLoAlgorithmOptimizer( type.getReturnedClass(), maxLo );
	}
}
 
Example 4
Project: lams   File: AbstractScrollableResults.java   View Source Code Vote up 5 votes
/**
 * Check that the requested type is compatible with the result type, and
 * return the column value.  This version makes sure the the classes
 * are identical.
 *
 * @param col the column
 * @param returnType a "final" type
 */
protected final Object getFinal(int col, Type returnType) throws HibernateException {
	if ( holderInstantiator!=null ) {
		throw new HibernateException("query specifies a holder class");
	}

	if ( returnType.getReturnedClass()==types[col].getReturnedClass() ) {
		return get(col);
	}
	else {
		return throwInvalidColumnTypeException(col, types[col], returnType);
	}
}
 
Example 5
Project: lams   File: MultipleHiLoPerTableGenerator.java   View Source Code Vote up 4 votes
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
	ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );

	tableName = normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( ID_TABLE, params, DEFAULT_TABLE ) );
	if ( tableName.indexOf( '.' ) < 0 ) {
		tableName = dialect.quote( tableName );
		final String schemaName = dialect.quote(
				normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) )
		);
		final String catalogName = dialect.quote(
				normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) )
		);
		tableName = Table.qualify( catalogName, schemaName, tableName );
	}
	else {
		// if already qualified there is not much we can do in a portable manner so we pass it
		// through and assume the user has set up the name correctly.
	}

	pkColumnName = dialect.quote(
			normalizer.normalizeIdentifierQuoting(
					ConfigurationHelper.getString( PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN )
			)
	);
	valueColumnName = dialect.quote(
			normalizer.normalizeIdentifierQuoting(
					ConfigurationHelper.getString( VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN )
			)
	);
	keySize = ConfigurationHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH);
	String keyValue = ConfigurationHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE) );

	query = "select " +
		valueColumnName +
		" from " +
		dialect.appendLockHint( LockMode.PESSIMISTIC_WRITE, tableName ) +
		" where " + pkColumnName + " = '" + keyValue + "'" +
		dialect.getForUpdateString();

	update = "update " +
		tableName +
		" set " +
		valueColumnName +
		" = ? where " +
		valueColumnName +
		" = ? and " +
		pkColumnName +
		" = '" +
		keyValue
		+ "'";

	insert = "insert into " + tableName +
		"(" + pkColumnName + ", " +	valueColumnName + ") " +
		"values('"+ keyValue +"', ?)";


	//hilo config
	maxLo = ConfigurationHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
	returnClass = type.getReturnedClass();

	if ( maxLo >= 1 ) {
		hiloOptimizer = new LegacyHiLoAlgorithmOptimizer( returnClass, maxLo );
	}
}
 
Example 6
Project: lams   File: IncrementGenerator.java   View Source Code Vote up 4 votes
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
	returnClass = type.getReturnedClass();

	ObjectNameNormalizer normalizer =
			( ObjectNameNormalizer ) params.get( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER );

	String column = params.getProperty( "column" );
	if ( column == null ) {
		column = params.getProperty( PersistentIdentifierGenerator.PK );
	}
	column = dialect.quote( normalizer.normalizeIdentifierQuoting( column ) );

	String tableList = params.getProperty( "tables" );
	if ( tableList == null ) {
		tableList = params.getProperty( PersistentIdentifierGenerator.TABLES );
	}
	String[] tables = StringHelper.split( ", ", tableList );

	final String schema = dialect.quote(
			normalizer.normalizeIdentifierQuoting(
					params.getProperty( PersistentIdentifierGenerator.SCHEMA )
			)
	);
	final String catalog = dialect.quote(
			normalizer.normalizeIdentifierQuoting(
					params.getProperty( PersistentIdentifierGenerator.CATALOG )
			)
	);

	StringBuilder buf = new StringBuilder();
	for ( int i=0; i < tables.length; i++ ) {
		final String tableName = dialect.quote( normalizer.normalizeIdentifierQuoting( tables[i] ) );
		if ( tables.length > 1 ) {
			buf.append( "select max(" ).append( column ).append( ") as mx from " );
		}
		buf.append( Table.qualify( catalog, schema, tableName ) );
		if ( i < tables.length-1 ) {
			buf.append( " union " );
		}
	}
	if ( tables.length > 1 ) {
		buf.insert( 0, "( " ).append( " ) ids_" );
		column = "ids_.mx";
	}

	sql = "select max(" + column + ") from " + buf.toString();
}
 
Example 7
Project: lams   File: IdentifierGeneratorHelper.java   View Source Code Vote up 4 votes
/**
 * Extract the value from the result set (which is assumed to already have been positioned to the apopriate row)
 * and wrp it in the appropriate Java numeric type.
 *
 * @param rs The result set from which to extract the value.
 * @param identifier The name of the identifier column
 * @param type The expected type of the value.
 *
 * @return The extracted value.
 *
 * @throws SQLException Indicates problems access the result set
 * @throws IdentifierGenerationException Indicates an unknown type.
 */
public static Serializable get(ResultSet rs, String identifier, Type type) throws SQLException, IdentifierGenerationException {
	if ( ResultSetIdentifierConsumer.class.isInstance( type ) ) {
		return ( ( ResultSetIdentifierConsumer ) type ).consumeIdentifier( rs );
	}
	if ( CustomType.class.isInstance( type ) ) {
		final CustomType customType = (CustomType) type;
		if ( ResultSetIdentifierConsumer.class.isInstance( customType.getUserType() ) ) {
			return ( (ResultSetIdentifierConsumer) customType.getUserType() ).consumeIdentifier( rs );
		}
	}

	Class clazz = type.getReturnedClass();
	if (rs.getMetaData().getColumnCount() == 1) {
		if ( clazz == Long.class ) {
			return rs.getLong( 1 );
		}
		else if ( clazz == Integer.class ) {
			return rs.getInt( 1 );
		}
		else if ( clazz == Short.class ) {
			return rs.getShort( 1 );
		}
		else if ( clazz == String.class ) {
			return rs.getString( 1 );
		}
		else if ( clazz == BigInteger.class ) {
			return rs.getBigDecimal( 1 ).setScale( 0, BigDecimal.ROUND_UNNECESSARY ).toBigInteger();
		}
		else if ( clazz == BigDecimal.class ) {
			return rs.getBigDecimal( 1 ).setScale( 0, BigDecimal.ROUND_UNNECESSARY );
		}
		else {
			throw new IdentifierGenerationException(
					"unrecognized id type : " + type.getName() + " -> " + clazz.getName()
			);
		}
	}
	else {
		if ( clazz == Long.class ) {
			return rs.getLong(identifier);
		}
		else if ( clazz == Integer.class ) {
			return rs.getInt(identifier);
		}
		else if ( clazz == Short.class ) {
			return rs.getShort(identifier);
		}
		else if ( clazz == String.class ) {
			return rs.getString(identifier);
		}
		else if ( clazz == BigInteger.class ) {
			return rs.getBigDecimal(identifier).setScale( 0, BigDecimal.ROUND_UNNECESSARY ).toBigInteger();
		}
		else if ( clazz == BigDecimal.class ) {
			return rs.getBigDecimal(identifier).setScale( 0, BigDecimal.ROUND_UNNECESSARY );
		}
		else {
			throw new IdentifierGenerationException(
					"unrecognized id type : " + type.getName() + " -> " + clazz.getName()
			);
		}
	}
}