Search in sources :

Example 6 with PersistenceException

use of io.requery.PersistenceException in project requery by requery.

the class SchemaModifier method createQueryBuilder.

private QueryBuilder createQueryBuilder() {
    if (queryOptions == null) {
        try (Connection connection = getConnection()) {
            String quoteIdentifier = connection.getMetaData().getIdentifierQuoteString();
            queryOptions = new QueryBuilder.Options(quoteIdentifier, true, configuration.getTableTransformer(), configuration.getColumnTransformer(), configuration.getQuoteTableNames(), configuration.getQuoteColumnNames());
        } catch (SQLException e) {
            throw new PersistenceException(e);
        }
    }
    return new QueryBuilder(queryOptions);
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(io.requery.PersistenceException)

Example 7 with PersistenceException

use of io.requery.PersistenceException in project requery by requery.

the class EntityDataStore method checkConnectionMetadata.

protected void checkConnectionMetadata() {
    synchronized (configuration) {
        // only done once metadata assumed to be the same for every connection
        if (!metadataChecked) {
            try (Connection connection = context.getConnection()) {
                DatabaseMetaData metadata = connection.getMetaData();
                if (!metadata.supportsTransactions()) {
                    transactionMode = TransactionMode.NONE;
                }
                supportsBatchUpdates = metadata.supportsBatchUpdates();
                String quoteIdentifier = metadata.getIdentifierQuoteString();
                queryOptions = new QueryBuilder.Options(quoteIdentifier, true, configuration.getTableTransformer(), configuration.getColumnTransformer(), configuration.getQuoteTableNames(), configuration.getQuoteColumnNames());
                metadataChecked = true;
            } catch (SQLException e) {
                throw new PersistenceException(e);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PersistenceException(io.requery.PersistenceException) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 8 with PersistenceException

use of io.requery.PersistenceException in project requery by requery.

the class PlatformFromConnection method apply.

@Override
public Platform apply(Connection connection) {
    Platform platform;
    String product;
    try {
        product = connection.getMetaData().getDatabaseProductName();
    } catch (SQLException e) {
        throw new PersistenceException(e);
    }
    if (product.contains("PostgreSQL")) {
        platform = new PostgresSQL();
    } else if (product.contains("SQLite")) {
        platform = new SQLite();
    } else if (product.contains("MySQL")) {
        platform = new MySQL();
    } else if (product.contains("H2")) {
        platform = new H2();
    } else if (product.contains("HSQL Database Engine")) {
        platform = new HSQL();
    } else if (product.contains("Apache Derby")) {
        platform = new Derby();
    } else if (product.contains("Oracle")) {
        platform = new Oracle();
    } else if (product.contains("Microsoft SQL Server")) {
        platform = new SQLServer();
    } else {
        platform = new Generic();
    }
    return platform;
}
Also used : Platform(io.requery.sql.Platform) SQLException(java.sql.SQLException) PersistenceException(io.requery.PersistenceException)

Aggregations

PersistenceException (io.requery.PersistenceException)8 SQLException (java.sql.SQLException)6 Connection (java.sql.Connection)4 Attribute (io.requery.meta.Attribute)2 QueryAttribute (io.requery.meta.QueryAttribute)2 PreparedStatement (java.sql.PreparedStatement)2 CollectionChanges (io.requery.proxy.CollectionChanges)1 UPDATE (io.requery.query.element.QueryType.UPDATE)1 WHERE (io.requery.sql.Keyword.WHERE)1 Platform (io.requery.sql.Platform)1 DefaultOutput (io.requery.sql.gen.DefaultOutput)1 FilteringIterator (io.requery.util.FilteringIterator)1 ObservableCollection (io.requery.util.ObservableCollection)1 Predicate (io.requery.util.function.Predicate)1 BatchUpdateException (java.sql.BatchUpdateException)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1