public int[] doBatchInsert() { if (params.size() == 0) { throw new JdbcException("No values"); } String finalSQL = sql.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } try { Object[][] objects = new Object[params.size()][columnsSize]; for (int i = 0; i < params.size(); i++) { objects[i] = params.get(i); } return sqlTemplate.batchInsert(finalSQL, objects); } catch (SQLException e) { if (e.getMessage().contains("Duplicate entry")) { throw new DupEntryException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } else if (e.getMessage().contains("doesn't exist Query:")) { throw new TableNotExistException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } throw new JdbcException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } catch (Exception e) { throw new JdbcException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } }
protected void createTable(String sql) throws JdbcException { if (config.getParameter(ExtConfig.NEED_CREATE_DB_TABLE, true)) { try { getSqlTemplate().createTable(sql); } catch (Exception e) { throw new JdbcException("Create table error, sql=" + sql, e); } } } }
public int doDelete() { String finalSQL = getSQL(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } return sqlTemplate.delete(finalSQL, params.toArray()); } catch (SQLException e) { throw new JdbcException("Delete SQL Error:" + SQLFormatter.format(finalSQL), e); } }
public <T> T single(ResultSetHandler<T> handler) { try { return sqlTemplate.query(getSQL(), handler, params.toArray()); } catch (Exception e) { throw new JdbcException("Select SQL Error:" + getSQL(), e); } }
public boolean doDrop() { String finalSQL = sql.toString(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } sqlTemplate.update(sql.toString()); } catch (Exception e) { throw new JdbcException("Drop Table Error:" + SQLFormatter.format(finalSQL), e); } return true; }
public <T> T single() { String finalSQL = getSQL(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } return sqlTemplate.queryForValue(finalSQL, params.toArray()); } catch (Exception e) { throw new JdbcException("Select SQL Error:" + SQLFormatter.format(finalSQL), e); } }
public int doInsert() { if (params.size() == 0) { throw new JdbcException("No values"); } if (params.size() > 1) { throw new JdbcException("values.length gt 1, please use doBatchInsert"); } String execSql = sql.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(execSql); } try { return sqlTemplate.insert(execSql, params.get(0)); } catch (SQLException e) { if (e.getMessage().contains("Duplicate entry")) { throw new DupEntryException("Insert SQL Error:" + execSql, e); } else if (e.getMessage().contains("doesn't exist Query:")) { throw new TableNotExistException("Insert SQL Error:" + execSql, e); } throw new JdbcException("Insert SQL Error:" + execSql, e); } catch (Exception e) { throw new JdbcException("Insert SQL Error:" + execSql, e); } }
public <T> List<T> list(ResultSetHandler<List<T>> handler) { try { return sqlTemplate.query(getSQL(), handler, params.toArray()); } catch (Exception e) { throw new JdbcException("Select SQL Error:" + getSQL(), e); } }
public boolean doDrop() { String finalSQL = sql.toString(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } sqlTemplate.update(sql.toString()); } catch (Exception e) { throw new JdbcException("Drop Table Error:" + SQLFormatter.format(finalSQL), e); } return true; }
public <T> T single() { String finalSQL = getSQL(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } return sqlTemplate.queryForValue(finalSQL, params.toArray()); } catch (Exception e) { throw new JdbcException("Select SQL Error:" + SQLFormatter.format(finalSQL), e); } }
public int doInsert() { if (params.size() == 0) { throw new JdbcException("No values"); } if (params.size() > 1) { throw new JdbcException("values.length gt 1, please use doBatchInsert"); } String execSql = sql.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(execSql); } try { return sqlTemplate.insert(execSql, params.get(0)); } catch (SQLException e) { if (e.getMessage().contains("Duplicate entry")) { throw new DupEntryException("Insert SQL Error:" + execSql, e); } else if (e.getMessage().contains("doesn't exist Query:")) { throw new TableNotExistException("Insert SQL Error:" + execSql, e); } throw new JdbcException("Insert SQL Error:" + execSql, e); } catch (Exception e) { throw new JdbcException("Insert SQL Error:" + execSql, e); } }
public <T> List<T> list(ResultSetHandler<List<T>> handler) { try { return sqlTemplate.query(getSQL(), handler, params.toArray()); } catch (Exception e) { throw new JdbcException("Select SQL Error:" + getSQL(), e); } }
public int doUpdate() { String finalSQL = getSQL(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } return sqlTemplate.update(finalSQL, params.toArray()); } catch (SQLException e) { throw new JdbcException("Update SQL Error:" + SQLFormatter.format(finalSQL), e); } }
public int doDelete() { String finalSQL = getSQL(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } return sqlTemplate.delete(finalSQL, params.toArray()); } catch (SQLException e) { throw new JdbcException("Delete SQL Error:" + SQLFormatter.format(finalSQL), e); } }
public <T> T single() { String finalSQL = getSQL(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } return sqlTemplate.queryForValue(finalSQL, params.toArray()); } catch (Exception e) { throw new JdbcException("Select SQL Error:" + SQLFormatter.format(finalSQL), e); } }
protected void createTable(String sql) throws JdbcException { if (config.getParameter(ExtConfig.NEED_CREATE_DB_TABLE, true)) { try { getSqlTemplate().createTable(sql); } catch (Exception e) { throw new JdbcException("Create table error, sql=" + sql, e); } } } }
public int doInsert() { if (params.size() == 0) { throw new JdbcException("No values"); } if (params.size() > 1) { throw new JdbcException("values.length gt 1, please use doBatchInsert"); } String execSql = sql.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(execSql); } try { return sqlTemplate.insert(execSql, params.get(0)); } catch (SQLException e) { if (e.getMessage().contains("Duplicate entry")) { throw new DupEntryException("Insert SQL Error:" + execSql, e); } else if (e.getMessage().contains("doesn't exist Query:")) { throw new TableNotExistException("Insert SQL Error:" + execSql, e); } throw new JdbcException("Insert SQL Error:" + execSql, e); } catch (Exception e) { throw new JdbcException("Insert SQL Error:" + execSql, e); } }
public int[] doBatchInsert() { if (params.size() == 0) { throw new JdbcException("No values"); } String finalSQL = sql.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } try { Object[][] objects = new Object[params.size()][columnsSize]; for (int i = 0; i < params.size(); i++) { objects[i] = params.get(i); } return sqlTemplate.batchInsert(finalSQL, objects); } catch (SQLException e) { if (e.getMessage().contains("Duplicate entry")) { throw new DupEntryException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } else if (e.getMessage().contains("doesn't exist Query:")) { throw new TableNotExistException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } throw new JdbcException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } catch (Exception e) { throw new JdbcException("Insert SQL Error:" + SQLFormatter.format(finalSQL), e); } }
public <T> T single(ResultSetHandler<T> handler) { try { return sqlTemplate.query(getSQL(), handler, params.toArray()); } catch (Exception e) { throw new JdbcException("Select SQL Error:" + getSQL(), e); } }
public int doUpdate() { String finalSQL = getSQL(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(SQLFormatter.format(finalSQL)); } return sqlTemplate.update(finalSQL, params.toArray()); } catch (SQLException e) { throw new JdbcException("Update SQL Error:" + SQLFormatter.format(finalSQL), e); } }