use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class TestDataLibDataDAO method readByVarious.
@Override
public AnswerList<TestDataLibData> readByVarious(Integer testDataLibID, String columnEmpty, String parsingAnswerEmpty, String columnPositionEmpty) {
List<TestDataLibData> testDataLibListData = new ArrayList<TestDataLibData>();
AnswerList answer = new AnswerList();
MessageEvent msg;
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testdatalibdata where `testDataLibID` = ? ");
if ("Y".equalsIgnoreCase(columnEmpty)) {
query.append(" and `Column`='' ");
} else if ("N".equalsIgnoreCase(columnEmpty)) {
query.append(" and `Column`!='' ");
}
if ("Y".equalsIgnoreCase(parsingAnswerEmpty)) {
query.append(" and `ParsingAnswer`='' ");
} else if ("N".equalsIgnoreCase(parsingAnswerEmpty)) {
query.append(" and `ParsingAnswer`!='' ");
}
if ("Y".equalsIgnoreCase(columnPositionEmpty)) {
query.append(" and `columnPosition`='' ");
} else if ("N".equalsIgnoreCase(columnPositionEmpty)) {
query.append(" and `columnPosition`!='' ");
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.testDataLibID : " + testDataLibID);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
preStat.setInt(1, testDataLibID);
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
testDataLibListData.add(this.loadFromResultSet(resultSet));
}
if (testDataLibListData.isEmpty()) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
testDataLibListData.clear();
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
testDataLibListData.clear();
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
testDataLibListData.clear();
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException ex) {
LOG.warn("Unable to close connection : " + ex.toString());
}
}
answer.setDataList(testDataLibListData);
answer.setTotalRows(testDataLibListData.size());
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class TestDataLibDataDAO method readByName.
@Override
public AnswerList readByName(String testDataLibName) {
AnswerList answer = new AnswerList();
MessageEvent msg;
List<TestDataLibData> testDataLibListData = new ArrayList<TestDataLibData>();
StringBuilder query = new StringBuilder();
query.append("SELECT tdld.*, tdl.`name`, tdl.type, tdl.system, tdl.country, tdl.environment FROM testdatalibdata tdld ");
query.append("inner join testdatalib tdl ");
query.append("on tdld.testDataLibID = tdl.testDataLibID ");
query.append("and tdl.`name` LIKE ? ");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.testDataLibName : " + testDataLibName);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
preStat.setString(1, testDataLibName);
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
testDataLibListData.add(this.loadFromResultSet(resultSet));
}
if (testDataLibListData.isEmpty()) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException ex) {
LOG.warn("Unable to close connection : " + ex.toString());
}
}
answer.setResultMessage(msg);
answer.setDataList(testDataLibListData);
// all lines are retrieved
answer.setTotalRows(testDataLibListData.size());
return answer;
}
use of org.cerberus.crud.entity.TestDataLibData in project cerberus-source by cerberustesting.
the class XMLTestDataLibHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equalsIgnoreCase(TESTDATALIB)) {
dataItem = new TestDataLib();
// temporary ID
dataItem.setTestDataLibID(dataFromFile.size());
} else if (qName.equalsIgnoreCase(TESTDATALIBDATASET)) {
currentList = new ArrayList<TestDataLibData>();
} else if (qName.equalsIgnoreCase(TESTDATALIBDATA)) {
subDataItem = new TestDataLibData();
subDataItem.setTestDataLibID(dataFromFile.size());
}
currentElement = qName;
}
Aggregations