/** * Synonym of {@link #connection()} for people who like getters. * * @return connection from current thread. */ public Connection getConnection(){ return connection(); }
private Statement createStreamingStatement() throws SQLException { Connection conn = connection(); Statement res; if ("mysql".equalsIgnoreCase(conn.getMetaData().getDatabaseProductName())) { res = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); res.setFetchSize(Integer.MIN_VALUE); } else { res = conn.createStatement(); } return res; }
private PreparedStatement createStreamingPreparedStatement(String query) throws SQLException { Connection conn = connection(); PreparedStatement res; if ("mysql".equalsIgnoreCase(conn.getMetaData().getDatabaseProductName())) { res = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); res.setFetchSize(Integer.MIN_VALUE); } else { res = conn.prepareStatement(query); } return res; }
/** * Creates a <code>java.sql.PreparedStatement</code> to be used in batch executions later. * * @param parametrizedStatement Example of a statement: <code>INSERT INTO employees VALUES (?, ?)</code>. * @return instance of <code>java.sql.PreparedStatement</code> with compiled query. */ public PreparedStatement startBatch(String parametrizedStatement){ try { return connection().prepareStatement(parametrizedStatement); } catch (SQLException e) { throw new DBException(e); } }
/** * Returns connection attached to a current thread and named "default". * * @return connection attached to a current thread and named "default". */ public static Connection connection() { return new DB(DB.DEFAULT_NAME).connection(); }
private void checkExistingConnection(String name) { if (null != ConnectionsAccess.getConnection(name)) { throw new DBException("Cannot open a new connection because existing connection is still on current thread, name: " + name + ", connection instance: " + connection() + ". This might indicate a logical error in your application."); } }
/** * Executes DML. Use it for inserts and updates. * * @param query raw DML. * @return number of rows afected by query. */ public int exec(String query){ long start = System.currentTimeMillis(); Statement s = null; try { s = connection().createStatement(); int count = s.executeUpdate(query); LogFilter.logQuery(LOGGER, query, null, start); return count; } catch (SQLException e) { logException("Query failed: " + query, e); throw new DBException(query, null, e); } finally { closeQuietly(s); } }
/** * Executes parametrized DML - will contain question marks as placeholders. * * @param query query to execute - will contain question marks as placeholders. * @param params query parameters. * @return number of records affected. */ public int exec(String query, Object... params){ if(query.indexOf('?') == -1) throw new IllegalArgumentException("query must be parametrized"); long start = System.currentTimeMillis(); PreparedStatement ps = null; try { ps = connection().prepareStatement(query); setParameters(ps, params); int count = ps.executeUpdate(); LogFilter.logQuery(LOGGER, query, params, start); return count; } catch (SQLException e) { logException("Failed query: " + query, e); throw new DBException(query, params, e); } finally { closeQuietly(ps); } }
/** * This method returns the value of the first column of the first row. * If query results have more than one column or more than one row, they will be ignored. * * @param query query * @param params parameters * @return fetched value, or null if query did not fetch anything. */ public Object firstCell(final String query, Object... params) { PreparedStatement ps = null; ResultSet rs = null; try { Object result = null; long start = System.currentTimeMillis(); ps = connection().prepareStatement(query); setParameters(ps, params); rs = ps.executeQuery(); if (rs.next()) { result = rs.getObject(1); } LogFilter.logQuery(LOGGER, query, params, start); return result; } catch (SQLException e) { throw new DBException(query, params, e); } finally { closeQuietly(rs); closeQuietly(ps); } }
List<Object> results = new ArrayList<>(); long start = System.currentTimeMillis(); ps = connection().prepareStatement(query); setParameters(ps, params); rs = ps.executeQuery();
PreparedStatement ps; try { Connection connection = connection(); ps = StatementCache.instance().getPreparedStatement(connection, query); if(ps == null){
Connection c = new DB(dbName).connection(); String dbType = c.getMetaData().getDatabaseProductName(); dialect = Dialects.getDialect(dbType);
/** * Synonym of {@link #connection()} for people who like getters. * * @return connection from current thread. */ public Connection getConnection(){ return connection(); }
private PreparedStatement createStreamingPreparedStatement(String query) throws SQLException { Connection conn = connection(); PreparedStatement res; if ("mysql".equalsIgnoreCase(conn.getMetaData().getDatabaseProductName())) { res = conn.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); res.setFetchSize(Integer.MIN_VALUE); } else { res = conn.prepareStatement(query); } return res; }
private Statement createStreamingStatement() throws SQLException { Connection conn = connection(); Statement res; if ("mysql".equalsIgnoreCase(conn.getMetaData().getDatabaseProductName())) { res = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); res.setFetchSize(Integer.MIN_VALUE); } else { res = conn.createStatement(); } return res; }
private Statement createStreamingStatement() throws SQLException { Connection conn = connection(); Statement res; if ("mysql".equalsIgnoreCase(conn.getMetaData().getDatabaseProductName())) { res = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); res.setFetchSize(Integer.MIN_VALUE); } else { res = conn.createStatement(); } return res; }
/** * Returns connection attached to a current thread and named "default". * * @return connection attached to a current thread and named "default". */ public static Connection connection() { return new DB(DB.DEFAULT_NAME).connection(); }
/** * Returns connection attached to a current thread and named "default". * * @return connection attached to a current thread and named "default". */ public static Connection connection() { return new DB(DB.DEFAULT_NAME).connection(); }
private void checkExistingConnection(String name) { if (null != ConnectionsAccess.getConnection(name)) { throw new DBException("Cannot open a new connection because existing connection is still on current thread, name: " + name + ", connection instance: " + connection() + ". This might indicate a logical error in your application."); } }
private void checkExistingConnection(String name) { if (null != ConnectionsAccess.getConnection(name)) { throw new DBException("Cannot open a new connection because existing connection is still on current thread, name: " + name + ", connection instance: " + connection() + ". This might indicate a logical error in your application."); } }