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);
}
}
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());
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations