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