Search in sources :

Example 6 with PropertyAccessException

use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.

the class JdbcPropertyStore method listPropertyNames.

/**
 * {@inheritDoc}
 */
public Set<String> listPropertyNames() {
    Set<String> propertyNames = new HashSet<String>();
    PreparedStatement ps = null;
    Connection sqlConn = null;
    ResultSet rs = null;
    try {
        sqlConn = getDataSource().getConnection();
        ps = buildStatement(sqlConn, getQueryBuilder().getAllPropertiesNames());
        rs = ps.executeQuery();
        while (rs.next()) {
            propertyNames.add(rs.getString(COL_PROPERTY_ID));
        }
    } catch (SQLException sqlEX) {
        throw new PropertyAccessException("Cannot read properties within database, SQL ERROR", sqlEX);
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeConnection(sqlConn);
    }
    return propertyNames;
}
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) HashSet(java.util.HashSet)

Example 7 with PropertyAccessException

use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.

the class PropertyStoreHttp method clear.

/**
 * {@inheritDoc}
 */
public void clear() {
    Util.assertHasLength(url);
    WebTarget wr = getJerseyClient().target(url).path(RESOURCE_PROPERTYSTORE).path(STORE_CLEAR);
    Response cRes = post(wr);
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new PropertyAccessException("Cannot clear property store - " + cRes.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) PropertyAccessException(org.ff4j.exception.PropertyAccessException) WebTarget(javax.ws.rs.client.WebTarget)

Example 8 with PropertyAccessException

use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.

the class PropertyStoreHttp method createSchema.

/**
 * {@inheritDoc}
 */
@Override
public void createSchema() {
    Util.assertHasLength(url);
    WebTarget wr = getJerseyClient().target(url).path(RESOURCE_PROPERTYSTORE).path(STORE_CREATESCHEMA);
    Response cRes = post(wr);
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new PropertyAccessException("Cannot clear property store - " + cRes.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) PropertyAccessException(org.ff4j.exception.PropertyAccessException) WebTarget(javax.ws.rs.client.WebTarget)

Example 9 with PropertyAccessException

use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.

the class JdbcPropertyStore method existProperty.

/**
 * {@inheritDoc}
 */
public boolean existProperty(String name) {
    Util.assertHasLength(name);
    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection sqlConn = null;
    try {
        sqlConn = getDataSource().getConnection();
        ps = buildStatement(sqlConn, getQueryBuilder().existProperty(), name);
        rs = ps.executeQuery();
        rs.next();
        return 1 == rs.getInt(1);
    } catch (SQLException sqlEX) {
        throw new PropertyAccessException("Cannot check feature existence, error related to database", sqlEX);
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeConnection(sqlConn);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JdbcUtils.closeResultSet(org.ff4j.utils.JdbcUtils.closeResultSet) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) PropertyAccessException(org.ff4j.exception.PropertyAccessException) PreparedStatement(java.sql.PreparedStatement)

Example 10 with PropertyAccessException

use of org.ff4j.exception.PropertyAccessException in project ff4j by ff4j.

the class JdbcPropertyStore method updateProperty.

/**
 * {@inheritDoc}
 */
public void updateProperty(String name, String newValue) {
    Util.assertHasLength(name);
    Connection sqlConn = null;
    PreparedStatement ps = null;
    try {
        sqlConn = getDataSource().getConnection();
        // Check existence
        Property<?> ab = readProperty(name);
        // Check new value validity
        ab.fromString(newValue);
        ps = buildStatement(sqlConn, getQueryBuilder().updateProperty(), newValue, name);
        ps.executeUpdate();
    } catch (SQLException sqlEX) {
        throw new PropertyAccessException("Cannot update property database, SQL ERROR", sqlEX);
    } finally {
        closeStatement(ps);
        closeConnection(sqlConn);
    }
}
Also used : 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