/** {@inheritDoc} */ public void clear() { Util.assertHasLength(url); WebTarget wr = getJerseyClient().target(url).path(RESOURCE_PROPERTYSTORE).path(STORE_CLEAR); Response cRes = post(wr); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new PropertyAccessException("Cannot clear property store - " + cRes.getStatus()); } }
/** {@inheritDoc} */ @Override public void createSchema() { Util.assertHasLength(url); WebTarget wr = getJerseyClient().target(url).path(RESOURCE_PROPERTYSTORE).path(STORE_CREATESCHEMA); Response cRes = post(wr); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new PropertyAccessException("Cannot clear property store - " + cRes.getStatus()); } }
/** {@inheritDoc} */ public boolean existProperty(String name) { Util.assertHasLength(name); Response cRes = ClientHttpUtils.invokeGetMethod(getStore().path(name), authorization); if (Status.OK.getStatusCode() == cRes.getStatus()) { return true; } if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { return false; } throw new PropertyAccessException("Cannot check existence of property, an HTTP error " + cRes.getStatus() + " occured : " + cRes.getEntity()); }
/** {@inheritDoc} */ public void deleteProperty(String name) { Util.assertHasLength(name); Response cRes = ClientHttpUtils.invokeDeleteMethod(getStore().path(name), authorization); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new PropertyNotFoundException(name); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new PropertyAccessException("Cannot delete property, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** {@inheritDoc} */ public Map<String, Property<?>> readAllProperties() { Response cRes = ClientHttpUtils.invokeGetMethod(getStore(), authorization); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new PropertyAccessException("Cannot read properties, an HTTP error " + cRes.getStatus() + OCCURED); } String resEntity = cRes.readEntity(String.class); Property<?>[] pArray = PropertyJsonParser.parsePropertyArray(resEntity); Map<String, Property<?>> properties = new HashMap<String, Property<?>>(); for (Property<?> pName : pArray) { properties.put(pName.getName(), pName); } return properties; }
/** {@inheritDoc} */ @Override public void deleteProperty(String name) { assertPropertyExist(name); try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(PROPERTIES_TABLENAME)) { List<Delete> list = new ArrayList<Delete>(); Delete del = new Delete(name.getBytes()); list.add(del); table.delete(list); } } catch (IOException e) { throw new PropertyAccessException("Cannot delete property ", e); } }
/** {@inheritDoc} */ public Map<String, Property<?>> readAllProperties() { ClientResponse cRes = getStore().get(ClientResponse.class); if (Status.OK.getStatusCode() != cRes.getStatus()) { throw new PropertyAccessException("Cannot read properties, an HTTP error " + cRes.getStatus() + OCCURED); } String resEntity = cRes.getEntity(String.class); Property<?>[] pArray = PropertyJsonParser.parsePropertyArray(resEntity); Map<String, Property<?>> properties = new HashMap<String, Property<?>>(); for (Property<?> pName : pArray) { properties.put(pName.getName(), pName); } return properties; }
/** {@inheritDoc} */ @Override public boolean existProperty(String name) { Util.assertHasLength(name); try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(PROPERTIES_TABLENAME)) { return !table.get(new Get(Bytes.toBytes(name))).isEmpty(); } } catch (IOException e) { throw new PropertyAccessException("Cannot check property existence", e); } }
/** {@inheritDoc} */ public Set<String> listPropertyNames() { Set < String > propertyNames = new HashSet<String>(); PreparedStatement ps = null; Connection sqlConn = null; ResultSet rs = null; try { sqlConn = getDataSource().getConnection(); ps = buildStatement(sqlConn, getQueryBuilder().getAllPropertiesNames()); rs = ps.executeQuery(); while (rs.next()) { propertyNames.add(rs.getString(COL_PROPERTY_ID)); } } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot read properties within database, SQL ERROR", sqlEX); } finally { closeResultSet(rs); closeStatement(ps); closeConnection(sqlConn); } return propertyNames; }
/** {@inheritDoc} */ @Override public Property<?> readProperty(String name) { assertPropertyExist(name); try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(PROPERTIES_TABLENAME)) { Result result = table.get(new Get(Bytes.toBytes(name))); return MAPPER.fromStore(result); } } catch (IOException e) { throw new PropertyAccessException("Cannot read property", e); } }
/** {@inheritDoc} */ public void clear() { PreparedStatement ps = null; Connection sqlConn = null; try { sqlConn = getDataSource().getConnection(); ps = buildStatement(sqlConn, getQueryBuilder().deleteAllProperties()); ps.executeUpdate(); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot clear properties table, SQL ERROR", sqlEX); } finally { closeStatement(ps); closeConnection(sqlConn); } }
/** {@inheritDoc} */ public boolean existProperty(String name) { Util.assertHasLength(name); PreparedStatement ps = null; ResultSet rs = null; Connection sqlConn = null; try { sqlConn = getDataSource().getConnection(); ps = buildStatement(sqlConn, getQueryBuilder().existProperty(), name); rs = ps.executeQuery(); rs.next(); return 1 == rs.getInt(1); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot check feature existence, error related to database", sqlEX); } finally { closeResultSet(rs); closeStatement(ps); closeConnection(sqlConn); } }
/** {@inheritDoc} */ public void deleteProperty(String name) { Util.assertHasLength(name); ClientResponse cRes = getStore().path(name).delete(ClientResponse.class); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new PropertyNotFoundException(name); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new PropertyAccessException("Cannot delete property, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** * PUT query. * * @param putQuery * query to insert into data */ private void executePutCommand(Put putQuery) { try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(PROPERTIES_TABLENAME)) { table.put(putQuery); } } catch (IOException e) { throw new PropertyAccessException("Cannot execute command", e); } }
/** {@inheritDoc} */ public boolean existProperty(String name) { Util.assertHasLength(name); ClientResponse cRes = getStore().path(name).get(ClientResponse.class); if (Status.OK.getStatusCode() == cRes.getStatus()) { return true; } if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { return false; } throw new PropertyAccessException("Cannot check existence of property, an HTTP error " + cRes.getStatus() + " occured : " + cRes.getEntityInputStream()); }
/** {@inheritDoc} */ @Override public Map<String, Property<?>> readAllProperties() { Map<String, Property<?>> properties = new LinkedHashMap<String, Property<?>>(); Connection sqlConn = null; PreparedStatement ps = null; ResultSet rs = null; try { sqlConn = getDataSource().getConnection(); ps = buildStatement(sqlConn, getQueryBuilder().getAllProperties()); rs = ps.executeQuery(); while (rs.next()) { Property<?> ap = JDBC_MAPPER.map(rs); properties.put(ap.getName(),ap); } } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot read properties within database, SQL ERROR", sqlEX); } finally { closeResultSet(rs); closeStatement(ps); closeConnection(sqlConn); } return properties; }
/** {@inheritDoc} */ public <T> void createProperty(Property<T> ap) { Util.assertNotNull(ap); Connection sqlConn = null; PreparedStatement ps = null; try { sqlConn = getDataSource().getConnection(); if (existProperty(ap.getName())) { throw new PropertyAlreadyExistException(ap.getName()); } ps = sqlConn.prepareStatement(getQueryBuilder().createProperty()); ps.setString(1, ap.getName()); ps.setString(2, ap.getType()); ps.setString(3, ap.asString()); ps.setString(4, ap.getDescription()); if (ap.getFixedValues() != null && !ap.getFixedValues().isEmpty()) { String fixedValues = ap.getFixedValues().toString(); ps.setString(5, fixedValues.substring(1, fixedValues.length() - 1)); } else { ps.setString(5, null); } ps.executeUpdate(); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot update properties database, SQL ERROR", sqlEX); } finally { // Connection is closed alse here within clos statement closeStatement(ps); closeConnection(sqlConn); } }
/** {@inheritDoc} */ @Override public Map<String, Property<?>> readAllProperties() { Map<String, Property<?>> mapOfProperty = new HashMap<>(); try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(PROPERTIES_TABLENAME)) { Scan scan = new Scan(); scan.setCaching(100); scan.setBatch(100); scan.addFamily(B_FEATURES_CF_PROPERTIES); try(ResultScanner resultScanner = table.getScanner(scan)) { Iterator<Result> iterator = resultScanner.iterator(); while (iterator.hasNext()) { Property<?> p = MAPPER.fromStore(iterator.next()); mapOfProperty.put(p.getName(), p); } } } } catch (IOException e) { throw new PropertyAccessException("Cannot read all property", e); } return mapOfProperty; }
/** {@inheritDoc} */ public void updateProperty(String name, String newValue) { Util.assertHasLength(name); Connection sqlConn = null; PreparedStatement ps = null; try { sqlConn = getDataSource().getConnection(); // Check existence Property<?> ab = readProperty(name); // Check new value validity ab.fromString(newValue); ps = buildStatement(sqlConn, getQueryBuilder().updateProperty(), newValue, name); ps.executeUpdate(); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot update property database, SQL ERROR", sqlEX); } finally { closeStatement(ps); closeConnection(sqlConn); } }
/** {@inheritDoc} */ public void deleteProperty(String name) { Util.assertHasLength(name); Connection sqlConn = null; PreparedStatement ps = null; try { sqlConn = getDataSource().getConnection(); if (!existProperty(name)) { throw new PropertyNotFoundException(name); } ps = buildStatement(sqlConn, getQueryBuilder().deleteProperty(), name); ps.executeUpdate(); } catch (SQLException sqlEX) { throw new PropertyAccessException("Cannot delete property database, SQL ERROR", sqlEX); } finally { closeStatement(ps); closeConnection(sqlConn); } }