Merge "Remove unnecessary parentheses"
[ccsdk/sli/core.git] / sli / common / src / main / java / org / onap / ccsdk / sli / core / sli / SvcLogicJdbcStore.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.core.sli;
23
24 import java.io.ByteArrayInputStream;
25 import java.io.ByteArrayOutputStream;
26 import java.io.ObjectInputStream;
27 import java.io.ObjectOutputStream;
28 import java.sql.Blob;
29 import java.sql.Connection;
30 import java.sql.DatabaseMetaData;
31 import java.sql.Driver;
32 import java.sql.DriverManager;
33 import java.sql.PreparedStatement;
34 import java.sql.ResultSet;
35 import java.sql.SQLException;
36 import java.sql.Statement;
37 import java.util.Properties;
38
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42
43 public class SvcLogicJdbcStore implements SvcLogicStore {
44         private static final Logger LOG = LoggerFactory.getLogger(SvcLogicJdbcStore.class);
45
46         private String dbUrl = null;
47         private String dbName = null;
48         private String dbUser = null;
49         private String dbPasswd = null;
50         private String dbDriver = null;
51
52         private Connection dbConn;
53         private PreparedStatement hasActiveGraphStmt = null;
54         private PreparedStatement hasVersionGraphStmt = null;
55         private PreparedStatement fetchActiveGraphStmt = null;
56         private PreparedStatement fetchVersionGraphStmt = null;
57         private PreparedStatement storeGraphStmt = null;
58         private PreparedStatement deleteGraphStmt = null;
59
60         private PreparedStatement deactivateStmt = null;
61         private PreparedStatement activateStmt = null;
62
63         private PreparedStatement registerNodeStmt = null;
64         private PreparedStatement unregisterNodeStmt = null;
65         private PreparedStatement validateNodeStmt = null;
66
67         private void getConnection() throws ConfigurationException
68         {
69
70                 Properties jdbcProps = new Properties();
71
72                 jdbcProps.setProperty("user", dbUser);
73                 jdbcProps.setProperty("password", dbPasswd);
74
75                 try {
76                         Driver dvr = new org.mariadb.jdbc.Driver();
77                         if (dvr.acceptsURL(dbUrl))
78                         {
79                                 LOG.debug("Driver com.mysql.jdbc.Driver accepts {}", dbUrl);
80                         }
81                         else
82                         {
83                                 LOG.warn("Driver com.mysql.jdbc.Driver does not accept {}", dbUrl);
84                         }
85                 } catch (SQLException e1) {
86                         LOG.error("Caught exception trying to load com.mysql.jdbc.Driver", e1);
87                 }
88
89                 try
90                 {
91                         this.dbConn = DriverManager.getConnection(dbUrl, jdbcProps);
92                 }
93                 catch (Exception e)
94                 {
95                         throw new ConfigurationException("failed to get database connection ["+dbUrl+"]", e);
96                 }
97
98         }
99
100         private void createTable() throws ConfigurationException
101         {
102
103                 DatabaseMetaData dbm;
104
105                 try {
106                         dbm = dbConn.getMetaData();
107                 } catch (SQLException e) {
108
109                         throw new ConfigurationException("could not get databse metadata", e);
110                 }
111
112                 // See if table SVC_LOGIC exists.  If not, create it.
113         Statement stmt = null;
114                 try
115                 {
116
117                         ResultSet tables = dbm.getTables(null, null, "SVC_LOGIC", null);
118                         if (tables.next()) {
119                 LOG.debug("SVC_LOGIC table already exists");
120                         }
121                         else {
122                 String crTableCmd = "CREATE TABLE "+dbName+".SVC_LOGIC ("
123                     + "module varchar(80) NOT NULL,"
124                     + "rpc varchar(80) NOT NULL,"
125                     + "version varchar(40) NOT NULL,"
126                     + "mode varchar(5) NOT NULL,"
127                     + "active varchar(1) NOT NULL,"
128                     + "graph BLOB,"
129                     + "CONSTRAINT P_SVC_LOGIC PRIMARY KEY(module, rpc, version, mode))";
130
131                 stmt = dbConn.createStatement();
132                 stmt.executeUpdate(crTableCmd);
133                         }
134                 }
135                 catch (Exception e)
136                 {
137                         throw new ConfigurationException("could not create SVC_LOGIC table", e);
138                 }
139         finally
140         {
141             if (stmt != null) {
142                 try {
143                     stmt.close();
144                 } catch (SQLException e) {
145                     LOG.error("Statement close error ", e);
146                 }
147             }
148         }
149
150                 // See if NODE_TYPES table exists and, if not, create it
151         stmt = null;
152                 try
153                 {
154
155                         ResultSet tables = dbm.getTables(null, null, "NODE_TYPES", null);
156                         if (tables.next()) {
157                 LOG.debug("NODE_TYPES table already exists");
158                         }
159                         else {
160                 String crTableCmd = "CREATE TABLE "+dbName+".NODE_TYPES ("
161                     + "nodetype varchar(80) NOT NULL,"
162                     + "CONSTRAINT P_NODE_TYPES PRIMARY KEY(nodetype))";
163
164                 stmt = dbConn.createStatement();
165
166                 stmt.executeUpdate(crTableCmd);
167                         }
168                 }
169                 catch (Exception e)
170                 {
171                         throw new ConfigurationException("could not create SVC_LOGIC table", e);
172                 }
173                 finally
174         {
175             if (stmt != null) {
176                 try {
177                     stmt.close();
178                 } catch (SQLException e) {
179                     LOG.error("Statement close error ", e);
180                 }
181             }
182         }
183         }
184
185         private void prepStatements() throws ConfigurationException
186         {
187
188                 // Prepare statements
189                 String hasVersionGraphSql = CommonConstants.JDBC_SELECT_COUNT + dbName + CommonConstants.SVCLOGIC_TABLE
190                                 + CommonConstants.JDBC_GRAPH_QUERY;
191
192                 try
193                 {
194                         hasVersionGraphStmt = dbConn.prepareStatement(hasVersionGraphSql);
195                 }
196                 catch (Exception e)
197                 {
198                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + hasVersionGraphSql, e);
199
200                 }
201
202                 String hasActiveGraphSql = CommonConstants.JDBC_SELECT_COUNT + dbName + CommonConstants.SVCLOGIC_TABLE
203                                 + CommonConstants.JDBC_ACTIVE_GRAPH_QUERY;
204
205                 try
206                 {
207                         hasActiveGraphStmt = dbConn.prepareStatement(hasActiveGraphSql);
208                 }
209                 catch (Exception e)
210                 {
211                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + hasVersionGraphSql, e);
212
213                 }
214
215                 String fetchVersionGraphSql = CommonConstants.JDBC_SELECT_GRAPGH + dbName+CommonConstants.SVCLOGIC_TABLE
216                                 + CommonConstants.JDBC_GRAPH_QUERY;
217
218                 try
219                 {
220                         fetchVersionGraphStmt = dbConn.prepareStatement(fetchVersionGraphSql);
221                 }
222                 catch (Exception e)
223                 {
224                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + fetchVersionGraphSql, e);
225
226                 }
227
228                 String fetchActiveGraphSql = CommonConstants.JDBC_SELECT_GRAPGH + dbName + CommonConstants.SVCLOGIC_TABLE
229                                 + CommonConstants.JDBC_ACTIVE_GRAPH_QUERY;
230
231                 try
232                 {
233                         fetchActiveGraphStmt = dbConn.prepareStatement(fetchActiveGraphSql);
234                 }
235                 catch (Exception e)
236                 {
237                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + fetchVersionGraphSql, e);
238
239                 }
240
241                 String storeGraphSql = CommonConstants.JDBC_INSERT+dbName
242             + ".SVC_LOGIC (module, rpc, version, mode, active, graph) VALUES(?, ?, ?, ?, ?, ?)";
243
244                 try
245                 {
246                         storeGraphStmt = dbConn.prepareStatement(storeGraphSql);
247                 }
248                 catch (Exception e)
249                 {
250                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + storeGraphSql, e);
251                 }
252
253                 String deleteGraphSql = CommonConstants.JDBC_DELETE+dbName
254             + ".SVC_LOGIC WHERE module = ? AND rpc = ? AND version = ? AND mode = ?";
255
256                 try
257                 {
258                         deleteGraphStmt = dbConn.prepareStatement(deleteGraphSql);
259                 }
260                 catch (Exception e)
261                 {
262                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + deleteGraphSql, e);
263                 }
264
265                 String deactivateSql = CommonConstants.JDBC_UPDATE + dbName
266             +".SVC_LOGIC SET active = 'N' WHERE module = ? AND rpc = ? AND mode = ?";
267
268                 try
269                 {
270                         deactivateStmt = dbConn.prepareStatement(deactivateSql);
271                 }
272                 catch (Exception e)
273                 {
274                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + deactivateSql, e);
275                 }
276
277                 String activateSql = CommonConstants.JDBC_UPDATE + dbName
278             +".SVC_LOGIC SET active = 'Y' WHERE module = ? AND rpc = ? AND version = ? AND mode = ?";
279
280                 try
281                 {
282                         activateStmt = dbConn.prepareStatement(activateSql);
283                 }
284                 catch (Exception e)
285                 {
286                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + activateSql, e);
287                 }
288
289                 String registerNodeSql = CommonConstants.JDBC_INSERT + dbName + ".NODE_TYPES (nodetype) VALUES(?)";
290                 try
291                 {
292                         registerNodeStmt = dbConn.prepareStatement(registerNodeSql);
293                 }
294                 catch (Exception e)
295                 {
296                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + registerNodeSql, e);
297                 }
298
299                 String unregisterNodeSql = CommonConstants.JDBC_DELETE + dbName + ".NODE_TYPES WHERE nodetype = ?";
300                 try
301                 {
302                         unregisterNodeStmt = dbConn.prepareStatement(unregisterNodeSql);
303                 }
304                 catch (Exception e)
305                 {
306                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + unregisterNodeSql, e);
307                 }
308
309                 String validateNodeSql = CommonConstants.JDBC_SELECT_COUNT + dbName + ".NODE_TYPES WHERE nodetype = ?";
310                 try
311                 {
312                         validateNodeStmt = dbConn.prepareStatement(validateNodeSql);
313                 }
314                 catch (Exception e)
315                 {
316                         throw new ConfigurationException(CommonConstants.JDBC_STATEMENT_ERR + validateNodeSql, e);
317                 }
318         }
319
320         private void initDbResources() throws ConfigurationException
321         {
322                 if ((dbDriver != null) && (dbDriver.length() > 0))
323                 {
324
325                     try
326                     {
327                             Class.forName(dbDriver);
328                     }
329                     catch (Exception e)
330                     {
331                         throw new ConfigurationException("could not load driver class "+dbDriver, e);
332                     }
333                 }
334                 getConnection();
335                 createTable();
336                 prepStatements();
337         }
338
339
340         @Override
341         public void init(Properties props) throws ConfigurationException {
342
343
344                 dbUrl = props.getProperty("org.onap.ccsdk.sli.jdbc.url");
345                 if ((dbUrl == null) || (dbUrl.length() == 0))
346                 {
347                         throw new ConfigurationException("property org.onap.ccsdk.sli.jdbc.url unset");
348                 }
349
350                 dbName = props.getProperty("org.onap.ccsdk.sli.jdbc.database");
351                 if ((dbName == null) || (dbName.length() == 0))
352                 {
353                         throw new ConfigurationException("property org.onap.ccsdk.sli.jdbc.database unset");
354                 }
355
356                 dbUser = props.getProperty("org.onap.ccsdk.sli.jdbc.user");
357                 if ((dbUser == null) || (dbUser.length() == 0))
358                 {
359                         throw new ConfigurationException("property org.onap.ccsdk.sli.jdbc.user unset");
360                 }
361
362
363                 dbPasswd = props.getProperty("org.onap.ccsdk.sli.jdbc.password");
364                 if ((dbPasswd == null) || (dbPasswd.length() == 0))
365                 {
366                         throw new ConfigurationException("property org.onap.ccsdk.sli.jdbc.password unset");
367                 }
368
369                 dbDriver = props.getProperty("org.onap.ccsdk.sli.jdbc.driver");
370
371
372                 initDbResources();
373
374         }
375
376         private boolean isDbConnValid()
377         {
378
379                 boolean isValid = false;
380
381                 try
382                 {
383                         if (dbConn != null)
384                         {
385                                 isValid = dbConn.isValid(1);
386                         }
387                 }
388                 catch (SQLException e)
389                 {
390                         LOG.error("Not a valid db connection: ", e);
391                 }
392
393                 return isValid;
394         }
395
396         @Override
397         public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
398
399                 if (!isDbConnValid())
400                 {
401
402                         // Try reinitializing
403                         initDbResources();
404
405                         if (!isDbConnValid())
406                         {
407                                 throw new ConfigurationException(CommonConstants.JDBC_CONN_ERR);
408                         }
409                 }
410
411                 boolean retval = false;
412                 ResultSet results = null;
413
414                 PreparedStatement hasGraphStmt;
415                 if (version == null)
416                 {
417                         hasGraphStmt = hasActiveGraphStmt;
418                 }
419                 else
420                 {
421                         hasGraphStmt = hasVersionGraphStmt;
422                 }
423
424                 try
425                 {
426                         hasGraphStmt.setString(1, module);
427                         hasGraphStmt.setString(2,  rpc);
428                         hasGraphStmt.setString(3,  mode);
429
430
431                         if (version != null)
432                         {
433                                 hasGraphStmt.setString(4, version);
434                         }
435                         boolean oldAutoCommit = dbConn.getAutoCommit();
436                         dbConn.setAutoCommit(false);
437                         results = hasGraphStmt.executeQuery();
438                         dbConn.commit();
439                         dbConn.setAutoCommit(oldAutoCommit);
440
441                         if (results.next())
442                         {
443                                 int cnt = results.getInt(1);
444
445                                 if (cnt > 0)
446                                 {
447                                         retval = true;
448                                 }
449
450                         }
451                 }
452                 catch (Exception e)
453                 {
454                         throw new ConfigurationException("SQL query failed", e);
455                 }
456                 finally
457                 {
458                         if (results != null)
459                         {
460                                 try
461                                 {
462                                         results.close();
463                                 }
464                                 catch (SQLException x)
465                                 {
466                                         LOG.error(CommonConstants.RESULTSET_CLOSE_ERR, x);
467                                 }
468                         }
469
470                 }
471
472                 return retval;
473
474         }
475
476         @Override
477         public SvcLogicGraph fetch(String module, String rpc, String version, String mode) throws SvcLogicException {
478
479
480                 if (!isDbConnValid())
481                 {
482
483                         // Try reinitializing
484                         initDbResources();
485
486                         if (!isDbConnValid())
487                         {
488                                 throw new ConfigurationException(CommonConstants.JDBC_CONN_ERR);
489                         }
490                 }
491
492                 SvcLogicGraph retval = null;
493                 ResultSet results = null;
494
495                 PreparedStatement fetchGraphStmt;
496                 if (version == null)
497                 {
498                         fetchGraphStmt = fetchActiveGraphStmt;
499                 }
500                 else
501                 {
502                         fetchGraphStmt = fetchVersionGraphStmt;
503                 }
504                 try
505                 {
506                         fetchGraphStmt.setString(1, module);
507                         fetchGraphStmt.setString(2,  rpc);
508                         fetchGraphStmt.setString(3,  mode);
509
510
511                         if (version != null)
512                         {
513                                 fetchGraphStmt.setString(4, version);
514                         }
515                         boolean oldAutoCommit = dbConn.getAutoCommit();
516                         dbConn.setAutoCommit(false);
517                         results = fetchGraphStmt.executeQuery();
518                         dbConn.commit();
519                         dbConn.setAutoCommit(oldAutoCommit);
520
521                         if (results.next())
522                         {
523                                 Blob graphBlob = results.getBlob("graph");
524
525                                 ObjectInputStream gStream = new ObjectInputStream(graphBlob.getBinaryStream());
526
527                                 Object graphObj = gStream.readObject();
528                                 gStream.close();
529
530                                 if (graphObj instanceof SvcLogicGraph)
531                                 {
532                                         retval = (SvcLogicGraph) graphObj;
533                                 }
534                                 else
535                                 {
536                                         throw new ConfigurationException("invalid type for graph ("+graphObj.getClass().getName());
537
538                                 }
539                         }
540
541                 }
542                 catch (Exception e)
543                 {
544                         throw new ConfigurationException("SQL query failed", e);
545                 }
546                 finally
547                 {
548                         if (results != null)
549                         {
550                                 try
551                                 {
552                                         results.close();
553                                 }
554                                 catch (SQLException x)
555                                 {
556                                         LOG.error(CommonConstants.RESULTSET_CLOSE_ERR, x);
557                                 }
558                         }
559
560                 }
561
562                 return retval;
563         }
564
565         public void store(SvcLogicGraph graph) throws SvcLogicException {
566
567
568                 if (!isDbConnValid())
569                 {
570
571                         // Try reinitializing
572                         initDbResources();
573
574                         if (!isDbConnValid())
575                         {
576                                 throw new ConfigurationException(CommonConstants.JDBC_CONN_ERR);
577                         }
578                 }
579
580                 if (graph == null)
581                 {
582                         throw new SvcLogicException("graph cannot be null");
583                 }
584
585                 byte[] graphBytes;
586
587                 try (ByteArrayOutputStream byteStr = new ByteArrayOutputStream();
588                         ObjectOutputStream goutStr = new ObjectOutputStream(byteStr))
589                 {
590
591                         goutStr.writeObject(graph);
592
593                         graphBytes = byteStr.toByteArray();
594
595                 }
596                 catch (Exception e)
597                 {
598                         throw new SvcLogicException("could not serialize graph", e);
599                 }
600
601                 // If object already stored in database, delete it
602                 if (hasGraph(graph.getModule(), graph.getRpc(), graph.getVersion(), graph.getMode()))
603                 {
604                         delete(graph.getModule(), graph.getRpc(), graph.getVersion(), graph.getMode());
605                 }
606
607                 try
608                 {
609                         boolean oldAutoCommit = dbConn.getAutoCommit();
610                         dbConn.setAutoCommit(false);
611                         storeGraphStmt.setString(1,  graph.getModule());
612                         storeGraphStmt.setString(2,  graph.getRpc());
613                         storeGraphStmt.setString(3, graph.getVersion());
614                         storeGraphStmt.setString(4, graph.getMode());
615                         storeGraphStmt.setString(5, "N");
616                         storeGraphStmt.setBlob(6,  new ByteArrayInputStream(graphBytes));
617
618                         storeGraphStmt.executeUpdate();
619                         dbConn.commit();
620
621                         dbConn.setAutoCommit(oldAutoCommit);
622                 }
623                 catch (Exception e)
624                 {
625                         throw new SvcLogicException("Could not write object to database", e);
626                 }
627         }
628
629         @Override
630         public void delete(String module, String rpc, String version, String mode) throws SvcLogicException
631         {
632                 if (!isDbConnValid())
633                 {
634
635                         // Try reinitializing
636                         initDbResources();
637
638                         if (!isDbConnValid())
639                         {
640                                 throw new ConfigurationException(CommonConstants.JDBC_CONN_ERR);
641                         }
642                 }
643
644                 try
645                 {
646                         boolean oldAutoCommit = dbConn.getAutoCommit();
647                         dbConn.setAutoCommit(false);
648                         deleteGraphStmt.setString(1,  module);
649                         deleteGraphStmt.setString(2,  rpc);
650                         deleteGraphStmt.setString(3, version);
651                         deleteGraphStmt.setString(4,  mode);
652
653
654                         deleteGraphStmt.executeUpdate();
655                         dbConn.commit();
656                         dbConn.setAutoCommit(oldAutoCommit);
657                 }
658                 catch (Exception e)
659                 {
660                         throw new SvcLogicException("Could not delete object from database", e);
661                 }
662         }
663
664         @Override
665         public void activate(SvcLogicGraph graph) throws SvcLogicException
666         {
667                 try
668                 {
669                         boolean oldAutoCommit = dbConn.getAutoCommit();
670
671                         dbConn.setAutoCommit(false);
672
673                         // Deactivate any current active version
674                         deactivateStmt.setString(1,  graph.getModule());
675                         deactivateStmt.setString(2, graph.getRpc());
676                         deactivateStmt.setString(3, graph.getMode());
677                         deactivateStmt.executeUpdate();
678
679                         // Activate this version
680                         activateStmt.setString(1,  graph.getModule());
681                         activateStmt.setString(2, graph.getRpc());
682                         activateStmt.setString(3, graph.getVersion());
683                         activateStmt.setString(4, graph.getMode());
684                         activateStmt.executeUpdate();
685
686                         dbConn.commit();
687
688                         dbConn.setAutoCommit(oldAutoCommit);
689
690                 }
691                 catch (Exception e)
692                 {
693                         throw new SvcLogicException("Could not activate graph", e);
694                 }
695         }
696
697         @Override
698         public void registerNodeType(String nodeType) throws SvcLogicException {
699
700                 if (isValidNodeType(nodeType))
701                 {
702                         return;
703                 }
704
705                 if (!isDbConnValid())
706                 {
707
708                         // Try reinitializing
709                         initDbResources();
710
711                         if (!isDbConnValid())
712                         {
713                                 throw new ConfigurationException(CommonConstants.JDBC_CONN_ERR);
714                         }
715                 }
716
717                 try
718                 {
719                         boolean oldAutoCommit = dbConn.getAutoCommit();
720                         dbConn.setAutoCommit(false);
721                         registerNodeStmt.setString(1,  nodeType);
722                         registerNodeStmt.executeUpdate();
723                         dbConn.commit();
724                         dbConn.setAutoCommit(oldAutoCommit);
725                 }
726                 catch (Exception e)
727                 {
728                         throw new SvcLogicException("Could not add node type to database", e);
729                 }
730
731         }
732
733         @Override
734         public void unregisterNodeType(String nodeType) throws SvcLogicException {
735
736                 if (!isValidNodeType(nodeType))
737                 {
738                         return;
739                 }
740
741                 if (!isDbConnValid())
742                 {
743
744                         // Try reinitializing
745                         initDbResources();
746
747                         if (!isDbConnValid())
748                         {
749                                 throw new ConfigurationException(CommonConstants.JDBC_CONN_ERR);
750                         }
751                 }
752
753                 try
754                 {
755                         boolean oldAutoCommit = dbConn.getAutoCommit();
756                         dbConn.setAutoCommit(false);
757                         unregisterNodeStmt.setString(1,  nodeType);
758                         unregisterNodeStmt.executeUpdate();
759                         dbConn.commit();
760                         dbConn.setAutoCommit(oldAutoCommit);
761                 }
762                 catch (Exception e)
763                 {
764                         throw new SvcLogicException("Could not delete node type from database", e);
765                 }
766
767         }
768
769         @Override
770         public boolean isValidNodeType(String nodeType) throws SvcLogicException {
771
772                 boolean isValid = false;
773
774                 if (!isDbConnValid())
775                 {
776
777                         // Try reinitializing
778                         initDbResources();
779
780                         if (!isDbConnValid())
781                         {
782                                 throw new ConfigurationException(CommonConstants.JDBC_CONN_ERR);
783                         }
784                 }
785
786                 ResultSet results = null;
787                 try
788                 {
789                         validateNodeStmt.setString(1, nodeType);
790
791                         boolean oldAutoCommit = dbConn.getAutoCommit();
792                         dbConn.setAutoCommit(false);
793                         results = validateNodeStmt.executeQuery();
794                         dbConn.commit();
795                         dbConn.setAutoCommit(oldAutoCommit);
796
797                         if (results.next())
798                         {
799                                 int cnt = results.getInt(1);
800
801                                 if (cnt > 0)
802                                 {
803                                         isValid = true;
804                                 }
805                         }
806
807                 }
808                 catch (Exception e)
809                 {
810                         throw new SvcLogicException("Cannot select node type from database", e);
811                 }
812                 finally
813                 {
814                         if (results != null)
815                         {
816                                 try
817                                 {
818                                         results.close();
819                                 }
820                                 catch (SQLException x)
821                                 {
822                                         LOG.error(CommonConstants.RESULTSET_CLOSE_ERR, x);
823                                 }
824                         }
825
826                 }
827
828                 return(isValid);
829         }
830
831 }