1717package org .apache .cloudstack .framework .config .dao ;
1818
1919import java .sql .PreparedStatement ;
20+ import java .sql .SQLException ;
2021import java .util .HashMap ;
2122import java .util .List ;
2223import java .util .Map ;
2627import javax .naming .ConfigurationException ;
2728
2829import org .apache .log4j .Logger ;
29- import org .apache .cloudstack .framework .config .impl .ConfigurationVO ;
3030import org .springframework .stereotype .Component ;
3131
32+ import org .apache .cloudstack .framework .config .impl .ConfigurationVO ;
33+
3234import com .cloud .utils .component .ComponentLifecycle ;
3335import com .cloud .utils .crypt .DBEncryptionUtil ;
3436import com .cloud .utils .db .DB ;
@@ -142,30 +144,44 @@ public void init() throws ConfigurationException {
142144 @ Deprecated
143145 public boolean update (String name , String value ) {
144146 TransactionLegacy txn = TransactionLegacy .currentTxn ();
147+ PreparedStatement stmt = null ;
145148 try {
146- PreparedStatement stmt = txn .prepareStatement (UPDATE_CONFIGURATION_SQL );
149+ stmt = txn .prepareStatement (UPDATE_CONFIGURATION_SQL );
147150 stmt .setString (1 , value );
148151 stmt .setString (2 , name );
149152 stmt .executeUpdate ();
150153 return true ;
151154 } catch (Exception e ) {
152155 s_logger .warn ("Unable to update Configuration Value" , e );
156+ } finally {
157+ try {
158+ if (stmt != null )
159+ stmt .close ();
160+ } catch (SQLException e ) {
161+ }
153162 }
154163 return false ;
155164 }
156165
157166 @ Override
158167 public boolean update (String name , String category , String value ) {
159168 TransactionLegacy txn = TransactionLegacy .currentTxn ();
169+ PreparedStatement stmt = null ;
160170 try {
161171 value = ("Hidden" .equals (category ) || "Secure" .equals (category )) ? DBEncryptionUtil .encrypt (value ) : value ;
162- PreparedStatement stmt = txn .prepareStatement (UPDATE_CONFIGURATION_SQL );
172+ stmt = txn .prepareStatement (UPDATE_CONFIGURATION_SQL );
163173 stmt .setString (1 , value );
164174 stmt .setString (2 , name );
165175 stmt .executeUpdate ();
166176 return true ;
167177 } catch (Exception e ) {
168178 s_logger .warn ("Unable to update Configuration Value" , e );
179+ } finally {
180+ try {
181+ if (stmt != null )
182+ stmt .close ();
183+ } catch (SQLException e ) {
184+ }
169185 }
170186 return false ;
171187 }
@@ -178,9 +194,9 @@ public String getValue(String name) {
178194
179195 @ Override
180196 public String getValueAndInitIfNotExist (String name , String category , String initValue ) {
181- return getValueAndInitIfNotExist (name , category , initValue , "" );
197+ return getValueAndInitIfNotExist (name , category , initValue , "" );
182198 }
183-
199+
184200 @ Override
185201 @ DB
186202 public String getValueAndInitIfNotExist (String name , String category , String initValue , String desc ) {
0 commit comments