diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataCacheMaintenance.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataCacheMaintenance.java index 7fdc3aaa2..1f6fa4088 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataCacheMaintenance.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/MetaDataCacheMaintenance.java @@ -44,28 +44,7 @@ public class MetaDataCacheMaintenance { private final BrokerFactory factory; private final OpenJPAConfiguration conf; private final boolean devpath; - private final Log log; - - /** - * @deprecated logging is routed to the logging system now. - */ - public MetaDataCacheMaintenance(BrokerFactory factory, boolean devpath, - boolean verbose) { - this(factory, devpath); - } - - /** - * @param factory The {@link BrokerFactory} for which cached metadata - * should be built. - * @param devpath Whether or not to scan the development environment paths - * to find persistent types to store. - */ - public MetaDataCacheMaintenance(BrokerFactory factory, boolean devpath) { - this.factory = factory; - this.conf = factory.getConfiguration(); - this.devpath = devpath; - this.log = conf.getLog(OpenJPAConfiguration.LOG_TOOL); - } + private Log log; public static void main(String[] args) { Options opts = new Options(); @@ -92,6 +71,31 @@ public class MetaDataCacheMaintenance { } } + /** + * @deprecated logging is routed to the logging system now. + */ + public MetaDataCacheMaintenance(BrokerFactory factory, boolean devpath, + boolean verbose) { + this(factory, devpath); + } + + /** + * @param factory The {@link BrokerFactory} for which cached metadata + * should be built. + * @param devpath Whether or not to scan the development environment paths + * to find persistent types to store. + */ + public MetaDataCacheMaintenance(BrokerFactory factory, boolean devpath) { + this.factory = factory; + this.conf = factory.getConfiguration(); + this.devpath = devpath; + this.log = conf.getLog(OpenJPAConfiguration.LOG_TOOL); + } + + public void setLog(Log log) { + this.log = log; + } + private static int usage() { System.err.println("Usage: java MetaDataCacheMaintenance " + "[-scanDevPath t|f] store | dump"); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestCacheMarshallerEndToEnd.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestCacheMarshallerEndToEnd.java index 8982d436b..462bcd5e5 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestCacheMarshallerEndToEnd.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestCacheMarshallerEndToEnd.java @@ -31,6 +31,7 @@ import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI; import org.apache.openjpa.persistence.query.NamedQueryEntity; import org.apache.openjpa.persistence.simple.AllFieldTypes; import org.apache.openjpa.persistence.test.PersistenceTestCase; +import org.apache.openjpa.lib.log.Log; public class TestCacheMarshallerEndToEnd extends PersistenceTestCase { @@ -75,22 +76,13 @@ public class TestCacheMarshallerEndToEnd emf.getConfiguration(), MetaDataCacheMaintenance.class.getName()); cm.getOutputFile().delete(); MetaDataCacheMaintenance maint = new MetaDataCacheMaintenance( - JPAFacadeHelper.toBrokerFactory(emf), false, true); - final List lines = new ArrayList(); - PrintStream out = new PrintStream(new ByteArrayOutputStream()) { - public void println(String line) { - lines.add(line); - } - - public void println(Object line) { - println(line.toString()); - } - }; - maint.setOutputStream(out); + JPAFacadeHelper.toBrokerFactory(emf), false); + LogImpl log = new LogImpl(); + maint.setLog(log); maint.store(); - assertContains(lines, " " + AllFieldTypes.class.getName()); - assertContains(lines, " " + NamedQueryEntity.class.getName()); - assertContains(lines, " NamedQueryEntity.namedQuery"); + assertContains(log.lines, " " + AllFieldTypes.class.getName()); + assertContains(log.lines, " " + NamedQueryEntity.class.getName()); + assertContains(log.lines, " NamedQueryEntity.namedQuery"); emf.close(); emf = createEMF(LOAD_PROPS); @@ -112,4 +104,68 @@ public class TestCacheMarshallerEndToEnd fail("should contain a line starting with " + prefix + ": " + lines); } + + private class LogImpl implements Log { + private List lines = new ArrayList(); + + public boolean isTraceEnabled() { + return true; + } + + public boolean isInfoEnabled() { + return true; + } + + public boolean isWarnEnabled() { + throw new UnsupportedOperationException(); + } + + public boolean isErrorEnabled() { + throw new UnsupportedOperationException(); + } + + public boolean isFatalEnabled() { + throw new UnsupportedOperationException(); + } + + public void trace(Object o) { + lines.add(o.toString()); + } + + public void trace(Object o, Throwable t) { + throw new UnsupportedOperationException(); + } + + public void info(Object o) { + lines.add(o.toString()); + } + + public void info(Object o, Throwable t) { + throw new UnsupportedOperationException(); + } + + public void warn(Object o) { + throw new UnsupportedOperationException(); + } + + public void warn(Object o, Throwable t) { + throw new UnsupportedOperationException(); + } + + public void error(Object o) { + throw new UnsupportedOperationException(); + } + + public void error(Object o, Throwable t) { + throw new UnsupportedOperationException(); + } + + public void fatal(Object o) { + throw new UnsupportedOperationException(); + } + + public void fatal(Object o, Throwable t) { + throw new UnsupportedOperationException(); + } + } }