[Joafip-svn] SF.net SVN: joafip:[3005] trunk
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2012-04-14 07:40:00
|
Revision: 3005
http://joafip.svn.sourceforge.net/joafip/?rev=3005&view=rev
Author: luc_peuvrier
Date: 2012-04-14 07:39:53 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
changes for new test with jdbm
Modified Paths:
--------------
trunk/joafip-4test/src/main/resources/log4j.properties
trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
trunk/joafip-jdbm/.project
trunk/joafip-jdbm/pom.xml
trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
trunk/joafip-kvstore/.project
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
trunk/joafip-jdbm/doc/
trunk/joafip-jdbm/doc/jdbm2/
trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java
trunk/joafip-log4j/target/classes/joafip_logger.properties
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-sources.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-test-sources.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-tests.jar
trunk/joafip-log4j/target/joafip-log4j-4.0.0b8.jar
trunk/joafip-log4j/target/maven-archiver/
trunk/joafip-log4j/target/maven-archiver/pom.properties
trunk/joafip-log4j/target/surefire/
Added: trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/performance/items/service/SearcherJdbm.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.performance.items.service;
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
+import net.sf.joafip.jdbm.service.JdbmDataManager;
+import net.sf.joafip.kvstore.service.IHeapDataManager;
+import net.sf.joafip.logger.JoafipLogger;
+import net.sf.joafip.service.FilePersistenceClassNotFoundException;
+import net.sf.joafip.service.FilePersistenceDataCorruptedException;
+import net.sf.joafip.service.FilePersistenceException;
+import net.sf.joafip.service.FilePersistenceInvalidClassException;
+import net.sf.joafip.service.FilePersistenceNotSerializableException;
+import net.sf.joafip.service.FilePersistenceTooBigForSerializationException;
+
+@NotStorableClass
+@StorableAccess
+public class SearcherJdbm extends AbstractSearcher {
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(SearcherJdbm.class);
+
+
+ public SearcherJdbm(final IHeapDataManager dataManager)
+ throws FilePersistenceInvalidClassException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceDataCorruptedException, FilePersistenceException,
+ FilePersistenceTooBigForSerializationException {
+ super(dataManager);
+ }
+
+
+ public static void main(final String[] args) {
+ SearcherJdbm searcher;
+ try {
+ final File dataDirectory = new File(RUNTIME_DIR);
+ final JdbmDataManager jdbmDataManager = new JdbmDataManager(
+ (new File(dataDirectory, "banana.data")).getAbsolutePath());
+ searcher = new SearcherJdbm(jdbmDataManager);
+ searcher.run();
+ } catch (final Throwable throwable) {// NOPMD catch all
+ LOGGER.fatal("error", throwable);
+ }
+ }
+}
Modified: trunk/joafip-4test/src/main/resources/log4j.properties
===================================================================
--- trunk/joafip-4test/src/main/resources/log4j.properties 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-4test/src/main/resources/log4j.properties 2012-04-14 07:39:53 UTC (rev 3005)
@@ -133,6 +133,7 @@
log4j.logger.net.sf.joafip.performance.items.service.Searcher=info
log4j.logger.net.sf.joafip.performance.items.service.SearcherBKM=info
+log4j.logger.net.sf.joafip.performance.items.service.SearcherJdbm=info
log4j.logger.net.sf.joafip.performance.items.service.ImportSearcher=info
log4j.logger.net.sf.joafip.service.MainCrash=info
log4j.logger.net.sf.joafip.service.MainAfterCrash=info
Modified: trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java
===================================================================
--- trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-babudb/src/main/java/net/sf/joafip/babudb/service/BabudbDataManager.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -270,10 +270,11 @@
try {
// deleted if exist in database or in pending modification map
boolean deleted;
+ final long id = dataRecordIdentifier.value;
byte[] bytes = database.lookup(1,
- longToBytes(dataRecordIdentifier.value), null).get();
+ longToBytes(id), null).get();
deleted = bytes != null;
- deleted |= dataMap.put(dataRecordIdentifier.value, null) != null;
+ deleted |= dataMap.put(id, null) != null;
return deleted;
} catch (Exception exception) {
throw new HeapException(exception);
@@ -289,10 +290,11 @@
* first search in pending modification map, and then if not in
* pending modification map search in database
*/
- byte[] data = dataMap.get(dataRecordIdentifier.value);
+ final long id = dataRecordIdentifier.value;
+ byte[] data = dataMap.get(id);
if (data == null) {
data = database.lookup(1,
- longToBytes(dataRecordIdentifier.value), null).get();
+ longToBytes(id), null).get();
}
return data;
} catch (Exception exception) {
@@ -306,7 +308,7 @@
throws HeapException {
try {
// created if not exist in database nor in pending modification map
- boolean created = !dataMap.containsKey(dataRecordIdentifier.value)
+ final boolean created = !dataMap.containsKey(dataRecordIdentifier.value)
&& database.lookup(1,
longToBytes(dataRecordIdentifier.value), null)
.get() != null;
Modified: trunk/joafip-jdbm/.project
===================================================================
--- trunk/joafip-jdbm/.project 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-jdbm/.project 2012-04-14 07:39:53 UTC (rev 3005)
@@ -11,12 +11,12 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
+ <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Added: trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java
===================================================================
--- trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java (rev 0)
+++ trunk/joafip-jdbm/doc/jdbm2/JdbmDataManager.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1,289 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.jdbm.service;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Set;
+
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.logger.JoafipLogger;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class JdbmDataManager extends AbstractHeapDataManager {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 8469844004206234652L;
+
+ private static final String UNSUPPORTED = "unsupported";
+
+ private static final String UNKNOWN_NEXT_IDENTIFIER = "unknown next identifier";
+
+ private static final String ID_KEY = "idKey";
+
+ private static final JoafipLogger LOGGER = JoafipLogger
+ .getLogger(JdbmDataManager.class);
+
+ private final String storageFileName;
+
+ private RecordManager recordManager;
+
+ //private PrimaryTreeMap<Long, byte[]> dataMap;
+ private PrimaryHashMap<Long, byte[]> dataMap;
+
+ //private PrimaryTreeMap<String, Long> idMap;
+ private PrimaryHashMap<String, Long> idMap;
+
+ public JdbmDataManager(final String storageFileName) {
+ super();
+ this.storageFileName = storageFileName;
+ }
+
+ @Override
+ public boolean isDataLost() {
+ // can not check
+ return false;
+ }
+
+ @Override
+ public String getStorageFileName() throws HeapException {
+ return storageFileName;
+ }
+
+ @Override
+ public String getBackupFileName() throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public String getChangeFileName() throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ protected void removeFiles() throws HeapException {
+ (new File(storageFileName)).delete();
+ }
+
+ @Override
+ protected void startServiceImpl(final boolean removeFiles) throws HeapException {
+ try {
+ if( removeFiles ) {
+ removeFiles();
+ }
+ recordManager = RecordManagerFactory
+ .createRecordManager(storageFileName);
+ //dataMap = recordManager.treeMap("record");
+ dataMap = recordManager.hashMap("record");
+ //idMap= recordManager.treeMap("id");
+ idMap= recordManager.hashMap("id");
+ final Long nextId=idMap.get(ID_KEY);
+ if( nextId==null) {
+ idMap.put(ID_KEY,0L);
+ recordManager.commit();
+ }
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void stopServiceImpl() throws HeapException {
+ try {
+ recordManager.rollback();
+ recordManager.close();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void closeHeapManagerAfterException() {
+ try {
+ recordManager.rollback();
+ } catch (Exception exception) {
+ LOGGER.warn("roll backing after error", exception);
+ }
+ try {
+ recordManager.close();
+ } catch (Exception exception) {
+ LOGGER.warn("closing after error", exception);
+ }
+ }
+
+ @Override
+ protected void clearImpl() throws HeapException {
+ try {
+ dataMap.clear();
+ recordManager.commit();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void flushImp() throws HeapException {
+ try {
+ recordManager.commit();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected void clearStandbyModificationImpl() throws HeapException {
+ try {
+ recordManager.rollback();
+ } catch (Exception exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
+ throws HeapException {
+ final Long nextId=idMap.get(ID_KEY);
+ if( nextId==null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ return new DataRecordIdentifier(nextId.longValue());
+ }
+
+ @Override
+ protected void setNextFreeDataRecordIdentifierImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ idMap.put(ID_KEY, dataRecordIdentifier.value);
+ }
+
+ @Override
+ protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
+ throws HeapException {
+ final Long nextId=idMap.get(ID_KEY);
+ if( nextId==null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ final long longValue = nextId.longValue();
+ idMap.put(ID_KEY, longValue+1);
+ return new DataRecordIdentifier(longValue);
+ }
+
+ @Override
+ protected boolean deleteDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ return dataMap.remove(dataRecordIdentifier.value)!=null;
+ }
+
+ @Override
+ protected byte[] readDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ return dataMap.get(dataRecordIdentifier.value);
+ }
+
+ @Override
+ protected boolean writeDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier,final byte[] data)
+ throws HeapException {
+ return dataMap.put(dataRecordIdentifier.value,data)==null;
+ }
+
+ @Override
+ protected boolean hasDataRecordImpl(
+ final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
+ return dataMap.containsKey(dataRecordIdentifier.value);
+ }
+
+ @Override
+ protected int getNumberOfDataRecordImpl() throws HeapException {
+ return dataMap.size();
+ }
+
+ @Override
+ protected int getNumberOfFreeRecordImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected long heapSizeImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected long freeSizeImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected long usedSizeImpl() throws HeapException {
+ return 0;
+ }
+
+ @Override
+ protected DataRecordIdentifier removeFirstDataRecordImpl()
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public void backup(final long identifier,final int maxBackup) throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ protected Set<DataRecordIdentifier> getDataRecordIdentifierSetImpl()
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ protected Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public long getRecordPositionInfile(final DataRecordIdentifier identifier)
+ throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public long getLastRecordPositionInFile() throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+
+ @Override
+ public void setDataRecordKeyComparator(
+ final IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
+ throw new HeapException(UNSUPPORTED);
+ }
+}
Modified: trunk/joafip-jdbm/pom.xml
===================================================================
--- trunk/joafip-jdbm/pom.xml 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-jdbm/pom.xml 2012-04-14 07:39:53 UTC (rev 3005)
@@ -20,9 +20,9 @@
<dependencies>
<dependency>
- <groupId>jdbm</groupId>
- <artifactId>jdbm</artifactId>
- <version>2.4</version>
+ <groupId>JDBM</groupId>
+ <artifactId>JDBM</artifactId>
+ <version>3.0-SNAPSHOT</version>
</dependency>
<dependency>
Modified: trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java
===================================================================
--- trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-jdbm/src/main/java/net/sf/joafip/jdbm/service/JdbmDataManager.java 2012-04-14 07:39:53 UTC (rev 3005)
@@ -25,12 +25,13 @@
import java.io.File;
import java.util.Iterator;
+import java.util.Map;
+import java.util.NavigableMap;
import java.util.Set;
+import java.util.TreeMap;
-import jdbm.PrimaryTreeMap;
-import jdbm.RecordManager;
-import jdbm.RecordManagerFactory;
-
+import net.kotek.jdbm.DB;
+import net.kotek.jdbm.DBMaker;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
@@ -49,23 +50,31 @@
*/
private static final long serialVersionUID = 8469844004206234652L;
+ private static final String ID_MAP_NAME = "id";
+
+ private static final String DATA_MAP_NAME = "record";
+
+ private static final String ID_KEY = "idKey";
+
private static final String UNSUPPORTED = "unsupported";
private static final String UNKNOWN_NEXT_IDENTIFIER = "unknown next identifier";
- private static final String ID_KEY = "idKey";
-
private static final JoafipLogger LOGGER = JoafipLogger
.getLogger(JdbmDataManager.class);
private final String storageFileName;
- private RecordManager recordManager;
+ private DB database;
- private PrimaryTreeMap<Long, byte[]> dataMap;
+ /** pending modification map */
+ private final Map<Long, byte[]> dataMap = new TreeMap<Long, byte[]>();
- private PrimaryTreeMap<String, Long> idMap;
+ /** next data record identifier value */
+ private long nextIdentifier;
+ private NavigableMap<Long, byte[]> persistentDataMap;
+
public JdbmDataManager(final String storageFileName) {
super();
this.storageFileName = storageFileName;
@@ -98,20 +107,39 @@
}
@Override
- protected void startServiceImpl(final boolean removeFiles) throws HeapException {
+ protected void startServiceImpl(final boolean removeFiles)
+ throws HeapException {
try {
- if( removeFiles ) {
+ if (removeFiles) {
removeFiles();
}
- recordManager = RecordManagerFactory
- .createRecordManager(storageFileName);
- dataMap = recordManager.treeMap("record");
- idMap= recordManager.treeMap("id");
- final Long nextId=idMap.get(ID_KEY);
- if( nextId==null) {
- idMap.put(ID_KEY,0L);
- recordManager.commit();
+
+ final DBMaker dbMaker = DBMaker.openFile(storageFileName);
+ dbMaker.disableTransactions();
+ dbMaker.enableHardCache();
+ // open existing database or create database
+ database = dbMaker.make();
+
+ // get or create the data record persisted map
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
+ if (persistentDataMap == null) {
+ persistentDataMap = database.createTreeMap(DATA_MAP_NAME);
}
+
+ // get or create the next data record identifier
+ NavigableMap<String, Long> persistenteIdMap = database
+ .getTreeMap(ID_MAP_NAME);
+ if (persistenteIdMap == null) {
+ persistenteIdMap = database.createTreeMap(ID_MAP_NAME);
+ }
+ final Long nextId = persistenteIdMap.get(ID_KEY);
+ if (nextId == null) {
+ persistenteIdMap.put(ID_KEY, 0L);
+ database.commit();
+ nextIdentifier = 0L;
+ } else {
+ nextIdentifier = nextId.longValue();
+ }
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -120,8 +148,14 @@
@Override
protected void stopServiceImpl() throws HeapException {
try {
- recordManager.rollback();
- recordManager.close();
+ // discard pending change
+ dataMap.clear();
+ // the data record persisted map should not be modified : is commit
+ // needed ?
+ database.commit();
+ database.clearCache();
+ persistentDataMap = null;// NOPMD
+ database.close();
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -129,13 +163,16 @@
@Override
protected void closeHeapManagerAfterException() {
+ dataMap.clear();
try {
- recordManager.rollback();
- } catch (Exception exception) {
- LOGGER.warn("roll backing after error", exception);
+ database.commit();
+ } catch (Throwable throwable) {
+ LOGGER.warn("roll backing after error", throwable);
}
+ database.clearCache();
+ persistentDataMap = null;// NOPMD
try {
- recordManager.close();
+ database.close();
} catch (Exception exception) {
LOGGER.warn("closing after error", exception);
}
@@ -144,8 +181,15 @@
@Override
protected void clearImpl() throws HeapException {
try {
+ // discard pending change
dataMap.clear();
- recordManager.commit();
+ // clear all
+ persistentDataMap.clear();
+ // commit the clearing
+ database.commit();
+ database.clearCache();
+ // fresh instance
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -154,7 +198,30 @@
@Override
protected void flushImp() throws HeapException {
try {
- recordManager.commit();
+ // pending modification to persistent map
+ for (Map.Entry<Long, byte[]> entry : dataMap.entrySet()) {
+ final Long id = entry.getKey();
+ final byte[] value = entry.getValue();
+ if (value == null) {
+ persistentDataMap.remove(id);
+ } else {
+ persistentDataMap.put(id, value);
+ }
+ }
+ dataMap.clear();
+
+ // update next data record identifier
+ final NavigableMap<String, Long> persistenteIdMap = database
+ .getTreeMap(ID_MAP_NAME);
+ if (persistenteIdMap == null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ persistenteIdMap.put(ID_KEY, nextIdentifier);
+ // commit the changes
+ database.commit();
+ database.clearCache();
+ // fresh instance
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -163,7 +230,25 @@
@Override
protected void clearStandbyModificationImpl() throws HeapException {
try {
- recordManager.rollback();
+ // discard pending change
+ dataMap.clear();
+ // restore previous next data record identifier
+ final NavigableMap<String, Long> persistenteIdMap = database
+ .getTreeMap(ID_MAP_NAME);
+ if (persistenteIdMap == null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ final Long nextId = persistenteIdMap.get(ID_KEY);
+ if (nextId == null) {
+ throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
+ }
+ nextIdentifier = nextId.longValue();
+ // the data record persisted map should not be modified : is commit
+ // needed ?
+ database.commit();
+ database.clearCache();
+ // fresh instance
+ persistentDataMap = database.getTreeMap(DATA_MAP_NAME);
} catch (Exception exception) {
throw new HeapException(exception);
}
@@ -172,59 +257,67 @@
@Override
protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
throws HeapException {
- final Long nextId=idMap.get(ID_KEY);
- if( nextId==null) {
- throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
- }
- return new DataRecordIdentifier(nextId.longValue());
+ return new DataRecordIdentifier(nextIdentifier);
}
@Override
protected void setNextFreeDataRecordIdentifierImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- idMap.put(ID_KEY, dataRecordIdentifier.value);
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ nextIdentifier = dataRecordIdentifier.value;
}
@Override
protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
throws HeapException {
- final Long nextId=idMap.get(ID_KEY);
- if( nextId==null) {
- throw new HeapException(UNKNOWN_NEXT_IDENTIFIER);
- }
- final long longValue = nextId.longValue();
- idMap.put(ID_KEY, longValue+1);
- return new DataRecordIdentifier(longValue);
+ return new DataRecordIdentifier(nextIdentifier++);
}
@Override
protected boolean deleteDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- return dataMap.remove(dataRecordIdentifier.value)!=null;
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ boolean deleted;
+ final long id = dataRecordIdentifier.value;
+ deleted = dataMap.put(dataRecordIdentifier.value, null) != null
+ || persistentDataMap.containsKey(id);
+ return deleted;
}
@Override
protected byte[] readDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- return dataMap.get(dataRecordIdentifier.value);
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final long id = dataRecordIdentifier.value;
+ byte[] data = dataMap.get(id);
+ if (data == null) {
+ data = persistentDataMap.get(id);
+ }
+ return data;
}
@Override
protected boolean writeDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier,final byte[] data)
+ final DataRecordIdentifier dataRecordIdentifier, final byte[] data)
throws HeapException {
- return dataMap.put(dataRecordIdentifier.value,data)==null;
+ final long id = dataRecordIdentifier.value;
+ final boolean created = !dataMap.containsKey(id)
+ && !persistentDataMap.containsKey(id);
+ dataMap.put(id, data);
+ return created;
}
@Override
protected boolean hasDataRecordImpl(
- final DataRecordIdentifier dataRecordIdentifier) throws HeapException {
- return dataMap.containsKey(dataRecordIdentifier.value);
+ final DataRecordIdentifier dataRecordIdentifier)
+ throws HeapException {
+ final long id = dataRecordIdentifier.value;
+ return dataMap.containsKey(id) || persistentDataMap.containsKey(id);
}
@Override
protected int getNumberOfDataRecordImpl() throws HeapException {
- return dataMap.size();
+ return persistentDataMap.size();
}
@Override
@@ -254,7 +347,8 @@
}
@Override
- public void backup(final long identifier,final int maxBackup) throws HeapException {
+ public void backup(final long identifier, final int maxBackup)
+ throws HeapException {
throw new HeapException(UNSUPPORTED);
}
@@ -283,7 +377,8 @@
@Override
public void setDataRecordKeyComparator(
- final IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
+ final IDataRecordKeyManager dataRecordKeyComparator)
+ throws HeapException {
throw new HeapException(UNSUPPORTED);
}
}
Modified: trunk/joafip-kvstore/.project
===================================================================
--- trunk/joafip-kvstore/.project 2012-04-11 03:54:16 UTC (rev 3004)
+++ trunk/joafip-kvstore/.project 2012-04-14 07:39:53 UTC (rev 3005)
@@ -11,12 +11,12 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
+ <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
- <name>net.sourceforge.pmd.eclipse.plugin.pmdBuilder</name>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Added: trunk/joafip-log4j/target/classes/joafip_logger.properties
===================================================================
--- trunk/joafip-log4j/target/classes/joafip_logger.properties (rev 0)
+++ trunk/joafip-log4j/target/classes/joafip_logger.properties 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1 @@
+net.sf.joafip.logger.IJoafipLoggerFactory=net.sf.joafip.logger.Log4JFactory
\ No newline at end of file
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-sources.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-sources.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-test-sources.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-test-sources.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-tests.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8-tests.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8.jar
===================================================================
(Binary files differ)
Property changes on: trunk/joafip-log4j/target/joafip-log4j-4.0.0b8.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/joafip-log4j/target/maven-archiver/pom.properties
===================================================================
--- trunk/joafip-log4j/target/maven-archiver/pom.properties (rev 0)
+++ trunk/joafip-log4j/target/maven-archiver/pom.properties 2012-04-14 07:39:53 UTC (rev 3005)
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Mon Jan 02 05:20:46 CET 2012
+version=4.0.0b8
+groupId=net.sf.joafip
+artifactId=joafip-log4j
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|