use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method createTestCaseCountryPropertiesBatch.
@Override
public Answer createTestCaseCountryPropertiesBatch(List<TestCaseCountryProperties> listOfPropertiesToInsert) {
Answer answer = new Answer();
MessageEvent rs = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` , `Description`, `Type`");
query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`) ");
query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
for (TestCaseCountryProperties prop : listOfPropertiesToInsert) {
preStat.setString(1, prop.getTest());
preStat.setString(2, prop.getTestCase());
preStat.setString(3, prop.getCountry());
preStat.setString(4, prop.getProperty());
preStat.setString(5, prop.getDescription());
preStat.setString(6, prop.getType());
preStat.setString(7, prop.getDatabase());
preStat.setString(8, prop.getValue1());
preStat.setString(9, prop.getValue2());
preStat.setString(10, prop.getLength());
preStat.setInt(11, prop.getRowLimit());
preStat.setString(12, prop.getNature());
preStat.setInt(13, prop.getRetryNb());
preStat.setInt(14, prop.getRetryPeriod());
preStat.addBatch();
}
// executes the batch
preStat.executeBatch();
int[] affectedRows = preStat.executeBatch();
// verify if some of the statements failed
boolean someFailed = ArrayUtils.contains(affectedRows, 0) || ArrayUtils.contains(affectedRows, Statement.EXECUTE_FAILED);
if (someFailed == false) {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
rs.setDescription(rs.getDescription().replace("%ITEM%", "Property").replace("%OPERATION%", "CREATE"));
} else {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
rs.setDescription(rs.getDescription().replace("%ITEM%", "Property").replace("%OPERATION%", "CREATE").replace("%REASON%", "Some problem occurred while creating the new property! "));
}
} catch (SQLException exception) {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "It was not possible to update table."));
LOG.error("Unable to execute query : " + exception.toString());
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "It was not possible to update table."));
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
answer.setResultMessage(rs);
return answer;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method findListOfPropertyPerTestTestCase.
@Override
public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCase(String test, String testcase) {
List<TestCaseCountryProperties> list = null;
final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ?";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, test);
preStat.setString(2, testcase);
ResultSet resultSet = preStat.executeQuery();
try {
list = new ArrayList<TestCaseCountryProperties>();
while (resultSet.next()) {
String country = resultSet.getString("country");
String property = resultSet.getString("property");
String description = resultSet.getString("description");
String type = resultSet.getString("type");
String database = resultSet.getString("database");
String value1 = resultSet.getString("value1");
String value2 = resultSet.getString("value2");
String length = resultSet.getString("length");
int rowLimit = resultSet.getInt("rowLimit");
String nature = resultSet.getString("nature");
int retryNb = resultSet.getInt("RetryNb");
int retryPeriod = resultSet.getInt("RetryPeriod");
int cacheExpire = resultSet.getInt("CacheExpire");
list.add(factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn(exception.toString());
}
}
return list;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method findListOfPropertyPerTestTestCaseCountry.
@Override
public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCaseCountry(String test, String testcase, String country) {
List<TestCaseCountryProperties> list = null;
final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.test : " + test);
LOG.debug("SQL.param.testcase : " + testcase);
LOG.debug("SQL.param.country : " + country);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, test);
preStat.setString(2, testcase);
preStat.setString(3, country);
ResultSet resultSet = preStat.executeQuery();
try {
list = new ArrayList<TestCaseCountryProperties>();
while (resultSet.next()) {
String property = resultSet.getString("property");
String description = resultSet.getString("description");
String type = resultSet.getString("type");
String database = resultSet.getString("database");
String value1 = resultSet.getString("value1");
String value2 = resultSet.getString("value2");
String length = resultSet.getString("length");
int rowLimit = resultSet.getInt("rowLimit");
String nature = resultSet.getString("nature");
int retryNb = resultSet.getInt("RetryNb");
int retryPeriod = resultSet.getInt("RetryPeriod");
int cacheExpire = resultSet.getInt("CacheExpire");
list.add(factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
return list;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method findDistinctPropertiesOfTestCase.
@Override
public List<TestCaseCountryProperties> findDistinctPropertiesOfTestCase(String test, String testcase) {
List<TestCaseCountryProperties> listProperties = null;
final StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ?");
query.append(" group by HEX(`property`), `type`, `database`, HEX(`value1`) , HEX(`value2`) , `length`, `rowlimit`, `nature`");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, test);
preStat.setString(2, testcase);
ResultSet resultSet = preStat.executeQuery();
try {
listProperties = new ArrayList<TestCaseCountryProperties>();
while (resultSet.next()) {
String country = resultSet.getString("country");
String property = resultSet.getString("property");
String description = resultSet.getString("description");
String type = resultSet.getString("type");
String database = resultSet.getString("database");
String value1 = resultSet.getString("value1");
String value2 = resultSet.getString("value2");
String length = resultSet.getString("length");
int rowLimit = resultSet.getInt("rowLimit");
String nature = resultSet.getString("nature");
int retryNb = resultSet.getInt("RetryNb");
int retryPeriod = resultSet.getInt("RetryPeriod");
int cacheExpire = resultSet.getInt("CacheExpire");
listProperties.add(factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
return listProperties;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class FactoryTestCaseCountryProperties method create.
@Override
public TestCaseCountryProperties create(String test, String testCase, String country, String property, String description, String type, String database, String value1, String value2, String length, int rowLimit, String nature, int retryNb, int retryPeriod, int cacheExpire) {
TestCaseCountryProperties testCaseCountryProperties = new TestCaseCountryProperties();
testCaseCountryProperties.setTest(test);
testCaseCountryProperties.setTestCase(testCase);
testCaseCountryProperties.setCountry(country);
testCaseCountryProperties.setProperty(property);
testCaseCountryProperties.setDescription(description == null ? "" : description);
testCaseCountryProperties.setType(type);
testCaseCountryProperties.setDatabase(database);
testCaseCountryProperties.setValue1(value1);
testCaseCountryProperties.setValue2(value2);
testCaseCountryProperties.setLength(length);
testCaseCountryProperties.setRowLimit(rowLimit);
testCaseCountryProperties.setNature(nature);
testCaseCountryProperties.setRetryNb(retryNb);
testCaseCountryProperties.setRetryPeriod(retryPeriod);
testCaseCountryProperties.setCacheExpire(cacheExpire);
return testCaseCountryProperties;
}
Aggregations