-
Notifications
You must be signed in to change notification settings - Fork 114
Refactor DAO classes and DB scripts #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fca2e51
11c6b94
b7e4e90
5b4b176
1975821
72ffe4e
123ea22
8c1d418
786eb93
b8f41fd
7b2cfd6
6f0276a
27254cc
91d9db1
6446be1
f8a2117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,8 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl { | |
| public int addOperation(Operation operation) throws OperationManagementDAOException { | ||
| int operationId; | ||
| PreparedStatement stmt = null; | ||
| ByteArrayOutputStream bao = null; | ||
| ObjectOutputStream oos = null; | ||
| try { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cant we use try with resource here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #1275 |
||
| operationId = super.addOperation(operation); | ||
| operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); | ||
|
|
@@ -48,12 +50,33 @@ public int addOperation(Operation operation) throws OperationManagementDAOExcept | |
| Connection conn = OperationManagementDAOFactory.getConnection(); | ||
| stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + | ||
| "VALUES(?, ?)"); | ||
|
|
||
| bao = new ByteArrayOutputStream(); | ||
| oos = new ObjectOutputStream(bao); | ||
| oos.writeObject(operation); | ||
|
|
||
| stmt.setInt(1, operationId); | ||
| stmt.setObject(2, policyOperation); | ||
| stmt.setBytes(2, bao.toByteArray()); | ||
| stmt.executeUpdate(); | ||
| } catch (SQLException e) { | ||
| throw new OperationManagementDAOException("Error occurred while adding policy operation", e); | ||
| } catch (IOException e) { | ||
| throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e); | ||
| } finally { | ||
| if (bao != null) { | ||
| try { | ||
| bao.close(); | ||
| } catch (IOException e) { | ||
| log.warn("Error occurred while closing ByteArrayOutputStream", e); | ||
| } | ||
| } | ||
| if (oos != null) { | ||
| try { | ||
| oos.close(); | ||
| } catch (IOException e) { | ||
| log.warn("Error occurred while closing ObjectOutputStream", e); | ||
| } | ||
| } | ||
| OperationManagementDAOUtil.cleanupResources(stmt); | ||
| } | ||
| return operationId; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,22 +37,46 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { | |
|
|
||
| public int addOperation(Operation operation) throws OperationManagementDAOException { | ||
| PreparedStatement stmt = null; | ||
| ByteArrayOutputStream bao = null; | ||
| ObjectOutputStream oos = null; | ||
|
|
||
| int operationId; | ||
| try { | ||
| operationId = super.addOperation(operation); | ||
| operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); | ||
| operation.setId(operationId); | ||
| operation.setEnabled(true); | ||
| ProfileOperation profileOp = (ProfileOperation) operation; | ||
| //ProfileOperation profileOp = (ProfileOperation) operation; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented line. And, can we change this to Java try with resource?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #1275 |
||
| Connection conn = OperationManagementDAOFactory.getConnection(); | ||
| stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, OPERATION_DETAILS) " + | ||
| "VALUES(?, ?)"); | ||
|
|
||
| bao = new ByteArrayOutputStream(); | ||
| oos = new ObjectOutputStream(bao); | ||
| oos.writeObject(operation); | ||
|
|
||
| stmt.setInt(1, operationId); | ||
| stmt.setObject(2, profileOp); | ||
| stmt.setBytes(2, bao.toByteArray()); | ||
| stmt.executeUpdate(); | ||
| } catch (SQLException e) { | ||
| throw new OperationManagementDAOException("Error occurred while adding profile operation", e); | ||
| } catch (IOException e) { | ||
| throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e); | ||
| } finally { | ||
| if (bao != null) { | ||
| try { | ||
| bao.close(); | ||
| } catch (IOException e) { | ||
| log.warn("Error occurred while closing ByteArrayOutputStream", e); | ||
| } | ||
| } | ||
| if (oos != null) { | ||
| try { | ||
| oos.close(); | ||
| } catch (IOException e) { | ||
| log.warn("Error occurred while closing ObjectOutputStream", e); | ||
| } | ||
| } | ||
| OperationManagementDAOUtil.cleanupResources(stmt); | ||
| } | ||
| return operationId; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 77c4c34