This patch allows to configure the autofetch statistic to be in a different directory than the dictionary.
example
ebean.autofetch.directory=${user.home}/avaje/autofetch
Index: ../ebean/src/com/avaje/ebean/server/resource/DefaultResourceManagerFactory.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/resource/DefaultResourceManagerFactory.java (revision 141)
+++ ../ebean/src/com/avaje/ebean/server/resource/DefaultResourceManagerFactory.java Tue Feb 24 11:52:10 CET 2009
@@ -19,12 +19,6 @@
*/
package com.avaje.ebean.server.resource;
-import java.io.File;
-import java.util.logging.Logger;
-
-import javax.persistence.PersistenceException;
-import javax.servlet.ServletContext;
-
import com.avaje.ebean.server.lib.GlobalProperties;
import com.avaje.ebean.server.lib.resource.DirectoryFinder;
import com.avaje.ebean.server.lib.resource.FileResourceSource;
@@ -34,6 +28,11 @@
import com.avaje.ebean.server.plugin.PluginProperties;
import com.avaje.lib.log.LogFactory;
+import javax.persistence.PersistenceException;
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.util.logging.Logger;
+
/**
* Creates a ResourceManager for a server depending on the avaje.properties.
*
@@ -61,9 +60,10 @@
ResourceSource resourceSource = createResourceSource();
File dictDir = getDictionaryDir(resourceSource);
+ File autofetchDir = getAutofetchDir(resourceSource);
File idxDir = getIndexDir(dictDir);
- return new DefaultResourceManager(resourceSource, dictDir, idxDir);
+ return new DefaultResourceManager(resourceSource, dictDir, idxDir, autofetchDir);
}
/**
@@ -102,7 +102,28 @@
}
}
- /**
+ /**
+ * Return the directory that autofetch serialized file goes into.
+ */
+ protected File getAutofetchDir(ResourceSource resourceSource) {
+
+ String dir = properties.getProperty("autofetch.directory", null);
+ if (dir != null) {
+ return new File(dir);
+ }
+
+ String realPath = resourceSource.getRealPath();
+ if (realPath != null) {
+ // same location as the sql files
+ return new File(realPath);
+
+ } else {
+ // be compatible to previous behaviour
+ return getDictionaryDir(resourceSource);
+ }
+ }
+
+ /**
* Return the resource loader for external sql files.
*
* This can be url based (for webapps) or otherwise file based.
Index: ../ebean/src/com/avaje/ebean/server/resource/DefaultResourceManager.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/resource/DefaultResourceManager.java (revision 141)
+++ ../ebean/src/com/avaje/ebean/server/resource/DefaultResourceManager.java Tue Feb 24 11:53:49 CET 2009
@@ -19,14 +19,13 @@
*/
package com.avaje.ebean.server.resource;
-import java.io.File;
-import java.io.IOException;
-
-import javax.persistence.PersistenceException;
-
import com.avaje.ebean.server.lib.resource.ResourceContent;
import com.avaje.ebean.server.lib.resource.ResourceSource;
+import javax.persistence.PersistenceException;
+import java.io.File;
+import java.io.IOException;
+
/**
* The default ResourceManager implementation.
*/
@@ -37,11 +36,14 @@
final File dictionaryFile;
final File indexDirectory;
-
+
- public DefaultResourceManager(ResourceSource resourceSource, File dictionaryFile, File indexDirectory) {
+ final File autofetchDir;
+
+ public DefaultResourceManager(ResourceSource resourceSource, File dictionaryFile, File indexDirectory, File autofetchDir) {
this.resourceSource = resourceSource;
this.dictionaryFile = dictionaryFile;
this.indexDirectory = indexDirectory;
+ this.autofetchDir = autofetchDir;
}
public ResourceSource getResourceSource() {
@@ -52,6 +54,10 @@
return dictionaryFile;
}
+ public File getAutofetchDirectory() {
+ return autofetchDir;
+ }
+
public File getIndexDirectory() {
return indexDirectory;
}
Index: ../ebean/src/com/avaje/ebean/server/resource/ResourceManager.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/resource/ResourceManager.java (revision 141)
+++ ../ebean/src/com/avaje/ebean/server/resource/ResourceManager.java Tue Feb 24 11:53:49 CET 2009
@@ -19,10 +19,10 @@
*/
package com.avaje.ebean.server.resource;
-import java.io.File;
-
import com.avaje.ebean.server.lib.resource.ResourceSource;
+import java.io.File;
+
/**
* Controls access to the required resources.
*/
@@ -36,7 +36,15 @@
*/
public File getDictionaryDirectory();
- /**
+ /**
+ * Return the directory the autofetch statistic is serialized to.
+ *
+ * This needs to be a directory with read/write permissions.
+ *
+ */
+ public File getAutofetchDirectory();
+
+ /**
* Return the directory to put lucene indexes in.
*
* This needs to be a directory with read/write permissions.
Index: ../ebean/src/com/avaje/ebean/server/plugin/PluginDbConfig.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/plugin/PluginDbConfig.java (revision 141)
+++ ../ebean/src/com/avaje/ebean/server/plugin/PluginDbConfig.java Tue Feb 24 12:02:16 CET 2009
@@ -19,15 +19,6 @@
*/
package com.avaje.ebean.server.plugin;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.ObjectInputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.persistence.PersistenceException;
-import javax.sql.DataSource;
-
import com.avaje.ebean.server.autofetch.AutoFetchManager;
import com.avaje.ebean.server.autofetch.DefaultAutoFetchManager;
import com.avaje.ebean.server.core.InternalEbeanServer;
@@ -44,6 +35,14 @@
import com.avaje.ebean.util.Message;
import com.avaje.lib.log.LogFactory;
+import javax.persistence.PersistenceException;
+import javax.sql.DataSource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.ObjectInputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
/**
* Plugin level that defines database specific settings.
*/
@@ -307,7 +306,7 @@
fileName = ".ebean."+fileName+".autofetch";
// autoFetch file in same directory as dictionary
- File dictDir = resourceManager.getDictionaryDirectory();
+ File dictDir = resourceManager.getAutofetchDirectory();
if (!dictDir.exists()) {
// automatically create the directory if it does not exist.