private static void setTableAttributes(String location, DataStructureSchemaModel result, JsonObject structure, String type, DataStructureTableModel table) { table.setLocation(location); table.setName(structure.get("name").getAsString()); table.setType(type); table.setCreatedAt(result.getCreatedAt()); table.setCreatedBy(result.getCreatedBy()); table.setHash(result.getHash()); JsonElement columnElement = structure.get("columns"); if (columnElement.isJsonObject()) { JsonObject column = columnElement.getAsJsonObject(); DataStructureTableColumnModel columnModel = new DataStructureTableColumnModel(); setColumnAttributes(column, columnModel); table.getColumns().add(columnModel); } else if (columnElement.isJsonArray()) { JsonArray columns = columnElement.getAsJsonArray(); for (int j=0; j<columns.size(); j++) { JsonObject column = columns.get(j).getAsJsonObject(); DataStructureTableColumnModel columnModel = new DataStructureTableColumnModel(); setColumnAttributes(column, columnModel); table.getColumns().add(columnModel); } } else { throw new IllegalArgumentException(format("Error in parsing columns of table [{0}] in schema [{1}]", table.getName(), location)); } }
@Override public DataStructureTableModel createTable(String location, String name, String hash) throws DataStructuresException { DataStructureTableModel tableModel = new DataStructureTableModel(); tableModel.setLocation(location); tableModel.setName(name); tableModel.setType(IDataStructureModel.TYPE_TABLE); tableModel.setHash(hash); tableModel.setCreatedBy(UserFacade.getName()); tableModel.setCreatedAt(new Timestamp(new java.util.Date().getTime())); try { Connection connection = null; try { connection = dataSource.getConnection(); tablePersistenceManager.insert(connection, tableModel); return tableModel; } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }