TableConnectionInfo
などのテーブルに関する詳細を含むという名前のクラスがtableName
ありますcolumns
。table.getColumns()
各テーブルのメソッドの列値を使用して、ランダムなselectsqlを生成するメソッドを作成しました。
table1の場合、次のような10個の列があるとします。
col1
col2
col3
col4
col5
col6
col7
col8
col9
col10
以下は、を使用してランダムなselectsqlを生成しようとしている私の方法ですtable.getColumns()
。これtable
がTableConnectionInfo
オブジェクトです。
private static Random random = new SecureRandom();
private String generateRandomSQL(TableConnectionInfo table) {
int rNumber = random.nextInt(table.getColumns().size());
List<String> shuffledColumns = new ArrayList<String>(table.getColumns());
Collections.shuffle(shuffledColumns);
String columnsList = "";
for (int i = 0; i < rNumber; i++) {
columnsList += ("," + shuffledColumns.get(i));
}
final String sql = "SELECT ID, CREATION_DATE, LAST_MODIFIED_DATE" + columnsList + " from " + table.getTableName() + " where id = ?";
return sql;
}
以下は私のTableConncectionInfo
クラスで開催されるtableName
もので、そのcolumns
リスト です
public class TableConnectionInfo {
public String tableName;
public ArrayList<String> columns;
public ArrayList<String> getColumns() {
return columns;
}
public void setColumns(ArrayList<String> columns) {
this.columns = columns;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
}
問題文:-
したがって、上記の方法の問題は、すべての列をランダムにシャッフルし、次のような結果を得るということです-
`SELECT ID, CREATION_DATE, LAST_MODIFIED_DATE, col3, col1, col5 from table1 where id = ?`
`SELECT ID, CREATION_DATE, LAST_MODIFIED_DATE, col7, col2, col3, col1 from table1 where id = ?`
`SELECT ID, CREATION_DATE, LAST_MODIFIED_DATE, col8, col1, col2, col6 from table1 where id = ?`
... Other possible combinations
そして、私はこのようなものを探しています。ArrayListに列を挿入する方法-これが順序であると仮定します-
col1, col2, col3, col4, col5, col6, col7, col8, col9, col10
次に、私の列SELECT SQL
は同じ順序になっているはずです。意味-
`SELECT ID, CREATION_DATE, LAST_MODIFIED_DATE, col1, col3, col5 from table1 where id = ?`
`SELECT ID, CREATION_DATE, LAST_MODIFIED_DATE, col7, col8, col9, col10 from table1 where id = ?`
`SELECT ID, CREATION_DATE, LAST_MODIFIED_DATE, col1, col4, col5, col6, col10 from table1 where id = ?`
col1
、then col5
、thenのようにランダムであってはなりませんcol2
(これは間違っています)。そのはず-
col5, col7, col10
col3, col6, col8, col10
other options
基本的に、私はSELECT sqlに、ArrayListに挿入された方法で、ランダムな順序で列を配置することを検討しています。Like-挿入された順序で任意の4を選択するか、挿入された順序で任意の6を選択するか、挿入された順序で任意の7を選択します