1717import org .fugerit .java .core .db .dao .RSExtractor ;
1818import org .fugerit .java .core .lang .helpers .StringUtils ;
1919import org .fugerit .java .core .log .LogObject ;
20+ import org .fugerit .java .core .util .checkpoint .CheckpointUtils ;
2021import org .slf4j .Logger ;
21- import org .slf4j .LoggerFactory ;
22+
23+ import lombok .extern .slf4j .Slf4j ;
2224
2325/**
2426 *
2729 *
2830 * @param <T> the type returned by this DAOHelper
2931 */
32+ @ Slf4j
3033public class BasicDAOHelper <T > implements Serializable , LogObject {
31-
32- protected static Logger logger = LoggerFactory .getLogger ( BasicDAOHelper .class );
3334
3435 @ Override
3536 public Logger getLogger () {
36- return logger ;
37+ return log ;
3738 }
3839
3940 /**
@@ -79,39 +80,45 @@ public void loadAllHelper( List<T> l, SelectHelper query, RSExtractor<T> re ) th
7980 this .loadAllHelper ( l , query .getQueryContent (), query .getFields (), re );
8081 }
8182
83+ protected String createQueryId ( long startTime ) {
84+ return String .format ( "%s_%s" , Thread .currentThread ().getId (), startTime );
85+ }
8286
8387 public void loadAllHelper ( List <T > l , String query , FieldList fields , RSExtractor <T > re ) throws DAOException {
8488 try {
85- logger .debug ( "loadAll START list : '{}' " , l .size () );
86- logger .debug ( "loadAll fields : '{}'" , fields .size () );
87- logger .debug ( "loadAll RSExtractor : '{}'" , re );
89+ long startTime = System .currentTimeMillis ();
90+ String queryId = this .createQueryId (startTime );
91+ log .debug ( "queryId:{}, loadAll START list : '{}' " , queryId , l .size () );
92+ log .debug ( "queryId:{}, loadAll fields : '{}'" , queryId , fields .size () );
93+ log .debug ( "queryId:{}, loadAll RSExtractor : '{}'" , queryId , re );
8894 Connection conn = this .daoContext .getConnection ();
8995 int i =0 ;
9096 try ( PreparedStatement ps = conn .prepareStatement ( query ) ) {
9197 DAOHelper .setAll ( ps , fields , this );
9298 try ( ResultSet rs = ps .executeQuery () ) {
99+ log .debug ("queryId:{}, loadAll query execute end time : '{}'" , queryId , CheckpointUtils .formatTimeDiff (startTime , System .currentTimeMillis ()) );
93100 while (rs .next ()) {
94101 l .add ( re .extractNext ( rs ) );
95102 i ++;
96103 }
104+ log .debug ("queryId:{}, loadAll query result end time : '{}'" , queryId , CheckpointUtils .formatTimeDiff (startTime , System .currentTimeMillis ()) );
97105 }
98106 } catch (SQLException e ) {
99107 throw (new DAOException ( e .getMessage ()+"[query:" +query +",record:" +i +"]" , e ));
100108 }
101- logger .debug ("loadAll END list : '{}'" , l .size ());
109+ log .debug ("queryId:{}, loadAll END list : '{}'" , queryId , l .size ());
102110 } catch (DAOException e ) {
103111 throw new DAOException ( e );
104112 }
105113 }
106114
107-
108115 public int update ( QueryHelper queryHelper ) throws DAOException {
109116 int res = 0 ;
110117 try {
111118 String query = queryHelper .getQueryContent ();
112119 FieldList fields = queryHelper .getFields ();
113- logger .debug ( "update START list : '{}' " , query );
114- logger .debug ( "update fields : '{}'" , fields .size () );
120+ log .debug ( "update START list : '{}' " , query );
121+ log .debug ( "update fields : '{}'" , fields .size () );
115122 Connection conn = this .daoContext .getConnection ();
116123 int i =0 ;
117124 try ( PreparedStatement ps = conn .prepareStatement ( query ) ) {
@@ -120,7 +127,7 @@ public int update( QueryHelper queryHelper ) throws DAOException {
120127 } catch (SQLException e ) {
121128 throw (new DAOException ( e .getMessage ()+"[query:" +query +",record:" +i +"]" , e ));
122129 }
123- logger .debug ("update END res : '{}'" , res );
130+ log .debug ("update END res : '{}'" , res );
124131 } catch (DAOException e ) {
125132 throw new DAOException ( e );
126133 }
@@ -130,7 +137,7 @@ public int update( QueryHelper queryHelper ) throws DAOException {
130137 public BigDecimal newSequenceValue ( String sequence ) throws DAOException {
131138 BigDecimal id = null ;
132139 String sql = " SELECT " +sequence +".NEXTVAL FROM DUAL" ;
133- logger .info ( "newSequenceValue() sql > " +sql );
140+ log .info ( "newSequenceValue() sql > " +sql );
134141 try ( Statement stm = this .daoContext .getConnection ().createStatement ();
135142 ResultSet rs = stm .executeQuery ( sql ) ) {
136143 if ( rs .next () ) {
0 commit comments