-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a resource object to intuitivly handle query resource rel…
…easing
- Loading branch information
Showing
6 changed files
with
93 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.activeorm.utility; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
/** | ||
* Created by Activate2 on 5/10/2016. | ||
* <p> | ||
* Resource is a object return from the query method in database. | ||
* It contains the results of the query and the ability to close them. | ||
*/ | ||
public class Resource { | ||
|
||
/** | ||
* The results of the resource. | ||
*/ | ||
private final ResultSet result; | ||
|
||
/** | ||
* The statement that made the resource. | ||
*/ | ||
private final Statement statement; | ||
|
||
/** | ||
* Constructs a new {@link Resource}. | ||
* | ||
* @param statement The statement that made the result. | ||
* @param result the result from the query. | ||
*/ | ||
public Resource(final Statement statement, final ResultSet result) { | ||
this.statement = statement; | ||
this.result = result; | ||
} | ||
|
||
/** | ||
* @return the result of this resource. | ||
*/ | ||
public ResultSet getResult() { | ||
return this.result; | ||
} | ||
|
||
/** | ||
* @return the statement of this resource | ||
*/ | ||
public Statement getStatment() { | ||
return this.statement; | ||
} | ||
|
||
/** | ||
* Releases all of the resources in this object. | ||
* | ||
* @return true if it releases without error. | ||
*/ | ||
public boolean release() { | ||
try { | ||
result.close(); | ||
statement.close(); | ||
return true; | ||
} catch (final SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters