Java Code Examples for org.hibernate.dialect.Dialect.supportsSequences()

The following are Jave code examples for showing how to use supportsSequences() of the org.hibernate.dialect.Dialect 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: DatabaseMetadata.java   View Source Code Vote up 6 votes
private void initSequences(Connection connection, Dialect dialect) throws SQLException {
	if ( dialect.supportsSequences() ) {
		String sql = dialect.getQuerySequencesString();
		if (sql!=null) {

			Statement statement = null;
			ResultSet rs = null;
			try {
				statement = connection.createStatement();
				rs = statement.executeQuery(sql);

				while ( rs.next() ) {
					sequences.add( StringHelper.toLowerCase(rs.getString(1)).trim() );
				}
			}
			finally {
				if ( rs != null ) {
					rs.close();
				}
				if ( statement != null ) {
					statement.close();
				}
			}
		}
	}
}
 
Example 2
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 3
Project: lams   File: SequenceStyleGenerator.java   View Source Code Vote up 5 votes
@Override
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
	this.identifierType = type;
	boolean forceTableUse = ConfigurationHelper.getBoolean( FORCE_TBL_PARAM, params, false );

	final String sequenceName = determineSequenceName( params, dialect );

	final int initialValue = determineInitialValue( params );
	int incrementSize = determineIncrementSize( params );

	final String optimizationStrategy = determineOptimizationStrategy( params, incrementSize );
	incrementSize = determineAdjustedIncrementSize( optimizationStrategy, incrementSize );

	if ( dialect.supportsSequences() && !forceTableUse ) {
		if ( !dialect.supportsPooledSequences() && OptimizerFactory.isPooledOptimizer( optimizationStrategy ) ) {
			forceTableUse = true;
			LOG.forcingTableUse();
		}
	}

	this.databaseStructure = buildDatabaseStructure(
			type,
			params,
			dialect,
			forceTableUse,
			sequenceName,
			initialValue,
			incrementSize
	);
	this.optimizer = OptimizerFactory.buildOptimizer(
			optimizationStrategy,
			identifierType.getReturnedClass(),
			incrementSize,
			ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 )
	);
	this.databaseStructure.prepare( optimizer );
}