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;
}
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);
}
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);
}
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);
}
}
Aggregations