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 开发者_JS百科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");
}
}
There are multiple ways to set Derby properties. Here's some docs: http://db.apache.org/derby/docs/10.5/devguide/cdevsetprop24222.html You don't say which part of this you find to be painful, though, so it's hard to know what sort of solution you're looking for.
Which properties are you trying to set, and what aspect of setting them is proving painful?
精彩评论