Home » geronimo-2.2-source-release » org.apache.geronimo.derby » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.derby;
   19   
   20   import org.slf4j.Logger;
   21   import org.slf4j.LoggerFactory;
   22   import org.apache.geronimo.gbean.GBeanInfo;
   23   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   24   import org.apache.geronimo.gbean.GBeanLifecycle;
   25   import org.apache.geronimo.system.serverinfo.ServerInfo;
   26   
   27   import java.sql.DriverManager;
   28   import java.sql.SQLException;
   29   
   30   /**
   31    * A GBean that represents an instance of an Apache Derby system (a system being
   32    * a collection of different databases).
   33    *
   34    * @version $Rev: 653782 $ $Date: 2008-05-06 07:10:14 -0700 (Tue, 06 May 2008) $
   35    */
   36   public class DerbySystemGBean implements DerbySystem, GBeanLifecycle {
   37       private static final Logger log = LoggerFactory.getLogger(DerbySystemGBean.class);
   38       private static final String SYSTEM_HOME = "derby.system.home";
   39       private static final String SHUTDOWN_ALL = "jdbc:derby:;shutdown=true";
   40   
   41       private final ServerInfo serverInfo;
   42       private final String systemHome;
   43       private String actualHome;
   44   
   45       public DerbySystemGBean(ServerInfo serverInfo, String derbySystemHome) {
   46           this.serverInfo = serverInfo;
   47           this.systemHome = derbySystemHome;
   48       }
   49   
   50       public String getDerbyHome() {
   51           return actualHome;
   52       }
   53   
   54       public void doStart() throws Exception {
   55           // set up the system property for the database home
   56           actualHome = System.getProperty(SYSTEM_HOME);
   57           if (actualHome == null) {
   58               actualHome = serverInfo.resolveServerPath(systemHome);
   59           }
   60           System.setProperty(SYSTEM_HOME, actualHome);
   61   
   62           // set the magic system property that causes derby to use explicity
   63           // file sync instead of relying on vm support for file open rws
   64           System.setProperty("derby.storage.fileSyncTransactionLog", "true");
   65   
   66           // load the Embedded driver to initialize the home
   67           new org.apache.derby.jdbc.EmbeddedDriver();
   68           log.debug("Started in " + actualHome);
   69       }
   70   
   71       public void doStop() throws Exception {
   72           try {
   73               DriverManager.getConnection(SHUTDOWN_ALL, null, null);
   74           } catch (SQLException e) {
   75               // SQLException gets thrown on successful shutdown so ignore
   76           }
   77           System.gc();  // Added per recommendation Derby documentation
   78           log.debug("Stopped");
   79       }
   80   
   81       public void doFail() {
   82           try {
   83               DriverManager.getConnection(SHUTDOWN_ALL, null, null);
   84           } catch (SQLException e) {
   85               // SQLException gets thrown on successful shutdown so ignore
   86           }
   87           System.gc();  // Added per recommendation Derby documentation
   88           log.warn("Failed");
   89       }
   90   
   91       public static final GBeanInfo GBEAN_INFO;
   92   
   93       public static GBeanInfo getGBeanInfo() {
   94           return GBEAN_INFO;
   95       }
   96   
   97       static {
   98           GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(DerbySystemGBean.class);
   99           infoFactory.addAttribute("derbySystemHome", String.class, true);
  100           infoFactory.addAttribute("derbyHome", String.class, false);
  101           infoFactory.addReference("ServerInfo", ServerInfo.class, "GBean");
  102           infoFactory.setConstructor(new String[]{"ServerInfo", "derbySystemHome"});
  103           infoFactory.setPriority(GBeanInfo.PRIORITY_CLASSLOADER);
  104           GBEAN_INFO = infoFactory.getBeanInfo();
  105       }
  106   }

Home » geronimo-2.2-source-release » org.apache.geronimo.derby » [javadoc | source]