Update of /var/cvs/src/org/mmbase/storage/implementation/database
In directory james.mmbase.org:/tmp/cvs-serv6818/implementation/database
Modified Files:
DatabaseStorageManager.java DatabaseStorageManagerFactory.java
GenericDataSource.java
Log Message:
MMB-1614
See also:
http://cvs.mmbase.org/viewcvs/src/org/mmbase/storage/implementation/database
See also: http://www.mmbase.org/jira/browse/MMB-1614
Index: DatabaseStorageManager.java
===================================================================
RCS file:
/var/cvs/src/org/mmbase/storage/implementation/database/DatabaseStorageManager.java,v
retrieving revision 1.190
retrieving revision 1.191
diff -u -b -r1.190 -r1.191
--- DatabaseStorageManager.java 19 Mar 2008 11:52:51 -0000 1.190
+++ DatabaseStorageManager.java 21 Mar 2008 13:44:23 -0000 1.191
@@ -32,7 +32,7 @@
*
* @author Pierre van Rooden
* @since MMBase-1.7
- * @version $Id: DatabaseStorageManager.java,v 1.190 2008/03/19 11:52:51
pierre Exp $
+ * @version $Id: DatabaseStorageManager.java,v 1.191 2008/03/21 13:44:23
michiel Exp $
*/
public class DatabaseStorageManager implements StorageManager {
@@ -681,7 +681,7 @@
* @return The File where to store or read the binary data
*/
protected File getBinaryFile(MMObjectNode node, String fieldName) {
- String basePath = factory.getBinaryFileBasePath();
+ File basePath = factory.getBinaryFileBasePath();
StringBuilder pathBuffer = new StringBuilder();
int number = node.getNumber() / 1000;
while (number > 0) {
@@ -710,8 +710,15 @@
else {
builderName = node.getBuilder().getFullTableName();
}
+ String canon;
+ try {
+ canon = basePath.getCanonicalPath();
+ } catch (Exception e) {
+ log.warn(e);
+ canon = basePath.toString();
+ }
- pathBuffer.insert(0, basePath + factory.getDatabaseName() +
File.separator + builderName);
+ pathBuffer.insert(0, canon + File.separator +
factory.getDatabaseName() + File.separator + builderName);
return new File(pathBuffer.toString(), "" + node.getNumber() + '.' +
fieldName);
}
@@ -721,7 +728,7 @@
*/
private File getLegacyBinaryFile(MMObjectNode node, String fieldName) {
// the same basePath, so you so need to set that up right.
- String basePath = factory.getBinaryFileBasePath();
+ File basePath = factory.getBinaryFileBasePath();
File f = new File(basePath, node.getBuilder().getTableName() +
File.separator + node.getNumber() + '.' + fieldName);
if (f.exists()) { // 1.6 storage or 'support' blobdatadir
@@ -732,7 +739,7 @@
}
}
- f = new File(basePath + File.separator + factory.getCatalog() +
File.separator + node.getBuilder().getFullTableName() + File.separator +
node.getNumber() + '.' + fieldName);
+ f = new File(basePath, factory.getCatalog() + File.separator +
node.getBuilder().getFullTableName() + File.separator + node.getNumber() + '.'
+ fieldName);
if (f.exists()) { // 1.7.0.rc1 blob data dir
if (!f.canRead()) {
log.warn("Found '" + f + "' but it cannot be read");
Index: DatabaseStorageManagerFactory.java
===================================================================
RCS file:
/var/cvs/src/org/mmbase/storage/implementation/database/DatabaseStorageManagerFactory.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- DatabaseStorageManagerFactory.java 22 Feb 2008 12:27:48 -0000 1.49
+++ DatabaseStorageManagerFactory.java 21 Mar 2008 13:44:23 -0000 1.50
@@ -12,6 +12,7 @@
import java.sql.*;
import java.util.StringTokenizer;
+
import javax.naming.*;
import javax.sql.DataSource;
import java.io.*;
@@ -41,7 +42,7 @@
*
* @author Pierre van Rooden
* @since MMBase-1.7
- * @version $Id: DatabaseStorageManagerFactory.java,v 1.49 2008/02/22 12:27:48
michiel Exp $
+ * @version $Id: DatabaseStorageManagerFactory.java,v 1.50 2008/03/21 13:44:23
michiel Exp $
*/
public class DatabaseStorageManagerFactory extends
StorageManagerFactory<DatabaseStorageManager> {
@@ -95,11 +96,11 @@
protected boolean supportsTransactions = false;
- private static final String BASE_PATH_UNSET = "UNSET";
+ private static final File BASE_PATH_UNSET = new File("UNSET");
/**
* Used by #getBinaryFileBasePath
*/
- private String basePath = BASE_PATH_UNSET;
+ private File basePath = BASE_PATH_UNSET;
public double getVersion() {
return 0.1;
@@ -152,7 +153,7 @@
* @param binaryFileBasePath For some datasource a file base path may be
needed (some configurations of hsql). It can be <code>null</code> during
bootstrap. In lookup.xml an alternative URL may be configured then which does
not need the file base path.
* @since MMBase-1.8
*/
- protected DataSource createDataSource(String binaryFileBasePath) {
+ protected DataSource createDataSource(File binaryFileBasePath) {
DataSource ds = null;
// get the Datasource for the database to use
// the datasource uri (i.e. 'jdbc/xa/MMBase' )
@@ -356,7 +357,7 @@
/**
* As [EMAIL PROTECTED] #getBinaryFileBasePath(boolean)} with
<code>true</code>
*/
- public String getBinaryFileBasePath() {
+ protected File getBinaryFileBasePath() {
return getBinaryFileBasePath(true);
}
@@ -365,19 +366,19 @@
* @param check If the path is only perhaps needed, you may want to
provide 'false' here.
* @since MMBase-1.8.1
*/
- public String getBinaryFileBasePath(boolean check) {
+ protected File getBinaryFileBasePath(boolean check) {
if (basePath == BASE_PATH_UNSET) {
- basePath = (String) getAttribute(Attributes.BINARY_FILE_PATH);
- if (basePath == null || basePath.equals("")) {
- basePath = getDataDir();
+ String path = (String) getAttribute(Attributes.BINARY_FILE_PATH);
+ if (path == null || path.equals("")) {
+ basePath = mmbase.getDataDir();
} else {
- MessageFormat mf = new MessageFormat(basePath);
- java.io.File baseFile = new
java.io.File(mf.format(getDataDir()));
+ MessageFormat mf = new MessageFormat(path);
+ java.io.File baseFile = new
java.io.File(mf.format(mmbase.getDataDir()));
if (! baseFile.isAbsolute()) {
ServletContext sc = MMBaseContext.getServletContext();
String absolute = sc != null ? sc.getRealPath("/") +
File.separator : null;
if (absolute == null) absolute =
System.getProperty("user.dir") + File.separator;
- basePath = absolute + basePath;
+ basePath = new File(absolute + basePath);
}
}
if (basePath == null) {
@@ -386,16 +387,7 @@
} else {
log.service("Binary file base path " + basePath);
}
- File baseDir = new File(basePath);
- try {
- basePath = baseDir.getCanonicalPath();
if (check) checkBinaryFileBasePath(basePath);
- } catch (IOException ioe) {
- log.error(ioe);
- }
- if (! basePath.endsWith(File.separator)) {
- basePath += File.separator;
- }
}
return basePath;
}
@@ -405,13 +397,12 @@
* @param basePath a Directory name
* @since MMBase-1.8.1
*/
- public static boolean checkBinaryFileBasePath(String basePath) {
- File baseDir = new File(basePath);
+ public static boolean checkBinaryFileBasePath(File baseDir) {
if (! baseDir.mkdirs() && ! baseDir.exists()) {
- log.error("Cannot create the binary file path " + basePath);
+ log.error("Cannot create the binary file path " + baseDir);
}
if (! baseDir.canWrite()) {
- log.error("Cannot write in the binary file path " + basePath);
+ log.error("Cannot write in the binary file path " + baseDir);
return false;
} else {
return true;
Index: GenericDataSource.java
===================================================================
RCS file:
/var/cvs/src/org/mmbase/storage/implementation/database/GenericDataSource.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- GenericDataSource.java 22 Feb 2008 12:27:48 -0000 1.16
+++ GenericDataSource.java 21 Mar 2008 13:44:23 -0000 1.17
@@ -11,6 +11,7 @@
import java.sql.*;
+import java.io.File;
import javax.sql.DataSource;
import java.lang.reflect.*;
@@ -32,7 +33,7 @@
* @author Pierre van Rooden
* @author Michiel Meeuwissen
* @since MMBase-1.7
- * @version $Id: GenericDataSource.java,v 1.16 2008/02/22 12:27:48 michiel Exp
$
+ * @version $Id: GenericDataSource.java,v 1.17 2008/03/21 13:44:23 michiel Exp
$
*/
public final class GenericDataSource implements DataSource {
private static final Logger log =
Logging.getLoggerInstance(GenericDataSource.class);
@@ -42,7 +43,7 @@
private java.io.PrintWriter printWriter = null;
- final private String dataDir;
+ final private File dataDir;
final private boolean meta;
private boolean basePathOk = false;
@@ -54,13 +55,13 @@
* @param A Datadir (as a string ending in a /) which may be used in some
URL's (most noticably those of HSQLDB). Can be <code>null</code> if not used.
* @throws StorageInaccessibleException if the JDBC module used in
creating the datasource is inaccessible
*/
- GenericDataSource(MMBase mmbase, String dataDir) throws
StorageInaccessibleException {
+ GenericDataSource(MMBase mmbase, File dataDir) throws
StorageInaccessibleException {
jdbc = Module.getModule(JDBC.class);
if (jdbc == null) {
throw new StorageInaccessibleException("Cannot load Datasource or
JDBC Module");
}
jdbc.startModule();
- this.dataDir = dataDir == null ? "" : dataDir;
+ this.dataDir = dataDir;
meta = false;
}
/**
@@ -209,7 +210,15 @@
}
}
String url = jdbc.makeUrl();
- String newUrl = url.replaceAll("\\$DATADIR", dataDir);
+ String data;
+ try {
+ data = dataDir.getCanonicalPath();
+ } catch (Exception e) {
+ log.error(e + " Falling back to " + dataDir);
+ data = dataDir.toString();
+
+ }
+ String newUrl = url.replaceAll("\\$DATADIR", data + File.separator);
if ((!basePathOk) && (! newUrl.equals(url))) {
basePathOk =
DatabaseStorageManagerFactory.checkBinaryFileBasePath(dataDir);
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs