4242 */
4343public class FBManager implements FBManagerMBean {
4444
45- private static final int DEFAULT_PORT = 3050 ;
4645 private static final System .Logger log = System .getLogger (FBManager .class .getName ());
4746
4847 private FbDatabaseFactory dbFactory ;
49- private String host = "localhost" ;
50- private Integer port ;
48+ private final IConnectionProperties connectionProperties = new FbConnectionProperties ();
5149 private String fileName ;
52- private String userName ;
53- private String password ;
54- private String roleName ;
55- private String enableProtocol ;
5650 private int dialect = ISCConstants .SQL_DIALECT_CURRENT ;
5751 private int pageSize = -1 ;
5852 private String defaultCharacterSet ;
@@ -71,10 +65,11 @@ public FBManager() {
7165
7266 public FBManager (GDSType type ) {
7367 this .type = type ;
68+ connectionProperties .setType (type .toString ());
7469 }
7570
7671 public FBManager (String type ) {
77- this . type = GDSType .getType (type );
72+ this ( GDSType .getType (type ) );
7873 }
7974
8075 //Service methods
@@ -129,22 +124,22 @@ public String getName() {
129124
130125 @ Override
131126 public void setServer (String host ) {
132- this . host = host ;
127+ connectionProperties . setServerName ( host ) ;
133128 }
134129
135130 @ Override
136131 public String getServer () {
137- return host ;
132+ return connectionProperties . getServerName () ;
138133 }
139134
140135 @ Override
141136 public void setPort (int port ) {
142- this . port = port ;
137+ connectionProperties . setPortNumber ( port ) ;
143138 }
144139
145140 @ Override
146141 public int getPort () {
147- return port != null ? port : DEFAULT_PORT ;
142+ return connectionProperties . getPortNumber () ;
148143 }
149144
150145 @ Override
@@ -159,7 +154,7 @@ public void setFileName(String fileName) {
159154
160155 @ Override
161156 public String getType () {
162- return this . type .toString ();
157+ return type .toString ();
163158 }
164159
165160 @ Override
@@ -171,46 +166,57 @@ public void setType(String type) {
171166 }
172167
173168 this .type = gdsType ;
169+ connectionProperties .setType (gdsType .toString ());
174170 }
175171
176172 @ Override
177173 public String getUserName () {
178- return userName ;
174+ return connectionProperties . getUser () ;
179175 }
180176
181177 @ Override
182178 public void setUserName (String userName ) {
183- this . userName = userName ;
179+ connectionProperties . setUser ( userName ) ;
184180 }
185181
186182 @ Override
187183 public String getPassword () {
188- return password ;
184+ return connectionProperties . getPassword () ;
189185 }
190186
191187 @ Override
192188 public void setPassword (String password ) {
193- this . password = password ;
189+ connectionProperties . setPassword ( password ) ;
194190 }
195191
196192 @ Override
197193 public String getRoleName () {
198- return roleName ;
194+ return connectionProperties . getRoleName () ;
199195 }
200196
201197 @ Override
202198 public void setRoleName (String roleName ) {
203- this .roleName = roleName ;
199+ connectionProperties .setRoleName (roleName );
200+ }
201+
202+ @ Override
203+ public String getAuthPlugins () {
204+ return connectionProperties .getAuthPlugins ();
205+ }
206+
207+ @ Override
208+ public void setAuthPlugins (String authPlugins ) {
209+ connectionProperties .setAuthPlugins (authPlugins );
204210 }
205211
206212 @ Override
207213 public void setEnableProtocol (String enableProtocol ) {
208- this . enableProtocol = enableProtocol ;
214+ connectionProperties . setEnableProtocol ( enableProtocol ) ;
209215 }
210216
211217 @ Override
212218 public String getEnableProtocol () {
213- return enableProtocol ;
219+ return connectionProperties . getEnableProtocol () ;
214220 }
215221
216222 @ Override
@@ -299,15 +305,16 @@ public synchronized void createDatabase(String fileName, String user, String pas
299305 IConnectionProperties connectionProperties = createDefaultConnectionProperties (user , password , roleName );
300306 connectionProperties .setDatabaseName (fileName );
301307 FbDatabase db = dbFactory .connect (connectionProperties );
302- db .attach ();
303-
304- // if forceCreate is set, drop the database correctly
305- // otherwise exit, database already exists
306- if (forceCreate )
307- db .dropDatabase ();
308- else {
309- db .close ();
310- return ; //database exists, don't wipe it out.
308+ try {
309+ db .attach ();
310+ if (forceCreate ) {
311+ db .dropDatabase ();
312+ } else {
313+ // database exists, don't wipe it out
314+ return ;
315+ }
316+ } finally {
317+ if (db .isAttached ()) db .close ();
311318 }
312319 } catch (SQLException e ) {
313320 // we ignore it
@@ -349,8 +356,12 @@ public synchronized void dropDatabase(String fileName, String user, String passw
349356 IConnectionProperties connectionProperties = createDefaultConnectionProperties (user , password , roleName );
350357 connectionProperties .setDatabaseName (fileName );
351358 FbDatabase db = dbFactory .connect (connectionProperties );
352- db .attach ();
353- db .dropDatabase ();
359+ try {
360+ db .attach ();
361+ db .dropDatabase ();
362+ } finally {
363+ if (db .isAttached ()) db .close ();
364+ }
354365 } catch (Exception e ) {
355366 log .log (System .Logger .Level .ERROR , "Exception dropping database" , e );
356367 throw e ;
@@ -363,23 +374,20 @@ public synchronized boolean isDatabaseExists(String fileName, String user, Strin
363374 try {
364375 IConnectionProperties connectionProperties = createDefaultConnectionProperties (user , password , null );
365376 connectionProperties .setDatabaseName (fileName );
366- FbDatabase db = dbFactory .connect (connectionProperties );
367- db .attach ();
368- db . close ();
377+ try ( FbDatabase db = dbFactory .connect (connectionProperties )) {
378+ db .attach ();
379+ }
369380 return true ;
370381 } catch (Exception e ) {
371382 return false ;
372383 }
373384 }
374385
375386 private IConnectionProperties createDefaultConnectionProperties (String user , String password , String roleName ) {
376- FbConnectionProperties connectionProperties = new FbConnectionProperties ();
387+ var connectionProperties = this . connectionProperties . asNewMutable ();
377388 connectionProperties .setUser (user );
378389 connectionProperties .setPassword (password );
379390 connectionProperties .setRoleName (roleName );
380- connectionProperties .setServerName (getServer ());
381- connectionProperties .setPortNumber (getPort ());
382- connectionProperties .setEnableProtocol (getEnableProtocol ());
383391 return connectionProperties ;
384392 }
385393
0 commit comments