Search in sources :

Example 1 with PropertyAccessException

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) PropertyAccessException(org.ff4j.exception.PropertyAccessException)

Example 2 with PropertyAccessException

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

Example 3 with PropertyAccessException

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);
    }
}
Also used : PropertyNotFoundException(org.ff4j.exception.PropertyNotFoundException) 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) PropertyAccessException(org.ff4j.exception.PropertyAccessException) PreparedStatement(java.sql.PreparedStatement)

Example 4 with PropertyAccessException

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;
}
Also used : 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) PropertyAccessException(org.ff4j.exception.PropertyAccessException) PreparedStatement(java.sql.PreparedStatement) Property(org.ff4j.property.Property) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with PropertyAccessException

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);
    }
}
Also used : PropertyNotFoundException(org.ff4j.exception.PropertyNotFoundException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) PropertyAccessException(org.ff4j.exception.PropertyAccessException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

PropertyAccessException (org.ff4j.exception.PropertyAccessException)18 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 JdbcUtils.closeConnection (org.ff4j.utils.JdbcUtils.closeConnection)8 Response (javax.ws.rs.core.Response)5 ResultSet (java.sql.ResultSet)4 PropertyNotFoundException (org.ff4j.exception.PropertyNotFoundException)4 Property (org.ff4j.property.Property)4 JdbcUtils.closeResultSet (org.ff4j.utils.JdbcUtils.closeResultSet)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 WebTarget (javax.ws.rs.client.WebTarget)2 Connection (org.apache.hadoop.hbase.client.Connection)2 Table (org.apache.hadoop.hbase.client.Table)2 HBaseConnection (org.ff4j.hbase.HBaseConnection)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1