Search in sources :

Example 31 with FeatureAccessException

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;
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) ResultSet(java.sql.ResultSet) JdbcUtils.closeResultSet(org.ff4j.utils.JdbcUtils.closeResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 32 with FeatureAccessException

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);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) FeatureAccessException(org.ff4j.exception.FeatureAccessException) HBaseConnection(org.ff4j.hbase.HBaseConnection) Connection(org.apache.hadoop.hbase.client.Connection) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 33 with FeatureAccessException

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);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) FeatureAccessException(org.ff4j.exception.FeatureAccessException) Get(org.apache.hadoop.hbase.client.Get) HBaseConnection(org.ff4j.hbase.HBaseConnection) Connection(org.apache.hadoop.hbase.client.Connection) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Example 34 with FeatureAccessException

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;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) HBaseConnection(org.ff4j.hbase.HBaseConnection) Connection(org.apache.hadoop.hbase.client.Connection) Scan(org.apache.hadoop.hbase.client.Scan) IOException(java.io.IOException) Feature(org.ff4j.core.Feature) Result(org.apache.hadoop.hbase.client.Result)

Example 35 with FeatureAccessException

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);
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) JsonObject(com.couchbase.client.java.document.json.JsonObject) Feature(org.ff4j.core.Feature) FeatureAccessException(org.ff4j.exception.FeatureAccessException)

Aggregations

FeatureAccessException (org.ff4j.exception.FeatureAccessException)50 SQLException (java.sql.SQLException)18 Connection (java.sql.Connection)17 PreparedStatement (java.sql.PreparedStatement)16 Response (javax.ws.rs.core.Response)16 JdbcUtils.closeConnection (org.ff4j.utils.JdbcUtils.closeConnection)15 Feature (org.ff4j.core.Feature)11 ResultSet (java.sql.ResultSet)10 ClientResponse (com.sun.jersey.api.client.ClientResponse)9 JdbcUtils.closeResultSet (org.ff4j.utils.JdbcUtils.closeResultSet)8 HashMap (java.util.HashMap)7 FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)7 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)5 WebResource (com.sun.jersey.api.client.WebResource)4 HashSet (java.util.HashSet)4 FeatureJsonParser.parseFeature (org.ff4j.utils.json.FeatureJsonParser.parseFeature)4 IOException (java.io.IOException)3 Connection (org.apache.hadoop.hbase.client.Connection)3 Table (org.apache.hadoop.hbase.client.Table)3 HBaseConnection (org.ff4j.hbase.HBaseConnection)3