Skip to content

Commit 2cb6e21

Browse files
committed
Derby requires a publicly accessible stream creation method (SPR-6346)
1 parent f49a8d2 commit 2cb6e21

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21-
import java.io.OutputStream;
2221
import java.sql.SQLException;
2322
import java.util.Properties;
2423
import javax.sql.DataSource;
@@ -54,8 +53,8 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure
5453
public static synchronized DerbyEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException {
5554
if (INSTANCE == null) {
5655
// disable log file
57-
System.setProperty("derby.stream.error.method",
58-
DerbyEmbeddedDatabaseConfigurer.class.getName() + ".getNoopOutputStream");
56+
System.setProperty("derby.stream.error.method",
57+
OutputStreamFactory.class.getName() + ".getNoopOutputStream");
5958
INSTANCE = new DerbyEmbeddedDatabaseConfigurer();
6059
}
6160
return INSTANCE;
@@ -101,17 +100,4 @@ private void purgeDatabase(String databaseName) {
101100
}
102101
}
103102

104-
105-
/**
106-
* Returns an {@link OutputStream} that ignores all data given to it.
107-
* Used by {@link #getInstance()} to prevent writing to Derby.log file.
108-
*/
109-
public static OutputStream getNoopOutputStream() {
110-
return new OutputStream() {
111-
public void write(int b) throws IOException {
112-
// ignore the output
113-
}
114-
};
115-
}
116-
117103
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2002-2009 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.jdbc.datasource.embedded;
18+
19+
import java.io.IOException;
20+
import java.io.OutputStream;
21+
22+
/**
23+
* Internal helper for exposing dummy OutputStreams to embedded databases
24+
* such as Derby, preventing the creation of a log file.
25+
*
26+
* @author Juergen Hoeller
27+
* @since 3.0
28+
*/
29+
public class OutputStreamFactory {
30+
31+
/**
32+
* Returns an {@link java.io.OutputStream} that ignores all data given to it.
33+
*/
34+
public static OutputStream getNoopOutputStream() {
35+
return new OutputStream() {
36+
public void write(int b) throws IOException {
37+
// ignore the output
38+
}
39+
};
40+
}
41+
42+
}

0 commit comments

Comments
 (0)