public static void insertFunctiontestIntCol(int id, String msg, final int testIntCol) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setInt(3, testIntCol); } }); }
@Override public void createTable(ColumnGenerator... extraColumns) throws SQLException { super.createTable(extraColumns); names = new String[extraColumns.length]; types = new String[extraColumns.length]; for (int i = 0; i < extraColumns.length; ++i) { names[i] = forIdx(i); types[i] = extraColumns[i].getType(); } createProcedure(names, types); }
private static void insertFunction(int id, String msg, SetExtraArgs setExtraArgs) throws SQLException { instanceForProcedure.functionCalls += 1; Connection con = instanceForProcedure.getConnection(); StringBuilder sql = new StringBuilder("insert into "); sql.append(instanceForProcedure.getTableName()); sql.append("(id, msg"); for (int i = 0; i < instanceForProcedure.names.length; ++i) { sql.append(","); sql.append(instanceForProcedure.names[i]); } sql.append(") values ("); for (int i = 0; i < instanceForProcedure.names.length + 2; ++i) { sql.append("?,"); } // Remove last , sql = sql.delete(sql.length() - 1, sql.length()); sql.append(")"); PreparedStatement statement = con.prepareStatement(sql.toString()); try { statement.setInt(1, id); statement.setString(2, msg); setExtraArgs.set(statement); statement.execute(); con.commit(); } finally { statement.close(); } }
@Override protected String[] getCodeGenArgv(String... extraArgs) { String[] myExtraArgs = newStrArray(extraArgs, "--" + ExportTool.CONN_MANAGER_CLASS_NAME, GenericJdbcManager.class.getName(), "--" + ExportTool.DRIVER_ARG, Driver.class.getName()); return super.getCodeGenArgv(myExtraArgs); }
@Override protected Connection getConnection() { if (connection != null) { return connection; } try { connection = DriverManager.getConnection(getConnectString()); connection.setAutoCommit(false); return connection; } catch (SQLException e) { throw new AssertionError(e.getMessage()); } }
protected void createProcedure(String[] extraNames, String[] extraTypes) throws SQLException { StringBuilder drop = new StringBuilder("DROP ALIAS IF EXISTS "); drop.append(PROCEDURE_NAME); StringBuilder create = new StringBuilder("CREATE ALIAS "); create.append(PROCEDURE_NAME); create.append(" FOR \""); create.append(getClass().getName()); create.append(".insertFunction"); if (extraNames.length > 0) { create.append(name.getMethodName()); } create.append('"'); Connection conn = getConnection(); Statement statement = conn.createStatement(); try { statement.execute(drop.toString()); statement.execute(create.toString()); conn.commit(); } finally { statement.close(); } }
@Override protected String[] getArgv(boolean includeHadoopFlags, int rowsPerStmt, int statementsPerTx, String... additionalArgv) { // we need different class names per test, or the classloader will // just use the old class definition even though we've compiled a // new one! String[] args = newStrArray(additionalArgv, "--" + ExportTool.CALL_ARG, PROCEDURE_NAME, "--" + ExportTool.CLASS_NAME_ARG, name.getMethodName(), "--" + ExportTool.CONN_MANAGER_CLASS_NAME, GenericJdbcManager.class.getName(), "--" + ExportTool.DRIVER_ARG, Driver.class.getName()); return super .getArgv(includeHadoopFlags, rowsPerStmt, statementsPerTx, args); }
public static void insertFunctiontestNumericTypes(int id, String msg, final BigDecimal f, final BigDecimal d) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setBigDecimal(3, f); on.setBigDecimal(4, d); } }); }
public static void insertFunction(int id, String msg) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { } }); }
public static void insertFunctiontestBigIntCol(int id, String msg, final long testBigIntCol) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setLong(3, testBigIntCol); } }); }
public static void insertFunctiontestDatesAndTimes(int id, String msg, final Date date, final Time time) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setDate(3, date); on.setTime(4, time); } }); }
/** * This test case is special - we're only inserting into a subset of the * columns in the table. */ public static void insertFunctiontestLessColumnsInFileThanInTableInputNullStringPassed(int id, String msg, final String str1) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setString(3, str1); on.setNull(4, Types.VARCHAR); } }); }
/** * This test case is special - we're only inserting into a subset of the * columns in the table. */ public static void insertFunctiontestColumnsExport(int id, String msg, final int int1, final int int2) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setInt(3, int1); on.setNull(4, Types.INTEGER); on.setInt(5, int2); } }); }
/** * This test case is special - we're only inserting into a subset of the * columns in the table. */ public static void insertFunctiontestLessColumnsInFileThanInTable(int id, String msg, final int number, final Timestamp t2) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setInt(3, number); on.setNull(4, Types.TIMESTAMP); } }); }
/** * This test case is special - we're only inserting into a subset of the * columns in the table. */ public static void insertFunctiontestLessColumnsInFileThanInTableInputNullIntPassed(int id, String msg, final int int1) throws SQLException { insertFunction(id, msg, new SetExtraArgs() { @Override public void set(PreparedStatement on) throws SQLException { on.setInt(3, int1); on.setNull(4, Types.INTEGER); } }); } }