1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.util.sql;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37
38 import org.apache.commons.lang3.NotImplementedException;
39
40 import java.sql.Connection;
41 import java.sql.PreparedStatement;
42 import java.sql.SQLException;
43
44
45
46
47
48 public class MultiPluginTransaction extends Transaction
49 {
50 private int _nNbTransactionsOpened;
51
52
53
54
55 public MultiPluginTransaction( )
56 {
57 super( );
58 _nNbTransactionsOpened = 1;
59 }
60
61
62
63
64
65
66
67 public MultiPluginTransaction( Plugin plugin )
68 {
69 super( plugin );
70 _nNbTransactionsOpened = 1;
71 }
72
73
74
75
76
77
78
79 public int getNbTransactionsOpened( )
80 {
81 return _nNbTransactionsOpened;
82 }
83
84
85
86
87 public void incrementNbTransactionsOpened( )
88 {
89 _nNbTransactionsOpened++;
90 }
91
92
93
94
95 public void decrementNbTransactionsOpened( )
96 {
97 _nNbTransactionsOpened--;
98 }
99
100
101
102
103 @Override
104 public PreparedStatement prepareStatement( String strSQL, boolean bLogQueries ) throws SQLException
105 {
106 return prepareStatement( strSQL, null, bLogQueries );
107 }
108
109
110
111
112 @Override
113 public PreparedStatement prepareStatement( String strSQL ) throws SQLException
114 {
115 return prepareStatement( strSQL, null, true );
116 }
117
118
119
120
121 @Override
122 public PreparedStatement prepareStatement( String strSQL, Integer autoGeneratedKeys ) throws SQLException
123 {
124 return prepareStatement( strSQL, autoGeneratedKeys, true );
125 }
126
127
128
129
130 @Override
131 public PreparedStatement prepareStatement( String strSQL, Integer autoGeneratedKeys, boolean bLogQueries ) throws SQLException
132 {
133
134 if ( getConnection( ) == null )
135 {
136 throw new SQLException( "MultiPluginTransaction - Connection has been closed. The new prepared statement can not be created : "
137 + ( bLogQueries ? strSQL : "(query log disabled)" ) );
138 }
139
140 Connection connection = getConnection( );
141 if ( autoGeneratedKeys != null )
142 {
143 return connection.prepareStatement( strSQL, autoGeneratedKeys );
144 }
145 else
146 {
147 return connection.prepareStatement( strSQL );
148 }
149 }
150
151
152
153
154 @Override
155 public void executeStatement( ) throws SQLException
156 {
157 throw new NotImplementedException(
158 "The method executeStatement( ) of class MultiPluginTransaction must not be called. Use manually PreparedStatement.executeQuery() instead." );
159 }
160
161
162
163
164 @Override
165 public void commit( )
166 {
167 _nNbTransactionsOpened = 0;
168 super.commit( );
169 }
170
171
172
173
174 @Override
175 public void rollback( Exception e )
176 {
177 _nNbTransactionsOpened = 0;
178 super.rollback( e );
179 }
180 }