Search in sources :

Example 1 with IdentifierHelper

use of org.hibernate.engine.jdbc.env.spi.IdentifierHelper in project hibernate-orm by hibernate.

the class SequenceInformationExtractorH2DatabaseImpl method extractMetadata.

@Override
public Iterable<SequenceInformation> extractMetadata(ExtractionContext extractionContext) throws SQLException {
    final IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment().getIdentifierHelper();
    final Statement statement = extractionContext.getJdbcConnection().createStatement();
    try {
        ResultSet resultSet = statement.executeQuery("select SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME, INCREMENT " + "from information_schema.sequences");
        try {
            final List<SequenceInformation> sequenceInformationList = new ArrayList<SequenceInformation>();
            while (resultSet.next()) {
                sequenceInformationList.add(new SequenceInformationImpl(new QualifiedSequenceName(identifierHelper.toIdentifier(resultSet.getString("SEQUENCE_CATALOG")), identifierHelper.toIdentifier(resultSet.getString("SEQUENCE_SCHEMA")), identifierHelper.toIdentifier(resultSet.getString("SEQUENCE_NAME"))), resultSet.getInt("INCREMENT")));
            }
            return sequenceInformationList;
        } finally {
            try {
                resultSet.close();
            } catch (SQLException ignore) {
            }
        }
    } finally {
        try {
            statement.close();
        } catch (SQLException ignore) {
        }
    }
}
Also used : QualifiedSequenceName(org.hibernate.boot.model.relational.QualifiedSequenceName) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) SequenceInformation(org.hibernate.tool.schema.extract.spi.SequenceInformation) IdentifierHelper(org.hibernate.engine.jdbc.env.spi.IdentifierHelper)

Example 2 with IdentifierHelper

use of org.hibernate.engine.jdbc.env.spi.IdentifierHelper in project hibernate-orm by hibernate.

the class SequenceInformationExtractorLegacyImpl method extractMetadata.

@Override
public Iterable<SequenceInformation> extractMetadata(ExtractionContext extractionContext) throws SQLException {
    final String lookupSql = extractionContext.getJdbcEnvironment().getDialect().getQuerySequencesString();
    // *should* never happen, but to be safe in the interest of performance...
    if (lookupSql == null) {
        return SequenceInformationExtractorNoOpImpl.INSTANCE.extractMetadata(extractionContext);
    }
    final IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment().getIdentifierHelper();
    final Statement statement = extractionContext.getJdbcConnection().createStatement();
    try {
        final ResultSet resultSet = statement.executeQuery(lookupSql);
        try {
            final List<SequenceInformation> sequenceInformationList = new ArrayList<SequenceInformation>();
            while (resultSet.next()) {
                sequenceInformationList.add(new SequenceInformationImpl(new QualifiedSequenceName(null, null, identifierHelper.toIdentifier(resultSet.getString(1))), -1));
            }
            return sequenceInformationList;
        } finally {
            try {
                resultSet.close();
            } catch (SQLException ignore) {
            }
        }
    } finally {
        try {
            statement.close();
        } catch (SQLException ignore) {
        }
    }
}
Also used : QualifiedSequenceName(org.hibernate.boot.model.relational.QualifiedSequenceName) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) SequenceInformation(org.hibernate.tool.schema.extract.spi.SequenceInformation) IdentifierHelper(org.hibernate.engine.jdbc.env.spi.IdentifierHelper)

Aggregations

ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 QualifiedSequenceName (org.hibernate.boot.model.relational.QualifiedSequenceName)2 IdentifierHelper (org.hibernate.engine.jdbc.env.spi.IdentifierHelper)2 SequenceInformation (org.hibernate.tool.schema.extract.spi.SequenceInformation)2