dates Table for bookmarksdb(needed for del.icio.us api)

Files in DATA/DATA
Migration: move bookmarks.db from SETTINGS in DATA

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1270 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 19 years ago
parent 11fe95832e
commit 9cce3c5709

@ -44,7 +44,9 @@ package de.anomic.data;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -61,8 +63,10 @@ import de.anomic.server.logging.serverLog;
public class bookmarksDB { public class bookmarksDB {
kelondroMap tagsTable; kelondroMap tagsTable;
kelondroMap bookmarksTable; kelondroMap bookmarksTable;
kelondroMap datesTable;
public bookmarksDB(File bookmarksFile, File tagsFile, int bufferkb){ public bookmarksDB(File bookmarksFile, File tagsFile, File datesFile, int bufferkb){
//bookmarks
//check if database exists //check if database exists
if(bookmarksFile.exists()){ if(bookmarksFile.exists()){
try { try {
@ -72,13 +76,15 @@ public class bookmarksDB {
//database reset :-(( //database reset :-((
bookmarksFile.delete(); bookmarksFile.delete();
bookmarksFile.getParentFile().mkdirs(); bookmarksFile.getParentFile().mkdirs();
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true)); //urlHash is 12 bytes long
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 12, 256, true));
} }
}else{ }else{
//new database //new database
bookmarksFile.getParentFile().mkdirs(); bookmarksFile.getParentFile().mkdirs();
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true)); this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 12, 256, true));
} }
//tags
//check if database exists //check if database exists
if(tagsFile.exists()){ if(tagsFile.exists()){
try { try {
@ -88,16 +94,36 @@ public class bookmarksDB {
//reset database //reset database
tagsFile.delete(); tagsFile.delete();
tagsFile.getParentFile().mkdirs(); tagsFile.getParentFile().mkdirs();
// max. 128 byte long tags
this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true)); this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));
rebuildTags(); rebuildTags();
} }
}else{ }else{
//new database //new database
tagsFile.getParentFile().mkdirs(); tagsFile.getParentFile().mkdirs();
this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true)); this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));
rebuildTags(); rebuildTags();
} }
// dates
//check if database exists
if(datesFile.exists()){
try {
//open it
this.datesTable=new kelondroMap(new kelondroDyn(datesFile, 1024*bufferkb));
} catch (IOException e) {
//reset database
datesFile.delete();
datesFile.getParentFile().mkdirs();
//YYYY-MM-DDTHH:mm:ssZ = 20 byte. currently used: YYYY-MM-DD = 10 bytes
this.datesTable = new kelondroMap(new kelondroDyn(datesFile, bufferkb * 1024, 20, 256, true));
rebuildDates();
}
}else{
//new database
datesFile.getParentFile().mkdirs();
this.datesTable = new kelondroMap(new kelondroDyn(datesFile, bufferkb * 1024, 20, 256, true));
rebuildDates();
}
} }
public void close(){ public void close(){
try { try {
@ -106,6 +132,9 @@ public class bookmarksDB {
try { try {
tagsTable.close(); tagsTable.close();
} catch (IOException e) {} } catch (IOException e) {}
try {
datesTable.close();
} catch (IOException e) {}
} }
public int bookmarksSize(){ public int bookmarksSize(){
return bookmarksTable.size(); return bookmarksTable.size();
@ -167,6 +196,24 @@ public class bookmarksDB {
} }
serverLog.logInfo("BOOKMARKS", "Rebuilt "+tagsTable.size()+" tags using your "+bookmarksTable.size()+" bookmarks."); serverLog.logInfo("BOOKMARKS", "Rebuilt "+tagsTable.size()+" tags using your "+bookmarksTable.size()+" bookmarks.");
} }
public void rebuildDates(){
serverLog.logInfo("BOOKMARKS", "rebuilding dates.db from bookmarks.db...");
Iterator it=bookmarkIterator(true);
Bookmark bookmark;
String date;
bookmarksDate bmDate;
while(it.hasNext()){
bookmark=(Bookmark) it.next();
date = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date(bookmark.getTimeStamp()));
bmDate=getDate(date);
if(bmDate==null){
bmDate=new bookmarksDate(date);
}
bmDate.add(bookmark.getUrlHash());
bmDate.setDatesTable();
}
serverLog.logInfo("BOOKMARKS", "Rebuilt "+datesTable.size()+" dates using your "+bookmarksTable.size()+" bookmarks.");
}
public Tag getTag(String tagName){ public Tag getTag(String tagName){
Map map; Map map;
try { try {
@ -177,6 +224,17 @@ public class bookmarksDB {
return null; return null;
} }
} }
public bookmarksDate getDate(String date){
Map map;
try {
map=datesTable.get(date);
if(map==null) return null;
return new bookmarksDate(date, map);
} catch (IOException e) {
return null;
}
}
public boolean renameTag(String oldName, String newName){ public boolean renameTag(String oldName, String newName){
Tag tag=getTag(oldName); Tag tag=getTag(oldName);
if (tag != null) { if (tag != null) {
@ -346,6 +404,67 @@ public class bookmarksDB {
return string2vector(((String)this.mem.get(URL_HASHES))).size(); return string2vector(((String)this.mem.get(URL_HASHES))).size();
} }
} }
class bookmarksDate{
public static final String URL_HASHES="urlHashes";
private Map mem;
String date;
public bookmarksDate(String mydate){
date=mydate;
mem=new HashMap();
mem.put(URL_HASHES, "");
}
public bookmarksDate(String mydate, Map map){
date=mydate;
mem=map;
}
public bookmarksDate(String mydate, Vector entries){
date=mydate;
mem=new HashMap();
mem.put(URL_HASHES, vector2string(entries));
}
public void add(String urlHash){
String urlHashes = (String)mem.get(URL_HASHES);
Vector list;
if(urlHashes != null && !urlHashes.equals("")){
list=string2vector(urlHashes);
}else{
list=new Vector();
}
if(!list.contains(urlHash) && !urlHash.equals("")){
list.add(urlHash);
}
this.mem.put(URL_HASHES, vector2string(list));
/*if(urlHashes!=null && !urlHashes.equals("") ){
if(urlHashes.indexOf(urlHash) <0){
this.mem.put(URL_HASHES, urlHashes+","+urlHash);
}
}else{
this.mem.put(URL_HASHES, urlHash);
}*/
}
public void delete(String urlHash){
Vector list=string2vector((String) this.mem.get(URL_HASHES));
if(list.contains(urlHash)){
list.remove(urlHash);
}
this.mem.put(URL_HASHES, vector2string(list));
}
public void setDatesTable(){
try {
if(this.size() >0){
bookmarksDB.this.datesTable.set(getDateString(), mem);
}else{
bookmarksDB.this.datesTable.remove(getDateString());
}
} catch (IOException e) {}
}
public String getDateString(){
return date;
}
public int size(){
return string2vector(((String)this.mem.get(URL_HASHES))).size();
}
}
/** /**
* Subclass, which stores the bookmark * Subclass, which stores the bookmark
* *

@ -434,9 +434,10 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser
//Init bookmarks DB //Init bookmarks DB
this.log.logConfig("Loading Bookmarks DB"); this.log.logConfig("Loading Bookmarks DB");
File bookmarksFile = new File(getRootPath(), "DATA/SETTINGS/bookmarks.db"); File bookmarksFile = new File(getRootPath(), "DATA/DATA/bookmarks.db");
File tagsFile = new File(getRootPath(), "DATA/SETTINGS/tags.db"); File tagsFile = new File(getRootPath(), "DATA/DATA/bookmarkTags.db");
this.bookmarksDB = new bookmarksDB(bookmarksFile, tagsFile, 512); File datesFile = new File(getRootPath(), "DATA/DATA/bookmarkDates.db");
this.bookmarksDB = new bookmarksDB(bookmarksFile, tagsFile, datesFile, 512);
this.log.logConfig("Loaded Bookmarks DB from files "+ bookmarksFile.getName()+ ", "+tagsFile.getName()); this.log.logConfig("Loaded Bookmarks DB from files "+ bookmarksFile.getName()+ ", "+tagsFile.getName());
this.log.logConfig(this.bookmarksDB.tagsSize()+" Tag, "+this.bookmarksDB.bookmarksSize()+" Bookmarks"); this.log.logConfig(this.bookmarksDB.tagsSize()+" Tag, "+this.bookmarksDB.bookmarksSize()+" Bookmarks");

Loading…
Cancel
Save