@Test public void getRecordCheck(){ InsertOrUpdateGeneratorMSSQL generator = new InsertOrUpdateGeneratorMSSQL(); MSSQLDatabase database = new MSSQLDatabase(); InsertOrUpdateStatement statement = new InsertOrUpdateStatement("myschema","mytable","pk_col1"); statement.addColumnValue("pk_col1","value1"); statement.addColumnValue("col2","value2"); String where = "1 = 1"; Class c = InsertOrUpdateGenerator.class.getClass(); String recordCheck = (String)invokePrivateMethod(generator,"getRecordCheck", new Object[] {statement,database,where}); Integer lineNumber = 0; String[] lines = recordCheck.split("\n"); assertEquals("DECLARE @reccount integer", lines[lineNumber]); lineNumber++; assertEquals("SELECT @reccount = count(*) FROM [myschema].[mytable] WHERE " + where, lines[lineNumber]); lineNumber++; assertEquals("IF @reccount = 0", lines[lineNumber]); }
protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { StringBuffer recordCheck = new StringBuffer(); recordCheck.append("DECLARE @reccount integer\n"); recordCheck.append("SELECT @reccount = count(*) FROM "); recordCheck.append(database.escapeTableName(insertOrUpdateStatement.getSchemaName(),insertOrUpdateStatement.getTableName())); recordCheck.append(" WHERE "); recordCheck.append(whereClause); recordCheck.append("\n"); recordCheck.append("IF @reccount = 0\n"); return recordCheck.toString(); }
InsertOrUpdateGeneratorMSSQL extends InsertOrUpdateGenerator { protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { StringBuffer recordCheck = new StringBuffer(); recordCheck.append("DECLARE @reccount integer\n"); recordCheck.append("SELECT @reccount = count(*) FROM "); recordCheck.append(database.escapeTableName(insertOrUpdateStatement.getSchemaName(),insertOrUpdateStatement.getTableName())); recordCheck.append(" WHERE "); recordCheck.append(whereClause); recordCheck.append("\n"); recordCheck.append("IF @reccount = 0\n"); return recordCheck.toString(); } }
InsertOrUpdateGeneratorMSSQL extends InsertOrUpdateGenerator { protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { StringBuffer recordCheck = new StringBuffer(); recordCheck.append("DECLARE @reccount integer\n"); recordCheck.append("SELECT @reccount = count(*) FROM "); recordCheck.append(database.escapeTableName(insertOrUpdateStatement.getSchemaName(),insertOrUpdateStatement.getTableName())); recordCheck.append(" WHERE "); recordCheck.append(whereClause); recordCheck.append("\n"); recordCheck.append("IF @reccount = 0\n"); return recordCheck.toString(); }  }
InsertOrUpdateGeneratorMSSQL extends InsertOrUpdateGenerator { protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { StringBuffer recordCheck = new StringBuffer(); recordCheck.append("DECLARE @reccount integer\n"); recordCheck.append("SELECT @reccount = count(*) FROM "); recordCheck.append(database.escapeTableName(insertOrUpdateStatement.getSchemaName(),insertOrUpdateStatement.getTableName())); recordCheck.append(" WHERE "); recordCheck.append(whereClause); recordCheck.append("\n"); recordCheck.append("IF @reccount = 0\n"); return recordCheck.toString(); }  boolean supports(InsertOrUpdateStatement statement, Database database); @Override Sql[] generateSql(InsertOrUpdateStatement insertOrUpdateStatement, Database database, SqlGeneratorChain sqlGeneratorChain); }
InsertOrUpdateGeneratorMSSQL extends InsertOrUpdateGenerator { protected String getRecordCheck(InsertOrUpdateStatement insertOrUpdateStatement, Database database, String whereClause) { StringBuffer recordCheck = new StringBuffer(); recordCheck.append("DECLARE @reccount integer\n"); recordCheck.append("SELECT @reccount = count(*) FROM "); recordCheck.append(database.escapeTableName(insertOrUpdateStatement.getSchemaName(),insertOrUpdateStatement.getTableName())); recordCheck.append(" WHERE "); recordCheck.append(whereClause); recordCheck.append("\n"); recordCheck.append("IF @reccount = 0\n"); return recordCheck.toString(); }  boolean supports(InsertOrUpdateStatement statement, Database database); @Override Sql[] generateSql(InsertOrUpdateStatement insertOrUpdateStatement, Database database, SqlGeneratorChain sqlGeneratorChain);  }