use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class PropertyStoreHttp method existProperty.
/**
* {@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());
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class PropertyStoreHBase method readAllProperties.
/**
* {@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;
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class JdbcPropertyStore method readProperty.
/**
* {@inheritDoc}
*/
public Property<?> readProperty(String name) {
Util.assertHasLength(name);
Connection sqlConn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
sqlConn = getDataSource().getConnection();
if (!existProperty(name)) {
throw new PropertyNotFoundException(name);
}
// Returns features
ps = buildStatement(sqlConn, getQueryBuilder().getProperty(), name);
rs = ps.executeQuery();
rs.next();
return JDBC_MAPPER.map(rs);
} catch (SQLException sqlEX) {
throw new PropertyAccessException("Cannot check property existence, error related to database", sqlEX);
} finally {
closeResultSet(rs);
closeStatement(ps);
closeConnection(sqlConn);
}
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class JdbcPropertyStore method readAllProperties.
/**
* {@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;
}
use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.
the class JdbcPropertyStore method deleteProperty.
/**
* {@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);
}
}
Aggregations