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