Derby has a series of configuration options that are controlled by system properties. It's quite painful to arrange system property settings in a webapp. Has anyone come up with a solution?
In addition, I have been unable to make them work in a webapp.
Here is the code of a servlet context listener. derby.log is still created in the cwd of the container, rather than calls being made to my logging procedure.
/**
* Listener to try to get Derby to behave better.
*/
public class ContextListener implements ServletContextListener {
private static final String TEMP_DIR_ATTRIBUTE = "javax.servlet.context.tempdir";
private static ServletContext context;
private static Writer logWriter;
private class LogWriter extends Writer {
@Override
public void close() throws IOException {
}
@Override
public void flush() throws IOException {
}
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
context.log(new String(cbuf, off, len));
}
}
/** {@inheritDoc}*/
public void contextDestroyed(ServletContextEvent sce) {
}
public static Writer getLogSteam() {
return logWriter;
}
/** {@inheritDoc}*/
public void contextInitialized(ServletContextEvent sce) {
logWriter = new LogWriter();
File tempDirFile = (File)sce.getServletContext().getAttribute(TEMP_DIR_ATTRIBUTE);
context = sce.getServletContext();
System.setProperty("derby.system.home", tempDirFile.getAbsolutePath());
System.setProperty("derby.stream.error.method", "com.basistech.vws.ContextListener.getLogStream");
}
}