Author: xor
Date: 2008-11-12 01:22:38 +0000 (Wed, 12 Nov 2008)
New Revision: 23505
Modified:
trunk/plugins/WoT/introduction/IntroductionPuzzle.java
Log:
New functions.
Modified: trunk/plugins/WoT/introduction/IntroductionPuzzle.java
===================================================================
--- trunk/plugins/WoT/introduction/IntroductionPuzzle.java 2008-11-12
00:39:08 UTC (rev 23504)
+++ trunk/plugins/WoT/introduction/IntroductionPuzzle.java 2008-11-12
01:22:38 UTC (rev 23505)
@@ -225,24 +225,45 @@
return mValidUntilTime;
}
+ public int getIndex() {
+ return mIndex;
+ }
+
public void store(ObjectContainer db) {
db.store(this);
db.commit();
}
- public static void deleteOldPuzzles(ObjectContainer db) {
+ public static void deleteExpiredPuzzles(ObjectContainer db) {
Query q = db.query();
q.constrain(IntroductionPuzzle.class);
q.descend("mValidUntilTime").constrain(System.currentTimeMillis()).smaller();
ObjectSet<IntroductionPuzzle> result = q.execute();
- Logger.debug(IntroductionPuzzle.class, "Deleting " +
result.size() + " old puzzles.");
+ Logger.debug(IntroductionPuzzle.class, "Deleting " +
result.size() + " expired puzzles.");
for(IntroductionPuzzle p : result)
db.delete(p);
db.commit();
}
+ public static void deleteOldestPuzzles(ObjectContainer db, int
puzzlePoolSize) {
+ Query q = db.query();
+ q.constrain(IntroductionPuzzle.class);
+ q.descend("mValidUntilTime").orderAscending();
+ ObjectSet<IntroductionPuzzle> result = q.execute();
+
+ int deleteCount = result.size() - puzzlePoolSize;
+
+ Logger.debug(IntroductionPuzzle.class, "Deleting " +
deleteCount + " old puzzles.");
+ while(deleteCount > 0) {
+ db.delete(result.next());
+ deleteCount--;
+ }
+
+ db.commit();
+ }
+
public void exportToXML(OutputStream os) throws TransformerException,
ParserConfigurationException {
// Create the output file
StreamResult resultStream = new StreamResult(os);
@@ -280,12 +301,14 @@
serializer.transform(domSource, resultStream);
}
- public static void importFromXML(ObjectContainer db, InputStream is,
FreenetURI puzzleURI ) throws SAXException, IOException,
ParserConfigurationException, UnknownIdentityException, ParseException {
+ public static IntroductionPuzzle importFromXML(ObjectContainer db,
InputStream is, FreenetURI puzzleURI ) throws SAXException, IOException,
ParserConfigurationException, UnknownIdentityException, ParseException {
PuzzleHandler puzzleHandler = new PuzzleHandler(db, puzzleURI);
SAXParserFactory.newInstance().newSAXParser().parse(is,
puzzleHandler);
db.store(puzzleHandler.getPuzzle());
db.commit();
+
+ return puzzleHandler.getPuzzle();
}
public static class PuzzleHandler extends DefaultHandler {
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs