View Javadoc
1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package tools.gsf.facade.install;
18  
19  import COM.FutureTense.Interfaces.ICS;
20  import tools.gsf.facade.sql.SqlHelper;
21  
22  import static tools.gsf.facade.sql.SqlHelper.quote;
23  
24  /**
25   * Helper for registering AssetEventListener in the database.
26   *
27   * @author Dolf.Dijkstra
28   * @since May 23, 2011
29   */
30  public class AssetListenerInstall {
31      public static final String REGISTRY_TABLE = "AssetListener_reg";
32  
33      /**
34       * Regsisters the AssetEventListener in the AssetListener table
35       *
36       * @param ics       Content Server context object
37       * @param classname class name
38       * @param blocking  flag for blocking
39       */
40      public static void register(ICS ics, String classname, boolean blocking) {
41          String id = ics.genID(true);
42          String listener = classname;
43          SqlHelper.execute(ics, REGISTRY_TABLE, "DELETE FROM " + REGISTRY_TABLE
44                  + " WHERE listener = " + quote(listener));
45          SqlHelper.execute(ics, REGISTRY_TABLE, "INSERT INTO " + REGISTRY_TABLE
46                  + " (id, listener, blocking) VALUES (" + quote(id) + ","
47                  + quote(listener) + "," + quote(blocking ? "Y" : "N") + ")");
48      }
49  
50      public static boolean isRegistered(ICS ics, String classname) {
51          return SqlHelper.select(
52                  ics,
53                  REGISTRY_TABLE,
54                  "SELECT * FROM " + REGISTRY_TABLE + " WHERE listener = "
55                          + quote(classname)).size() > 0;
56      }
57  
58  }