@@ -37,11 +37,18 @@ public JdbcVersionManager(
3737
3838 @ Override
3939 public void upgrade () throws SQLException {
40+ SqlLogger logger = logger (this .getClass ());
41+
42+ logger .info ("Locking" );
4043 lockup ();
44+ logger .info ("Locked" );
4145 try {
46+ logger .info ("Creating version table" );
4247 create ();
4348
49+ logger .info ("Detecting current version" );
4450 SqlVersion current = detect ();
51+ logger .info ("Current version is {}" , current );
4552
4653 String version = current != null ? current .getVersion () : null ;
4754 int ordinal = current != null ? current .getSuccess () ? current .getOrdinal () + 1 : current .getOrdinal () : 0 ;
@@ -51,6 +58,10 @@ public void upgrade() throws SQLException {
5158 ordinal = 0 ;
5259 }
5360
61+ if (sources .hasMoreElements ()) {
62+ logger .info ("DataSource upgrading" );
63+ }
64+
5465 while (sources .hasMoreElements ()) {
5566 SqlSource source = sources .nextElement ();
5667 SqlScript script = resolve (source );
@@ -65,22 +76,28 @@ public void upgrade() throws SQLException {
6576 }
6677 }
6778
79+ logger .info ("DataSource is up to date" );
6880 } catch (SQLException ex ) {
6981 throw ex ;
7082 } catch (Exception ex ) {
7183 throw new SQLException (ex .getMessage (), ex );
7284 } finally {
85+ logger .info ("Unlocking" );
7386 unlock ();
87+ logger .info ("Unlocked" );
7488 }
7589 }
7690
7791 @ Override
7892 public void upgrade (final SqlScript script ) throws SQLException {
93+ SqlLogger logger = logger (this .getClass ());
94+
7995 Set <String > instructions = script .instructions ();
8096 boolean atomic = instructions != null && instructions .contains (INSTRUCTION_ATOMIC );
8197
8298 // 原子执行
8399 if (atomic ) {
100+ logger .info ("Executing script {} atomically" , script .name ());
84101 perform (new JdbcAction () {
85102 @ Override
86103 public void perform (Connection connection ) throws SQLException {
@@ -93,6 +110,7 @@ public void perform(Connection connection) throws SQLException {
93110 }
94111 // 逐条执行
95112 else {
113+ logger .info ("Executing script {} non-atomically" , script .name ());
96114 int sqls = script .sqls ();
97115 for (int ordinal = 0 ; ordinal < sqls ; ordinal ++) {
98116 upgrade (script , ordinal );
@@ -102,28 +120,48 @@ public void perform(Connection connection) throws SQLException {
102120
103121 @ Override
104122 public void upgrade (final SqlScript script , final int ordinal ) throws SQLException {
123+ final SqlLogger logger = logger (this .getClass ());
124+
105125 Integer rowEffected = null ;
106126 SQLException sqlException = null ;
107127 try {
108128 rowEffected = execute (new JdbcTransaction <Integer >() {
109129 @ Override
110130 public Integer execute (Connection connection ) throws SQLException {
111131 try {
132+ String isolation ;
112133 Set <String > instructions = script .instructions ();
113134 if (instructions != null && instructions .contains (INSTRUCTION_SERIALIZABLE )) {
114135 connection .setTransactionIsolation (Connection .TRANSACTION_SERIALIZABLE );
136+ isolation = "serializable" ;
115137 } else if (instructions != null && instructions .contains (INSTRUCTION_REPEATABLE_READ )) {
116138 connection .setTransactionIsolation (Connection .TRANSACTION_REPEATABLE_READ );
139+ isolation = "repeatable read" ;
117140 } else if (instructions != null && instructions .contains (INSTRUCTION_READ_COMMITTED )) {
118141 connection .setTransactionIsolation (Connection .TRANSACTION_READ_COMMITTED );
142+ isolation = "read committed" ;
119143 } else if (instructions != null && instructions .contains (INSTRUCTION_READ_UNCOMMITTED )) {
120144 connection .setTransactionIsolation (Connection .TRANSACTION_READ_UNCOMMITTED );
145+ isolation = "read uncommitted" ;
146+ } else {
147+ isolation = "default" ;
121148 }
122149
123150 SqlSentence sentence = script .sentence (ordinal );
124151 String sql = sentence .value ();
152+
153+ if (logger .isDebugEnabled ()) {
154+ logger .info ("Executing sentence {}/{} of script version {} in {} transaction isolation level \n {}" , ordinal + 1 , script .sqls (), script .version (), isolation , sql );
155+ } else {
156+ logger .info ("Executing sentence {}/{} of script version {} in {} transaction isolation level" , ordinal + 1 , script .sqls (), script .version (), isolation );
157+ }
158+
125159 PreparedStatement statement = connection .prepareStatement (sql );
126- return statement .executeUpdate ();
160+ int rows = statement .executeUpdate ();
161+
162+ logger .info ("Execution completed with {} rows effected" , rows );
163+
164+ return rows ;
127165 } catch (SQLException ex ) {
128166 throw ex ;
129167 } catch (Exception ex ) {
0 commit comments