use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class JdbcPropertyStore method createProperty.
/**
* {@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);
}
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class JdbcPropertyStore method clear.
/**
* {@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);
}
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class PropertyStoreHBase method deleteProperty.
/**
* {@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);
}
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class PropertyStoreHttp method deleteProperty.
/**
* {@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);
}
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class PropertyStoreHttp method readAllProperties.
/**
* {@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;
}
Aggregations