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 com.fatwire.gst.foundation.facade.install;
18  
19  import COM.FutureTense.Interfaces.ICS;
20  
21  import com.fatwire.gst.foundation.facade.sql.Row;
22  import com.fatwire.gst.foundation.facade.sql.SqlHelper;
23  
24  import static com.fatwire.gst.foundation.facade.sql.SqlHelper.quote;
25  
26  /**
27   * Helper for registring AssetEventListener in the database.
28   * 
29   * @author Dolf.Dijkstra
30   * @since May 23, 2011
31   */
32  public class AssetListenerInstall {
33      public static final String REGISTRY_TABLE = "AssetListener_reg";
34  
35      /**
36       * Regsisters the AssetEventListener in the AssetListener table
37       * 
38       * @param ics
39       * @param classname
40       * @param blocking
41       */
42      public static void register(ICS ics, String classname, boolean blocking) {
43          String id = ics.genID(true);
44          String listener = classname;
45          SqlHelper
46                  .execute(ics, REGISTRY_TABLE, "DELETE FROM " + REGISTRY_TABLE + " WHERE listener = " + quote(listener));
47          SqlHelper.execute(ics, REGISTRY_TABLE, "INSERT INTO " + REGISTRY_TABLE + " (id, listener, blocking) VALUES ("
48                  + quote(id) + "," + quote(listener) + "," + quote(blocking ? "Y" : "N") + ")");
49      }
50  
51      public static boolean isRegistered(ICS ics, String classname) {
52          for (Row row : SqlHelper.select(ics, REGISTRY_TABLE, "SELECT * FROM "+REGISTRY_TABLE+" WHERE listener = " + quote(classname))) {
53              return true;
54          }
55          return false;
56      }
57  
58  }