use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class JdbcEventRepository method computeHitCount.
/**
* {@inheritDoc}
*/
private Map<String, MutableHitCount> computeHitCount(String sqlQuery, String columnName, long from, long to) {
Connection sqlConn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
try {
// Returns features
sqlConn = dataSource.getConnection();
ps = sqlConn.prepareStatement(sqlQuery);
ps.setTimestamp(1, new Timestamp(from));
ps.setTimestamp(2, new Timestamp(to));
rs = ps.executeQuery();
while (rs.next()) {
hitCount.put(rs.getString(columnName), new MutableHitCount(rs.getInt("NB")));
}
} catch (SQLException sqlEX) {
throw new FeatureAccessException(CANNOT_BUILD_PIE_CHART_FROM_REPOSITORY, sqlEX);
} finally {
closeResultSet(rs);
closeStatement(ps);
closeConnection(sqlConn);
}
return hitCount;
}
use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class FeatureStoreHBase method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(String uid) {
assertFeatureExist(uid);
try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) {
try (Table table = hbConn.getTable(FEATURES_TABLENAME)) {
List<Delete> list = new ArrayList<Delete>();
Delete del = new Delete(uid.getBytes());
list.add(del);
table.delete(list);
}
} catch (IOException e) {
throw new FeatureAccessException("Cannot delete feature ", e);
}
}
use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class FeatureStoreHBase method read.
/**
* {@inheritDoc}
*/
@Override
public Feature read(String uid) {
assertFeatureExist(uid);
try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) {
try (Table table = hbConn.getTable(FEATURES_TABLENAME)) {
Get queryByIdQuery = new Get(Bytes.toBytes(uid));
Result result = table.get(queryByIdQuery);
return MAPPER.fromStore(result);
}
} catch (IOException e) {
throw new FeatureAccessException("Cannot check feature existence", e);
}
}
use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class FeatureStoreHBase method readAll.
/**
* {@inheritDoc}
*/
@Override
public Map<String, Feature> readAll() {
Map<String, Feature> mapOfFeature = new HashMap<>();
try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) {
try (Table table = hbConn.getTable(FEATURES_TABLENAME)) {
Scan scan = new Scan();
scan.setCaching(100);
scan.setBatch(100);
scan.addFamily(B_FEATURES_CF_CORE);
scan.addFamily(B_FEATURES_CF_PROPERTIES);
try (ResultScanner resultScanner = table.getScanner(scan)) {
Iterator<Result> iterator = resultScanner.iterator();
while (iterator.hasNext()) {
Feature f = MAPPER.fromStore(iterator.next());
mapOfFeature.put(f.getUid(), f);
}
}
}
} catch (IOException e) {
throw new FeatureAccessException("Cannot read all features", e);
}
return mapOfFeature;
}
use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class FeatureCouchbaseMapper method toStore.
/**
* {@inheritDoc}
*/
@Override
public JsonDocument toStore(Feature feature) {
if (feature == null)
return null;
JsonObject jsonObject;
try {
jsonObject = TRANSCODER.stringToJsonObject(feature.toJson());
jsonObject.put("_class", Feature.class.getCanonicalName());
} catch (Exception e) {
throw new FeatureAccessException("Cannot parse the feature", e);
}
return JsonDocument.create(feature.getUid(), jsonObject);
}
Aggregations