ResultSet rset = null; try { c = useTxnConnection ? t.getConnection() : dataSource.getConnection();
public Object nextId(Transaction t) { boolean useTxnConnection = t != null; Connection c = null; PreparedStatement pstmt = null; ResultSet rset = null; try { c = useTxnConnection ? t.getConnection() : dataSource.getConnection(); pstmt = c.prepareStatement(sql); rset = pstmt.executeQuery(); if (rset.next()) { int val = rset.getInt(1); return Integer.valueOf(val); } else { String m = "Always expecting 1 row from " + sql; throw new PersistenceException(m); } } catch (SQLException e) { throw new PersistenceException("Error getting sequence nextval", e); } finally { if (useTxnConnection) { closeResources(rset, pstmt, null); } else { closeResources(rset, pstmt, c); } } }
public Object nextId(Transaction t) { boolean useTxnConnection = t != null; Connection c = null; PreparedStatement pstmt = null; ResultSet rset = null; try { c = useTxnConnection ? t.getConnection() : dataSource.getConnection(); pstmt = c.prepareStatement(sql); rset = pstmt.executeQuery(); if (rset.next()){ int val = rset.getInt(1); return Integer.valueOf(val); } else { String m = "Always expecting 1 row from "+sql; throw new PersistenceException(m); } } catch (SQLException e){ throw new PersistenceException("Error getting sequence nextval", e); } finally { if (useTxnConnection){ closeResources(rset, pstmt, null); } else { closeResources(rset, pstmt, c); } } }
ResultSet rset = null; try { c = useTxnConnection ? t.getConnection() : dataSource.getConnection();
public Object nextId(Transaction t) { boolean useTxnConnection = t != null; Connection c = null; PreparedStatement pstmt = null; ResultSet rset = null; try { c = useTxnConnection ? t.getConnection() : dataSource.getConnection(); pstmt = c.prepareStatement(sql); rset = pstmt.executeQuery(); if (rset.next()) { return rset.getInt(1); } else { String m = "Always expecting 1 row from " + sql; throw new PersistenceException(m); } } catch (SQLException e) { throw new PersistenceException("Error getting sequence nextval", e); } finally { if (useTxnConnection) { closeResources(rset, pstmt, null); } else { closeResources(rset, pstmt, c); } } }
@Override public Company findCompanyUsingSimpleStaticStatement(Integer pid) { // I didn't find a way how to setup EBean so the query is executed statically (using JDBC regular Statement // not PreparedStatement). However, EBean is polite and provides way how to access the underlying JDBC connection // -> therefore we can actually fall back to JDBC way of doing things (which is not such a big deal since we need simple // Statements only rarely): try { String query = "SELECT pid, address, name " + "FROM company " + "WHERE pid = " + pid; Connection connection = ebean.currentTransaction().getConnection(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query); Company result = null; if (resultSet.next()) { result = new Company(); result.setPid(resultSet.getInt("pid")); result.setAddress(resultSet.getString("address")); result.setName(resultSet.getString("name")); } return result; } catch (SQLException e) { // just wrap checked exceptions as e throw new RuntimeException(e); } }
ResultSet rset = null; try { c = useTxnConnection ? t.getConnection() : dataSource.getConnection();
/** * Execute all the DDL statements in the script. */ public void runScript(boolean expectErrors, String content) { StringReader sr = new StringReader(content); List<String> statements = parseStatements(sr); Transaction t = server.createTransaction(); try { Connection connection = t.getConnection(); out.println("runScript"); out.flush(); runStatements(expectErrors, statements, connection); out.println("... end of script"); out.flush(); t.commit(); } catch (Exception e){ String msg = "Error: "+e.getMessage(); throw new PersistenceException(msg, e); } finally { t.end(); } }
/** * Execute all the DDL statements in the script. */ public void runScript(boolean expectErrors, String content) { StringReader sr = new StringReader(content); List<String> statements = parseStatements(sr); Transaction t = server.createTransaction(); try { Connection connection = t.getConnection(); out.println("runScript"); out.flush(); runStatements(expectErrors, statements, connection); out.println("... end of script"); out.flush(); t.commit(); } catch (Exception e){ String msg = "Error: "+e.getMessage(); throw new PersistenceException(msg, e); } finally { t.end(); } }
/** * Execute all the DDL statements in the script. */ public int runScript(boolean expectErrors, String content, String scriptName) { DdlRunner runner = new DdlRunner(expectErrors, scriptName); Transaction transaction = server.createTransaction(); Connection connection = transaction.getConnection(); try { if (expectErrors) { connection.setAutoCommit(true); } int count = runner.runAll(content, connection); if (expectErrors) { connection.setAutoCommit(false); } transaction.commit(); return count; } catch (SQLException e) { throw new PersistenceException("Failed to run script", e); } finally { transaction.end(); } }