Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2011-01-06 06:16:01 -0500
committerGreg Wilkins2011-01-06 06:16:01 -0500
commitdb7d2afe822948ca2da378b45ec8dcee7dc097bc (patch)
tree10125a165c119264425eeedc49837695843b31b3
parenta3efe35e4a64413c968b8d2dc556381ac867f204 (diff)
downloadorg.eclipse.jetty.project-db7d2afe822948ca2da378b45ec8dcee7dc097bc.tar.gz
org.eclipse.jetty.project-db7d2afe822948ca2da378b45ec8dcee7dc097bc.tar.xz
org.eclipse.jetty.project-db7d2afe822948ca2da378b45ec8dcee7dc097bc.zip
file destroyer
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2628 7e9141cc-0065-0410-87d8-b60c137991c4
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/DataSourceCloser.java43
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/component/FileDestroyable.java68
2 files changed, 102 insertions, 9 deletions
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/DataSourceCloser.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/DataSourceCloser.java
index d4b53d1e32..4c3db97973 100644
--- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/DataSourceCloser.java
+++ b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/DataSourceCloser.java
@@ -1,6 +1,7 @@
package org.eclipse.jetty.jndi;
import java.lang.reflect.Method;
+import java.sql.Statement;
import javax.sql.DataSource;
@@ -18,26 +19,50 @@ import org.eclipse.jetty.util.log.Log;
public class DataSourceCloser implements Destroyable
{
final DataSource _datasource;
+ final String _shutdown;
public DataSourceCloser(DataSource datasource)
{
+ if (datasource==null)
+ throw new IllegalArgumentException();
_datasource=datasource;
+ _shutdown=null;
+ }
+
+ public DataSourceCloser(DataSource datasource,String shutdownSQL)
+ {
+ if (datasource==null)
+ throw new IllegalArgumentException();
+ _datasource=datasource;
+ _shutdown=shutdownSQL;
}
public void destroy()
{
- if (_datasource != null)
+ try
{
- try
+ if (_shutdown!=null)
{
- Method close = _datasource.getClass().getMethod("close", new Class[]{});
- close.invoke(_datasource, new Object[]{});
- }
- catch (Exception e)
- {
- Log.warn(e);
+ Log.info("Shutdown datasource {}",_datasource);
+ Statement stmt = _datasource.getConnection().createStatement();
+ stmt.executeUpdate(_shutdown);
+ stmt.close();
}
}
+ catch (Exception e)
+ {
+ Log.warn(e);
+ }
+
+ try
+ {
+ Method close = _datasource.getClass().getMethod("close", new Class[]{});
+ Log.info("Close datasource {}",_datasource);
+ close.invoke(_datasource, new Object[]{});
+ }
+ catch (Exception e)
+ {
+ Log.warn(e);
+ }
}
-
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/FileDestroyable.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/FileDestroyable.java
new file mode 100644
index 0000000000..740007ab45
--- /dev/null
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/FileDestroyable.java
@@ -0,0 +1,68 @@
+package org.eclipse.jetty.util.component;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jetty.util.IO;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.resource.Resource;
+
+public class FileDestroyable implements Destroyable
+{
+ final List<File> _files = new ArrayList<File>();
+
+ public FileDestroyable()
+ {
+ }
+
+ public FileDestroyable(String file) throws IOException
+ {
+ _files.add(Resource.newResource(file).getFile());
+ }
+
+ public FileDestroyable(File file)
+ {
+ _files.add(file);
+ }
+
+ public void addFile(String file) throws IOException
+ {
+ _files.add(Resource.newResource(file).getFile());
+ }
+
+ public void addFile(File file)
+ {
+ _files.add(file);
+ }
+
+ public void addFiles(Collection<File> files)
+ {
+ _files.addAll(files);
+ }
+
+ public void removeFile(String file) throws IOException
+ {
+ _files.remove(Resource.newResource(file).getFile());
+ }
+
+ public void removeFile(File file)
+ {
+ _files.remove(file);
+ }
+
+ public void destroy()
+ {
+ for (File file : _files)
+ {
+ if (file.exists())
+ {
+ Log.debug("Destroy {}",file);
+ IO.delete(file);
+ }
+ }
+ }
+
+}

Back to the top