use of mom.trd.opentheso.core.exports.privatesdatas.TablesColumn in project opentheso by miledrousset.
the class ExportPrivatesDatas method getDatasOfTable.
public ArrayList<Table> getDatasOfTable(HikariDataSource ds, String tableName) {
ArrayList<Table> tableList = new ArrayList<>();
if (!isTableToIgnore(tableName)) {
ArrayList<TablesColumn> tablesColumns = new ArrayList<>();
Connection conn;
Statement stmt;
ResultSet resultSet;
String colomneNameTemp;
try {
conn = ds.getConnection();
try {
stmt = conn.createStatement();
try {
// récupération des noms des colonnes de la table
// et sont type de données
String query = "SELECT COLUMN_NAME," + " data_type FROM INFORMATION_SCHEMA.COLUMNS" + " where TABLE_NAME='" + tableName + "'";
resultSet = stmt.executeQuery(query);
while (resultSet.next()) {
colomneNameTemp = resultSet.getString("COLUMN_NAME");
if (!isToIgnore(colomneNameTemp)) {
TablesColumn tablesColumn = new TablesColumn();
tablesColumn.setColumnName(colomneNameTemp);
tablesColumn.setColumnType(resultSet.getString("data_type"));
tablesColumns.add(tablesColumn);
}
}
// récupération des données de la table
query = "SELECT * FROM " + tableName;
resultSet = stmt.executeQuery(query);
while (resultSet.next()) {
Table table = new Table();
ArrayList<LineOfData> lineOfDatas = new ArrayList<>();
for (TablesColumn tablesColumn : tablesColumns) {
LineOfData lineOfData = new LineOfData();
lineOfData.setColomne(tablesColumn.getColumnName());
if (tablesColumn.getColumnType().equalsIgnoreCase("integer")) {
lineOfData.setValue("" + resultSet.getInt(tablesColumn.getColumnName()));
}
if (tablesColumn.getColumnType().equalsIgnoreCase("character varying")) {
lineOfData.setValue(resultSet.getString(tablesColumn.getColumnName()));
}
if (tablesColumn.getColumnType().equalsIgnoreCase("character")) {
lineOfData.setValue(resultSet.getString(tablesColumn.getColumnName()));
}
if (tablesColumn.getColumnType().equalsIgnoreCase("text")) {
lineOfData.setValue(resultSet.getString(tablesColumn.getColumnName()));
}
if (tablesColumn.getColumnType().equalsIgnoreCase("timestamp with time zone")) {
lineOfData.setValue("" + resultSet.getDate(tablesColumn.getColumnName()));
}
if (tablesColumn.getColumnType().equalsIgnoreCase("timestamp without time zone")) {
lineOfData.setValue("" + resultSet.getDate(tablesColumn.getColumnName()));
}
if (tablesColumn.getColumnType().equalsIgnoreCase("boolean")) {
lineOfData.setValue("" + resultSet.getBoolean(tablesColumn.getColumnName()));
}
if (tablesColumn.getColumnType().equalsIgnoreCase("USER-DEFINED")) {
lineOfData.setValue(resultSet.getString(tablesColumn.getColumnName()));
}
lineOfDatas.add(lineOfData);
}
table.setLineOfDatas(lineOfDatas);
tableList.add(table);
}
} finally {
stmt.close();
}
} finally {
conn.close();
}
} catch (SQLException ex) {
Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
}
}
return tableList;
}
Aggregations