/** * Creates a table model from the raw content. * * @param content * the table definition * @return the table model instance */ public static DataStructureTableModel parseTable(String content) { DataStructureTableModel result = GsonHelper.GSON.fromJson(content, DataStructureTableModel.class); result.setHash(DigestUtils.md5Hex(content)); return result; }
/** * Creates a table model from the raw content. * * @param bytes * the table definition * @return the table model instance */ public static DataStructureTableModel parseTable(byte[] bytes) { DataStructureTableModel result = GsonHelper.GSON.fromJson( new InputStreamReader(new ByteArrayInputStream(bytes), StandardCharsets.UTF_8), DataStructureTableModel.class); result.setHash(DigestUtils.md5Hex(bytes)); return result; }
@Override public void updateTable(String location, String name, String hash) throws DataStructuresException { try { Connection connection = null; try { connection = dataSource.getConnection(); DataStructureTableModel tableModel = getTable(location); tableModel.setName(name); tableModel.setHash(hash); tablePersistenceManager.update(connection, tableModel); } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }
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); } }