Search in sources :

Example 1 with PropertyNotFoundException

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

the class PropertyStoreAwsSSM method createOrUpdate.

private <T> void createOrUpdate(Property<T> property, boolean overwrite) {
    Util.assertNotNull(property);
    Util.assertHasLength(property.getName());
    if (overwrite && !existProperty(property.getName())) {
        throw new PropertyNotFoundException(property.getName());
    }
    try {
        client.putParameter(builder -> builder.name(path + "/" + property.getName()).type(ParameterType.STRING).value(property.asString()).overwrite(overwrite).description(property.getDescription()));
    } catch (ParameterAlreadyExistsException pae) {
        throw new PropertyAlreadyExistException(property.getName());
    }
}
Also used : PropertyNotFoundException(org.ff4j.exception.PropertyNotFoundException) PropertyAlreadyExistException(org.ff4j.exception.PropertyAlreadyExistException)

Example 2 with PropertyNotFoundException

use of org.ff4j.exception.PropertyNotFoundException 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 3 with PropertyNotFoundException

use of org.ff4j.exception.PropertyNotFoundException 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)

Example 4 with PropertyNotFoundException

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

the class PropertyStoreHttp method readProperty.

/**
 * {@inheritDoc}
 */
public Property<?> readProperty(String name) {
    if (name == null || name.isEmpty()) {
        throw new IllegalArgumentException("Property name cannot be null nor empty");
    }
    Response cRes = ClientHttpUtils.invokeGetMethod(getStore().path(name), authorization);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new PropertyNotFoundException(name);
    }
    String resEntity = (String) cRes.readEntity(String.class);
    return PropertyJsonParser.parseProperty(resEntity);
}
Also used : Response(javax.ws.rs.core.Response) PropertyNotFoundException(org.ff4j.exception.PropertyNotFoundException)

Example 5 with PropertyNotFoundException

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

the class PropertyStoreCommonsConfig method readProperty.

/**
 * {@inheritDoc}
 */
@Override
public Property<?> readProperty(String name) {
    Util.assertHasLength(name);
    String value = conf().getString(name);
    if (value == null) {
        throw new PropertyNotFoundException(name);
    }
    return new PropertyString(name, value);
}
Also used : PropertyString(org.ff4j.property.PropertyString) PropertyNotFoundException(org.ff4j.exception.PropertyNotFoundException) PropertyString(org.ff4j.property.PropertyString)

Aggregations

PropertyNotFoundException (org.ff4j.exception.PropertyNotFoundException)8 PropertyAccessException (org.ff4j.exception.PropertyAccessException)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 Response (javax.ws.rs.core.Response)2 JdbcUtils.closeConnection (org.ff4j.utils.JdbcUtils.closeConnection)2 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 ResultSet (java.sql.ResultSet)1 PropertyAlreadyExistException (org.ff4j.exception.PropertyAlreadyExistException)1 PropertyString (org.ff4j.property.PropertyString)1 JdbcUtils.closeResultSet (org.ff4j.utils.JdbcUtils.closeResultSet)1