Author: xor
Date: 2008-11-09 22:27:17 +0000 (Sun, 09 Nov 2008)
New Revision: 23454
Removed:
trunk/plugins/Freetalk/WoT/FTMessageWoT.java
Modified:
trunk/plugins/Freetalk/
trunk/plugins/Freetalk/FTBoard.java
trunk/plugins/Freetalk/FTMessage.java
trunk/plugins/Freetalk/FTOwnIdentity.java
trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java
trunk/plugins/Freetalk/WoT/FTIdentityWoT.java
trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java
trunk/plugins/Freetalk/WoT/FTOwnIdentityWoT.java
Log:
Refactor: Do not store references to the database in the data-holding classes.
Delete the FTMessageWoT class as messages should be the same for all ways of
retrieving them.
Property changes on: trunk/plugins/Freetalk
___________________________________________________________________
Name: svn:ignore
+ build.xml
dist
Modified: trunk/plugins/Freetalk/FTBoard.java
===================================================================
--- trunk/plugins/Freetalk/FTBoard.java 2008-11-09 21:54:18 UTC (rev 23453)
+++ trunk/plugins/Freetalk/FTBoard.java 2008-11-09 22:27:17 UTC (rev 23454)
@@ -73,13 +73,13 @@
FTMessage parentThread =
findParentThread(newMessage);
if(parentThread != null)
- newMessage.setThread(parentThread);
+ newMessage.setThread(db, parentThread);
if(parentMessage != null) {
- newMessage.setParent(parentMessage);
+ newMessage.setParent(db, parentMessage);
} else { /* The message is an orphan */
if(parentThread != null) {
-
newMessage.setParent(parentThread); /* We found its parent thread so just
stick it in there for now */
+ newMessage.setParent(db,
parentThread); /* We found its parent thread so just stick it in there for now
*/
}
else {
/* The message is an absolute
orphan */
@@ -102,18 +102,18 @@
Iterator<FTMessage> absoluteOrphans =
absoluteOrphanIterator(newMessage.getURI());
while(absoluteOrphans.hasNext()){ /* Search in
the absolute orphans for messages which belong to this thread */
FTMessage orphan = absoluteOrphans.next();
- orphan.setParent(newMessage);
+ orphan.setParent(db, newMessage);
}
}
else {
FTMessage parentThread = newMessage.getThread();
if(parentThread != null) { /* Search in its parent
thread for its children */
- Iterator<FTMessage> iter =
parentThread.childrenIterator(this);
+ Iterator<FTMessage> iter =
parentThread.childrenIterator(db, this);
while(iter.hasNext()) {
FTMessage parentThreadChild =
iter.next();
if(parentThreadChild.getParentURI().equals(newMessage.getURI())) { /* We found
its parent, yeah! */
-
parentThreadChild.setParent(newMessage); /* It's a child of the newMessage, not
of the parentThread */
+ parentThreadChild.setParent(db,
newMessage); /* It's a child of the newMessage, not of the parentThread */
}
}
}
@@ -126,7 +126,7 @@
* cache the list of absolute orphans
locally.
*/
if(orphan.getParentURI().equals(newMessage.getURI()))
- orphan.setParent(newMessage);
+ orphan.setParent(db,
newMessage);
}
}
}
Modified: trunk/plugins/Freetalk/FTMessage.java
===================================================================
--- trunk/plugins/Freetalk/FTMessage.java 2008-11-09 21:54:18 UTC (rev
23453)
+++ trunk/plugins/Freetalk/FTMessage.java 2008-11-09 22:27:17 UTC (rev
23454)
@@ -19,10 +19,8 @@
* @author saces, xor
*
*/
-public abstract class FTMessage {
-
- protected ObjectContainer db;
-
+public class FTMessage {
+
/**
* The URI of this message.
*/
@@ -81,7 +79,7 @@
return new String[] { "mURI", "mThreadURI", "mBoards"};
}
- public FTMessage(ObjectContainer db, FreenetURI newURI, FreenetURI
newThreadURI, FreenetURI newParentURI, Set<FTBoard> newBoards, FTIdentity
newAuthor, String newTitle, Date newDate, String newText, List<FreenetURI>
newAttachments) {
+ public FTMessage(FreenetURI newURI, FreenetURI newThreadURI, FreenetURI
newParentURI, Set<FTBoard> newBoards, FTIdentity newAuthor, String newTitle,
Date newDate, String newText, List<FreenetURI> newAttachments) {
if (newURI == null || newBoards == null || newAuthor == null)
throw new IllegalArgumentException();
@@ -178,26 +176,24 @@
return mThread;
}
- public synchronized void setThread(FTMessage newParentThread) {
+ public synchronized void setThread(ObjectContainer db, FTMessage
newParentThread) {
assert(mThread == null);
assert(mThreadURI == null);
mThread = newParentThread;
- db.store(this);
- db.commit();
+ store(db);
}
public synchronized FTMessage getParent() {
return mParent;
}
- public synchronized void setParent(FTMessage newParent) throws
UpdatableSortedLinkedListKilledException {
+ public synchronized void setParent(ObjectContainer db, FTMessage
newParent) throws UpdatableSortedLinkedListKilledException {
/* TODO: assert(newParent contains at least one board which
mBoards contains) */
mParent = newParent;
- db.store(this);
- db.commit();
+ store(db);
}
- public synchronized Iterator<FTMessage> childrenIterator(final FTBoard
board) {
+ public synchronized Iterator<FTMessage> childrenIterator(final
ObjectContainer db, final FTBoard board) {
return new Iterator<FTMessage>() {
private Iterator<FTMessage> iter;
@@ -262,4 +258,9 @@
// FIXME: Implement.
return text;
}
+
+ public void store(ObjectContainer db) {
+ db.store(this);
+ db.commit();
+ }
}
Modified: trunk/plugins/Freetalk/FTOwnIdentity.java
===================================================================
--- trunk/plugins/Freetalk/FTOwnIdentity.java 2008-11-09 21:54:18 UTC (rev
23453)
+++ trunk/plugins/Freetalk/FTOwnIdentity.java 2008-11-09 22:27:17 UTC (rev
23454)
@@ -6,6 +6,8 @@
import java.util.Date;
import java.util.Iterator;
+import com.db4o.ObjectContainer;
+
import freenet.keys.FreenetURI;
/**
@@ -18,11 +20,11 @@
public boolean wantsMessagesFrom(FTIdentity identity);
- public void postMessage(FTMessage message);
+ public void postMessage(ObjectContainer db, FTMessage message);
- public void subscribeToBoard(FTBoard board);
+ public void subscribeToBoard(ObjectContainer db, FTBoard board);
- public void unsubscribeFromBoard(FTBoard board);
+ public void unsubscribeFromBoard(ObjectContainer db, FTBoard board);
public Iterator<FTBoard> subscribedBoardsIterator();
}
Modified: trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java
===================================================================
--- trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java 2008-11-09
21:54:18 UTC (rev 23453)
+++ trunk/plugins/Freetalk/WoT/FTIdentityManagerWoT.java 2008-11-09
22:27:17 UTC (rev 23454)
@@ -7,6 +7,7 @@
import java.util.List;
import plugins.Freetalk.FTIdentityManager;
+import plugins.Freetalk.FTMessage;
import plugins.Freetalk.Freetalk;
import com.db4o.ObjectContainer;
@@ -78,10 +79,10 @@
if(result.size() == 0) {
try {
- id = bOwnIdentities ?
new FTOwnIdentityWoT(db, uid, new FreenetURI(requestURI), new
FreenetURI(insertURI), nickname) :
-
new FTIdentityWoT(db, uid, new FreenetURI(requestURI),
nickname);
- db.store(id);
- db.commit();
+ id = bOwnIdentities ?
new FTOwnIdentityWoT(uid, new FreenetURI(requestURI), new
FreenetURI(insertURI), nickname) :
+
new FTIdentityWoT(uid, new FreenetURI(requestURI),
nickname);
+
+ id.store(db);
}
catch(MalformedURLException e) {
Logger.error(this,
"Error in OnReply()", e);
@@ -93,7 +94,7 @@
if(bOwnIdentities)
addFreetalkContext(id);
- id.setLastReceivedFromWoT(time);
+ id.setLastReceivedFromWoT(db, time);
}
}
}
@@ -161,7 +162,7 @@
/* FIXME: This function does not lock, it should probably. But
we cannot lock on the message manager because it locks on the identity
* manager and therefore this might cause deadlock. */
Query q = db.query();
- q.constrain(FTMessageWoT.class);
+ q.constrain(FTMessage.class);
q.descend("mAuthor").equals(i);
return (q.execute().size() == 0);
}
Modified: trunk/plugins/Freetalk/WoT/FTIdentityWoT.java
===================================================================
--- trunk/plugins/Freetalk/WoT/FTIdentityWoT.java 2008-11-09 21:54:18 UTC
(rev 23453)
+++ trunk/plugins/Freetalk/WoT/FTIdentityWoT.java 2008-11-09 22:27:17 UTC
(rev 23454)
@@ -16,8 +16,6 @@
*/
public class FTIdentityWoT implements FTIdentity {
- private final ObjectContainer db;
-
private final String mUID;
/** The requestURI used to fetch this identity from Freenet */
private final FreenetURI mRequestURI;
@@ -35,11 +33,10 @@
*/
private boolean mIsNeeded;
- public FTIdentityWoT(ObjectContainer myDB, String myUID, FreenetURI
myRequestURI, String myNickname) {
+ public FTIdentityWoT(String myUID, FreenetURI myRequestURI, String
myNickname) {
if(myUID == null || myUID.length() == 0 || myRequestURI == null
|| myNickname == null || myNickname.length() == 0)
throw new IllegalArgumentException();
- db = myDB;
mUID = myUID;
mRequestURI = myRequestURI;
mNickname = myNickname;
@@ -63,9 +60,9 @@
return mLastReceivedFromWoT;
}
- public synchronized void setLastReceivedFromWoT(long time) {
+ public synchronized void setLastReceivedFromWoT(ObjectContainer db,
long time) {
mLastReceivedFromWoT = time;
- store();
+ store(db);
}
public synchronized boolean isNeeded() {
@@ -76,7 +73,7 @@
mIsNeeded = newValue;
}
- protected void store() {
+ public void store(ObjectContainer db) {
db.store(this);
db.commit();
}
Modified: trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java
===================================================================
--- trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java 2008-11-09 21:54:18 UTC
(rev 23453)
+++ trunk/plugins/Freetalk/WoT/FTMessageManagerWoT.java 2008-11-09 22:27:17 UTC
(rev 23454)
@@ -6,6 +6,7 @@
import java.util.NoSuchElementException;
import plugins.Freetalk.FTBoard;
+import plugins.Freetalk.FTMessage;
import plugins.Freetalk.FTMessageManager;
import com.db4o.ObjectContainer;
@@ -36,7 +37,7 @@
}
private synchronized void onMessageReceived(String newMessageData)
throws UpdatableSortedLinkedListKilledException {
- FTMessageWoT newMessage = new FTMessageWoT(db, null, null,
null, null, null, null, null, null, null);
+ FTMessage newMessage = new FTMessage(null, null, null, null,
null, null, null, null, null);
String boardName = "";
/* FIXME: Store the description in FTOwnIdentity. We cannot
store in FTBoard because we want to allow per-identity customization */
Deleted: trunk/plugins/Freetalk/WoT/FTMessageWoT.java
===================================================================
--- trunk/plugins/Freetalk/WoT/FTMessageWoT.java 2008-11-09 21:54:18 UTC
(rev 23453)
+++ trunk/plugins/Freetalk/WoT/FTMessageWoT.java 2008-11-09 22:27:17 UTC
(rev 23454)
@@ -1,31 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package plugins.Freetalk.WoT;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-import plugins.Freetalk.FTBoard;
-import plugins.Freetalk.FTIdentity;
-import plugins.Freetalk.FTMessage;
-
-import com.db4o.ObjectContainer;
-
-import freenet.keys.FreenetURI;
-
-/**
- * @author xor
- *
- */
-public class FTMessageWoT extends FTMessage {
-
- public FTMessageWoT(ObjectContainer myDB, FreenetURI newURI, FreenetURI
newThreadURI, FreenetURI newParentURI, Set<FTBoard> newBoards, FTIdentity
newAuthor,
- String newTitle, Date newDate, String newText,
List<FreenetURI> newAttachments) {
- super(myDB, newURI, newThreadURI, newParentURI, newBoards,
newAuthor, newTitle, newDate, newText, newAttachments);
- // TODO Auto-generated constructor stub
- }
-
-
-}
Modified: trunk/plugins/Freetalk/WoT/FTOwnIdentityWoT.java
===================================================================
--- trunk/plugins/Freetalk/WoT/FTOwnIdentityWoT.java 2008-11-09 21:54:18 UTC
(rev 23453)
+++ trunk/plugins/Freetalk/WoT/FTOwnIdentityWoT.java 2008-11-09 22:27:17 UTC
(rev 23454)
@@ -25,8 +25,8 @@
private final FreenetURI mInsertURI;
- public FTOwnIdentityWoT(ObjectContainer myDB, String myUID, FreenetURI
myRequestURI, FreenetURI myInsertURI, String myNickname) {
- super(myDB, myUID, myRequestURI, myNickname);
+ public FTOwnIdentityWoT(String myUID, FreenetURI myRequestURI,
FreenetURI myInsertURI, String myNickname) {
+ super(myUID, myRequestURI, myNickname);
if(myInsertURI == null)
throw new IllegalArgumentException();
mInsertURI = myInsertURI;
@@ -36,24 +36,24 @@
return mInsertURI;
}
- public synchronized void postMessage(FTMessage message) {
+ public synchronized void postMessage(ObjectContainer db, FTMessage
message) {
// TODO Auto-generated method stub
}
- public synchronized void subscribeToBoard(FTBoard board) {
+ public synchronized void subscribeToBoard(ObjectContainer db, FTBoard
board) {
if(mSubscribedBoards.contains(board)) {
assert(false); /* TODO: Add logging / check whether
this should be allowed to happen */
return;
}
mSubscribedBoards.add(board);
- store();
+ store(db);
}
- public synchronized void unsubscribeFromBoard(FTBoard board) {
+ public synchronized void unsubscribeFromBoard(ObjectContainer db,
FTBoard board) {
mSubscribedBoards.remove(board);
- store();
+ store(db);
}
public synchronized Iterator<FTBoard> subscribedBoardsIterator() {