Search in sources :

Example 41 with FeatureAccessException

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

the class PropertyStoreHttp method createProperty.

/**
 * {@inheritDoc}
 */
public <T> void createProperty(Property<T> value) {
    Util.assertNotNull(value);
    Util.assertHasLength(value.getName());
    if (existProperty(value.getName())) {
        throw new PropertyAlreadyExistException("Property already exist");
    }
    ClientResponse cRes = // 
    getStore().path(value.getName()).type(// 
    MediaType.APPLICATION_JSON).put(ClientResponse.class, new PropertyApiBean(value));
    // Check response code CREATED or raised error
    if (Status.CREATED.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot create properties, an HTTP error " + cRes.getStatus() + OCCURED);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) PropertyApiBean(org.ff4j.web.api.resources.domain.PropertyApiBean) FeatureAccessException(org.ff4j.exception.FeatureAccessException) PropertyAlreadyExistException(org.ff4j.exception.PropertyAlreadyExistException)

Example 42 with FeatureAccessException

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

the class PropertyStoreHttp method createSchema.

/**
 * {@inheritDoc}
 */
@Override
public void createSchema() {
    Util.assertHasLength(url);
    WebResource wr = getJerseyClient().resource(url).path(RESOURCE_STORE).path(STORE_CREATESCHEMA);
    if (null != authorization) {
        wr.header(HEADER_AUTHORIZATION, authorization);
    }
    ClientResponse cRes = wr.post(ClientResponse.class);
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot create schema for property store - " + cRes.getStatus());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) WebResource(com.sun.jersey.api.client.WebResource)

Example 43 with FeatureAccessException

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

the class JdbcFeatureDataSourceTest method testClosess.

@Test
public void testClosess() {
    Connection sqlConn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        // Pick connection
        sqlConn = sqlDataSource.getConnection();
        // Query Exist
        ps = JdbcUtils.buildStatement(sqlConn, SQL_EXIST, F1);
        JdbcUtils.rollback(sqlConn);
        ps.close();
    // rs = ps.executeQuery();
    } catch (SQLException sqlEX) {
        throw new FeatureAccessException("Cannot check feature existence, error related to database", sqlEX);
    } finally {
        closeResultSet(rs);
        closeResultSet(rs);
        closeResultSet(null);
        closeStatement(ps);
        closeStatement(ps);
        closeStatement(null);
        closeConnection(sqlConn);
        closeConnection(sqlConn);
        closeConnection(null);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) 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) Test(org.junit.Test)

Example 44 with FeatureAccessException

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

the class JdbcUtils method isTableExist.

/**
 * Check if target Table exist.
 *
 * @param ds the ds
 * @param tableName      table to create
 * @param schemaPattern the schema
 * @return      if the table exist or not
 */
public static boolean isTableExist(DataSource ds, String tableName, String schemaPattern) {
    Util.assertHasLength(tableName);
    Connection sqlConn = null;
    ResultSet rs = null;
    try {
        sqlConn = ds.getConnection();
        DatabaseMetaData dbmd = sqlConn.getMetaData();
        if (dbmd.storesLowerCaseIdentifiers()) {
            tableName = tableName.toLowerCase();
        }
        rs = dbmd.getTables(null, schemaPattern, tableName, new String[] { "TABLE" });
        return rs.next();
    } catch (SQLException sqlEX) {
        throw new FeatureAccessException("Cannot check table existence", sqlEX);
    } finally {
        closeResultSet(rs);
        closeConnection(sqlConn);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 45 with FeatureAccessException

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

the class JdbcUtils method executeUpdate.

/**
 * Create table based on SQL.
 *
 * @param sqlQuery
 *      sql query
 */
public static void executeUpdate(DataSource ds, String sqlQuery) {
    Util.assertHasLength(sqlQuery);
    Connection sqlConn = null;
    Statement sqlStmt = null;
    try {
        // Create connection
        sqlConn = ds.getConnection();
        sqlStmt = sqlConn.createStatement();
        sqlStmt.executeUpdate(sqlQuery);
    } catch (SQLException sqlEX) {
        rollback(sqlConn);
        throw new FeatureAccessException("Cannot execute SQL " + sqlQuery, sqlEX);
    } finally {
        closeStatement(sqlStmt);
        closeConnection(sqlConn);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection)

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