[power-matchmaker] r2779 committed - Deleting a folder now deletes all of the derby dbs associated with the...

0 views
Skip to first unread message

power-ma...@googlecode.com

unread,
Jan 28, 2011, 4:46:14 PM1/28/11
to matchmake...@googlegroups.com
Revision: 2779
Author: ThomasObrien95
Date: Fri Jan 28 13:45:42 2011
Log: Deleting a folder now deletes all of the derby dbs associated with the
projects in the folder.
Renaming a folder or project also renames the correct derby db to keep the
db associated with the correct project.
http://code.google.com/p/power-matchmaker/source/detail?r=2779

Modified:
/branches/0.9.7/src/ca/sqlpower/matchmaker/FolderParent.java
/branches/0.9.7/src/ca/sqlpower/matchmaker/MatchMakerUtils.java
/branches/0.9.7/src/ca/sqlpower/matchmaker/PlFolder.java
/branches/0.9.7/src/ca/sqlpower/matchmaker/Project.java

=======================================
--- /branches/0.9.7/src/ca/sqlpower/matchmaker/FolderParent.java Thu Apr 9
19:56:43 2009
+++ /branches/0.9.7/src/ca/sqlpower/matchmaker/FolderParent.java Fri Jan 28
13:45:42 2011
@@ -19,6 +19,8 @@

package ca.sqlpower.matchmaker;

+import java.io.File;
+

/**
* A holder for folders.
@@ -51,6 +53,7 @@
public void deleteAndRemoveChild(PlFolder child) {
this.session.getDAO(PlFolder.class).delete(child);
super.removeChild(child);
+ MatchMakerUtils.deleteDirectory(new
File(MatchMakerUtils.makeGraphDBFolderLocation(child.getName())));
}


=======================================
--- /branches/0.9.7/src/ca/sqlpower/matchmaker/MatchMakerUtils.java Fri Jan
28 12:59:01 2011
+++ /branches/0.9.7/src/ca/sqlpower/matchmaker/MatchMakerUtils.java Fri Jan
28 13:45:42 2011
@@ -19,6 +19,10 @@

package ca.sqlpower.matchmaker;

+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.log4j.Logger;

import ca.sqlpower.matchmaker.event.MatchMakerListener;
@@ -150,7 +154,48 @@
return db;
}

+ public static void deleteDirectory(File dbLocation) {
+ if (dbLocation.exists() && dbLocation.isDirectory()) {
+ //Must clean up files in the directory before we can delete it.
+ List<String> innerFiles = new ArrayList<String>();
+ innerFiles.add(dbLocation.getAbsolutePath());
+ for (File file : dbLocation.listFiles()) {
+ innerFiles.add(0, file.getAbsolutePath());
+ }
+ while (!innerFiles.isEmpty()) {
+ File innerFile = new File(innerFiles.get(0));
+ if (innerFile.isDirectory()) {
+ if (!innerFile.delete()) {
+ for (File file : innerFile.listFiles()) {
+ innerFiles.add(0, file.getAbsolutePath());
+ }
+ } else {
+ innerFiles.remove(0);
+ }
+ } else {
+ if (innerFile.canWrite() && !innerFile.delete()) {
+ logger.error("Cannot clean up file " + innerFile);
+ }
+ innerFiles.remove(0);
+ }
+ }
+ }
+ }
+
+ /**
+ * Helper method to keep the graph db names consistent.
+ */
public static String makeGraphDBLocation(Project project) {
- return System.getProperty("user.home")+"/.mm/" +
project.getParent().getName() + "/" + project.getName();
+ if (project == null || project.getParent() == null) return "";
+ return makeGraphDBFolderLocation(project.getParent().getName()) + "/" +
project.getName();
+ }
+
+ /**
+ * Helper method to keep the graph db folder names consistent.
+ * @param folderName
+ * @return
+ */
+ public static String makeGraphDBFolderLocation(String folderName) {
+ return System.getProperty("user.home")+"/.mm/" + folderName;
}
}
=======================================
--- /branches/0.9.7/src/ca/sqlpower/matchmaker/PlFolder.java Fri Jan 28
12:59:01 2011
+++ /branches/0.9.7/src/ca/sqlpower/matchmaker/PlFolder.java Fri Jan 28
13:45:42 2011
@@ -20,8 +20,6 @@
package ca.sqlpower.matchmaker;

import java.io.File;
-import java.util.ArrayList;
-import java.util.List;

import org.apache.log4j.Logger;

@@ -163,31 +161,17 @@
super.removeChild(child);
if (child instanceof Project) {
File dbLocation = new File(fileLocation);
- if (dbLocation.exists() && dbLocation.isDirectory()) {
- //Must clean up files in the directory before we can delete it.
- List<String> innerFiles = new ArrayList<String>();
- innerFiles.add(fileLocation);
- for (File file : dbLocation.listFiles()) {
- innerFiles.add(0, file.getAbsolutePath());
- }
- while (!innerFiles.isEmpty()) {
- File innerFile = new File(innerFiles.get(0));
- if (innerFile.isDirectory()) {
- if (!innerFile.delete()) {
- for (File file : innerFile.listFiles()) {
- innerFiles.add(0, file.getAbsolutePath());
- }
- } else {
- innerFiles.remove(0);
- }
- } else {
- if (innerFile.canWrite() && !innerFile.delete()) {
- logger.error("Cannot clean up file " + innerFile);
- }
- innerFiles.remove(0);
- }
- }
- }
+ MatchMakerUtils.deleteDirectory(dbLocation);
}
};
-}
+
+ @Override
+ public void setName(String name) {
+ String oldName = getName();
+ super.setName(name);
+ File file = new File(MatchMakerUtils.makeGraphDBFolderLocation(oldName));
+ File newFile = new File(MatchMakerUtils.makeGraphDBFolderLocation(name));
+ file.renameTo(newFile);
+ }
+
+}
=======================================
--- /branches/0.9.7/src/ca/sqlpower/matchmaker/Project.java Thu Jan 27
10:06:15 2011
+++ /branches/0.9.7/src/ca/sqlpower/matchmaker/Project.java Fri Jan 28
13:45:42 2011
@@ -19,6 +19,7 @@

package ca.sqlpower.matchmaker;

+import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
@@ -1076,4 +1077,14 @@
public Monitorable getRunningEngine() {
return runningEngine.get();
}
-}
+
+ @Override
+ public void setName(String name) {
+ File file = new File(MatchMakerUtils.makeGraphDBLocation(this));
+ super.setName(name);
+ File newFile = new File(MatchMakerUtils.makeGraphDBLocation(this));
+ if (file.exists()) {
+ file.renameTo(newFile);
+ }
+ }
+}

Reply all
Reply to author
Forward
0 new messages