net.sf.jabb.util.db
Class StartAndStopSQL

java.lang.Object
  extended by net.sf.jabb.util.db.StartAndStopSQL
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle

public class StartAndStopSQL
extends Object
implements org.springframework.context.Lifecycle, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean

Helper class to execute SQL when Spring context starts and stops. It should be used as singleton.

Author:
James Hu

Field Summary
protected  DataSource dataSource
           
protected static int RUNNING
           
protected static int STARTING
           
protected  String startSQL
           
protected  AtomicInteger state
           
protected static String[] stateNames
           
protected static int STOPPING
           
protected  String stopSQL
           
protected static int UNKNOWN
           
 
Constructor Summary
StartAndStopSQL()
           
 
Method Summary
 void afterPropertiesSet()
           
 void destroy()
           
protected  void executeSQL(String sql)
          Execute one SQL statement.
 DataSource getDataSource()
           
 String getStartSQL()
           
 String getStopSQL()
           
 boolean isRunning()
           
 void setDataSource(DataSource dataSource)
           
 void setStartSQL(String startSQL)
           
 void setStopSQL(String shutdownSQL)
           
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN

protected static final int UNKNOWN
See Also:
Constant Field Values

STARTING

protected static final int STARTING
See Also:
Constant Field Values

RUNNING

protected static final int RUNNING
See Also:
Constant Field Values

STOPPING

protected static final int STOPPING
See Also:
Constant Field Values

stateNames

protected static final String[] stateNames

state

protected AtomicInteger state

dataSource

protected DataSource dataSource

startSQL

protected String startSQL

stopSQL

protected String stopSQL
Constructor Detail

StartAndStopSQL

public StartAndStopSQL()
Method Detail

executeSQL

protected void executeSQL(String sql)
Execute one SQL statement. RuntimeException will be thrown if SQLException was caught.

Parameters:
sql - the statement to be executed

isRunning

public boolean isRunning()
Specified by:
isRunning in interface org.springframework.context.Lifecycle

start

public void start()
Specified by:
start in interface org.springframework.context.Lifecycle

stop

public void stop()
Specified by:
stop in interface org.springframework.context.Lifecycle

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
Exception

getDataSource

public DataSource getDataSource()

setDataSource

public void setDataSource(DataSource dataSource)

getStartSQL

public String getStartSQL()

setStartSQL

public void setStartSQL(String startSQL)

getStopSQL

public String getStopSQL()

setStopSQL

public void setStopSQL(String shutdownSQL)


Copyright © 2012. All Rights Reserved.