/** * Creates a view model from the raw content. * * @param content * the view definition * @return the view model instance */ public static DataStructureViewModel parseView(String content) { DataStructureViewModel result = GsonHelper.GSON.fromJson(content, DataStructureViewModel.class); result.setHash(DigestUtils.md5Hex(content)); return result; }
/** * Creates a view model from the raw content. * * @param bytes * the view definition * @return the view model instance */ public static DataStructureViewModel parseView(byte[] bytes) { DataStructureViewModel result = GsonHelper.GSON.fromJson( new InputStreamReader(new ByteArrayInputStream(bytes), StandardCharsets.UTF_8), DataStructureViewModel.class); result.setHash(DigestUtils.md5Hex(bytes)); return result; }
private static void setViewAttributes(String location, DataStructureSchemaModel result, JsonObject structure, String type, DataStructureViewModel view) { view.setLocation(location); view.setName(structure.get("name").getAsString()); view.setType(type); view.setQuery(structure.get("columns").getAsJsonArray().get(0).getAsJsonObject().get("query").getAsString()); view.setCreatedAt(result.getCreatedAt()); view.setCreatedBy(result.getCreatedBy()); view.setHash(result.getHash()); }
@Override public void updateView(String location, String name, String hash) throws DataStructuresException { try { Connection connection = null; try { connection = dataSource.getConnection(); DataStructureViewModel viewModel = getView(location); viewModel.setName(name); viewModel.setHash(hash); viewPersistenceManager.update(connection, viewModel); } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }
@Override public DataStructureViewModel createView(String location, String name, String hash) throws DataStructuresException { DataStructureViewModel viewModel = new DataStructureViewModel(); viewModel.setLocation(location); viewModel.setName(name); viewModel.setType(IDataStructureModel.TYPE_VIEW); viewModel.setHash(hash); viewModel.setCreatedBy(UserFacade.getName()); viewModel.setCreatedAt(new Timestamp(new java.util.Date().getTime())); try { Connection connection = null; try { connection = dataSource.getConnection(); viewPersistenceManager.insert(connection, viewModel); return viewModel; } finally { if (connection != null) { connection.close(); } } } catch (SQLException e) { throw new DataStructuresException(e); } }