Modified CommentDAOImpl

Reformatted
feature/appm-store/pbac
nishadi 7 years ago
parent c35ccf9888
commit 30ae09b067

@ -51,25 +51,24 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
throws CommentManagementException, DBConnectionException, SQLException { throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add comment for application release ("+uuid+")"); log.debug("Request received in DAO Layer to add comment for application release (" + uuid + ")");
} }
Connection conn=this.getDBConnection(); Connection conn = this.getDBConnection();
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs=null; ResultSet rs = null;
int commentId = -1; int commentId = -1;
String sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + String sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID,"
"AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + + "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
"(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));";
try{ try {
stmt = conn.prepareStatement(sql,new String[] {"id"}); stmt = conn.prepareStatement(sql, new String[] { "id" });
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setString(2, comment.getComment()); stmt.setString(2, comment.getComment());
stmt.setString(3,createdBy); stmt.setString(3, createdBy);
stmt.setInt(4,parentId); stmt.setInt(4, parentId);
stmt.setString(5,uuid); stmt.setString(5, uuid);
stmt.setString(6,uuid); stmt.setString(6, uuid);
stmt.executeUpdate(); stmt.executeUpdate();
rs = stmt.getGeneratedKeys(); rs = stmt.getGeneratedKeys();
if (rs.next()) { if (rs.next()) {
commentId = rs.getInt(1); commentId = rs.getInt(1);
@ -81,37 +80,35 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
} }
@Override @Override
public int addComment(int tenantId,Comment comment, String createdBy, String appType, String appName, public int addComment(int tenantId, Comment comment, String createdBy, String appType, String appName,
String version) throws CommentManagementException, DBConnectionException, SQLException { String version) throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add to application ("+appName+") and version ("+version+")"); log.debug("Request received in DAO Layer to add to application (" + appName + ") and version (" + version
+ ")");
} }
Connection conn = this.getDBConnection();
Connection conn=this.getDBConnection();
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
int commentId = -1; int commentId = -1;
String sql = "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + String sql = "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) "
"VALUES (?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE VERSION =? AND (SELECT ID FROM AP_APP WHERE " + + "VALUES (?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE VERSION =? AND (SELECT ID FROM AP_APP WHERE "
"TYPE=? AND NAME=?)),(SELECT ID FROM AP_APP WHERE TYPE=? AND NAME=?));"; + "TYPE=? AND NAME=?)),(SELECT ID FROM AP_APP WHERE TYPE=? AND NAME=?));";
try{ try {
stmt = conn.prepareStatement(sql, new String[] {"id"}); stmt = conn.prepareStatement(sql, new String[] { "id" });
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setString(2, comment.getComment()); stmt.setString(2, comment.getComment());
stmt.setString(3,createdBy); stmt.setString(3, createdBy);
stmt.setString(4,version); stmt.setString(4, version);
stmt.setString(5,appType); stmt.setString(5, appType);
stmt.setString(6,appName); stmt.setString(6, appName);
stmt.setString(7,appType); stmt.setString(7, appType);
stmt.setString(8,appName); stmt.setString(8, appName);
stmt.executeUpdate(); stmt.executeUpdate();
rs = stmt.getGeneratedKeys(); rs = stmt.getGeneratedKeys();
if (rs.next()) { if (rs.next()) {
commentId = rs.getInt(1); commentId = rs.getInt(1);
} }
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
@ -119,17 +116,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
} }
@Override @Override
public Comment updateComment(int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) public Comment updateComment(int CommentId, String updatedComment, String modifiedBy,
throws CommentManagementException, DBConnectionException, SQLException { Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to update the comment with ID ("+ CommentId +")"); log.debug("Request received in DAO Layer to update the comment with ID (" + CommentId + ")");
} }
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;"; String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
@ -137,38 +132,34 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
statement.setString(1, updatedComment); statement.setString(1, updatedComment);
statement.setString(2, modifiedBy); statement.setString(2, modifiedBy);
statement.setInt(3, CommentId); statement.setInt(3, CommentId);
statement.executeUpdate(); statement.executeUpdate();
rs = statement.executeQuery(); rs = statement.executeQuery();
} finally { } finally {
Util.cleanupResources(statement, rs); Util.cleanupResources(statement, rs);
} }
return getComment(CommentId); return getComment(CommentId);
} }
public Comment updateComment(String uuid, int CommentId,String updatedComment, String modifiedBy, Timestamp @Override
modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { public Comment updateComment(String uuid, int CommentId, String updatedComment, String modifiedBy,
Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to update the comment with application ("+uuid+") and " + log.debug("Request received in DAO Layer to update the comment with application (" + uuid + ") and "
"comment id ( "+ CommentId +")"); + "comment id ( " + CommentId + ")");
} }
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; "; String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; ";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, updatedComment); statement.setString(1, updatedComment);
statement.setString(2,modifiedBy); statement.setString(2, modifiedBy);
statement.setInt(3, CommentId); statement.setInt(3, CommentId);
statement.executeUpdate(); statement.executeUpdate();
rs= statement.getResultSet(); rs = statement.getResultSet();
} finally { } finally {
Util.cleanupResources(statement, rs); Util.cleanupResources(statement, rs);
} }
@ -177,24 +168,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
@Override @Override
public Comment getComment(int CommentId) throws CommentManagementException { public Comment getComment(int CommentId) throws CommentManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comment with the comment id(" + CommentId + ") from the database"); log.debug("Getting comment with the comment id(" + CommentId + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs ; ResultSet rs;
String sql = ""; String sql = "";
Comment comment=new Comment(); Comment comment = new Comment();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, CommentId); stmt.setInt(1, CommentId);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -203,15 +192,14 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("MODEFIED_AT")); comment.setModifiedBy(rs.getString("MODEFIED_AT"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
Util.cleanupResources(stmt, rs);
Util.cleanupResources(stmt,rs);
return comment; return comment;
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new CommentManagementException("Error occurred while retrieving information of the comment "+ CommentId, e); throw new CommentManagementException(
"SQL Error occurred while retrieving information of the comment " + CommentId, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurred while retrieving information of the comment " + CommentId, e);
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
@ -222,26 +210,23 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
public List<Comment> getComment(String uuid) throws CommentManagementException{ public List<Comment> getComment(String uuid) throws CommentManagementException{
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comment with the application release(" +uuid + ") from the database"); log.debug("Getting comment with the application release(" + uuid + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs ; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments=new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND " + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND "
"(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?);"; + "(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?);";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid); stmt.setString(1, uuid);
stmt.setString(2,uuid); stmt.setString(2, uuid);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -250,7 +235,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("MODEFIED_AT")); comment.setModifiedBy(rs.getString("MODEFIED_AT"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -264,30 +248,28 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
} }
@Override @Override
public List<Comment> getAllComments(String uuid,PaginationRequest request) throws CommentManagementException, SQLException, public List<Comment> getAllComments(String uuid, PaginationRequest request)
DBConnectionException { throws CommentManagementException, SQLException, DBConnectionException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release ("+uuid+") from the database"); log.debug("Getting comment of the application release (" + uuid + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
List<Comment> comments=new ArrayList<>(); List<Comment> comments = new ArrayList<>();
String sql = ""; String sql = "";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "\n" + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID "
"SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID " + + "AND AP_APP_RELEASE.UUID =? LIMIT ? OFFSET ?;";
"AND AP_APP_RELEASE.UUID =? LIMIT ? OFFSET ?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1,uuid); stmt.setString(1, uuid);
stmt.setInt(2,request.getLimit()); stmt.setInt(2, request.getLimit());
stmt.setInt(3,request.getOffSet()); stmt.setInt(3, request.getOffSet());
rs= stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -296,7 +278,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("MODEFIED_BY")); comment.setModifiedBy(rs.getString("MODEFIED_BY"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -312,22 +293,19 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
boolean isUuidProvided=false; boolean isUuidProvided = false;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
if (uuid!= null) { if (uuid != null) {
isUuidProvided = true; isUuidProvided = true;
} }
if (isUuidProvided) { if (isUuidProvided) {
String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE "
"WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND " + + "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND "
"AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; + "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid); stmt.setString(1, uuid);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
commentCount = rs.getInt("COMMENTS_COUNT"); commentCount = rs.getInt("COMMENTS_COUNT");
} }
@ -346,26 +324,23 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
public List<Comment> getComments(int appReleasedId, int appId) throws CommentManagementException { public List<Comment> getComments(int appReleasedId, int appId) throws CommentManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the application release id(" + appReleasedId + ") and " + log.debug("Getting comments with the application release id(" + appReleasedId + ") and " + "application id("
"application id("+appId+") from the database"); + appId + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs ; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, appReleasedId); stmt.setInt(1, appReleasedId);
stmt.setInt(2,appId); stmt.setInt(2, appId);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -374,15 +349,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurred while retrieving information of comments", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new CommentManagementException("Error occurred while retrieving information of comments", e); throw new CommentManagementException("SQL Error occurred while retrieving information of comments", e);
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
@ -392,32 +364,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
@Override @Override
public List<Comment> getComments(String appType, String appName, String version) throws CommentManagementException, public List<Comment> getComments(String appType, String appName, String version) throws CommentManagementException,
DBConnectionException, SQLException { DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the application name(" + appName + "),application type("+appType+") " + log.debug("Getting comments with the application name(" + appName + "),application type(" + appType + ") "
"and application version ("+version+") from the database"); + "and application version (" + version + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments =new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT C ,"+ sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT C ,"
"(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=?) R,"+ + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=?) R,"
"(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P"+ + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P"
" WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID"+ + " WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID"
"ORDER BY CREATED_AT DESC;"; + "ORDER BY CREATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, version); stmt.setString(1, version);
stmt.setString(2,appName); stmt.setString(2, appName);
stmt.setString(3,appType); stmt.setString(3, appType);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -426,7 +396,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -442,23 +411,19 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the tenant_id(" + tenantId + ") from the database"); log.debug("Getting comments with the tenant_id(" + tenantId + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE TENANT_ID='?';"; sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE TENANT_ID='?';";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -467,7 +432,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -483,24 +447,20 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the created by(" + createdBy + ") from the database"); log.debug("Getting comments with the created by(" + createdBy + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?" + sql += "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?"
" ORDER BY CREATED_AT DESC;"; + " ORDER BY CREATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, createdBy); stmt.setString(1, createdBy);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -509,7 +469,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -523,27 +482,24 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
DBConnectionException, SQLException { DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the created by(" + createdBy + ") at ("+createdAt+") from the database"); log.debug(
"Getting comments with the created by(" + createdBy + ") at (" + createdAt + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?" + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?"
"AND CREATED_AT= ? ORDER BY CREATED_AT DESC;"; + "AND CREATED_AT= ? ORDER BY CREATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, createdBy); stmt.setString(1, createdBy);
stmt.setTimestamp(2,createdAt); stmt.setTimestamp(2, createdAt);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -552,7 +508,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -566,26 +521,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
DBConnectionException, SQLException { DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the modified by(" +modifiedBy + ") from the database"); log.debug("Getting comments with the modified by(" + modifiedBy + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs ; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT " + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT "
"WHERE MODEFIED_BY= ? ORDER BY CREATED_AT DESC;"; + "WHERE MODEFIED_BY= ? ORDER BY CREATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, modifiedBy); stmt.setString(1, modifiedBy);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -594,7 +545,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -608,28 +558,24 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
throws CommentManagementException, DBConnectionException, SQLException { throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the modified by(" +modifiedBy + ") at ("+modifiedAt+") from the " + log.debug("Getting comments with the modified by(" + modifiedBy + ") at (" + modifiedAt + ") from the "
"database"); + "database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?," + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?,"
"MODEFIED_AT=? ORDER BY CREATED_AT DESC;"; + "MODEFIED_AT=? ORDER BY CREATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, modifiedBy); stmt.setString(1, modifiedBy);
stmt.setTimestamp(2,modifiedAt); stmt.setTimestamp(2, modifiedAt);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -638,7 +584,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -652,33 +597,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
throws CommentManagementException, DBConnectionException, SQLException { throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comments with the application name(" + appName + "),application type("+appType+") and" + log.debug(
"application version ("+version+") from the database"); "Getting comments with the application name(" + appName + "),application type(" + appType + ") and"
+ "application version (" + version + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
String sql = ""; String sql = "";
List<Comment> comments =new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql += "SELECT COMMENT_TEXT,TENANT_ID FROM AP_APP_COMMENT C ," + sql += "SELECT COMMENT_TEXT,TENANT_ID FROM AP_APP_COMMENT C ,"
"(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? ) " + + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? ) "
"R,(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P " + + "R,(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P "
"WHERE PARENT_ID=? AND AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND " + + "WHERE PARENT_ID=? AND AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND "
"AP_APP_ID=RELEASE_AP_APP_ID ORDER BY CREATED_AT DESC;"; + "AP_APP_ID=RELEASE_AP_APP_ID ORDER BY CREATED_AT DESC;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, version); stmt.setString(1, version);
stmt.setString(2,appName); stmt.setString(2, appName);
stmt.setString(3,appType); stmt.setString(3, appType);
stmt.setInt(4,parentId); stmt.setInt(4, parentId);
rs=stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Comment comment=new Comment(); Comment comment = new Comment();
comment.setId(rs.getInt("ID")); comment.setId(rs.getInt("ID"));
comment.setTenantId(rs.getInt("TENANT_ID")); comment.setTenantId(rs.getInt("TENANT_ID"));
comment.setComment(rs.getString("COMMENT_TEXT")); comment.setComment(rs.getString("COMMENT_TEXT"));
@ -687,7 +629,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
comment.setModifiedBy(rs.getString("modifiedBy")); comment.setModifiedBy(rs.getString("modifiedBy"));
comment.setParent(rs.getInt("PARENT_ID")); comment.setParent(rs.getInt("PARENT_ID"));
comments.add(comment); comments.add(comment);
} }
} finally { } finally {
@ -699,17 +640,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
@Override @Override
public int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, public int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException,
SQLException { SQLException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int commentCount = 0; int commentCount = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "\n" + String sql = "\n" + "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE "
"SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_COMMENT.AP_APP_ID="
"AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_COMMENT.AP_APP_ID=" + + "AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
"AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid); stmt.setString(1, uuid);
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
@ -729,15 +668,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int commentCount = 0; int commentCount = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;"; String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, createdBy); stmt.setString(1, createdBy);
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
commentCount = rs.getInt("COMMENT_COUNT"); commentCount = rs.getInt("COMMENT_COUNT");
} }
@ -745,7 +681,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
return commentCount; return commentCount;
} }
@Override @Override
@ -755,7 +690,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int commentCount = 0; int commentCount = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;"; String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;";
@ -763,7 +697,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
stmt.setString(1, modifiedBy); stmt.setString(1, modifiedBy);
stmt.setTimestamp(2, modifedAt); stmt.setTimestamp(2, modifedAt);
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
commentCount = rs.getInt("COMMENT_COUNT"); commentCount = rs.getInt("COMMENT_COUNT");
} }
@ -780,16 +713,13 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int commentCount = 0; int commentCount = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, appReleaseId); stmt.setInt(1, appReleaseId);
stmt.setInt(2, appId); stmt.setInt(2, appId);
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
commentCount = rs.getInt("COMMENT_COUNT"); commentCount = rs.getInt("COMMENT_COUNT");
} }
@ -806,20 +736,17 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int commentCount = 0; int commentCount = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + String sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, "
"(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R," + + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R,"
"(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P " + + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P "
"WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;"; + "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, version); stmt.setString(1, version);
stmt.setString(2, appName); stmt.setString(2, appName);
stmt.setString(3, appType); stmt.setString(3, appType);
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
commentCount = rs.getInt("COMMENT_COUNT"); commentCount = rs.getInt("COMMENT_COUNT");
} }
@ -834,16 +761,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int commentCount = 0; int commentCount = 0;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE "
"AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND "
"AP_APP_COMMENT.AP_APP_ID=AP_APP_RELEASE.AP_APP_ID and AP_APP_RELEASE.UUID=? and PARENT_ID=?;"; + "AP_APP_COMMENT.AP_APP_ID=AP_APP_RELEASE.AP_APP_ID and AP_APP_RELEASE.UUID=? and PARENT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1,uuid); stmt.setString(1, uuid);
stmt.setInt(2,parentId); stmt.setInt(2, parentId);
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
commentCount = rs.getInt("COMMENT_COUNT"); commentCount = rs.getInt("COMMENT_COUNT");
@ -875,16 +801,14 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "DELETE FROM AP_APP_COMMENT WHERE " + String sql = "DELETE FROM AP_APP_COMMENT WHERE "
"(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?)AND (SELECT AP_APP_ID FROM AP_APP_RELEASE " + + "(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?)AND (SELECT AP_APP_ID FROM AP_APP_RELEASE "
"WHERE UUID=?);"; + "WHERE UUID=?);";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1,uuid); stmt.setString(1, uuid);
stmt.setString(2,uuid); stmt.setString(2, uuid);
stmt.executeUpdate(); stmt.executeUpdate();
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
@ -897,14 +821,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;"; String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, appReleaseID); stmt.setInt(1, appReleaseID);
stmt.setInt(2,appId); stmt.setInt(2, appId);
stmt.executeUpdate(); stmt.executeUpdate();
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
@ -916,25 +838,23 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "DELETE FROM AP_APP_COMMENT WHERE " + String sql = "DELETE FROM AP_APP_COMMENT WHERE "
"(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND "
"(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND "
"(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);"; + "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, version); stmt.setString(1, version);
stmt.setString(2,appName); stmt.setString(2, appName);
stmt.setString(3,appType); stmt.setString(3, appType);
stmt.setString(4,appName); stmt.setString(4, appName);
stmt.setString(5,appType); stmt.setString(5, appType);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurred while deleting comments", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new CommentManagementException("Error occurred while deleting comments", e); throw new CommentManagementException("SQL Error occurred while deleting comments", e);
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
} }
@ -946,24 +866,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "DELETE FROM AP_APP_COMMENT WHERE " + String sql = "DELETE FROM AP_APP_COMMENT WHERE "
"(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND "
"(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND "
"(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? and TYPE=?) AND CREATED_BY=?;"; + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? and TYPE=?) AND CREATED_BY=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, version); stmt.setString(1, version);
stmt.setString(2,appName); stmt.setString(2, appName);
stmt.setString(3,appType); stmt.setString(3, appType);
stmt.setString(4,appName); stmt.setString(4, appName);
stmt.setString(5,appType); stmt.setString(5, appType);
stmt.setString(6,createdBy); stmt.setString(6, createdBy);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurred while deleting comments ", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new CommentManagementException("Error occurred while deleting comments", e); throw new CommentManagementException("Error occurred while deleting comments", e);
} finally { } finally {
@ -977,19 +895,18 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " + String sql =
"AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;"; "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) "
+ "AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1,uuid); stmt.setString(1, uuid);
stmt.setString(2,uuid); stmt.setString(2, uuid);
stmt.setInt(3,parentId); stmt.setInt(3, parentId);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurred while deleting comments.", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new CommentManagementException("Error occurred while deleting comments", e); throw new CommentManagementException("Error occurred while deleting comments", e);
} finally { } finally {
@ -1006,34 +923,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
String sql = "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;"; String sql = "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;";
stmt = connection.prepareStatement(sql); stmt = connection.prepareStatement(sql);
stmt.setInt(1,stars); stmt.setInt(1, stars);
stmt.setString(2, uuid); stmt.setString(2, uuid);
resultSet = stmt.executeQuery(sql); resultSet = stmt.executeQuery(sql);
if (resultSet != null) { if (resultSet != null) {
resultSet.getInt("STARS"); resultSet.getInt("STARS");
} }
int numORows=resultSet.getRow(); int numORows = resultSet.getRow();
if (resultSet.next()) { if (resultSet.next()) {
ApplicationRelease applicationRelease=new ApplicationRelease(); ApplicationRelease applicationRelease = new ApplicationRelease();
applicationRelease.setStars(resultSet.getInt("STARS")); applicationRelease.setStars(resultSet.getInt("STARS"));
Util.cleanupResources(stmt, resultSet); Util.cleanupResources(stmt, resultSet);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"SQL Exception while trying to add stars to an application (UUID : " + uuid + "), by executing " + "SQL Exception while trying to add stars to an application (UUID : " + uuid + "), by executing "
"the query " + e); + "the query " + e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception while trying to add stars to an application (UUID : " + uuid + "), ",
e);
} finally { } finally {
Util.cleanupResources(stmt, null); Util.cleanupResources(stmt, null);
return getStars(uuid); return getStars(uuid);
} }
} }
@Override @Override
@ -1043,32 +956,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql; String sql;
int Stars=0; int Stars = 0;
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
sql="SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; sql = "SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;";
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1,uuid); statement.setString(1, uuid);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
ApplicationRelease applicationRelease = new ApplicationRelease(); ApplicationRelease applicationRelease = new ApplicationRelease();
Stars=resultSet.getInt("STARS"); Stars = resultSet.getInt("STARS");
return Stars; return Stars;
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"SQL Exception while trying to get stars from an application (UUID : " + uuid + "), by executing " + "SQL Exception while trying to get stars from an application (UUID : " + uuid + "), by executing "
"the query " + e); + "the query " + e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error(
"DB Connection Exception while trying to get stars from an application (UUID : " + uuid + ")," + e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); Util.cleanupResources(statement, resultSet);
} }
return Stars ; return Stars;
} }
@Override @Override

Loading…
Cancel
Save