@Bean @Qualifier("Runelite Cache SQL2O") public Sql2o sql2o(DataSource dataSource) { Map<Class, Converter> converters = new HashMap<>(); converters.put(Instant.class, new InstantConverter()); return new Sql2o(dataSource, new NoQuirks(converters)); }
/** * Creates a new instance of the Sql2o class. Internally this constructor will create a {@link GenericDatasource}, * and call the {@link Sql2o#Sql2o(javax.sql.DataSource)} constructor which takes a DataSource as parameter. * @param url JDBC database url * @param user database username * @param pass database password */ public Sql2o(String url, String user, String pass){ this(url, user, pass, QuirksDetector.forURL(url)); }
/** * Creates a new instance of the Sql2o class, which uses the given DataSource to acquire connections to the database. * @param dataSource The DataSource Sql2o uses to acquire connections to the database. */ public Sql2o(DataSource dataSource) { this(dataSource, QuirksDetector.forObject(dataSource)); }
public static Quirks forURL(String jdbcUrl) { for (QuirksProvider quirksProvider : ServiceLoader.load(QuirksProvider.class)) { if (quirksProvider.isUsableForUrl(jdbcUrl)){ return quirksProvider.provide(); } } return new NoQuirks(); }
public static Quirks forObject(Object jdbcObject) { String jdbcObjectClassName = jdbcObject.getClass().getName().contains("$") ? jdbcObject.getClass().getSuperclass().getCanonicalName() : jdbcObject.getClass().getCanonicalName(); for (QuirksProvider quirksProvider : ServiceLoader.load(QuirksProvider.class)) { if (quirksProvider.isUsableForClass(jdbcObjectClassName)){ return quirksProvider.provide(); } } return new NoQuirks(); } }
@Override public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, value); } });
public T handle(ResultSet resultSet) throws SQLException { Object value = quirks.getRSVal(resultSet, 1); try { return (converter.convert(value)); } catch (ConverterException e) { throw new Sql2oException("Error occurred while converting value from database to type " + returnType, e); } } };
@SuppressWarnings("unchecked") private Object convertParameter(Object value) { if (value == null) { return null; } Converter converter = getQuirks().converterOf(value.getClass()); if (converter == null) { // let's try to add parameter AS IS return value; } return converter.toDatabaseParam(value); }
protected String getColumnName(int colIdx) throws SQLException { return quirks.getColumnName(meta, colIdx); }
public Query createQuery(String queryText){ boolean returnGeneratedKeys = this.sql2o.getQuirks().returnGeneratedKeysByDefault(); return createQuery(queryText, returnGeneratedKeys); }
public void close() { if(preparedStatement != null) { connection.removeStatement(preparedStatement); try { this.getQuirks().closeStatement(preparedStatement); } catch (Throwable ex) { logger.warn("Could not close statement.", ex); } } }
@Override public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { if(values.length == 0) { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, (Object) null); } else { for (Object value : values) { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx++, value); } } } });
@Override protected Row readNext() throws SQLException { Row row = new Row(columnNameToIdxMap, columns.size(), isCaseSensitive,this.quirks); for (Column column : columns) { row.addValue(column.getIndex(), quirks.getRSVal(rs, column.getIndex() + 1)); } return row; } }
public <V> V executeScalar(Class<V> returnType){ try { Converter<V> converter; //noinspection unchecked converter = throwIfNull(returnType, getQuirks().converterOf(returnType)); //noinspection unchecked logExecution(); return executeScalar(converter); } catch (ConverterException e) { throw new Sql2oException("Error occured while converting value from database to type " + returnType, e); } }
@Override public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, value); } });
@Override public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, value); } });
public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, value); } });
public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, value); } });
public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, value); } });
public void setParameter(int paramIdx, PreparedStatement statement) throws SQLException { getConnection().getSql2o().getQuirks().setParameter(statement, paramIdx, value); } });