Search in sources :

Example 1 with Quirks

use of org.sql2o.quirks.Quirks in project sql2o by aaberg.

the class Connection method getKeys.

// need to change Convert
@SuppressWarnings("unchecked")
public <V> List<V> getKeys(Class<V> returnType) {
    final Quirks quirks = sql2o.getQuirks();
    if (!this.canGetKeys) {
        throw new Sql2oException("Keys where not fetched from database. Please set the returnGeneratedKeys parameter in the createQuery() method to enable fetching of generated keys.");
    }
    if (this.keys != null) {
        try {
            Converter<V> converter = throwIfNull(returnType, quirks.converterOf(returnType));
            List<V> convertedKeys = new ArrayList<V>(this.keys.size());
            for (Object key : this.keys) {
                convertedKeys.add(converter.convert(key));
            }
            return convertedKeys;
        } catch (ConverterException e) {
            throw new Sql2oException("Exception occurred while converting value from database to type " + returnType.toString(), e);
        }
    }
    return null;
}
Also used : ConverterException(org.sql2o.converters.ConverterException) ArrayList(java.util.ArrayList) Quirks(org.sql2o.quirks.Quirks)

Example 2 with Quirks

use of org.sql2o.quirks.Quirks in project sql2o by aaberg.

the class Query method newResultSetHandlerFactory.

private <T> ResultSetHandlerFactory<T> newResultSetHandlerFactory(Class<T> returnType) {
    final Quirks quirks = getConnection().getSql2o().getQuirks();
    ResultSetHandlerFactoryBuilder builder = getResultSetHandlerFactoryBuilder();
    if (builder == null)
        builder = new DefaultResultSetHandlerFactoryBuilder();
    builder.setAutoDeriveColumnNames(this.autoDeriveColumnNames);
    builder.setCaseSensitive(this.caseSensitive);
    builder.setColumnMappings(this.getColumnMappings());
    builder.setQuirks(quirks);
    builder.throwOnMappingError(this.throwOnMappingFailure);
    return builder.newFactory(returnType);
}
Also used : Quirks(org.sql2o.quirks.Quirks)

Example 3 with Quirks

use of org.sql2o.quirks.Quirks in project sql2o by aaberg.

the class BidirectionalConverterTest method setUp.

@Before
public void setUp() {
    Quirks quirks = new NoQuirks() {

        {
            this.converters.put(UUID.class, new CustomUUIDConverter());
        }
    };
    this.sql2o = new Sql2o("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "", quirks);
    this.wrappers = randomWrappers();
    this.createAndFillTable(this.wrappers);
}
Also used : NoQuirks(org.sql2o.quirks.NoQuirks) Quirks(org.sql2o.quirks.Quirks) NoQuirks(org.sql2o.quirks.NoQuirks) Before(org.junit.Before)

Example 4 with Quirks

use of org.sql2o.quirks.Quirks in project sql2o by aaberg.

the class Connection method getKey.

// need to change Convert
@SuppressWarnings("unchecked")
public <V> V getKey(Class returnType) {
    final Quirks quirks = this.sql2o.getQuirks();
    Object key = getKey();
    try {
        Converter<V> converter = throwIfNull(returnType, quirks.converterOf(returnType));
        return converter.convert(key);
    } catch (ConverterException e) {
        throw new Sql2oException("Exception occurred while converting value from database to type " + returnType.toString(), e);
    }
}
Also used : ConverterException(org.sql2o.converters.ConverterException) Quirks(org.sql2o.quirks.Quirks)

Aggregations

Quirks (org.sql2o.quirks.Quirks)4 ConverterException (org.sql2o.converters.ConverterException)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 NoQuirks (org.sql2o.quirks.NoQuirks)1