@ -58,13 +58,16 @@ public class TaskRecordDao {
/ * *
* get task record flag
*
* @return whether startup taskrecord
* /
public static boolean getTaskRecordFlag ( ) {
return conf . getBoolean ( Constants . TASK_RECORD_FLAG ) ;
}
/ * *
* create connection
*
* @return connection
* /
private static Connection getConn ( ) {
@ -90,6 +93,7 @@ public class TaskRecordDao {
/ * *
* generate where sql string
*
* @param filterMap filterMap
* @return sql string
* /
@ -139,6 +143,7 @@ public class TaskRecordDao {
/ * *
* count task record
*
* @param filterMap filterMap
* @param table table
* @return task record count
@ -148,6 +153,7 @@ public class TaskRecordDao {
int count = 0 ;
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
try {
conn = getConn ( ) ;
if ( conn = = null ) {
@ -156,7 +162,7 @@ public class TaskRecordDao {
String sql = String . format ( "select count(1) as count from %s" , table ) ;
sql + = getWhereString ( filterMap ) ;
pstmt = conn . prepareStatement ( sql ) ;
ResultSet rs = pstmt . executeQuery ( ) ;
rs = pstmt . executeQuery ( ) ;
while ( rs . next ( ) ) {
count = rs . getInt ( "count" ) ;
break ;
@ -164,22 +170,14 @@ public class TaskRecordDao {
} catch ( SQLException e ) {
logger . error ( "Exception " , e ) ;
} finally {
try {
if ( pstmt ! = null ) {
pstmt . close ( ) ;
}
if ( conn ! = null ) {
conn . close ( ) ;
}
} catch ( SQLException e ) {
logger . error ( "Exception " , e ) ;
}
closeResource ( rs , pstmt , conn ) ;
}
return count ;
}
/ * *
* query task record by filter map paging
*
* @param filterMap filterMap
* @param table table
* @return task record list
@ -204,6 +202,7 @@ public class TaskRecordDao {
/ * *
* convert result set to task record
*
* @param resultSet resultSet
* @return task record
* @throws SQLException if error throws SQLException
@ -232,6 +231,7 @@ public class TaskRecordDao {
/ * *
* query task list by select sql
*
* @param selectSql select sql
* @return task record list
* /
@ -239,13 +239,14 @@ public class TaskRecordDao {
List < TaskRecord > recordList = new ArrayList < > ( ) ;
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
try {
conn = getConn ( ) ;
if ( conn = = null ) {
return recordList ;
}
pstmt = conn . prepareStatement ( selectSql ) ;
ResultSet rs = pstmt . executeQuery ( ) ;
rs = pstmt . executeQuery ( ) ;
while ( rs . next ( ) ) {
TaskRecord taskRecord = convertToTaskRecord ( rs ) ;
@ -254,22 +255,14 @@ public class TaskRecordDao {
} catch ( SQLException e ) {
logger . error ( "Exception " , e ) ;
} finally {
try {
if ( pstmt ! = null ) {
pstmt . close ( ) ;
}
if ( conn ! = null ) {
conn . close ( ) ;
}
} catch ( SQLException e ) {
logger . error ( "Exception " , e ) ;
}
closeResource ( rs , pstmt , conn ) ;
}
return recordList ;
}
/ * *
* according to procname and procdate query task record
*
* @param procName procName
* @param procDate procDate
* @return task record status
@ -300,4 +293,27 @@ public class TaskRecordDao {
}
}
private static void closeResource ( ResultSet rs , PreparedStatement pstmt , Connection conn ) {
if ( rs ! = null ) {
try {
rs . close ( ) ;
} catch ( SQLException e ) {
logger . error ( "Exception " , e ) ;
}
}
if ( pstmt ! = null ) {
try {
pstmt . close ( ) ;
} catch ( SQLException e ) {
logger . error ( "Exception " , e ) ;
}
}
if ( conn ! = null ) {
try {
conn . close ( ) ;
} catch ( SQLException e ) {
logger . error ( "Exception " , e ) ;
}
}
}
}