public int[] getBatchResult() { if (this.batchResult == null){ throw new Sql2oException("It is required to call executeBatch() method before calling getBatchResult()."); } return this.batchResult; }
public int getResult(){ if (this.result == null){ throw new Sql2oException("It is required to call executeUpdate() method before calling getResult()."); } return this.result; }
public Object newInstance() { try { return ctor.newInstance((Object[])null); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new Sql2oException("Could not create a new instance of class " + clazz, e); } } };
public Object[] getKeys(){ 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){ return this.keys.toArray(); } return null; }
public Object getProperty(Object obj) { try { return this.field.get(obj); } catch (IllegalAccessException e) { throw new Sql2oException("could not get field " + this.field.getName() + " on class " + obj.getClass().toString(), e); } }
public void setProperty(Object obj, Object value) { if (value == null && type.isPrimitive()){ return; // dont try to set null to a setter to a primitive type. } try { this.method.invoke(obj, value); } catch (IllegalAccessException e) { throw new Sql2oException("error while calling setter method with name " + method.getName() + " on class " + obj.getClass().toString(), e); } catch (InvocationTargetException e) { throw new Sql2oException("error while calling setter method with name " + method.getName() + " on class " + obj.getClass().toString(), e); } }
public void setProperty(Object obj, Object value) { if (value == null && this.field.getType().isPrimitive()){ return; // dont try set null to a primitive field } try { this.field.set(obj, value); } catch (IllegalAccessException e) { throw new Sql2oException("could not set field " + this.field.getName() + " on class " + obj.getClass().toString(), e); } }
public Getter getPropertyGetter(String propertyName) { Getter getter = getPropertyGetterIfExists(propertyName); if (getter != null) { return getter; } else { String errorMsg = "Property with name '" + propertyName + "' not found on class " + this.clazz.toString(); if (this.caseSensitive) { errorMsg += " (You have turned on case sensitive property search. Is this intentional?)"; } throw new Sql2oException(errorMsg); } }
public Object getProperty(Object obj) { try { return methodAccessor.invoke(obj, null); } catch (InvocationTargetException e) { throw new Sql2oException("error while calling getter method with name " + method.getName() + " on class " + obj.getClass().toString(), e); } }
public void setProperty(Object obj, Object value) { if (value == null && type.isPrimitive()) return; try { methodAccessor.invoke(obj, new Object[]{value}); } catch (InvocationTargetException e) { throw new Sql2oException("error while calling setter method with name " + method.getName() + " on class " + obj.getClass().toString(), e); } }
@Override public Object newInstance() { try { return constructorAccessor.newInstance(null); } catch (InstantiationException | InvocationTargetException e) { throw new Sql2oException("Could not create a new instance of class " + cls, e); } } };
private void createConnection(){ try{ this.jdbcConnection = connectionSource.getConnection(); this.originalAutoCommit = jdbcConnection.getAutoCommit(); } catch(Exception ex){ throw new Sql2oException("Could not acquire a connection from DataSource - " + ex.getMessage(), ex); } }
private void addParameterInternal(String name, ParameterSetter parameterSetter) { if (!this.getParamNameToIdxMap().containsKey(name)) { throw new Sql2oException("Failed to add parameter with name '" + name + "'. No parameter with that name is declared in the sql."); } parameters.put(name, parameterSetter); }
public ResultSetIterableBase() { try { start = System.currentTimeMillis(); logExecution(); rs = buildPreparedStatement().executeQuery(); afterExecQuery = System.currentTimeMillis(); } catch (SQLException ex) { throw new Sql2oException("Database error: " + ex.getMessage(), ex); } }
public Object getObject(String columnName){ Integer index = columnNameToIdxMap.get( isCaseSensitive?columnName :columnName.toLowerCase()); if(index!=null) return getObject(index); throw new Sql2oException(String.format("Column with name '%s' does not exist", columnName)); }
public Setter getPropertySetter(String propertyName) { Setter setter = getPropertySetterIfExists(propertyName); if (setter != null) { return setter; } else { String errorMsg = "Property with name '" + propertyName + "' not found on class " + this.clazz.toString(); if (this.caseSensitive) { errorMsg += " (You have turned on case sensitive property search. Is this intentional?)"; } throw new Sql2oException(errorMsg); } }
public Query createQuery(String queryText, String ... columnNames) { try { if (jdbcConnection.isClosed()) { createConnection(); } } catch(SQLException e) { throw new Sql2oException("Error creating connection", e); } return new Query(this, queryText, columnNames); }
public Query createQuery(String queryText, boolean returnGeneratedKeys){ try { if (jdbcConnection.isClosed()){ createConnection(); } } catch (SQLException e) { throw new Sql2oException("Error creating connection", e); } return new Query(this, queryText, returnGeneratedKeys); }
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") // need to change Convert 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); } }