joafip-svn Mailing List for java data object persistence in file (Page 14)
Brought to you by:
luc_peuvrier
You can subscribe to this list here.
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
(102) |
Nov
(52) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2012 |
Jan
(4) |
Feb
|
Mar
(14) |
Apr
(116) |
May
(100) |
Jun
(14) |
Jul
|
Aug
|
Sep
(30) |
Oct
|
Nov
(108) |
Dec
(2) |
|
From: <luc...@us...> - 2012-04-18 08:20:12
|
Revision: 3017
http://joafip.svn.sourceforge.net/joafip/?rev=3017&view=rev
Author: luc_peuvrier
Date: 2012-04-18 08:20:01 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
changes for heap element manager tests
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/RecordForTest.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManagerWithHeapRecord.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 03:29:26
|
Revision: 3016
http://joafip.svn.sourceforge.net/joafip/?rev=3016&view=rev
Author: luc_peuvrier
Date: 2012-04-18 03:29:16 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapRecord
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -132,12 +132,12 @@
// }
public HeapRecord getHeapRecord() throws HeapException {
- return heapElementManager.readHeapFileDataRecord(positionInFile);
+ return readHeapFileDataRecord(positionInFile);
}
/**
* get this node mirroring in heap file position <br>
- * should be used only by heap red black tree node manager ( sp�cialization
+ * should be used only by heap red black tree node manager ( specialization
* of {@link AbstractHeapNodeManager}) and this<br>
*
* @return the position of this node mirroring in heap file
@@ -283,8 +283,7 @@
*/
HeapRecord heapRecord;
try {
- heapRecord = heapElementManager
- .readHeapFileDataRecord(parentPositionInFile);
+ heapRecord = readHeapFileDataRecord(parentPositionInFile);
} catch (HeapException exception) {
throw new RBTException(exception);
}
@@ -316,8 +315,7 @@
*/
HeapRecord heapRecord;
try {
- heapRecord = heapElementManager
- .readHeapFileDataRecord(leftPositionInFile);
+ heapRecord = readHeapFileDataRecord(leftPositionInFile);
} catch (HeapException exception) {
throw new RBTException(exception);
}
@@ -351,8 +349,7 @@
*/
HeapRecord heapRecord;
try {
- heapRecord = heapElementManager
- .readHeapFileDataRecord(rightPositionInFile);
+ heapRecord = readHeapFileDataRecord(rightPositionInFile);
} catch (HeapException exception) {
throw new RBTException(exception);
}
@@ -507,6 +504,12 @@
}
}
+ private HeapRecord readHeapFileDataRecord(final long positionInFile)
+ throws HeapException {
+ return (HeapRecord) heapElementManager
+ .readHeapFileDataRecord(positionInFile);
+ }
+
@Override
public void detach() {
valueChanged = false;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -51,7 +51,7 @@
public int compareTo(final IRBTComparableNode<Integer> node)
throws RBTException {
int nodeSize;
- nodeSize = ((HeapFreeNode) node).getAreaSize();
+ nodeSize = ((HeapFreeNode) node).getRecordSize();
final int compareTo;
if (areaSize > nodeSize) {
compareTo = 1;
@@ -75,7 +75,7 @@
return compareTo;
}
- public int getAreaSize() {
+ public int getRecordSize() {
return areaSize;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -84,6 +84,16 @@
}
@Override
+ public long getPreviousRecordPositionInFile() throws HeapException {
+ return -1L;
+ }
+
+ @Override
+ public int getRecordSize() throws HeapException {
+ return HEAP_HEADER_SIZE;
+ }
+
+ @Override
protected void valueChangedAction() throws HeapException {
// no implementation
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -42,11 +42,11 @@
private static final String DATA_SIZE_MISMATCH =
/**/"data size mismatch";
- private static final String CAN_NOT_INCREASE_RECORD_AREA_SIZE =
- /**/"can not increase record area size";
+ private static final String CAN_NOT_INCREASE_RECORD_RECORD_SIZE =
+ /**/"can not increase record size";
- private static final String AREA_SIZE_TO_SMALL_FOR_DATA =
- /**/"area size to small for data";
+ private static final String RECORD_SIZE_TO_SMALL_FOR_DATA =
+ /**/"record size to small for data";
private static final String NO_DATA_TO_WRITE_SET =
/**/"no data to write set";
@@ -129,8 +129,8 @@
private HeapFreeNode freeNode;
- /** the area size in file ( record header size + data size ) */
- private Integer areaSize;
+ /** the record size ( record header size + data size ) */
+ private int recordSize;
private int dataRecordHeaderSize;
@@ -169,15 +169,15 @@
* @param dataAssociatedSize
* size of associated data if not a free record, else it is the
* free space
- * @param areaSize
+ * @param recordSize
* area size for this record
* @throws HeapException
*/
public HeapRecord(final IHeapElementManager heapElementManager,
final long positionInFile, final Long previousRecordPositionInFile,
final DataRecordIdentifier nodeIdentifier,
- final boolean freeRecord, final Integer dataAssociatedSize,
- final Integer areaSize) throws HeapException {
+ final boolean freeRecord, final int dataAssociatedSize,
+ final int recordSize) throws HeapException {
/* length=areaSize */
super(heapElementManager.getFileForStorable(), positionInFile);
this.heapElementManager = heapElementManager;
@@ -190,28 +190,49 @@
*/
// ASSERTX
assert assertAreaSizeForData(freeRecord, nodeIdentifier,
- dataAssociatedSize, areaSize);
- this.areaSize = areaSize;
+ dataAssociatedSize, recordSize);
+ this.recordSize = recordSize;
this.nodeIdentifier = nodeIdentifier;
clearNodeData();
// ASSERTX
assert assertPreviousPositionInFile();
}
+ /**
+ * construction for reading, unknown data associated size, and unknown node
+ * identification<br>
+ * should be only used bye {@link HeapElementManager}<br>
+ *
+ * @param heapElementManager
+ * heap header and record manager in heap file
+ * @param positionInFile
+ * record position in file
+ * @throws HeapException
+ */
+ public HeapRecord(final IHeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ this(heapElementManager, positionInFile,
+ /**/null/* previous record position in file unknown */,
+ /**/null/* node identification unknown */,
+ /**/false/* a data record is not a free record */,
+ /**/0/* Unknown data Associated Size */,
+ /**/0/* Unknown areaSize */);
+ }
+
private boolean assertAreaSizeForData(final boolean freeRecord,
final DataRecordIdentifier nodeIdentifier,
- final Integer dataAssociatedSize, final Integer areaSize)
+ final int dataAssociatedSize, final int recordSize)
throws HeapException {
// if (!freeRecord && areaSize != null
// && areaSize < MAX_RECORD_HEADER_SIZE + dataAssociatedSize + 4) {
if (!freeRecord
- && areaSize != null
- && areaSize < DATA_RECORD_HEADER_SIZE
+ && recordSize != 0
+ && recordSize < DATA_RECORD_HEADER_SIZE
+ nodeIdentifier.getKeyDataSize() + dataAssociatedSize
+ 4) {
- logger.fatal(AREA_SIZE_TO_SMALL_FOR_DATA);
+ logger.fatal(RECORD_SIZE_TO_SMALL_FOR_DATA);
throw new HeapException(new HeapException(
- AREA_SIZE_TO_SMALL_FOR_DATA));
+ RECORD_SIZE_TO_SMALL_FOR_DATA));
}
return true;
}
@@ -235,27 +256,6 @@
return true;
}
- /**
- * construction for reading, unknown data associated size, and unknown node
- * identification<br>
- * should be only used bye {@link HeapElementManager}<br>
- *
- * @param heapElementManager
- * heap header and record manager in heap file
- * @param positionInFile
- * record position in file
- * @throws HeapException
- */
- public HeapRecord(final IHeapElementManager heapElementManager,
- final long positionInFile) throws HeapException {
- this(heapElementManager, positionInFile,
- /**/null/* previous record position in file unknown */,
- /**/null/* node identification unknown */,
- /**/false/* a data record is not a free record */,
- /**/null/* Unknown data Associated Size */,
- /**/null/* Unknown areaSize */);
- }
-
@Override
protected void valueChangedAction() throws HeapException {
/*
@@ -273,26 +273,26 @@
clearNodeData();
}
- public void unfreeRecord(final int dataAssociatedSize, final int areaSize,
- final DataRecordIdentifier nodeIdentifier, final boolean manageData)
- throws HeapException {
+ public void unfreeRecord(final int dataAssociatedSize,
+ final int recordSize, final DataRecordIdentifier nodeIdentifier,
+ final boolean manageData) throws HeapException {
// ASSERTX
- assert assertCanUnFreeRecordForAreaSize(areaSize);
- this.areaSize = areaSize;
+ assert assertCanUnFreeRecordForRecordSize(recordSize);
+ this.recordSize = recordSize;
assertedUnfreeRecord(dataAssociatedSize, nodeIdentifier);
}
- private boolean assertCanUnFreeRecordForAreaSize(final int areaSize)
+ private boolean assertCanUnFreeRecordForRecordSize(final int recordSize)
throws HeapException {
if (!freeRecord) {
throw new HeapException("already a free record");
}
- assertAreaSizeKnew();
- if (areaSize > this.areaSize) {
- logger.fatal(CAN_NOT_INCREASE_RECORD_AREA_SIZE + " current size="
- + this.areaSize + " asked size=" + areaSize);
+ assertRecordSizeKnew();
+ if (recordSize > this.recordSize) {
+ logger.fatal(CAN_NOT_INCREASE_RECORD_RECORD_SIZE + " current size="
+ + this.recordSize + " asked size=" + recordSize);
throw new HeapException(new HeapException(
- CAN_NOT_INCREASE_RECORD_AREA_SIZE));
+ CAN_NOT_INCREASE_RECORD_RECORD_SIZE));
}
return true;
}
@@ -309,12 +309,12 @@
if (!freeRecord) {
throw new HeapException("already a free record");
}
- assertAreaSizeKnew();
+ assertRecordSizeKnew();
// dataAssociatedSize + 4 : +4 for crc32
- if (areaSize < MAX_RECORD_HEADER_SIZE + dataAssociatedSize + 4) {
- logger.fatal(AREA_SIZE_TO_SMALL_FOR_DATA);
+ if (recordSize < MAX_RECORD_HEADER_SIZE + dataAssociatedSize + 4) {
+ logger.fatal(RECORD_SIZE_TO_SMALL_FOR_DATA);
throw new HeapException(new HeapException(
- AREA_SIZE_TO_SMALL_FOR_DATA));
+ RECORD_SIZE_TO_SMALL_FOR_DATA));
}
return true;
}
@@ -331,12 +331,12 @@
@Override
protected int toMarshallSize() throws HeapException {
// ASSERTX
- assert assertAreaSizeKnew();
+ assert assertRecordSizeKnew();
int toMarshallSize;
if (freeRecord) {
toMarshallSize = FREE_RECORD_HEADER_SIZE;
} else if (dataValueChanged) {
- toMarshallSize = areaSize;
+ toMarshallSize = recordSize;
} else {
// only header will be write
final byte[] keyData = nodeIdentifier.getKeyData();
@@ -358,8 +358,8 @@
assert previousRecordPositionInFile != null : "previous position in file not defined";
writeLong(previousRecordPositionInFile);
// ASSERTX
- assert assertAreaSizeValue(freeRecord);
- writeInteger(areaSize);
+ assert assertRecordSizeValue(freeRecord);
+ writeInteger(recordSize);
if (freeRecord) {
marshallFreeRecord();
} else {
@@ -493,9 +493,9 @@
freeRecord = readBoolean();
previousRecordPositionInFile = readLong();
assertPreviousPositionInFile();
- areaSize = readInteger();
+ recordSize = readInteger();
// ASSERTX
- assert assertAreaSizeValue(freeRecord);
+ assert assertRecordSizeValue(freeRecord);
if (freeRecord) {
// ASSERTX
assert read >= FREE_RECORD_HEADER_SIZE : "expected a minimum of "
@@ -588,10 +588,10 @@
* @param freeRecord
* @throws HeapException
*/
- private boolean assertAreaSizeValue(final boolean freeRecord)
+ private boolean assertRecordSizeValue(final boolean freeRecord)
throws HeapException {
- if (areaSize == null) {
- throw new HeapException("area size must be defined");
+ if (recordSize <= 0) {
+ throw new HeapException("record size must be defined");
}
final int minimal;
if (freeRecord) {
@@ -599,9 +599,10 @@
} else {
minimal = DATA_RECORD_HEADER_SIZE;
}
- if (areaSize < minimal) {
- throw new HeapException("area size too small: areaSize=" + areaSize
- + ", minimal=" + minimal + ", free record=" + freeRecord);
+ if (recordSize < minimal) {
+ throw new HeapException("record size too small: areaSize="
+ + recordSize + ", minimal=" + minimal + ", free record="
+ + freeRecord);
}
return true;
}
@@ -635,7 +636,7 @@
freeNode = new HeapFreeNode(heapElementManager, positionInFile,
parentPositionInFile, leftPositionInFile,
rightPositionInFile, colorSetted, color, numberOfChild,
- areaSize);
+ recordSize);
}
return freeNode;
}
@@ -649,6 +650,7 @@
return freeRecord;
}
+ @Override
public long getPreviousRecordPositionInFile() throws HeapException {
// ASSERTX
assert previousRecordPositionInFile != null : "previous position in file not defined";
@@ -663,8 +665,8 @@
}
public long getNextRecordFilePosition() throws HeapException {
- assertAreaSizeKnew();
- long nextRecordFilePosition = positionInFile + areaSize;
+ assertRecordSizeKnew();
+ long nextRecordFilePosition = positionInFile + recordSize;
final HeapHeader header = (HeapHeader) heapElementManager
.getHeapHeader();
if (nextRecordFilePosition >= header.getEndOfRecordPositionInFile()) {
@@ -676,9 +678,9 @@
/**
* @throws HeapException
*/
- private boolean assertAreaSizeKnew() throws HeapException {
- if (areaSize == null) {
- throw new HeapException("area size is unknow");
+ private boolean assertRecordSizeKnew() throws HeapException {
+ if (recordSize <= 0) {
+ throw new HeapException("record size is unknow");
}
return true;
}
@@ -693,23 +695,18 @@
return true;
}
- /**
- * get the area in file size ( data size or may be more add to header size )
- *
- * @return the area size in file, null if not defined
- * @throws HeapException
- */
- public int getAreaSize() throws HeapException {
+ @Override
+ public int getRecordSize() throws HeapException {
// ASSERTX
- assert assertAreaSizeKnew();
- return areaSize;
+ assert assertRecordSizeKnew();
+ return recordSize;
}
- public void setAreaSize(final int areaSize) {
+ public void setRecordSize(final int recordSize) {
// only for free node update
- this.areaSize = areaSize;
+ this.recordSize = recordSize;
if (freeNode != null) {
- freeNode.setAreaSize(areaSize);
+ freeNode.setAreaSize(recordSize);
}
}
@@ -821,7 +818,7 @@
// (freeNode != null && freeNode
// .equals(heapRecord.freeNode)))
&&
- /**/integerEquals(areaSize, heapRecord.areaSize)
+ /**/integerEquals(recordSize, heapRecord.recordSize)
&&
/**/integerEquals(dataAssociatedSize,
heapRecord.dataAssociatedSize)
@@ -877,8 +874,8 @@
buffer.append(dataAssociatedSize);
buffer.append("\nnodeIdentifier=");
buffer.append(getNodeIdentifier());
- buffer.append("\nareaSize=");
- buffer.append(areaSize);
+ buffer.append("\nrecordSize=");
+ buffer.append(recordSize);
buffer.append("\ndataAssociated=");
buffer.append(dataAssociated);
return buffer.toString();
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -28,11 +28,9 @@
import net.sf.joafip.file.service.FileIOException;
import net.sf.joafip.file.service.HelperFileUtil;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.entity.EnumFileState;
import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
@@ -41,7 +39,7 @@
/**
* Heap elements manager in heap file.<br>
- * elements are {@link HeapHeader} and {@link HeapRecord}<br>
+ * elements are one heap header and the heap records<br>
* see {@link IHeapElementManager} for role description<br>
* implement a cache for elements read and to write<br>
* data in the cache that was modified will be saved when closing transaction<br>
@@ -202,11 +200,11 @@
* read are put in cache to guaranty that same object for same record is
* returned in same transaction<br>
*/
- private final Map<Long, HeapRecord> heapRecordToWriteMap =
- /**/new TreeMap<Long, HeapRecord>();
+ private final Map<Long, IFileStorable> heapRecordToWriteMap =
+ /**/new TreeMap<Long, IFileStorable>();
- private final Map<Long, HeapRecord> readHeapRecordMap =
- /**/new TreeMap<Long, HeapRecord>();
+ private final Map<Long, IFileStorable> readHeapRecordMap =
+ /**/new TreeMap<Long, IFileStorable>();
private final boolean fileOpenedInTransaction;
@@ -218,11 +216,14 @@
private final int fileOperationRetryMsDelay;
+ private final IHeapRecordFactory heapRecordFactory;
+
private IDataRecordKeyManager dataRecordKeyManager;
/**
* construction for crash safe mode disabled<br>
*
+ * @param heapRecordFactory
* @param fileForStorable
* data file
* @param deleteRenaming
@@ -231,11 +232,13 @@
* @param fileOperationRetryMsDelay
* @param openFileTraceFile
*/
- public HeapElementManager(final IFileForStorable fileForStorable,
+ public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
+ final IFileForStorable fileForStorable,
final boolean deleteRenaming, final boolean clearResizeFile,
final int maxFileOperationRetry,
final int fileOperationRetryMsDelay, final File openFileTraceFile) {
super();
+ this.heapRecordFactory = heapRecordFactory;
crashSafeMode = false;
fileOpenedInTransaction = false;
this.fileForStorable = fileForStorable;
@@ -253,6 +256,7 @@
/**
* construction for crash safe mode enabled<br>
*
+ * @param heapRecordFactory
* @param fileForStorable
* data file
* @param stateOkFlagFile
@@ -271,14 +275,15 @@
* @throws HeapException
* no files in stable state
*/
- public HeapElementManager(final FileForStorable fileForStorable,
- final File stateOkFlagFile,
+ public HeapElementManager(final IHeapRecordFactory heapRecordFactory,
+ final FileForStorable fileForStorable, final File stateOkFlagFile,
final FileForStorable fileForStorableBackup,
final File stateBackupOkFlagFile, final File globalStateFlagFile,
final boolean deleteRenaming, final boolean clearResizeFile,
final int maxFileOperationRetry,
final int fileOperationRetryMsDelay, final File openFileTraceFile) {
super();
+ this.heapRecordFactory = heapRecordFactory;
crashSafeMode = true;
fileOpenedInTransaction = true;
this.fileForStorable = fileForStorable;
@@ -785,9 +790,9 @@
throws HeapException {
long lastWrotePositionInFile = HeapHeader.HEAP_HEADER_SIZE - 1;
long lastRecordPositionInFile = 0;
- for (Map.Entry<Long, HeapRecord> entry : heapRecordToWriteMap
+ for (Map.Entry<Long, IFileStorable> entry : heapRecordToWriteMap
.entrySet()) {
- final HeapRecord heapRecord = entry.getValue();
+ final IFileStorable heapRecord = entry.getValue();
try {
assert false;
} catch (AssertionError error) {
@@ -821,7 +826,7 @@
previousRecordPositionInFile);
}
lastWrotePositionInFile = recordPositionInFile
- + heapRecord.getAreaSize() - 1;
+ + heapRecord.getRecordSize() - 1;
lastRecordPositionInFile = recordPositionInFile;
}
saveHeapRecord(heapRecord, toBackupList);
@@ -915,7 +920,7 @@
}
}
- private void saveHeapRecord(final HeapRecord heapRecord,
+ private void saveHeapRecord(final IFileStorable heapRecord,
final Set<ToBackupRecord> toBackupList) throws HeapException {
// ASSERTX
assert heapRecord.isValueChangedToSave() : "value not change for:\n"
@@ -943,28 +948,27 @@
final long previousRecordPositionInFile) throws HeapException {
String nextOfPrevious;
try {
- final HeapRecord heapRecord2 = readHeapRecordInFile(previousRecordPositionInFile);
+ final IFileStorable heapRecord = readHeapRecordInFile(previousRecordPositionInFile);
final long nNextOfPrevious = previousRecordPositionInFile
- + heapRecord2.getAreaSize();
+ + heapRecord.getRecordSize();
nextOfPrevious = String.valueOf(nNextOfPrevious);
} catch (Exception exception) {
nextOfPrevious = exception.getMessage();
}
- final HeapRecord heapRecord2 = heapRecordToWriteMap
+ final IFileStorable heapRecord = heapRecordToWriteMap
.get(lastRecordPositionInFile);
final long nEndOfFilePosition = lastRecordPositionInFile
- + heapRecord2.getAreaSize();
+ + heapRecord.getRecordSize();
throw new HeapException("for record at " + recordPositionInFile
+ ", bad previous position in file "
+ previousRecordPositionInFile + ", last record position is "
+ lastRecordPositionInFile + ",next of previous position "
+ nextOfPrevious + ",next of last " + nEndOfFilePosition
- + ", last is free " + heapRecord2.isFreeRecord()
- + ", last size " + heapRecord2.getAreaSize() + ", "
- + Thread.currentThread().getName());
+ + Thread.currentThread().getName() + "\nrecord:\n"
+ + heapRecord.toString());
}
/**
@@ -975,9 +979,10 @@
* @return
* @throws HeapException
*/
- private HeapRecord readHeapRecordInFile(final long positionInFile)
+ private IFileStorable readHeapRecordInFile(final long positionInFile)
throws HeapException {
- final HeapRecord heapRecord = new HeapRecord(this, positionInFile);
+ final IFileStorable heapRecord = heapRecordFactory.createHeapRecord(
+ this, positionInFile);
try {
heapRecord.readFromFile();
} catch (HeapException exception) {
@@ -1002,7 +1007,7 @@
}
@Override
- public HeapRecord readHeapFileDataRecord(final long positionInFile)
+ public IFileStorable readHeapFileDataRecord(final long positionInFile)
throws HeapException {
assertTransactionOpened();
// ASSERTX
@@ -1012,13 +1017,14 @@
* same record is returned in same transaction<br>
*/
- HeapRecord heapRecord;
+ IFileStorable heapRecord;
heapRecord = heapRecordToWriteMap.get(positionInFile);
if (heapRecord == null) {
heapRecord = readHeapRecordMap.get(positionInFile);
}
if (heapRecord == null) {
- heapRecord = new HeapRecord(this, positionInFile);
+ heapRecord = heapRecordFactory.createHeapRecord(this,
+ positionInFile);
try {
heapRecord.readFromFile();
} catch (HeapException exception) {
@@ -1035,22 +1041,26 @@
private boolean assertPositionInFile(final long positionInFile)
throws HeapException {
- if (positionInFile < HeapHeader.HEAP_HEADER_SIZE) {
+ if (positionInFile < header.getRecordSize()) {
LOGGER.fatal(READ_HEAP_FILE_NODE_FAILED + " position in heap file "
+ positionInFile + " in header of size="
- + HeapHeader.HEAP_HEADER_SIZE);
+ + header.getRecordSize());
throw new HeapException(READ_HEAP_FILE_NODE_FAILED);
}
return true;
}
@Override
- public void appendHeapFileRecord(final HeapRecord heapRecord)
+ public void appendHeapFileRecord(final IFileStorable heapRecord)
throws HeapException {
final long positionInFile = heapRecord.getPositionInFile();
- HeapRecord previous;
- previous = heapRecordToWriteMap.put(positionInFile, heapRecord);
// ASSERTX
+ assert assertTransactionOpened();
+ // ASSERTX
+ assert assertPositionInFile(positionInFile);
+ IFileStorable previous = heapRecordToWriteMap.put(positionInFile,
+ heapRecord);
+ // ASSERTX
assert assertNoPreviousOrPreviousSameAsCurrent(previous, heapRecord);
if (previous == null) {
previous = readHeapRecordMap.remove(positionInFile);
@@ -1062,38 +1072,8 @@
}
}
- @Override
- public HeapRecord newHeapFileRecord(final long positionInFile,
- final long previousRecordPositionInFile,
- final DataRecordIdentifier nodeIdentification,
- final boolean freeRecord, final Integer dataAssociatedSize,
- final int areaSize) throws HeapException {
- // ASSERTX
- assert assertTransactionOpened();
- // ASSERTX
- assert assertPositionInFile(positionInFile);
- // ASSERTX
- assert !readHeapRecordMap.containsKey(positionInFile) : "must not exist in read cache";
- final HeapRecord heapRecord = new HeapRecord(this, positionInFile,
- previousRecordPositionInFile, nodeIdentification, freeRecord,
- dataAssociatedSize, areaSize);
- final HeapRecord previous = heapRecordToWriteMap.put(positionInFile,
- heapRecord);
- // ASSERTX
- assert assertNoPrevious(heapRecord, previous);
- return heapRecord;
- }
-
- private boolean assertNoPrevious(final HeapRecord heapRecord,
- final HeapRecord previous) throws HeapException {
- if (previous != null) {
- mustNotHavePreviousException(previous, heapRecord);
- }
- return true;
- }
-
private boolean assertNoPreviousOrPreviousSameAsCurrent(
- final HeapRecord previous, final HeapRecord current)
+ final IFileStorable previous, final IFileStorable current)
throws HeapException {
if (previous != null && previous != current) {// NOPMD I want to compare
// reference
@@ -1102,8 +1082,8 @@
return true;
}
- private void mustNotHavePreviousException(final HeapRecord previous,
- final HeapRecord current) throws HeapException {
+ private void mustNotHavePreviousException(final IFileStorable previous,
+ final IFileStorable current) throws HeapException {
throw new HeapException(
"must not have a previous heap record: current=\n"
+ current.toString() + "\nprevious=\n"
@@ -1141,7 +1121,7 @@
* @return heap record in read cache for position in file, null if none
*/
@Fortest
- public HeapRecord getHeapFileRecordInReadCache(final long positionInFile) {
+ public IFileStorable getHeapFileRecordInReadCache(final long positionInFile) {
return readHeapRecordMap.get(positionInFile);
}
@@ -1153,7 +1133,7 @@
* @return heap record in write cache for position in file, null if none
*/
@Fortest
- public HeapRecord getHeapFileRecordInWriteCache(final long positionInFile) {
+ public IFileStorable getHeapFileRecordInWriteCache(final long positionInFile) {
return heapRecordToWriteMap.get(positionInFile);
}
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -57,7 +57,7 @@
if (freeRootNodeFilePosition == -1) {
heapFreeRootNode = null;
} else {
- final HeapRecord heapRecord = heapElementManager
+ final HeapRecord heapRecord = (HeapRecord) heapElementManager
.readHeapFileDataRecord(freeRootNodeFilePosition);
heapFreeRootNode = (HeapFreeNode) heapRecord.getFreeNode();
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -64,7 +64,7 @@
if (idRootNodeFilePosition == -1) {
heapIdRootNode = null;
} else {
- final HeapRecord heapRecord = heapElementManager
+ final HeapRecord heapRecord = (HeapRecord) heapElementManager
.readHeapFileDataRecord(idRootNodeFilePosition);
heapIdRootNode = (HeapIdNode) heapRecord.getIdNode();
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -17,16 +17,14 @@
package net.sf.joafip.heapfile.record.service;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
-import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.entity.IFileStorable;
-import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.kvstore.service.IFileForStorable;
/**
* Heap elements manager in heap file interface.<br>
- * elements are {@link HeapHeader} and {@link HeapRecord}<br>
+ * elements are one header and the heap records<br>
* heap element are heap header, heap record, and data block<br>
* make able to get the heap element for read and possible modification<br>
* the closing save the header and records modification<br>
@@ -144,7 +142,7 @@
* @throws HeapException
*
*/
- HeapRecord readHeapFileDataRecord(final long positionInFile)
+ IFileStorable readHeapFileDataRecord(final long positionInFile)
throws HeapException;
/**
@@ -154,35 +152,13 @@
* the heap file record to append
* @throws HeapException
*/
- void appendHeapFileRecord(final HeapRecord heapRecord) throws HeapException;
+ void appendHeapFileRecord(IFileStorable heapRecord) throws HeapException;
/**
*
* @param positionInFile
- * record position in file
- * @param previousRecordPositionInFile
- * previous record position in file
- * @param nodeIdentification
- * data node identification number
- * @param freeRecord
- * true if free record
- * @param dataAssociatedSize
- * size of associated data if not a free record, else it is null
- * @param areaSize
- * area size for this record
- * @return
* @throws HeapException
*/
- HeapRecord newHeapFileRecord(long positionInFile,
- long previousRecordPositionInFile,
- DataRecordIdentifier nodeIdentification, boolean freeRecord,
- Integer dataAssociatedSize, int areaSize) throws HeapException;
-
- /**
- *
- * @param positionInFile
- * @throws HeapException
- */
void delete(long positionInFile) throws HeapException;
/**
Added: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java (rev 0)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -0,0 +1,38 @@
+/*
+ * 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.heapfile.record.service;
+
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface IHeapRecordFactory {
+
+ IFileStorable createHeapRecord(HeapElementManager heapElementManager,
+ long positionInFile) throws HeapException;
+}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -36,7 +36,9 @@
import net.sf.joafip.heapfile.record.service.HeapFreeNodeManager;
import net.sf.joafip.heapfile.record.service.HeapIdNodeManager;
import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.heapfile.record.service.IHeapRecordFactory;
import net.sf.joafip.kvstore.entity.EnumFileState;
+import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.AbstractHeapDataManager;
@@ -54,7 +56,8 @@
*
*/
@NotStorableClass
-public class HeapFileDataManager extends AbstractHeapDataManager {// NOPMD
+public class HeapFileDataManager extends AbstractHeapDataManager implements
+ IHeapRecordFactory {// NOPMD
// FIXMELUC ______HeapFileDataManager not accept empty data
@@ -182,13 +185,13 @@
}
final File openFileTraceFile = setup.getOpenFileTraceFile();
if (crashSafeMode) {
- heapElementManager = new HeapElementManager(fileForStorable,
+ heapElementManager = new HeapElementManager(this, fileForStorable,
stateOkFlagFile, fileForStorableBackup,
stateBackupOkFlagFile, globalStateFlagFile, deleteRenaming,
clearResizeFile, maxFileOperationRetry,
fileOperationRetryMsDelay, openFileTraceFile);
} else {
- heapElementManager = new HeapElementManager(fileForStorable,
+ heapElementManager = new HeapElementManager(this, fileForStorable,
deleteRenaming, clearResizeFile, maxFileOperationRetry,
fileOperationRetryMsDelay, openFileTraceFile);
}
@@ -365,22 +368,21 @@
/* will update heap header for free and used size */
final HeapHeader heapHeader = (HeapHeader) heapElementManager
.getHeapHeader();
- heapHeader.addFreeSize(heapRecord.getAreaSize());
+ heapHeader.addFreeSize(heapRecord.getRecordSize());
long positionInFile = heapRecord.getPreviousRecordPositionInFile();
final HeapRecord previous;
if (positionInFile == -1) {
previous = null;
} else {
- previous = heapElementManager
- .readHeapFileDataRecord(positionInFile);
+ previous = readHeapFileDataRecord(positionInFile);
}
positionInFile = heapRecord.getNextRecordFilePosition();
final HeapRecord next;
if (positionInFile == -1) {
next = null;
} else {
- next = heapElementManager.readHeapFileDataRecord(positionInFile);
+ next = readHeapFileDataRecord(positionInFile);
}
if (canMergeWithOnlyPrevious(heapRecord, previous, next)) {
@@ -415,22 +417,26 @@
&& previous.isFreeRecord()
&& next != null
&& next.isFreeRecord()
- && !intOverflow(heapRecord.getAreaSize(),
- previous.getAreaSize(), next.getAreaSize());
+ && !intOverflow(heapRecord.getRecordSize(),
+ previous.getRecordSize(), next.getRecordSize());
}
private boolean canMergeWithOnlyNext(final HeapRecord heapRecord,
final HeapRecord previous, final HeapRecord next)
throws HeapException {
- return (previous == null || !previous.isFreeRecord()) && next != null
+ return (previous == null || !previous.isFreeRecord())
+ && next != null
&& next.isFreeRecord()
- && !intOverflow(heapRecord.getAreaSize(), next.getAreaSize());
+ && !intOverflow(heapRecord.getRecordSize(),
+ next.getRecordSize());
}
private boolean canMergeWithNextIgnorePrevious(final HeapRecord heapRecord,
final HeapRecord next) throws HeapException {
- return next != null && next.isFreeRecord()
- && !intOverflow(heapRecord.getAreaSize(), next.getAreaSize());
+ return next != null
+ && next.isFreeRecord()
+ && !intOverflow(heapRecord.getRecordSize(),
+ next.getRecordSize());
}
private boolean canMergeWithOnlyPrevious(final HeapRecord heapRecord,
@@ -439,16 +445,16 @@
return previous != null
&& previous.isFreeRecord()
&& (next == null || !next.isFreeRecord())
- && !intOverflow(heapRecord.getAreaSize(),
- previous.getAreaSize());
+ && !intOverflow(heapRecord.getRecordSize(),
+ previous.getRecordSize());
}
private boolean canMergeWithPreviousIgnoreNext(final HeapRecord heapRecord,
final HeapRecord previous) throws HeapException {
return previous != null
&& previous.isFreeRecord()
- && !intOverflow(heapRecord.getAreaSize(),
- previous.getAreaSize());
+ && !intOverflow(heapRecord.getRecordSize(),
+ previous.getRecordSize());
}
private void freeRecord(final long positionInFile, final int areaSize,
@@ -460,12 +466,11 @@
}
// ASSERTX
assert freeHeapRecord.isFreeRecord() : "must be a free heap record";
- freeHeapRecord.setAreaSize(areaSize);
+ freeHeapRecord.setRecordSize(areaSize);
freeNodeTreeAppend(freeHeapRecord);
if (nextPositionInFile != -1) {
- final HeapRecord nextOfFreeHeapRecord = heapElementManager
- .readHeapFileDataRecord(nextPositionInFile);
+ final HeapRecord nextOfFreeHeapRecord = readHeapFileDataRecord(nextPositionInFile);
nextOfFreeHeapRecord
.setPreviousRecordPositionInFile(positionInFile);
}
@@ -473,7 +478,7 @@
private void noMerge(final HeapRecord heapRecord) throws HeapException {
heapRecord.freeRecord();
- freeRecord(heapRecord.getPositionInFile(), heapRecord.getAreaSize(),
+ freeRecord(heapRecord.getPositionInFile(), heapRecord.getRecordSize(),
heapRecord.getNextRecordFilePosition(), heapRecord);
}
@@ -481,8 +486,8 @@
final HeapRecord next, final HeapRecord heapRecord,
final HeapHeader heapHeader) throws HeapException {
final long positionInFile = previous.getPositionInFile();
- final int areaSize = previous.getAreaSize() + next.getAreaSize()
- + heapRecord.getAreaSize();
+ final int areaSize = previous.getRecordSize() + next.getRecordSize()
+ + heapRecord.getRecordSize();
/* first delete from free node tree */
freeNodeTreeDelete(previous);
freeNodeTreeDelete(next);
@@ -504,7 +509,7 @@
throws HeapException {
heapRecord.freeRecord();
final long positionInFile = heapRecord.getPositionInFile();
- final int areaSize = next.getAreaSize() + heapRecord.getAreaSize();
+ final int areaSize = next.getRecordSize() + heapRecord.getRecordSize();
/* first delete from free node tree */
final HeapRecord nextHeapRecord = next;
freeNodeTreeDelete(nextHeapRecord);
@@ -523,7 +528,8 @@
throws HeapException {
heapElementManager.delete(heapRecord.getPositionInFile());
final long positionInFile = previous.getPositionInFile();
- final int areaSize = previous.getAreaSize() + heapRecord.getAreaSize();
+ final int areaSize = previous.getRecordSize()
+ + heapRecord.getRecordSize();
/* first delete from free node tree */
freeNodeTreeDelete(previous);
/* then delete record */
@@ -682,6 +688,13 @@
return dataAssociated;
}
+ @Override
+ public IFileStorable createHeapRecord(
+ final HeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ return new HeapRecord(heapElementManager, positionInFile);
+ }
+
/**
* @param neededDataSize
* the needed data associated size
@@ -697,13 +710,13 @@
*/
private HeapRecord createRecordForDataFromFree(final int neededDataSize,
final DataRecordIdentifier nodeIdentifier,
- final int neededAreaSize, final HeapFreeNode freeNode)
+ final int neededRecordSize, final HeapFreeNode freeNode)
throws HeapException {
final HeapRecord heapRecord;
/* usable free area size */
- final int freeAreaSize = freeNode.getAreaSize();
+ final int freeRecordSize = freeNode.getRecordSize();
/* unused area size is usable minus needed area size */
- final int newFreeAreaSize = freeAreaSize - neededAreaSize;
+ final int newFreeRecordSize = freeRecordSize - neededRecordSize;
heapRecord = freeNode.getHeapRecord();
/* no more free */
freeNodeTreeDelete(heapRecord);
@@ -713,24 +726,35 @@
final HeapHeader heapHeader = (HeapHeader) heapElementManager
.getHeapHeader();
- if (newFreeAreaSize >= HeapRecord.MAX_RECORD_HEADER_SIZE
+ if (newFreeRecordSize >= HeapRecord.MAX_RECORD_HEADER_SIZE
+ MINIMUM_RECORD_DATA_SIZE + 4) {
/*
* split free record : one part used for data the other keep free
*/
final long nextRecordFilePosition = heapRecord
.getNextRecordFilePosition();
- heapRecord.unfreeRecord(neededDataSize, neededAreaSize,
+ heapRecord.unfreeRecord(neededDataSize, neededRecordSize,
nodeIdentifier, false);
final long positionInFile = heapRecord.getPositionInFile();
final long newFreeRecordPositionInFile = positionInFile
- + neededAreaSize;
- final HeapRecord newFreeHeapRecord = heapElementManager
- .newHeapFileRecord(
- newFreeRecordPositionInFile/* positionInFile */,
- positionInFile/* previousPositionInFile */,
- null/* nodeIdentifier */, true/* freeRecord */,
- null/* newFreeDataSize */, newFreeAreaSize);
+ + neededRecordSize;
+
+ final HeapRecord newFreeHeapRecord = new HeapRecord(
+ heapElementManager,
+ newFreeRecordPositionInFile/* positionInFile */,
+ positionInFile/* previousPositionInFile */,
+ null/* nodeIdentifier */, true/* freeRecord */,
+ 0/* dataAssociatedSize */, newFreeRecordSize/* recordSize */);
+
+ // final HeapRecord newFreeHeapRecord = heapElementManager
+ // .newHeapFileRecord(
+ // newFreeRecordPositionInFile/* positionInFile */,
+ // positionInFile/* previousPositionInFile */,
+ // null/* nodeIdentifier */, true/* freeRecord */,
+ // null/* dataAssociatedSize */, newFreeRecordSize/*recordSize*/);
+
+ heapElementManager.appendHeapFileRecord(newFreeHeapRecord);
+
if (heapRecord.getPositionInFile() == heapHeader
.getLastRecordPositionInFile()) {
heapHeader
@@ -738,15 +762,14 @@
}
freeNodeTreeAppend(newFreeHeapRecord);
if (nextRecordFilePosition != -1) {
- final HeapRecord nextHeapRecord = heapElementManager
- .readHeapFileDataRecord(nextRecordFilePosition);
+ final HeapRecord nextHeapRecord = readHeapFileDataRecord(nextRecordFilePosition);
nextHeapRecord
.setPreviousRecordPositionInFile(newFreeRecordPositionInFile);
}
} else {
heapRecord.unfreeRecord(neededDataSize, nodeIdentifier);
}
- heapHeader.unfreeSize(heapRecord.getAreaSize());
+ heapHeader.unfreeSize(heapRecord.getRecordSize());
return heapRecord;
}
@@ -786,9 +809,13 @@
heapHeader.setLastRecordPositionInFile(positionInFile);
heapHeader.addUsedSize(needAreaSize);
/* new at end of file with a new record identification */
- final HeapRecord heapRecord = heapElementManager.newHeapFileRecord(
+ final HeapRecord heapRecord = new HeapRecord(heapElementManager,
positionInFile, previousRecordPositionInFile, nodeIdentifier,
false, needDataSize, needAreaSize);
+ // final HeapRecord heapRecord = heapElementManager.newHeapFileRecord(
+ // positionInFile, previousRecordPositionInFile, nodeIdentifier,
+ // false, needDataSize, needAreaSize);
+ heapElementManager.appendHeapFileRecord(heapRecord);
return heapRecord;
}
@@ -817,12 +844,17 @@
heapRecord = null;
} else {
final long positionInFile = heapIdNode.getPositionInFile();
- heapRecord = heapElementManager
- .readHeapFileDataRecord(positionInFile);
+ heapRecord = readHeapFileDataRecord(positionInFile);
}
return heapRecord;
}
+ private HeapRecord readHeapFileDataRecord(final long recordFilePosition)
+ throws HeapException {
+ return (HeapRecord) heapElementManager
+ .readHeapFileDataRecord(recordFilePosition);
+ }
+
@Override
protected boolean hasDataRecordImpl(
final DataRecordIdentifier dataRecordIdentifier)
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -27,13 +27,17 @@
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.heapfile.record.service.HeapElementManager;
+import net.sf.joafip.heapfile.record.service.IHeapRecordFactory;
+import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.service.RBTException;
@NotStorableClass
@DoNotTransform
-public class TestIdNode extends AbstractCommonDeleteFileTestCase {// NOPMD
+public class TestIdNode extends AbstractCommonDeleteFileTestCase implements
+ IHeapRecordFactory {// NOPMD
private HeapIdNode heapIdNode; // NOPMD
@@ -78,7 +82,7 @@
fileForStorable = new FileForStorable(dataFile, 1, 0);
backupFileForStorable = new FileForStorable(backupFile, 1, 0);
- heapElementManager = new HeapElementManager(fileForStorable,
+ heapElementManager = new HeapElementManager(this, fileForStorable,
stateDataFile, backupFileForStorable, stateDataBackupFile,
globalStateFlag, false, false, 1, 0, openFileTraceFile);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
@@ -87,12 +91,21 @@
// final HeapRecord heapRecord = new HeapRecord(heapElementManager,
// HeapHeader.HEAP_HEADER_SIZE);
- final HeapRecord heapRecord = heapElementManager.newHeapFileRecord(
+ final HeapRecord heapRecord = new HeapRecord(heapElementManager,
HeapHeader.HEAP_HEADER_SIZE,
- -1/* previousRecordPositionInFile */,
+ -1L/* previousRecordPositionInFile */,
DataRecordIdentifier.ZERO/* nodeIdentification */,
false/* freeRecord */, 0/* dataAssociatedSize */,
HeapRecord.DATA_RECORD_HEADER_SIZE + 4/* areaSize */);
+
+ // final HeapRecord heapRecord = heapElementManager.newHeapFileRecord(
+ // HeapHeader.HEAP_HEADER_SIZE,
+ // -1/* previousRecordPositionInFile */,
+ // DataRecordIdentifier.ZERO/* nodeIdentification */,
+ // false/* freeRecord */, 0/* dataAssociatedSize */,
+ // HeapRecord.DATA_RECORD_HEADER_SIZE + 4/* areaSize */);
+ heapElementManager.appendHeapFileRecord(heapRecord);
+
heapIdNode = new HeapIdNode(heapElementManager,
heapRecord.getPositionInFile(), -1, -1, -1, false, false, 0,
heapRecord.getNodeIdentifier());
@@ -130,4 +143,10 @@
super.tearDown();
}
+ @Override
+ public IFileStorable createHeapRecord(
+ final HeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ return new HeapRecord(heapElementManager, positionInFile);
+ }
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -25,6 +25,7 @@
import net.sf.joafip.TestException;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
+import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
@@ -33,7 +34,8 @@
@NotStorableClass
@DoNotTransform
-public class TestHeapElementManager extends AbstractCommonDeleteFileTestCase {// NOPMD
+public class TestHeapElementManager extends AbstractCommonDeleteFileTestCase
+ implements IHeapRecordFactory {// NOPMD
private FileForStorable fileForStorable; // NOPMD
@@ -84,7 +86,7 @@
globalStateFile = new File(runtimePath + File.separator + "global.flag");
final File openFileTraceFile = new File(runtimePath + File.separator
+ "trace.txt");
- heapElementManager = new HeapElementManager(fileForStorable,
+ heapElementManager = new HeapElementManager(this, fileForStorable,
stateDataFile, backupFileForStorable, stateDataBackupFile,
globalStateFile, false, false, 1, 0, openFileTraceFile);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
@@ -188,8 +190,7 @@
heapElementManager.openTransaction();
final int dataSize = 100;
- final HeapRecord heapRecord1 = heapElementManager
- .readHeapFileDataRecord(record1pos);
+ final HeapRecord heapRecord1 = readHeapFileDataRecord(record1pos);
assertEquals("bad record position", record1pos,
heapRecord1.getPositionInFile());
assertEquals("bad record data size", dataSize, heapRecord1
@@ -202,8 +203,7 @@
assertEquals("read must be equals appened", heapRecordAppened1,
heapRecord1);
- final HeapRecord heapRecord2 = heapElementManager
- .readHeapFileDataRecord(record2pos);
+ final HeapRecord heapRecord2 = readHeapFileDataRecord(record2pos);
assertEquals("bad record position", record2pos,
heapRecord2.getPositionInFile());
assertEquals("bad record data size", dataSize, heapRecord2
@@ -228,7 +228,7 @@
heapElementManager.startService();
heapElementManager.openTransaction();
- HeapRecord heapRecord1 = heapElementManager.readHeapFileDataRecord(pos);
+ HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
byte[] data1 = heapRecord1.getDataAssociated();
for (int index = 0; index < data1.length; index++) {
data1[index] = (byte) (data1.length - index);
@@ -237,7 +237,7 @@
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
- heapRecord1 = heapElementManager.readHeapFileDataRecord(pos);
+ heapRecord1 = readHeapFileDataRecord(pos);
data1 = heapRecord1.getDataAssociated();
for (int index = 0; index < data1.length; index++) {
assertEquals("bad record data", data1.length - index, data1[index]);
@@ -254,7 +254,7 @@
heapElementManager.startService();
heapElementManager.openTransaction();
- HeapRecord heapRecord1 = heapElementManager.readHeapFileDataRecord(pos);
+ HeapRecord heapRecord1 = readHeapFileDataRecord(pos);
try {
assert false;
@@ -280,14 +280,14 @@
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
- heapRecord1 = heapElementManager.readHeapFileDataRecord(pos);
+ heapRecord1 = readHeapFileDataRecord(pos);
node = heapRecord1.getIdNode();
assertEquals("color must have changed", !color, node.getColor());
assertFalse("not modified record", heapRecord1.isValueChangedToSave());
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
- heapRecord1 = heapElementManager.readHeapFileDataRecord(pos);
+ heapRecord1 = readHeapFileDataRecord(pos);
heapRecord1.freeRecord();
try {
assert false;
@@ -310,7 +310,7 @@
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
- heapRecord1 = heapElementManager.readHeapFileDataRecord(pos);
+ heapRecord1 = readHeapFileDataRecord(pos);
node = heapRecord1.getFreeNode();
assertEquals("color must have changed", !color, node.getColor());
heapElementManager.closeTransaction();
@@ -325,7 +325,7 @@
/*
* read record 1 whithout data managing and check state
*/
- HeapRecord heapRecord1 = heapElementManager.readHeapFileDataRecord(
+ HeapRecord heapRecord1 = readHeapFileDataRecord(
/**/pos/* position in file */);
assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
assertFalse("record1 must be in state just created",
@@ -349,7 +349,7 @@
/*
* change to manage data mode
*/
- heapRecord1 = heapElementManager.readHeapFileDataRecord(
+ heapRecord1 = readHeapFileDataRecord(
/**/pos/* position in file */);
assertFalse("record1 must be data record", heapRecord1.isFreeRecord());
assertFalse("must not be just created", heapRecord1.isJustCreated());
@@ -402,13 +402,21 @@
record1pos = HeapHeader.HEAP_HEADER_SIZE;
final int dataSize = 100;
final DataRecordIdentifier dataRecordIdentifier = DataRecordIdentifier.ZERO;
- heapRecordAppened1 = heapElementManager.newHeapFileRecord(record1pos,
+ heapRecordAppened1 = new HeapRecord(heapElementManager, record1pos,
-1L/* prev pos */, dataRecordIdentifier/* id */,
false/* free */, dataSize, dataSize
+ HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
* area size: +
* 4 for crc32
*/);
+ // heapRecordAppened1 = heapElementManager.newHeapFileRecord(record1pos,
+ // -1L/* prev pos */, dataRecordIdentifier/* id */,
+ // false/* free */, dataSize, dataSize
+ // + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
+ // * area size: +
+ // * 4 for crc32
+ // */);
+ heapElementManager.appendHeapFileRecord(heapRecordAppened1);
try {
assert false;
} catch (AssertionError error) {
@@ -431,13 +439,20 @@
heapElementManager.openTransaction();
- record2pos = record1pos + heapRecordAppened1.getAreaSize();
- heapRecordAppened2 = heapElementManager.newHeapFileRecord(record2pos,
+ record2pos = record1pos + heapRecordAppened1.getRecordSize();
+ heapRecordAppened2 = new HeapRecord(heapElementManager, record2pos,
record1pos, dataRecordIdentifier/* id */, false/* free */,
dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
* 4 for
* crc32
*/);
+ // heapRecordAppened2 = heapElementManager.newHeapFileRecord(record2pos,
+ // record1pos, dataRecordIdentifier/* id */, false/* free */,
+ // dataSize, dataSize + HeapRecord.MAX_RECORD_HEADER_SIZE + 4/*
+ // * 4 for
+ // * crc32
+ // */);
+ heapElementManager.appendHeapFileRecord(heapRecordAppened2);
heapRecordAppened2.setDataAssociated(testData);
heapElementManager.closeTransaction();
heapElementManager.stopService();
@@ -467,4 +482,17 @@
}
return heapHeader;
}
+
+ private HeapRecord readHeapFileDataRecord(final long positionInFile)
+ throws HeapException {
+ return (HeapRecord) heapElementManager
+ .readHeapFileDataRecord(positionInFile);
+ }
+
+ @Override
+ public IFileStorable createHeapRecord(
+ final HeapElementManager heapElementManager,
+ final long positionInFile) throws HeapException {
+ return new HeapRecord(heapElementManager, positionInFile);
+ }
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-18 00:29:55 UTC (rev 3015)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-18 03:29:16 UTC (rev 3016)
@@ -26,6 +26,7 @@
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
+import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
@@ -35,7 +36,8 @@
@NotStorableClass
@DoNotTransform
-public class TestHeapRecordManage extends AbstractCommonDeleteFileTestCase {// NOPMD
+public class TestHeapRecordManage extends AbstractCommonDeleteFileTestCase
+ implements IHeapRecordFactory {// NOPMD
/** the heap element manager, data record are accessible by position in file */
private IHeapElementManager heapElementManager; // NOPMD
@@ -80,7 +82,7 @@
fileForStorable = new FileForStorable(dataFile, 1, 0);
final FileForStorable backupFileForStorage;
backupFileForStorage = new FileForStorable(backupFile, 1, 0);
- heapElementManager = new HeapElementManager(fileForStorable,
+ heapElementManager = new HeapElementManager(this, fileForStorable,
stateDataFile, backupFileForStorage, stateDataBackupFile,
globalStateFile, false, false, 1, 0, openFileTraceFile);
heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
@@ -122,11 +124,15 @@
for (int index = 0; index < 10; index++) {
final long position = (long) HeapHeader.HEAP_HEADER_SIZE
+ (long) index * 100;
- final HeapRecord heapRecord = heapElementManager
- .newHeapFileRecord(position, previousPosition,
- newDataRecordIdentifier(index),
- false/* freeRecord */, 10/* dataAssociatedSize */,
- 100/* areaSize */);
+ final HeapRecord heapRecord = new HeapRecord(heapElementManager,
+ position, previousPosition, newDataRecordIdentifier(index),
+ false/* freeRecord...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-18 03:29:22
|
Revision: 3016
http://joafip.svn.sourceforge.net/joafip/?rev=3016&view=rev
Author: luc_peuvrier
Date: 2012-04-18 03:29:16 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapRecord
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/AbstractHeapRBTNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapFreeNode.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapFreeNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapIdNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapRecordFactory.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 00:30:02
|
Revision: 3015
http://joafip.svn.sourceforge.net/joafip/?rev=3015&view=rev
Author: luc_peuvrier
Date: 2012-04-18 00:29:55 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapHeader
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -665,7 +665,8 @@
public long getNextRecordFilePosition() throws HeapException {
assertAreaSizeKnew();
long nextRecordFilePosition = positionInFile + areaSize;
- final HeapHeader header = heapElementManager.getHeapHeader();
+ final HeapHeader header = (HeapHeader) heapElementManager
+ .getHeapHeader();
if (nextRecordFilePosition >= header.getEndOfRecordPositionInFile()) {
nextRecordFilePosition = -1;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -39,7 +39,8 @@
public IRBTNode<E> getRootNode() throws RBTException {
try {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return getRootNode(heapHeader);
} catch (HeapException exception) {
throw new RBTException(exception);
@@ -60,7 +61,7 @@
public void setRootNode(final IRBTNode<E> rootNode) throws RBTException {
final HeapHeader heapHeader;
try {
- heapHeader = heapElementManager.getHeapHeader();
+ heapHeader = (HeapHeader) heapElementManager.getHeapHeader();
} catch (HeapException exception) {
throw new RBTException(exception);
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -191,7 +191,7 @@
private boolean openedTransaction = false;
/** the header node */
- private HeapHeader header;
+ private IFileStorable header;
/** true if data loose, updated by {@link #wasBadFileStableState()} */
private boolean dataLost = false;
@@ -630,7 +630,7 @@
openFile();
}
} else {
- readHeader(header);
+ header.readFromFile();
}
openedTransaction = true;
} catch (HeapException exception) {
@@ -781,14 +781,6 @@
return true;
}
- /**
- * @param heapHeader
- * @throws HeapException
- */
- private void readHeader(final HeapHeader heapHeader) throws HeapException {
- heapHeader.readFromFile();
- }
-
private void save(final Set<ToBackupRecord> toBackupList)
throws HeapException {
long lastWrotePositionInFile = HeapHeader.HEAP_HEADER_SIZE - 1;
@@ -1004,7 +996,7 @@
}
@Override
- public HeapHeader getHeapHeader() throws HeapException {
+ public IFileStorable getHeapHeader() throws HeapException {
assertTransactionOpened();
return header;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -18,6 +18,7 @@
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
+import net.sf.joafip.kvstore.entity.IFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.HeapException;
@@ -132,7 +133,7 @@
* @return the heap header in file
* @throws HeapException
*/
- HeapHeader getHeapHeader() throws HeapException;
+ IFileStorable getHeapHeader() throws HeapException;
/**
* read heap record in file
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -363,7 +363,8 @@
throws HeapException {
final HeapRecord heapRecord = deleteAndGetDataRecord(heapIdNode);
/* will update heap header for free and used size */
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
heapHeader.addFreeSize(heapRecord.getAreaSize());
long positionInFile = heapRecord.getPreviousRecordPositionInFile();
@@ -582,7 +583,8 @@
@Override
protected DataRecordIdentifier getNextFreeDataRecordIdentifierImpl()
throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
final DataRecordIdentifier dataRecordIdentifier = new DataRecordIdentifier(
heapHeader.getNextDataRecordIdentifier());
return dataRecordIdentifier;
@@ -592,14 +594,16 @@
protected void setNextFreeDataRecordIdentifierImpl(
final DataRecordIdentifier dataRecordIdentifier)
throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
heapHeader.setNextDataRecordIdentifier(dataRecordIdentifier);
}
@Override
protected DataRecordIdentifier getNewDataRecordIdentifierImpl()
throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
final long nextDataRecordIdentifier = heapHeader
.getNextDataRecordIdentifier();
final DataRecordIdentifier dataRecordIdentifier = new DataRecordIdentifier(
@@ -706,7 +710,8 @@
// NO NO NO do not delete, reused as data record
// heapElementManager.delete(heapRecord.getPositionInFile());
/* will update heap header for free and used size */
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
if (newFreeAreaSize >= HeapRecord.MAX_RECORD_HEADER_SIZE
+ MINIMUM_RECORD_DATA_SIZE + 4) {
@@ -764,7 +769,8 @@
* will update heap header last record position in file information, end
* of record position in file, and used size
*/
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
/* position at end of heap */
final long positionInFile = heapHeader.getEndOfRecordPositionInFile();
heapHeader.setEndOfRecordPositionInFile(positionInFile + needAreaSize);
@@ -1074,19 +1080,22 @@
@Override
protected long heapSizeImpl() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return heapHeader.getEndOfRecordPositionInFile();
}
@Override
protected long freeSizeImpl() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return heapHeader.getFreeSize();
}
@Override
protected long usedSizeImpl() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
return heapHeader.getUsedSize();
}
@@ -1223,7 +1232,8 @@
@Fortest
@Override
public long getLastRecordPositionInFile() throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
final long lastRecordPositionInFile = heapHeader
.getLastRecordPositionInFile();
return lastRecordPositionInFile;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -454,7 +454,8 @@
*/
private HeapHeader getHeapHeaderAndCheckPosition(
final HeapHeader heapHeaderReference) throws HeapException {
- final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final HeapHeader heapHeader = (HeapHeader) heapElementManager
+ .getHeapHeader();
assertEquals("header must be at file beginning", 0,
heapHeader.getPositionInFile());
if (heapHeaderReference != null) {
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -54,7 +54,7 @@
if (heapSize == 0) {
header = null;
} else {
- header = manager.getHeapHeader();
+ header = (HeapHeader) manager.getHeapHeader();
// header = new HeapHeader(manager);
// header.readFromFile();
lastRecordPositionInFile = header.getLastRecordPositionInFile();
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -91,6 +91,7 @@
this.positionInFile = positionInFile;
}
+ @Override
public void clear() {
valueChangedToSave = false;
justCreated = true;
@@ -100,6 +101,7 @@
return positionInFile;
}
+ @Override
public void readFromFile() throws HeapException {
// ASSERTX
assert justCreated : ALREADY_READ;
@@ -159,20 +161,12 @@
return justCreated;
}
- /**
- * to know if the value state change
- *
- * @return true if value changed
- */
+ @Override
public boolean isValueChangedToSave() {
return valueChangedToSave;
}
- /**
- * set this record have value changed, so to save
- *
- * @throws HeapException
- */
+ @Override
public void setValueIsChangedValueToSave() throws HeapException {
if (!valueChangedToSave) {
valueChangedToSave = true;
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java 2012-04-17 19:01:37 UTC (rev 3014)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java 2012-04-18 00:29:55 UTC (rev 3015)
@@ -48,4 +48,22 @@
*/
void readFromFile() throws HeapException;
+ /**
+ * initial state:no value to save since not read and not write
+ */
+ void clear();
+
+ /**
+ * set this record have value changed, so to save
+ *
+ * @throws HeapException
+ */
+ void setValueIsChangedValueToSave() throws HeapException;
+
+ /**
+ * to know if the value state change
+ *
+ * @return true if value changed
+ */
+ boolean isValueChangedToSave();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-18 00:30:02
|
Revision: 3015
http://joafip.svn.sourceforge.net/joafip/?rev=3015&view=rev
Author: luc_peuvrier
Date: 2012-04-18 00:29:55 +0000 (Wed, 18 Apr 2012)
Log Message:
-----------
HeapElementManager no more dependent of HeapHeader
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/AbstractHeapNodeManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/HeapRecordIterator.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 19:01:44
|
Revision: 3014
http://joafip.svn.sourceforge.net/joafip/?rev=3014&view=rev
Author: luc_peuvrier
Date: 2012-04-17 19:01:37 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
dead code removed
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 19:01:44
|
Revision: 3014
http://joafip.svn.sourceforge.net/joafip/?rev=3014&view=rev
Author: luc_peuvrier
Date: 2012-04-17 19:01:37 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
dead code removed
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -129,8 +129,6 @@
private HeapFreeNode freeNode;
- private int readSession = -1;
-
/** the area size in file ( record header size + data size ) */
private Integer areaSize;
@@ -620,13 +618,11 @@
// ASSERTX
assert !freeRecord : "is free record";
updateIdNodeData();
- final int currentReadSession = heapElementManager.getReadSession();
- if (idNode == null || readSession != currentReadSession) {
+ if (idNode == null) {
idNode = new HeapIdNode(heapElementManager, positionInFile,
parentPositionInFile, leftPositionInFile,
rightPositionInFile, colorSetted, color, numberOfChild,
nodeIdentifier);
- readSession = currentReadSession;
}
return idNode;
}
@@ -635,13 +631,11 @@
// ASSERTX
assert freeRecord : "is data record";
updateFreeNodeData();
- final int currentReadSession = heapElementManager.getReadSession();
- if (freeNode == null || readSession != currentReadSession) {
+ if (freeNode == null) {
freeNode = new HeapFreeNode(heapElementManager, positionInFile,
parentPositionInFile, leftPositionInFile,
rightPositionInFile, colorSetted, color, numberOfChild,
areaSize);
- readSession = currentReadSession;
}
return freeNode;
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -210,8 +210,6 @@
private final boolean fileOpenedInTransaction;
- private int readSession;
-
private final boolean deleteRenamig;
private final boolean clearResizeFile;
@@ -573,7 +571,7 @@
stopperTrace = new Exception("stopper trace");
serviceStarted = false;
if (!fileOpenedInTransaction) {
- closeFile();
+ closeFiles();
}
}
@@ -628,7 +626,7 @@
header.writeToFile();
flushOnFile();
if (fileOpenedInTransaction) {
- closeFile();
+ closeFiles();
openFile();
}
} else {
@@ -691,25 +689,6 @@
}
@Override
- public void clearNotToWrite() throws HeapException {
- // was for debug assert
- // for (HeapRecord heapRecord : readHeapRecordMap.values()) {
- // // if (heapRecord.isValueChangedToSave()) {
- // // throw new HeapRuntimeException("must not be in read cache");
- // // }
- // }
-
- // FIXMELUC x this increase execution time
- // readHeapRecordMap.clear();
- // readSession++;
- }
-
- @Override
- public int getReadSession() {
- return readSession;
- }
-
- @Override
public void closeTransaction() throws HeapException {
// ASSERTX
assert assertTransactionOpened();
@@ -735,7 +714,7 @@
flushOnFile();
}
if (fileOpenedInTransaction) {
- closeFile();
+ closeFiles();
}
openedTransaction = false;
}
@@ -747,7 +726,7 @@
clearHeaprecordToWriteMap();
readHeapRecordMap.clear();
if (fileOpenedInTransaction) {
- closeFile();
+ closeFiles();
}
openedTransaction = false;
}
@@ -756,7 +735,7 @@
heapRecordToWriteMap.clear();
}
- private void closeFile() throws HeapException {
+ private void closeFiles() throws HeapException {
try {
if (openFileTraceFile != null && !openFileTraceFile.delete()) {
LOGGER.error("while deleting open file trace");
@@ -1151,6 +1130,17 @@
return readHeapRecordMap.size() + heapRecordToWriteMap.size();
}
+ @Override
+ public void setDataRecordKeyManager(
+ final IDataRecordKeyManager dataRecordKeyManager) {
+ this.dataRecordKeyManager = dataRecordKeyManager;
+ }
+
+ @Override
+ public IDataRecordKeyManager getDataRecordKeyManager() {
+ return dataRecordKeyManager;
+ }
+
/**
* FOR TEST ONLY<br>
*
@@ -1174,15 +1164,4 @@
public HeapRecord getHeapFileRecordInWriteCache(final long positionInFile) {
return heapRecordToWriteMap.get(positionInFile);
}
-
- @Override
- public void setDataRecordKeyManager(
- final IDataRecordKeyManager dataRecordKeyManager) {
- this.dataRecordKeyManager = dataRecordKeyManager;
- }
-
- @Override
- public IDataRecordKeyManager getDataRecordKeyManager() {
- return dataRecordKeyManager;
- }
}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -105,15 +105,6 @@
void closeTransaction() throws HeapException;
/**
- * clear from memory not to write record (the read heap record cache)
- *
- * @throws HeapException
- */
- void clearNotToWrite() throws HeapException;
-
- int getReadSession();
-
- /**
* close the heap file transaction management without commit modification in
* file
*
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -268,7 +268,6 @@
logger.debug("create heap record #" + dataRecordIdentifier
+ FOR_DATA_SIZE + data.length);
}
- heapElementManager.clearNotToWrite();
return created;
}
@@ -348,7 +347,6 @@
deleteDataRecord(heapIdNode);
deleted = true;
}
- heapElementManager.clearNotToWrite();
return deleted;
}
@@ -677,7 +675,6 @@
} else {
dataAssociated = heapRecord.getDataAssociated();
}
- heapElementManager.clearNotToWrite();
return dataAssociated;
}
@@ -825,7 +822,6 @@
final DataRecordIdentifier dataRecordIdentifier)
throws HeapException {
final boolean haveDataRecord = idNodeSearchMayBeNotExist(dataRecordIdentifier) != null;
- heapElementManager.clearNotToWrite();
return haveDataRecord;
}
@@ -1020,11 +1016,6 @@
@Override
protected void closeHeapManagerAfterException() {
try {
- heapElementManager.clearNotToWrite();
- } catch (Exception exception) {
- logger.warn("closing after exception", exception);
- }
- try {
if (heapElementManager.isTransactionOpened()) {
heapElementManager.closeTransactionDiscardChange();
}
@@ -1067,7 +1058,6 @@
} catch (RBTException exception) {
throw new HeapException(exception);
}
- heapElementManager.clearNotToWrite();
return numberOfDataRecord;
}
@@ -1079,7 +1069,6 @@
} catch (RBTException exception) {
throw new HeapException(exception);
}
- heapElementManager.clearNotToWrite();
return numberOfFreeRecord;
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -128,7 +128,6 @@
heapElementManager.startService();
heapElementManager.openTransaction();
getHeapHeaderAndCheckPosition(heapHeader1);
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
}
@@ -158,7 +157,6 @@
// heapElementManager, heapRecord).getPositionInFile());
heapHeader2.setIdRootNodeFilePosition(heapRecord.getPositionInFile());
/* write modifications */
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
/* read the last modification */
@@ -174,7 +172,6 @@
+ HeapHeader.HEAP_HEADER_SIZE, HeapHeader.HEAP_HEADER_SIZE,
heapHeader3.getIdRootNodeFilePosition());
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
}
@@ -221,7 +218,6 @@
assertEquals("read must be equals appened", heapRecordAppened2,
heapRecord2);
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
}
@@ -238,7 +234,6 @@
data1[index] = (byte) (data1.length - index);
}
heapRecord1.setDataAssociated(data1);
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
@@ -247,7 +242,6 @@
for (int index = 0; index < data1.length; index++) {
assertEquals("bad record data", data1.length - index, data1[index]);
}
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
@@ -283,7 +277,6 @@
node.setColor(!color);
assertTrue("value must have changed",
heapRecord1.isValueChangedToSave());
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
@@ -291,7 +284,6 @@
node = heapRecord1.getIdNode();
assertEquals("color must have changed", !color, node.getColor());
assertFalse("not modified record", heapRecord1.isValueChangedToSave());
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
@@ -315,14 +307,12 @@
color = true;
}
node.setColor(!color);
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
heapRecord1 = heapElementManager.readHeapFileDataRecord(pos);
node = heapRecord1.getFreeNode();
assertEquals("color must have changed", !color, node.getColor());
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
}
@@ -353,7 +343,6 @@
// heapRecord1.createDataArea();
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
@@ -370,7 +359,6 @@
assertNotNull("must be in cache",
heapElementManager.getHeapFileRecordInReadCache(pos));
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
}
@@ -394,7 +382,6 @@
// .isValueChangedToSave());
assertFalse("created header must be saved",
heapHeader1.isValueChangedToSave());
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
assertFalse("saving implies no more value changed",
@@ -439,7 +426,6 @@
}
heapRecordAppened1.setDataAssociated(testData);
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
logger.debug("appened heap record1\n" + heapRecordAppened1.toString());
@@ -453,7 +439,6 @@
* crc32
*/);
heapRecordAppened2.setDataAssociated(testData);
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.stopService();
logger.debug("appened heap record2\n" + heapRecordAppened2.toString());
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -164,7 +164,6 @@
previousPosition = position;
final HeapIdNode node = (HeapIdNode) heapRecord.getIdNode();
idNodeTree.append(node);
- heapElementManager.clearNotToWrite();
heapElementManager.closeTransaction();
heapElementManager.openTransaction();
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -232,16 +232,6 @@
}
@Override
- public void clearNotToWrite() {
- // do nothing
- }
-
- @Override
- public int getReadSession() {
- return 0;
- }
-
- @Override
public void closeTransaction() throws HeapException {// NOPMD do nothing
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java 2012-04-17 06:44:59 UTC (rev 3013)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileDataManagerIntegrityChecker.java 2012-04-17 19:01:37 UTC (rev 3014)
@@ -125,7 +125,6 @@
checkTotalNumberOfRecord(freeRecordCount, dataRecordCount);
}
- heapElementManager.clearNotToWrite();
}
private void checkFreeNodeInTree(final HeapRecord heapRecord)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 06:45:15
|
Revision: 3013
http://joafip.svn.sourceforge.net/joafip/?rev=3013&view=rev
Author: luc_peuvrier
Date: 2012-04-17 06:44:59 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for tests some moves from joafip-heapfile to joafip-kvstore and joafip-file
Modified Paths:
--------------
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-testsuite/pom.xml
trunk/joafip-testsuite/src/main/java/net/sf/joafip/PersistanceTestsNoLongTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/FileTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/RecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/entity/RecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java
trunk/joafip-kvstore/src/test/java/net/
trunk/joafip-kvstore/src/test/java/net/sf/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/KeyValueStoreTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/KVRecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/service/
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -241,8 +241,8 @@
}
@Override
- protected void writeImpl(final byte[] data,final int offset,final int length)
- throws FileIOException {
+ protected void writeImpl(final byte[] data, final int offset,
+ final int length) throws FileIOException {
try {
randomAccessFile.write(data, offset, length);
} catch (IOException exception) {
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -269,18 +269,18 @@
@Override
public void writeImpl(final byte[] data) throws FileIOException {
- writeImpl(data,0, data.length);
+ writeImpl(data, 0, data.length);
}
@Override
public void writeImpl(final byte[] data, final int length)
throws FileIOException {
- writeImpl(data,0, length);
+ writeImpl(data, 0, length);
}
@Override
- protected void writeImpl(final byte[] data,final int offset,final int length)
- throws FileIOException {
+ protected void writeImpl(final byte[] data, final int offset,
+ final int length) throws FileIOException {
int wrote = 0;
byte[] page;
do {
@@ -294,7 +294,8 @@
} else {
lengthToCopy = inPage;
}
- System.arraycopy(data, offset+wrote, page, positionInPage, lengthToCopy);
+ System.arraycopy(data, offset + wrote, page, positionInPage,
+ lengthToCopy);
wrote += lengthToCopy;
positionInFile += lengthToCopy;
Modified: trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java
===================================================================
--- trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -35,11 +35,11 @@
private final byte[] data;
- public FileAccessRecord(final long positionInFile, final byte[] data,final int offset,
- final int length) {
+ public FileAccessRecord(final long positionInFile, final byte[] data,
+ final int offset, final int length) {
super();
this.positionInFile = positionInFile;
- this.data = Arrays.copyOfRange(data, offset, offset+length);
+ this.data = Arrays.copyOfRange(data, offset, offset + length);
}
public long getPositionInFile() {
Copied: trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java (from rev 3012, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java)
===================================================================
--- trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java (rev 0)
+++ trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -0,0 +1,232 @@
+/*
+ * 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.file.service;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.file.service.FileIOException;
+import net.sf.joafip.file.service.RandomAccessFileDirectNio;
+import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
+
+@NotStorableClass
+@DoNotTransform
+public class TestRandomAccessFileCache extends AbstractCommonDeleteFileTestCase {
+
+ private static final int NUMBER_OF_PAGE = 10;
+
+ private static final int PAGE_SIZE = 1024;
+
+ private RandomAccessFileReadWriteCache fileCache; // NOPMD
+
+ public TestRandomAccessFileCache() throws TestException {
+ super();
+ }
+
+ public TestRandomAccessFileCache(final String name) throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {// NOPMD override test case
+ super.setUp();
+ final File file = new File(TestConstant.getWinRamDiskRuntimeDir()
+ + "/data");
+ // final RandomAccessFileDirect direct = new
+ // RandomAccessFileDirect(file);
+ final RandomAccessFileDirectNio direct = new RandomAccessFileDirectNio(
+ file, 1, 0);
+ fileCache = new RandomAccessFileReadWriteCache(direct, PAGE_SIZE,
+ NUMBER_OF_PAGE);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {// NOPMD override test case
+ try {
+ fileCache.close();
+ } catch (Throwable throwable) {// NOPMD ignore all errors
+ }
+ fileCache = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testEmptyFile() throws FileIOException {
+ fileCache.open();
+ final byte[] data = new byte[100];
+ assertEquals("must have nothing to read", -1, fileCache.read(data));
+ }
+
+ public void test100bytes() throws FileIOException {// NOPMD
+ fileCache.open();
+ fileCache.seek(0);
+ writeBlock(0);
+ fileCache.close();
+
+ fileCache.open();
+ fileCache.seek(0);
+ assertBlockContent(0);
+ fileCache.close();
+ }
+
+ public void testWroteInCache() throws FileIOException {
+ writeData();
+ assertWroteReading();
+ }
+
+ public void testWroteInFile() throws FileIOException {
+ writeData();
+ fileCache.close();
+ fileCache.clearCache();
+ fileCache.open();
+ assertWroteReading();
+ }
+
+ public void testRandomBlock() throws FileIOException {
+ writeData();
+ fileCache.close();
+ fileCache.clearCache();
+ fileCache.open();
+
+ writeBlock(25, 200);
+ fileCache.seek(50 * 100);
+ assertBlockContent(50);
+ writeBlock(50, 201);
+ assertBlockContent(50, 201);
+ assertBlockContent(25, 200);
+ }
+
+ /**
+ * test page to write are not lost
+ *
+ * @throws FileIOException
+ */
+ public void testToWriteNotLost() throws FileIOException {
+ /*
+ * write 2 NUMBER_OF_PAGE pages
+ */
+ fileCache.open();
+ fileCache.seek(0);
+ byte[] data = new byte[PAGE_SIZE];
+ for (int pageNumber = 0; pageNumber < NUMBER_OF_PAGE * 2; pageNumber++) {
+ for (int index = 0; index < PAGE_SIZE; index++) {
+ data[index] = (byte) pageNumber;
+ }
+ fileCache.write(data);
+ }
+ fileCache.flush();
+ fileCache.close();
+ fileCache.clearCache();
+
+ /*
+ * change value in first page, when read enough to activate old page
+ * clearing
+ */
+ fileCache.open();
+ fileCache.seek(0);
+ for (int index = 0; index < PAGE_SIZE; index++) {
+ data[index] = (byte) 0xff;
+ }
+ fileCache.write(data);
+ for (int pageNumber = 0; pageNumber < NUMBER_OF_PAGE * 2; pageNumber++) {
+ fileCache.read(data);
+ }
+ fileCache.flush();
+ fileCache.close();
+ fileCache.clearCache();
+ /*
+ * check if first page wrote
+ */
+ fileCache.open();
+ fileCache.seek(0);
+ fileCache.read(data);
+ for (int index = 0; index < PAGE_SIZE; index++) {
+ assertEquals("not wrote data", (byte) 0xff, data[index]);
+ }
+
+ }
+
+ /**
+ * @throws FileIOException
+ */
+ private void assertWroteReading() throws FileIOException {
+ fileCache.seek(0);
+ for (int count = 0; count < 100; count++) {
+ assertBlockContent(count);
+ }
+ }
+
+ private void assertBlockContent(final int block, final int count)
+ throws FileIOException {
+ fileCache.seek(block * 100);
+ assertBlockContent(count);
+ }
+
+ /**
+ * @param count
+ * @throws FileIOException
+ */
+ private void assertBlockContent(final int count) throws FileIOException {
+ final byte[] data = new byte[100];
+ assertEquals("must read 100 bytes (value " + count + ")", 100,
+ fileCache.read(data));
+ for (int index = 0; index < 100; index++) {
+ assertEquals("bad byte value", (byte) count, data[index]);
+ }
+ }
+
+ /**
+ * @throws FileIOException
+ */
+ private void writeData() throws FileIOException {
+ fileCache.open();
+ fileCache.seek(0);
+ for (int count = 0; count < 100; count++) {
+ writeBlock(count);
+ }
+ }
+
+ /**
+ *
+ * @param block
+ * 100 byte block number
+ * @param valueOfAllData
+ * value of all byte in data block
+ * @throws FileIOException
+ */
+ private void writeBlock(final int block, final int valueOfAllData)
+ throws FileIOException {
+ fileCache.seek(block * 100);
+ writeBlock(valueOfAllData);
+ }
+
+ /**
+ * @param valueOfAllData
+ * value of all byte in data block
+ * @throws FileIOException
+ */
+ private void writeBlock(final int valueOfAllData) throws FileIOException {
+ byte[] data = new byte[100];
+ for (int index = 0; index < 100; index++) {
+ data[index] = (byte) valueOfAllData;
+ }
+ fileCache.write(data);
+ }
+}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -17,7 +17,7 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.record.service.HeapElementManager;
+import net.sf.joafip.heapfile.record.service.IHeapElementManager;
import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
@@ -71,7 +71,7 @@
* construct header for reading in heap file or for an empty heap
*
*/
- public HeapHeader(final HeapElementManager heapElementManager) {
+ public HeapHeader(final IHeapElementManager heapElementManager) {
/* always at the begin of the file */
/* length=HEAP_HEADER_SIZE */
super(heapElementManager.getFileForStorable(), 0L/* position */);
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -191,7 +191,7 @@
private boolean openedTransaction = false;
/** the header node */
- private final HeapHeader header;
+ private HeapHeader header;
/** true if data loose, updated by {@link #wasBadFileStableState()} */
private boolean dataLost = false;
@@ -250,7 +250,6 @@
this.clearResizeFile = clearResizeFile;
this.maxFileOperationRetry = maxFileOperationRetry;
this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- header = new HeapHeader(this);
}
/**
@@ -295,7 +294,6 @@
this.clearResizeFile = clearResizeFile;
this.maxFileOperationRetry = maxFileOperationRetry;
this.fileOperationRetryMsDelay = fileOperationRetryMsDelay;
- header = new HeapHeader(this);
}
@Override
@@ -1021,25 +1019,12 @@
return heapRecord;
}
- /**
- * the heap size is the current byte position after the last record
- *
- * @return the heap size in bytes
- * @throws HeapException
- */
@Override
- public long heapSize() throws HeapException {
- assertTransactionOpened();
- return header.getEndOfRecordPositionInFile();
+ public void setHeapHeader(final HeapHeader heapHeader) throws HeapException {
+ this.header = heapHeader;
}
@Override
- public long getLastRecordPositionInFile() throws HeapException {
- assertTransactionOpened();
- return header.getLastRecordPositionInFile();
- }
-
- @Override
public HeapHeader getHeapHeader() throws HeapException {
assertTransactionOpened();
return header;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -16,7 +16,6 @@
*/
package net.sf.joafip.heapfile.record.service;
-import net.sf.joafip.Fortest;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
@@ -130,7 +129,15 @@
boolean isTransactionOpened();
/**
+ * set heap header
*
+ * @param heapHeader
+ * @throws HeapException
+ */
+ void setHeapHeader(HeapHeader heapHeader) throws HeapException;
+
+ /**
+ *
* @return the heap header in file
* @throws HeapException
*/
@@ -187,21 +194,6 @@
void delete(long positionInFile) throws HeapException;
/**
- *
- * @return heap file size in bytes
- * @throws HeapException
- */
- long heapSize() throws HeapException;
-
- /**
- *
- * @return last record in file position
- * @throws HeapException
- */
- @Fortest
- long getLastRecordPositionInFile() throws HeapException;
-
- /**
* @return file for storage size
* @throws HeapException
*/
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -192,6 +192,7 @@
deleteRenaming, clearResizeFile, maxFileOperationRetry,
fileOperationRetryMsDelay, openFileTraceFile);
}
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
final HeapFreeNodeManager heapFreeNodeManager = new HeapFreeNodeManager(
heapElementManager);
freeNodeTree = new RedBlackTree<Integer>(heapFreeNodeManager, false,
@@ -1084,7 +1085,8 @@
@Override
protected long heapSizeImpl() throws HeapException {
- return heapElementManager.heapSize();
+ final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ return heapHeader.getEndOfRecordPositionInFile();
}
@Override
@@ -1232,7 +1234,8 @@
@Fortest
@Override
public long getLastRecordPositionInFile() throws HeapException {
- final long lastRecordPositionInFile = heapElementManager
+ final HeapHeader heapHeader = heapElementManager.getHeapHeader();
+ final long lastRecordPositionInFile = heapHeader
.getLastRecordPositionInFile();
return lastRecordPositionInFile;
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -81,6 +81,7 @@
heapElementManager = new HeapElementManager(fileForStorable,
stateDataFile, backupFileForStorable, stateDataBackupFile,
globalStateFlag, false, false, 1, 0, openFileTraceFile);
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
heapElementManager.startService();
heapElementManager.openTransaction();
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -1,206 +0,0 @@
-/*
- * 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.heapfile.record.entity;
-
-import java.io.File;
-
-import net.sf.joafip.AbstractCommonDeleteFileTestCase;
-import net.sf.joafip.DoNotTransform;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestConstant;
-import net.sf.joafip.TestException;
-import net.sf.joafip.kvstore.entity.AbstractFileStorable;
-import net.sf.joafip.kvstore.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-
-@NotStorableClass
-@DoNotTransform
-public class TestAbstractFileStorable extends AbstractCommonDeleteFileTestCase {// NOPMD
-
- private String fileName;
-
- private static final String DATA1 = "abcdefghijkl";
-
- private static final String DATA2 = "0123456789abcdefghijkl";
-
- @NotStorableClass
- private class Storable extends AbstractFileStorable {
-
- public byte data[]; // NOPMD
-
- public int dataSize; // NOPMD
-
- public Storable(final FileForStorable fileForStorable,
- final long positionInFile) {
- super(fileForStorable, positionInFile);
- }
-
- @Override
- protected void valueChangedAction() throws HeapException {
- // no implementation
- }
-
- @Override
- protected int toMarshallSize() throws HeapException {
- return dataSize + 4;
- }
-
- @Override
- protected void unmarshallImpl() throws HeapException {
- readFileToIoBuffer(dataSize + 4);// +4 for crc32
- data = readBytes(dataSize);
- readAndCheckCrc32();
- logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
- }
-
- @Override
- protected void marshallImpl() throws HeapException {
- writeBytes(data);
- writeCrc32();
- logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
- }
-
- @Override
- public boolean equals(final Object obj) {// NOPMD hascode not needed
- boolean equals;
- if (obj == null) {
- equals = false;
- } else if (obj instanceof Storable) {
- final Storable storable = (Storable) obj;
- equals = positionInFile == storable.positionInFile;
- if (equals) {
- equals = data.length == storable.data.length;
- }
- for (int index = 0; equals && index < data.length; index++) {
- equals = data[index] == storable.data[index];
- }
- } else {
- equals = false;
- }
- return equals;
- }
-
- };
-
- private Storable storableIn1; // NOPMD
-
- private Storable storableOut1; // NOPMD
-
- private Storable storableIn2; // NOPMD
-
- private Storable storableOut2; // NOPMD
-
- private FileForStorable fileForStorable; // NOPMD
-
- public TestAbstractFileStorable() throws TestException {
- super();
- }
-
- public TestAbstractFileStorable(final String name) throws TestException {
- super(name);
- }
-
- protected void setUp() throws Exception {// NOPMD inherit test case
- super.setUp();
- fileName = TestConstant.getWinRamDiskRuntimeDir() + File.separator
- + "test.dat";
- fileForStorable = new FileForStorable(fileName, 1, 0);
- /* length = DATA1.length() + 4 */
- storableIn1 = new Storable(fileForStorable, 0);
- /* length= DATA1.length() + 4 */
- storableOut1 = new Storable(fileForStorable, 0);
- storableOut1.setValueIsChangedValueToSave();
- /* length= DATA2.length() + 4 : +4 for crc32 */
- storableIn2 = new Storable(fileForStorable, DATA1.length() + 4);
- /* length= DATA2.length() + 4 : +4 for crc32 */
- storableOut2 = new Storable(fileForStorable, DATA1.length() + 4);
- storableOut2.setValueIsChangedValueToSave();
- }
-
- protected void tearDown() throws Exception {// NOPMD
- try {
- fileForStorable.close();
- } catch (Throwable throwable) {// NOPMD
- // ignore error
- }
- fileForStorable = null;// NOPMD
- storableIn1 = null;// NOPMD
- storableOut1 = null;// NOPMD
- storableIn2 = null;// NOPMD
- storableOut2 = null;// NOPMD
- super.tearDown();
- }
-
- public void testInOut1() throws HeapException {// NOPMD assertion in outIn
- new File(fileName).delete();
- outIn();
- }
-
- public void testInOut2() throws HeapException {// NOPMD assertion in out in
- new File(fileName).delete();
- output();
- input();
- }
-
- private void outIn() throws HeapException {
- output();
- input();
- assertEquals("in1 must be equals to out1", storableIn1, storableOut1);
- assertEquals("in2 must be equals to out2", storableIn2, storableOut2);
- }
-
- /**
- * @throws HeapException
- * @throws FileCorruptedException
- */
- private void input() throws HeapException {
- storableIn1.dataSize = DATA1.length();
- storableIn2.dataSize = DATA2.length();
-
- fileForStorable.open();
- // fileForStorable.readStorable(storableIn2);
- storableIn2.readFromFile();
- // fileForStorable.readStorable(storableIn1);
- storableIn1.readFromFile();
- fileForStorable.close();
- }
-
- /**
- * @throws HeapException
- * @throws FileCorruptedException
- */
- private void output() throws HeapException {
- storableOut1.data = DATA1.getBytes();
- storableOut1.dataSize = DATA1.length();
-
- fileForStorable.open();
- // fileForStorable.writeStorable(storableOut1);
- storableOut1.writeToFile();
- fileForStorable.close();
-
- storableOut2.data = DATA2.getBytes();
- storableOut2.dataSize = DATA2.length();
-
- fileForStorable.open();
- // fileForStorable.writeStorable(storableOut2);
- storableOut2.writeToFile();
- // long fileSize = fileForStorable.getFileSize();
- fileForStorable.close();
- // because of cache can not test that
- // assertEquals(DATA1.length() + DATA2.length(), fileSize);
- }
-}
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -1,79 +0,0 @@
-/*
- * Copyright 2008 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.heapfile.record.entity;
-
-import net.sf.joafip.AbstractJoafipCommonTestCase;
-import net.sf.joafip.DoNotTransform;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestException;
-import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
-
-@NotStorableClass
-@DoNotTransform
-public class TestDataRecordIdentifier extends AbstractJoafipCommonTestCase {
-
- public TestDataRecordIdentifier() throws TestException {
- super();
- }
-
- public TestDataRecordIdentifier(final String name) throws TestException {
- super(name);
- }
-
- public void testSmall() {
- final DataRecordIdentifier identifier0 = new DataRecordIdentifier(0);
-
- assertEquals("id0 long1 must be 0", 0, identifier0.value);
-
- final DataRecordIdentifier identifier1 = new DataRecordIdentifier(1);
-
- assertEquals("id1 long1 must be 1", 1, identifier1.value);
-
- final DataRecordIdentifier identifier0Bis = new DataRecordIdentifier(0);
-
- assertEquals("id0 must be equals to itself", identifier0, identifier0);
- assertEquals("id0 and id0bis must be equals", identifier0,
- identifier0Bis);
- assertEquals("id0 must be equals to itself thru compareTo", 0,
- identifier0.compareTo(identifier0));
- assertEquals("id0 and id0bis must be equals compareTo", 0,
- identifier0.compareTo(identifier0Bis));
- assertEquals("id0 and id0bis must be equals compareTo", 0,
- identifier0Bis.compareTo(identifier0));
- assertTrue("id0 must be less than id1",
- identifier0.compareTo(identifier1) < 0);
- assertTrue("id1 must be greater than id0",
- identifier1.compareTo(identifier0) > 0);
- }
-
- public void testIncremente() {
- final DataRecordIdentifier identifier = new DataRecordIdentifier(0);
- final DataRecordIdentifier nextIdentifier = new DataRecordIdentifier(
- identifier);
- assertCompareWithNext(identifier, nextIdentifier);
- final DataRecordIdentifier expectedNext = new DataRecordIdentifier(1);
- assertEquals("not expected", expectedNext, nextIdentifier);
- }
-
- private void assertCompareWithNext(final DataRecordIdentifier identifier,
- final DataRecordIdentifier nextIdentifier) {
- assertTrue("id must be less than next",
- identifier.compareTo(nextIdentifier) < 0);
- assertTrue("next must be greater than id",
- nextIdentifier.compareTo(identifier) > 0);
- }
-}
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -1,213 +0,0 @@
-/*
- * 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.heapfile.record.entity;
-
-import java.io.File;
-
-import net.sf.joafip.AbstractCommonDeleteFileTestCase;
-import net.sf.joafip.DoNotTransform;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestConstant;
-import net.sf.joafip.TestException;
-import net.sf.joafip.kvstore.entity.AbstractFileStorable;
-import net.sf.joafip.kvstore.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-
-@NotStorableClass
-@DoNotTransform
-public class TestMarshall extends AbstractCommonDeleteFileTestCase {// NOPMD
-
- @NotStorableClass
- private class Marshallizable extends AbstractFileStorable {
-
- public Marshallizable(final FileForStorable fileForStorable) {
- /* length=8 + 4 + 1 + 4 : 1 long + 1 integer + 1 boolean + 1 integer */
- super(fileForStorable, 0/* , 8 + 4 + 1 + 4 *//*
- * 1 long + 1 integer +
- * 1 boolean + 1 integer
- */);
- }
-
- @Override
- protected void valueChangedAction() throws HeapException {
- // no implementation
- }
-
- public long longValue;
-
- public int intValue; // NOPMD
-
- public boolean booleanValue; // NOPMD
-
- @Override
- protected int toMarshallSize() throws HeapException {
- return 8 + 4 + 1 + 4;
- }
-
- @Override
- protected void marshallImpl() throws HeapException {
- writeLong(longValue);
- writeInteger(intValue);
- writeBoolean(booleanValue);
- writeCrc32();
- }
-
- @Override
- protected void unmarshallImpl() throws HeapException {
- readFileToIoBuffer(8 + 4 + 1 + 4);
- longValue = readLong();
- intValue = readInteger();
- booleanValue = readBoolean();
- readAndCheckCrc32();
- }
- };
-
- private Marshallizable fileStorableForWrite; // NOPMD
-
- private FileForStorable fileForStorable; // NOPMD
-
- public TestMarshall() throws TestException {
- super();
- }
-
- public TestMarshall(final String name) throws TestException {
- super(name);
- }
-
- protected void setUp() throws Exception {// NOPMD inherit test case
- super.setUp();
- fileForStorable = new FileForStorable(
- TestConstant.getWinRamDiskRuntimeDir() + File.separator
- + "test.dat", 1, 0);
- }
-
- protected void tearDown() throws Exception {// NOPMD inherit test case
- try {
- if (fileForStorable.isOpened()) {
- fileForStorable.close();
- }
- } catch (Throwable throwable) {// NOPMD ignore all errors
- /* ignore error */
- }
- fileStorableForWrite = null;// NOPMD
- fileForStorable = null;// NOPMD
- super.tearDown();
- }
-
- public void testInOut() throws HeapException {
- fileStorableForWrite = new Marshallizable(fileForStorable);
- assertTrue("must be in state just created",
- fileStorableForWrite.isJustCreated());
- assertFalse("must be in state value not changed",
- fileStorableForWrite.isValueChangedToSave());
- fileStorableForWrite.longValue = 0;
- fileStorableForWrite.intValue = 0;
- fileStorableForWrite.booleanValue = false;
- fileStorableForWrite.setValueIsChangedValueToSave();
- assertFalse("must not be in state just created",
- fileStorableForWrite.isJustCreated());
- assertTrue("must be in state value changed",
- fileStorableForWrite.isValueChangedToSave());
- check();
-
- fileStorableForWrite = new Marshallizable(fileForStorable);
- fileStorableForWrite.longValue = 0xff;
- fileStorableForWrite.intValue = 0xff;
- fileStorableForWrite.booleanValue = true;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite = new Marshallizable(fileForStorable);
- fileStorableForWrite.longValue = 0xff00;
- fileStorableForWrite.intValue = 0xff00;
- fileStorableForWrite.booleanValue = false;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite = new Marshallizable(fileForStorable);
- fileStorableForWrite.longValue = 0xff0000;
- fileStorableForWrite.intValue = 0xff0000;
- fileStorableForWrite.booleanValue = true;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite = new Marshallizable(fileForStorable);
- fileStorableForWrite.longValue = 0xff000000;
- fileStorableForWrite.intValue = 0xff000000;
- fileStorableForWrite.booleanValue = false;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite = new Marshallizable(fileForStorable);
- fileStorableForWrite.longValue = 0xff00000000L;
- fileStorableForWrite.intValue = 0xff00ff00;
- fileStorableForWrite.booleanValue = true;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite.longValue = 0xff0000000000L;
- fileStorableForWrite.intValue = 0x00ff00ff;
- fileStorableForWrite.booleanValue = false;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite.longValue = 0xff000000000000L;
- fileStorableForWrite.intValue = 0xf0f0f0f0;
- fileStorableForWrite.booleanValue = false;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite.longValue = 0xff00000000000000L;
- fileStorableForWrite.intValue = 0x0f0f0f0f;
- fileStorableForWrite.booleanValue = true;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
-
- fileStorableForWrite.longValue = 0xff00ff00ff00ff00L;
- fileStorableForWrite.intValue = 0xffffffff;
- fileStorableForWrite.booleanValue = false;
- fileStorableForWrite.setValueIsChangedValueToSave();
- check();
- }
-
- /**
- * @throws HeapException
- * @throws FileCorruptedException
- *
- */
- private void check() throws HeapException {
- final Marshallizable fileStorableForRead;
- fileForStorable.open();
- fileStorableForWrite.writeToFile(/* fileForStorable */);
- assertFalse("must not be in state value changed since just wrote",
- fileStorableForWrite.isValueChangedToSave());
- fileStorableForRead = new Marshallizable(fileForStorable);
- fileStorableForRead.readFromFile(/* fileForStorable */);
- assertFalse("must be in state just created",
- fileStorableForRead.isJustCreated());
- assertFalse("must not be in state value changed",
- fileStorableForRead.isValueChangedToSave());
- fileForStorable.close();
- assertEquals("wrote and read long value must be equals",
- fileStorableForWrite.longValue, fileStorableForRead.longValue);
- assertEquals("wrote and read int value must be equals",
- fileStorableForWrite.intValue, fileStorableForRead.intValue);
- assertEquals("wrote and read boolean value must be equals",
- fileStorableForWrite.booleanValue,
- fileStorableForRead.booleanValue);
- }
-}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -87,6 +87,7 @@
heapElementManager = new HeapElementManager(fileForStorable,
stateDataFile, backupFileForStorable, stateDataBackupFile,
globalStateFile, false, false, 1, 0, openFileTraceFile);
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
}
@Override
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -83,11 +83,7 @@
heapElementManager = new HeapElementManager(fileForStorable,
stateDataFile, backupFileForStorage, stateDataBackupFile,
globalStateFile, false, false, 1, 0, openFileTraceFile);
- // heapElementManager = new HeapElementManager(fileForStorable);
-
- // HeapFreeNodeManager heapFreeNodeManager = new HeapFreeNodeManager(
- // heapElementManager);
- // freeNodeTree = new RedBlackTree(heapFreeNodeManager);
+ heapElementManager.setHeapHeader(new HeapHeader(heapElementManager));
final HeapIdNodeManager heapIdNodeManager = new HeapIdNodeManager(
heapElementManager);
idNodeTree = new RedBlackTree<DataRecordIdentifier>(heapIdNodeManager,
Deleted: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -1,232 +0,0 @@
-/*
- * 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.heapfile.record.service;
-
-import java.io.File;
-
-import net.sf.joafip.AbstractCommonDeleteFileTestCase;
-import net.sf.joafip.DoNotTransform;
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.TestConstant;
-import net.sf.joafip.TestException;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.file.service.RandomAccessFileDirectNio;
-import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
-
-@NotStorableClass
-@DoNotTransform
-public class TestRandomAccessFileCache extends AbstractCommonDeleteFileTestCase {
-
- private static final int NUMBER_OF_PAGE = 10;
-
- private static final int PAGE_SIZE = 1024;
-
- private RandomAccessFileReadWriteCache fileCache; // NOPMD
-
- public TestRandomAccessFileCache() throws TestException {
- super();
- }
-
- public TestRandomAccessFileCache(final String name) throws TestException {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {// NOPMD override test case
- super.setUp();
- final File file = new File(TestConstant.getWinRamDiskRuntimeDir()
- + "/data");
- // final RandomAccessFileDirect direct = new
- // RandomAccessFileDirect(file);
- final RandomAccessFileDirectNio direct = new RandomAccessFileDirectNio(
- file, 1, 0);
- fileCache = new RandomAccessFileReadWriteCache(direct, PAGE_SIZE,
- NUMBER_OF_PAGE);
- }
-
- @Override
- protected void tearDown() throws Exception {// NOPMD override test case
- try {
- fileCache.close();
- } catch (Throwable throwable) {// NOPMD ignore all errors
- }
- fileCache = null;// NOPMD
- super.tearDown();
- }
-
- public void testEmptyFile() throws FileIOException {
- fileCache.open();
- final byte[] data = new byte[100];
- assertEquals("must have nothing to read", -1, fileCache.read(data));
- }
-
- public void test100bytes() throws FileIOException {// NOPMD
- fileCache.open();
- fileCache.seek(0);
- writeBlock(0);
- fileCache.close();
-
- fileCache.open();
- fileCache.seek(0);
- assertBlockContent(0);
- fileCache.close();
- }
-
- public void testWroteInCache() throws FileIOException {
- writeData();
- assertWroteReading();
- }
-
- public void testWroteInFile() throws FileIOException {
- writeData();
- fileCache.close();
- fileCache.clearCache();
- fileCache.open();
- assertWroteReading();
- }
-
- public void testRandomBlock() throws FileIOException {
- writeData();
- fileCache.close();
- fileCache.clearCache();
- fileCache.open();
-
- writeBlock(25, 200);
- fileCache.seek(50 * 100);
- assertBlockContent(50);
- writeBlock(50, 201);
- assertBlockContent(50, 201);
- assertBlockContent(25, 200);
- }
-
- /**
- * test page to write are not lost
- *
- * @throws FileIOException
- */
- public void testToWriteNotLost() throws FileIOException {
- /*
- * write 2 NUMBER_OF_PAGE pages
- */
- fileCache.open();
- fileCache.seek(0);
- byte[] data = new byte[PAGE_SIZE];
- for (int pageNumber = 0; pageNumber < NUMBER_OF_PAGE * 2; pageNumber++) {
- for (int index = 0; index < PAGE_SIZE; index++) {
- data[index] = (byte) pageNumber;
- }
- fileCache.write(data);
- }
- fileCache.flush();
- fileCache.close();
- fileCache.clearCache();
-
- /*
- * change value in first page, when read enough to activate old page
- * clearing
- */
- fileCache.open();
- fileCache.seek(0);
- for (int index = 0; index < PAGE_SIZE; index++) {
- data[index] = (byte) 0xff;
- }
- fileCache.write(data);
- for (int pageNumber = 0; pageNumber < NUMBER_OF_PAGE * 2; pageNumber++) {
- fileCache.read(data);
- }
- fileCache.flush();
- fileCache.close();
- fileCache.clearCache();
- /*
- * check if first page wrote
- */
- fileCache.open();
- fileCache.seek(0);
- fileCache.read(data);
- for (int index = 0; index < PAGE_SIZE; index++) {
- assertEquals("not wrote data", (byte) 0xff, data[index]);
- }
-
- }
-
- /**
- * @throws FileIOException
- */
- private void assertWroteReading() throws FileIOException {
- fileCache.seek(0);
- for (int count = 0; count < 100; count++) {
- assertBlockContent(count);
- }
- }
-
- private void assertBlockContent(final int block, final int count)
- throws FileIOException {
- fileCache.seek(block * 100);
- assertBlockContent(count);
- }
-
- /**
- * @param count
- * @throws FileIOException
- */
- private void assertBlockContent(final int count) throws FileIOException {
- final byte[] data = new byte[100];
- assertEquals("must read 100 bytes (value " + count + ")", 100,
- fileCache.read(data));
- for (int index = 0; index < 100; index++) {
- assertEquals("bad byte value", (byte) count, data[index]);
- }
- }
-
- /**
- * @throws FileIOException
- */
- private void writeData() throws FileIOException {
- fileCache.open();
- fileCache.seek(0);
- for (int count = 0; count < 100; count++) {
- writeBlock(count);
- }
- }
-
- /**
- *
- * @param block
- * 100 byte block number
- * @param valueOfAllData
- * value of all byte in data block
- * @throws FileIOException
- */
- private void writeBlock(final int block, final int valueOfAllData)
- throws FileIOException {
- fileCache.seek(block * 100);
- writeBlock(valueOfAllData);
- }
-
- /**
- * @param valueOfAllData
- * value of all byte in data block
- * @throws FileIOException
- */
- private void writeBlock(final int valueOfAllData) throws FileIOException {
- byte[] data = new byte[100];
- for (int index = 0; index < 100; index++) {
- data[index] = (byte) valueOfAllData;
- }
- fileCache.write(data);
- }
-}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -260,13 +260,13 @@
}
@Override
- public HeapHeader getHeapHeader() {
- return null;
+ public void setHeapHeader(final HeapHeader heapHeader) throws HeapException {
+ // do nothing
}
@Override
- public long heapSize() throws HeapException {
- return 0;
+ public HeapHeader getHeapHeader() {
+ return null;
}
@Override
@@ -318,11 +318,6 @@
}
@Override
- public long getLastRecordPositionInFile() {
- return 0;
- }
-
- @Override
public FileForStorable getFileForStorable() {
return fileForStorable;
}
Modified: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java 2012-04-17 05:05:53 UTC (rev 3012)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -648,7 +648,8 @@
}
}
- protected abstract Iterator<DataRecordIdentifier> dataRecordIteratorImpl() throws HeapException;
+ protected abstract Iterator<DataRecordIdentifier> dataRecordIteratorImpl()
+ throws HeapException;
/**
* assert the data management service is started
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java (from rev 3012, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -0,0 +1,206 @@
+/*
+ * 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.heapfile.record.entity;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+@NotStorableClass
+@DoNotTransform
+public class TestAbstractFileStorable extends AbstractCommonDeleteFileTestCase {// NOPMD
+
+ private String fileName;
+
+ private static final String DATA1 = "abcdefghijkl";
+
+ private static final String DATA2 = "0123456789abcdefghijkl";
+
+ @NotStorableClass
+ private class Storable extends AbstractFileStorable {
+
+ public byte data[]; // NOPMD
+
+ public int dataSize; // NOPMD
+
+ public Storable(final FileForStorable fileForStorable,
+ final long positionInFile) {
+ super(fileForStorable, positionInFile);
+ }
+
+ @Override
+ protected void valueChangedAction() throws HeapException {
+ // no implementation
+ }
+
+ @Override
+ protected int toMarshallSize() throws HeapException {
+ return dataSize + 4;
+ }
+
+ @Override
+ protected void unmarshallImpl() throws HeapException {
+ readFileToIoBuffer(dataSize + 4);// +4 for crc32
+ data = readBytes(dataSize);
+ readAndCheckCrc32();
+ logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
+ }
+
+ @Override
+ protected void marshallImpl() throws HeapException {
+ writeBytes(data);
+ writeCrc32();
+ logger.info("wrote crc32 " + getCrc32() + " pos=" + positionInFile);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {// NOPMD hascode not needed
+ boolean equals;
+ if (obj == null) {
+ equals = false;
+ } else if (obj instanceof Storable) {
+ final Storable storable = (Storable) obj;
+ equals = positionInFile == storable.positionInFile;
+ if (equals) {
+ equals = data.length == storable.data.length;
+ }
+ for (int index = 0; equals && index < data.length; index++) {
+ equals = data[index] == storable.data[index];
+ }
+ } else {
+ equals = false;
+ }
+ return equals;
+ }
+
+ };
+
+ private Storable storableIn1; // NOPMD
+
+ private Storable storableOut1; // NOPMD
+
+ private Storable storableIn2; // NOPMD
+
+ private Storable storableOut2; // NOPMD
+
+ private FileForStorable fileForStorable; // NOPMD
+
+ public TestAbstractFileStorable() throws TestException {
+ super();
+ }
+
+ public TestAbstractFileStorable(final String name) throws TestException {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {// NOPMD inherit test case
+ super.setUp();
+ fileName = TestConstant.getWinRamDiskRuntimeDir() + File.separator
+ + "test.dat";
+ fileForStorable = new FileForStorable(fileName, 1, 0);
+ /* length = DATA1.length() + 4 */
+ storableIn1 = new Storable(fileForStorable, 0);
+ /* length= DATA1.length() + 4 */
+ storableOut1 = new Storable(fileForStorable, 0);
+ storableOut1.setValueIsChangedValueToSave();
+ /* length= DATA2.length() + 4 : +4 for crc32 */
+ storableIn2 = new Storable(fileForStorable, DATA1.length() + 4);
+ /* length= DATA2.length() + 4 : +4 for crc32 */
+ storableOut2 = new Storable(fileForStorable, DATA1.length() + 4);
+ storableOut2.setValueIsChangedValueToSave();
+ }
+
+ protected void tearDown() throws Exception {// NOPMD
+ try {
+ fileForStorable.close();
+ } catch (Throwable throwable) {// NOPMD
+ // ignore error
+ }
+ fileForStorable = null;// NOPMD
+ storableIn1 = null;// NOPMD
+ storableOut1 = null;// NOPMD
+ storableIn2 = null;// NOPMD
+ storableOut2 = null;// NOPMD
+ super.tearDown();
+ }
+
+ public void testInOut1() throws HeapException {// NOPMD assertion in outIn
+ new File(fileName).delete();
+ outIn();
+ }
+
+ public void testInOut2() throws HeapException {// NOPMD assertion in out in
+ new File(fileName).delete();
+ output();
+ input();
+ }
+
+ private void outIn() throws HeapException {
+ output();
+ input();
+ assertEquals("in1 must be equals to out1", storableIn1, storableOut1);
+ assertEquals("in2 must be equals to out2", storableIn2, storableOut2);
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ */
+ private void input() throws HeapException {
+ storableIn1.dataSize = DATA1.length();
+ storableIn2.dataSize = DATA2.length();
+
+ fileForStorable.open();
+ // fileForStorable.readStorable(storableIn2);
+ storableIn2.readFromFile();
+ // fileForStorable.readStorable(storableIn1);
+ storableIn1.readFromFile();
+ fileForStorable.close();
+ }
+
+ /**
+ * @throws HeapException
+ * @throws FileCorruptedException
+ */
+ private void output() throws HeapException {
+ storableOut1.data = DATA1.getBytes();
+ storableOut1.dataSize = DATA1.length();
+
+ fileForStorable.open();
+ // fileForStorable.writeStorable(storableOut1);
+ storableOut1.writeToFile();
+ fileForStorable.close();
+
+ storableOut2.data = DATA2.getBytes();
+ storableOut2.dataSize = DATA2.length();
+
+ fileForStorable.open();
+ // fileForStorable.writeStorable(storableOut2);
+ storableOut2.writeToFile();
+ // long fileSize = fileForStorable.getFileSize();
+ fileForStorable.close();
+ // because of cache can not test that
+ // assertEquals(DATA1.length() + DATA2.length(), fileSize);
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java (from rev 3012, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2008 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.heapfile.record.entity;
+
+import net.sf.joafip.AbstractJoafipCommonTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+
+@NotStorableClass
+@DoNotTransform
+public class TestDataRecordIdentifier extends AbstractJoafipCommonTestCase {
+
+ public TestDataRecordIdentifier() throws TestException {
+ super();
+ }
+
+ public TestDataRecordIdentifier(final String name) throws TestException {
+ super(name);
+ }
+
+ public void testSmall() {
+ final DataRecordIdentifier identifier0 = new DataRecordIdentifier(0);
+
+ assertEquals("id0 long1 must be 0", 0, identifier0.value);
+
+ final DataRecordIdentifier identifier1 = new DataRecordIdentifier(1);
+
+ assertEquals("id1 long1 must be 1", 1, identifier1.value);
+
+ final DataRecordIdentifier identifier0Bis = new DataRecordIdentifier(0);
+
+ assertEquals("id0 must be equals to itself", identifier0, identifier0);
+ assertEquals("id0 and id0bis must be equals", identifier0,
+ identifier0Bis);
+ assertEquals("id0 must be equals to itself thru compareTo", 0,
+ identifier0.compareTo(identifier0));
+ assertEquals("id0 and id0bis must be equals compareTo", 0,
+ identifier0.compareTo(identifier0Bis));
+ assertEquals("id0 and id0bis must be equals compareTo", 0,
+ identifier0Bis.compareTo(identifier0));
+ assertTrue("id0 must be less than id1",
+ identifier0.compareTo(identifier1) < 0);
+ assertTrue("id1 must be greater than id0",
+ identifier1.compareTo(identifier0) > 0);
+ }
+
+ public void testIncremente() {
+ final DataRecordIdentifier identifier = new DataRecordIdentifier(0);
+ final DataRecordIdentifier nextIdentifier = new DataRecordIdentifier(
+ identifier);
+ assertCompareWithNext(identifier, nextIdentifier);
+ final DataRecordIdentifier expectedNext = new DataRecordIdentifier(1);
+ assertEquals("not expected", expectedNext, nextIdentifier);
+ }
+
+ private void assertCompareWithNext(final DataRecordIdentifier identifier,
+ final DataRecordIdentifier nextIdentifier) {
+ assertTrue("id must be less than next",
+ identifier.compareTo(nextIdentifier) < 0);
+ assertTrue("next must be greater than id",
+ nextIdentifier.compareTo(identifier) > 0);
+ }
+}
Copied: trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java (from rev 3012, trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java)
===================================================================
--- trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java (rev 0)
+++ trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java 2012-04-17 06:44:59 UTC (rev 3013)
@@ -0,0 +1,213 @@
+/*
+ * 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.heapfile.record.entity;
+
+import java.io.File;
+
+import net.sf.joafip.AbstractCommonDeleteFileTestCase;
+import net.sf.joafip.DoNotTransform;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestConstant;
+import net.sf.joafip.TestException;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-17 06:45:06
|
Revision: 3013
http://joafip.svn.sourceforge.net/joafip/?rev=3013&view=rev
Author: luc_peuvrier
Date: 2012-04-17 06:44:59 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for tests some moves from joafip-heapfile to joafip-kvstore and joafip-file
Modified Paths:
--------------
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
trunk/joafip-file/src/test/java/net/sf/joafip/file/entity/FileAccessRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/AbstractHeapDataManager.java
trunk/joafip-testsuite/pom.xml
trunk/joafip-testsuite/src/main/java/net/sf/joafip/PersistanceTestsNoLongTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/FileTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/RecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/entity/RecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/heapfile/record/service/RecordServiceTests.java
Added Paths:
-----------
trunk/joafip-file/src/test/java/net/sf/joafip/file/service/TestRandomAccessFileCache.java
trunk/joafip-kvstore/src/test/java/net/
trunk/joafip-kvstore/src/test/java/net/sf/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-kvstore/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/file/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/KeyValueStoreTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/KVRecordTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/entity/KVRecordEntityTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/record/service/KVRecordServiceTests.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/kvstore/service/
Removed Paths:
-------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestDataRecordIdentifier.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestRandomAccessFileCache.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 05:06:03
|
Revision: 3012
http://joafip.svn.sourceforge.net/joafip/?rev=3012&view=rev
Author: luc_peuvrier
Date: 2012-04-17 05:05:53 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for for storable management moved to joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/ToBackupRecord.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/IFileForStorable.java
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,424 +0,0 @@
-/*
- * 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.heapfile.entity;
-
-import java.util.Arrays;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.service.FileForStorable;
-import net.sf.joafip.heapfile.service.IFileForStorable;
-import net.sf.joafip.kvstore.entity.EnumFileState;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * all that is common to storable in file using {@link FileForStorable}:<br>
- * <ul>
- * <li>the {@link FileForStorable} manager to use</li>
- * <li>position of data in file</li>
- * <li>flags for first creation and state change</li>
- * <li>primitive type read and write in file</li>
- * <li>crc32 compute and check for data integrity check</li>
- * </ul>
- *
- * by extension make able to create mutable or immutable object, immutable are
- * for file record unique representation, mutable make able to change the file
- * record represented<br>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public abstract class AbstractFileStorable implements IFileStorable {
-
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
- private static final String ALREADY_READ = "already read";
-
- private static final String RECORD_INTEGRITY_ERROR = "record integrity error";
-
- private static final String NO_VALUE_CHANGE_TO_WRITE = "no value change to write";
-
- private static final String READING_ERASE_VALUE_CHANGE = "reading erase value change";
-
- /** position in file of this in marshallized forms */
- protected final long positionInFile;
-
- /** to read/write this in file */
- protected final IFileForStorable fileForStorable;
-
- /** to compute crc32 record header */
- private transient int crc32;
-
- /** current number of byte read or wrote */
- private transient int numberOfByteReadWrote = 0;
-
- /** input output buffer */
- private transient byte[] ioBuffer;
-
- private transient int readInIoBuffer;
-
- /**
- * true if this value changed, creation implies no value to save since not
- * read and not write
- */
- protected boolean valueChangedToSave = false;
-
- /** true if just created in memory, never read from file */
- protected boolean justCreated = true;
-
- /**
- * @param fileForStorable
- * @param positionInFile
- */
- public AbstractFileStorable(final IFileForStorable fileForStorable,
- final long positionInFile) {
- super();
- this.fileForStorable = fileForStorable;
- this.positionInFile = positionInFile;
- }
-
- public void clear() {
- valueChangedToSave = false;
- justCreated = true;
- }
-
- public long getPositionInFile() {
- return positionInFile;
- }
-
- public void readFromFile() throws HeapException {
- // ASSERTX
- assert justCreated : ALREADY_READ;
- // ASSERTX
- assert !valueChangedToSave : READING_ERASE_VALUE_CHANGE;
- fileForStorable.seek(positionInFile);
- crc32 = 0;
- ioBuffer = null;// NOPMD
- unmarshallImpl();
- ioBuffer = null;// NOPMD
- justCreated = false;
- }
-
- public byte[] writeToFile() throws HeapException {
- // ASSERTX
- assert valueChangedToSave : NO_VALUE_CHANGE_TO_WRITE;
- fileForStorable.seek(positionInFile);
- crc32 = 0;
- numberOfByteReadWrote = 0;
- ioBuffer = new byte[toMarshallSize()];
- marshallImpl();
- fileForStorable.write(ioBuffer);
- valueChangedToSave = false;
- final byte[] result = ioBuffer;
- ioBuffer = null;// NOPMD discard
- return result;
- }
-
- /**
- *
- * @return number of byte to marshal
- * @throws HeapException
- */
- protected abstract int toMarshallSize() throws HeapException;
-
- /**
- * Unmarshalling implementation for read<br>
- * {@link #crc32} is set to zero<br>
- *
- * @throws HeapException
- */
- protected abstract void unmarshallImpl() throws HeapException;
-
- /**
- * marshaling implementation for write<br>
- * {@link #crc32} is set to zero<br>
- *
- * @throws HeapException
- */
- protected abstract void marshallImpl() throws HeapException;
-
- /**
- *
- * @return true if just created ( not read from file and not setted )
- */
- public boolean isJustCreated() {
- return justCreated;
- }
-
- /**
- * to know if the value state change
- *
- * @return true if value changed
- */
- public boolean isValueChangedToSave() {
- return valueChangedToSave;
- }
-
- /**
- * set this record have value changed, so to save
- *
- * @throws HeapException
- */
- public void setValueIsChangedValueToSave() throws HeapException {
- if (!valueChangedToSave) {
- valueChangedToSave = true;
- justCreated = false;
- valueChangedAction();
- }
- }
-
- protected abstract void valueChangedAction() throws HeapException;
-
- public void setValueIsNotChanged() {
- valueChangedToSave = false;
- }
-
- /**
- * update crc32 with byte value in buffer
- *
- * @param buffer
- * bytes for crc32 update
- */
- private void updateCrc32(final byte[] buffer) {
- updateCrc32(buffer, 0, buffer.length);
- }
-
- private void updateCrc32(final byte[] buffer, final int start,
- final int length) {
-
- for (int i = 0; i < length; i++) {
- final byte byteValue = buffer[start + i];
- updateCrc32(byteValue);
- }
-
- }
-
- private void updateCrc32(final byte byteValue) {
- for (int j = 0; j < 8; j++) {
- final int testbit = ((crc32 >> 31) & 1) ^ ((byteValue >> j) & 1);
- crc32 <<= 2;
- if (testbit != 0) {
- crc32 ^= 0x8005; /* 32 bit crc */
- }
- }
- }
-
- protected void clearCrc32() {
- crc32 = 0;
- }
-
- protected int getCrc32() {
- return crc32;
- }
-
- protected int readFileToIoBuffer(final int size) throws HeapException {
- ioBuffer = new byte[size];
- readInIoBuffer = fileForStorable.read(ioBuffer);
- numberOfByteReadWrote = 0;
- return readInIoBuffer;
- }
-
- /**
- * read extending ioBuffer
- *
- * @param newSize
- * ioBuffer new size
- * @throws HeapException
- */
- protected void readFileAppendToIoBuffer(final int newSize)
- throws HeapException {
- if (newSize > ioBuffer.length) {
- ioBuffer = Arrays.copyOf(ioBuffer, newSize);
- final int appendSize = newSize - readInIoBuffer;
- final byte[] tempBuffer = new byte[appendSize];
- // FIXMELUC _________________use of additional read
- // read(iobuffer,readInIoBuffer/*offset*/,appendSize/*length*/);
- fileForStorable.read(tempBuffer);
- System.arraycopy(tempBuffer, 0, ioBuffer, readInIoBuffer,
- appendSize);
- }
- }
-
- /**
- * read and check CRC32
- *
- * @throws HeapException
- * read error crc32 error in record
- */
- protected void readAndCheckCrc32() throws HeapException {
- final int computedCrc32 = crc32;
- final int readCrc32 = readInteger();
- if (computedCrc32 != readCrc32) {
- throw new HeapException(RECORD_INTEGRITY_ERROR
- + " record position=" + positionInFile + " read="
- + readCrc32 + " computed=" + computedCrc32 + " nb rd/wr="
- + numberOfByteReadWrote, EnumFileState.STATE_CORRUPTED);
- }
- }
-
- /**
- * read bytes
- *
- * @param length
- * number of bytes to read
- * @return the bytes read
- * @throws HeapException
- */
- protected byte[] readBytes(final int length) throws HeapException {
- final byte[] dataByteArray = new byte[length];
- System.arraycopy(ioBuffer, numberOfByteReadWrote, dataByteArray, 0,
- length);
- numberOfByteReadWrote += length;
- updateCrc32(dataByteArray);
- return dataByteArray;
- }
-
- /**
- * unmarshal from byte array current {@link #dataByteArrayIndex} index to
- * long<br>
- * {@link #dataByteArrayIndex} is updated to next data to read position<br>
- *
- * @param dataByteArray
- * @return the unmarshaled value
- * @throws HeapException
- */
- protected long readLong() throws HeapException {
- long value = 0;
- for (int byteIndex = 7; byteIndex >= 0; byteIndex--) {
- final byte byteValue = ioBuffer[numberOfByteReadWrote + byteIndex];
- value = (value << 8) | (((long) byteValue) & 0xff);
- }
- updateCrc32(ioBuffer, numberOfByteReadWrote, 8);
- numberOfByteReadWrote += 8;
- return value;
- }
-
- protected int readInteger() throws HeapException {
- int value = 0;
- for (int byteIndex = 3; byteIndex >= 0; byteIndex--) {
- final byte byteValue = ioBuffer[numberOfByteReadWrote + byteIndex];
- value = (value << 8) | (((int) byteValue) & 0xff);
- }
- updateCrc32(ioBuffer, numberOfByteReadWrote, 4);
- numberOfByteReadWrote += 4;
- return value;
- }
-
- protected boolean readBoolean() throws HeapException {
- final byte byteValue = ioBuffer[numberOfByteReadWrote++];
- updateCrc32(byteValue);
- return byteValue == 0 ? false : true;
- }
-
- protected byte readByte() throws HeapException {
- final byte byteValue = ioBuffer[numberOfByteReadWrote++];
- updateCrc32(byteValue);
- return byteValue;
- }
-
- /**
- * write bytes
- *
- * @param dataByteArray
- * bytes to write
- * @throws HeapException
- */
- protected void writeBytes(final byte[] dataByteArray) throws HeapException {
- System.arraycopy(dataByteArray, 0, ioBuffer, numberOfByteReadWrote,
- dataByteArray.length);
- numberOfByteReadWrote += dataByteArray.length;
- updateCrc32(dataByteArray);
- }
-
- /**
- * Marshal long value to byte array current {@link #dataByteArrayIndex}
- * index<br>
- * {@link #dataByteArrayIndex} is updated to next data to write position<br>
- *
- * @param value
- * the value to marshal
- * @throws HeapException
- */
- protected void writeLong(final long value) throws HeapException {
- long localValue = value;
- for (int byteIndex = 0; byteIndex < 8; byteIndex++) {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) localValue);
- localValue >>= 8;
- }
- }
-
- protected void writeInteger(final int value) throws HeapException {
- int localValue = value;
- for (int byteIndex = 0; byteIndex < 4; byteIndex++) {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) localValue);
- localValue >>= 8;
- }
- }
-
- protected void writeCrc32() throws HeapException {
- int localValue = crc32;
- for (int byteIndex = 0; byteIndex < 4; byteIndex++) {
- ioBuffer[numberOfByteReadWrote++] = (byte) localValue;
- localValue >>= 8;
- }
- }
-
- protected void writeBoolean(final boolean value) throws HeapException {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) (value ? 1 : 0));
- }
-
- protected void writeByte(final byte value) throws HeapException {
- updateCrc32(ioBuffer[numberOfByteReadWrote++] = value);
- }
-
- @Override
- public int hashCode() {
- return (int) (positionInFile ^ (positionInFile >>> 32));
- }
-
- @Override
- public boolean equals(final Object obj) {
- final boolean equals;
- if (obj == this) {
- equals = true;
- } else {
- assert obj != null : "do no accept null parameter";
- assert obj instanceof AbstractFileStorable : "must be instance of AbstractFileStorable";
- final AbstractFileStorable storable = (AbstractFileStorable) obj;
- equals = positionInFile == storable.positionInFile;
- }
- return equals;
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("AbstractFileStorable ");
- builder.append(super.toString());
- builder.append(" [fileForStorable=");
- builder.append(fileForStorable);
- builder.append(", justCreated=");
- builder.append(justCreated);
- builder.append(", positionInFile=");
- builder.append(positionInFile);
- builder.append(", valueChangedToSave=");
- builder.append(valueChangedToSave);
- builder.append("]");
- return builder.toString();
- }
-}
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,51 +0,0 @@
-/*
- * 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.heapfile.entity;
-
-import net.sf.joafip.heapfile.service.FileForStorable;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- * class implementing this can be store in file using {@link FileForStorable}<br>
- *
- * @author luc peuvrier
- *
- */
-public interface IFileStorable {
-
- /**
- *
- * @return position in file of this file storable
- */
- long getPositionInFile();
-
- /**
- * write this file storable to file
- *
- * @return bytes wrote
- * @throws HeapException
- */
- byte[] writeToFile() throws HeapException;
-
- /**
- * read this file storable from file
- *
- * @throws HeapException
- */
- void readFromFile() throws HeapException;
-
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -17,8 +17,8 @@
package net.sf.joafip.heapfile.record.entity;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.entity.AbstractFileStorable;
import net.sf.joafip.heapfile.record.service.HeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.service.HeapException;
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -20,9 +20,9 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.heapfile.entity.AbstractFileStorable;
import net.sf.joafip.heapfile.record.service.HeapElementManager;
import net.sf.joafip.heapfile.record.service.IHeapElementManager;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.entity.IDataRecordKey;
import net.sf.joafip.kvstore.service.HeapException;
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,84 +0,0 @@
-/*
- * Copyright 2008 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.heapfile.record.entity;
-
-import net.sf.joafip.NotStorableClass;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class ToBackupRecord implements Comparable<ToBackupRecord> {
-
- private final long positionInFile;
-
- private final byte[] data;
-
- public ToBackupRecord(final long positionInFile, final byte[] data) {// NOPMD
- // expose
- // data
- super();
- this.positionInFile = positionInFile;
- this.data = data;
- }
-
- public byte[] getData() {
- return data;// NOPMD expose data
- }
-
- public long getPositionInFile() {
- return positionInFile;
- }
-
- public int compareTo(final ToBackupRecord other) {
- final int compareTo;
- if (positionInFile < other.positionInFile) {
- compareTo = -1;
- } else if (positionInFile > other.positionInFile) {
- compareTo = 1;
- } else {
- compareTo = 0;
- }
- return compareTo;
- }
-
- @Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result
- + (int) (positionInFile ^ (positionInFile >>> 32));
- return result;
- }
-
- @Override
- @SuppressWarnings("PMD")
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- // if (obj == null)
- // return false;
- // if (getClass() != obj.getClass())
- // return false;
- final ToBackupRecord other = (ToBackupRecord) obj;
- if (positionInFile != other.positionInFile)
- return false;
- return true;
- }
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -27,16 +27,16 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.file.service.FileIOException;
import net.sf.joafip.file.service.HelperFileUtil;
-import net.sf.joafip.heapfile.entity.IFileStorable;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
-import net.sf.joafip.heapfile.service.FileForStorable;
-import net.sf.joafip.heapfile.service.IFileForStorable;
import net.sf.joafip.kvstore.entity.EnumFileState;
+import net.sf.joafip.kvstore.entity.IFileStorable;
+import net.sf.joafip.kvstore.entity.ToBackupRecord;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
import net.sf.joafip.logger.JoafipLogger;
/**
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -19,10 +19,10 @@
import net.sf.joafip.Fortest;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.service.IFileForStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
/**
* Heap elements manager in heap file interface.<br>
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,387 +0,0 @@
-/*
- * 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.heapfile.service;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.file.service.IRandomAccessFile;
-import net.sf.joafip.file.service.RandomAccessFileDirectNio;
-import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
-import net.sf.joafip.heapfile.entity.IFileStorable;
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * to read/write class implementing {@link IFileStorable} to/from file.<br>
- * {@link #open()} and {@link #close()}<br>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class FileForStorable implements IFileForStorable {
-
- private static final String FILE_IS_OPENED = "file is opened";
-
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
- protected static final String FILE_ALREADY_CLOSED = "file already closed";
-
- protected static final String FILE_NOT_OPENNED = "file not opened";
-
- private static final String FILE_ALREADY_OPENED = "file already opened";
-
- protected static final String FAILED_DELETE_FILE = "failed delete file ";
-
- /** the file object for file heap */
- private final File file;
-
- /** for random read write file access */
- protected IRandomAccessFile randomAccessFile;
-
- /** true if file opened */
- private boolean opened = false;
-
- private Exception opennerTrace;
-
- private Exception closerTrace = new Exception("closer trace");
-
- /**
- * create a file to read from and write to {@link IFileStorable} object.<br>
- * no cache used for file management<br>
- *
- * @param fileName
- * the file name of file to use for storing storable object
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final String fileName, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this(fileName == null ? null : new File(fileName), maxRetry,
- retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * no cache used for file management<br>
- *
- * @param file
- * the file to use for storable object storing
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final File file, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this.file = file;
- randomAccessFile = new RandomAccessFileDirectNio(file, maxRetry,
- retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param fileName
- * the file name of file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final String fileName, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this(fileName == null ? null : new File(fileName), pageSize, maxPage,
- maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- *
- * @param file
- * the file to use for storable object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, maxRetry,
- retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param file
- * the file to use for storable object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param haveReadCache
- * true if have read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final boolean haveReadCache, final int maxRetry,
- final int retryMsDelay) {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, haveReadCache);
- }
-
- @Override
- public void open() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_ALREADY_OPENED, opennerTrace);
- } else {
- try {
- randomAccessFile.open();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- opened = true;
- opennerTrace = new Exception("openner trace");
- }
- }
-
- @Override
- public void close() throws HeapException {
- if (opened) {
- opened = false;
- closerTrace = new Exception("closer trace");
- try {
- randomAccessFile.close();
- } catch (FileIOException e) {
- throw new HeapException(e);
- }
- } else {
- throw new HeapException(FILE_ALREADY_CLOSED, closerTrace);
- }
- }
-
- @Override
- public void flush() throws HeapException {
- assertOpened();
- try {
- randomAccessFile.flush();
- } catch (FileIOException e) {
- throw new HeapException(e);
- }
- }
-
- @Override
- public void resetFileSize() throws HeapException {
- assertOpened();
- try {
- randomAccessFile.setLength(0);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public void deleteFileIfExists() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_IS_OPENED);
- }
- if (logger.debugEnabled) {
- logger.debug("delete " + file);
- }
- try {
- randomAccessFile.deleteIfExists();
- } catch (FileIOException exception) {
- throw new HeapException(FAILED_DELETE_FILE + file, exception);
- }
- }
-
- @Override
- public void deleteFileIfExistsRenaming() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_IS_OPENED);
- }
- if (logger.debugEnabled) {
- logger.debug("delete " + file);
- }
- try {
- randomAccessFile.deleteIfExistsRenaming();
- } catch (FileIOException exception) {
- throw new HeapException(FAILED_DELETE_FILE + file, exception);
- }
- }
-
- /**
- * @throws HeapException
- *
- */
- private void assertOpened() throws HeapException {
- if (!opened) {
- throw new HeapException(FILE_NOT_OPENNED, closerTrace);
- }
- }
-
- public boolean isOpened() {
- return opened;
- }
-
- @Override
- public void seek(final long positionInFile) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.seek(positionInFile);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public int read(final byte[] data) throws HeapException {
- assertOpened();
- try {
- return randomAccessFile.read(data);// NOPMD
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public void write(final byte[] data) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.write(data);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public void write(final ToBackupRecord toBackupRecord) throws HeapException {
- try {
- randomAccessFile.seek(toBackupRecord.getPositionInFile());
- randomAccessFile.write(toBackupRecord.getData());
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
-
- @Override
- public File getFile() {
- return file;
- }
-
- @Override
- public long getFileSize() throws HeapException {
- long size;
- assertOpened();
- try {
- size = randomAccessFile.length();
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- return size;
- }
-
- /**
- * set the size of this file
- *
- * @param newSize
- * the file new size
- * @throws HeapException
- * if an I/O error occurs.
- */
- public void setFileSize(final long newSize) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.setLength(newSize);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- /**
- * copy this file to an other file
- *
- * @param fileForStorable
- * @throws HeapException
- */
- public void copy(final FileForStorable fileForStorable)
- throws HeapException {
- try {
- randomAccessFile.copy(fileForStorable.getFile().getAbsolutePath());
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
-
- /**
- * close after io exception
- */
- protected HeapException closeAfterIOException(
- final FileIOException exception) throws HeapException {
- final HeapException fileForStorageException =
- /**/new HeapException(exception);
- try {
- close();
- } catch (HeapException exception2) {
- logger.warn("closing after exception", exception2);
- }
- return fileForStorageException;
- }
-
- public void copy(final String fileName) throws FileIOException {
- randomAccessFile.copy(fileName);
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("AbstractFileFor [file=");
- builder.append(file);
- builder.append(", opened=");
- builder.append(opened);
- builder.append("]");
- return builder.toString();
- }
-}
Modified: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -40,6 +40,7 @@
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.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.IRBTVisitor;
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/IFileForStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/IFileForStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/IFileForStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -1,134 +0,0 @@
-/*
- * Copyright 2010 Luc Peuvrier
- *
- * 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.heapfile.service;
-
-import java.io.File;
-import java.io.RandomAccessFile;
-
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.kvstore.service.HeapRuntimeException;//NOPMD
-
-/**
- *
- * @author luc peuvrier
- *
- */
-public interface IFileForStorable {
-
- /**
- * Returns the size of this file.
- *
- * @return the size of this file, measured in bytes.
- * @exception HeapException
- * if an I/O error occurs.
- */
- long getFileSize() throws HeapException;
-
- File getFile();
-
- /**
- * delete file if exists
- *
- * @throws HeapException
- */
- void deleteFileIfExists() throws HeapException;
-
- /**
- * delete file if exists
- *
- * @throws HeapException
- */
- void deleteFileIfExistsRenaming() throws HeapException;
-
- /**
- * open heap file for access operation<br>
- *
- * @throws HeapException
- * if an I/O error occurs while opening file
- */
- void open() throws HeapException;
-
- /**
- * flush modification to disk
- *
- * @throws HeapException
- *
- */
- void flush() throws HeapException;
-
- void resetFileSize() throws HeapException;
-
- /**
- * close heap file access operation<br>
- *
- * @throws HeapException
- * if an I/O error occurs while closing the the file
- * @throws FileForStorableRuntimeException
- * file already closed
- */
- void close() throws HeapException;
-
- /**
- * delegate to {@link RandomAccessFile#seek(long)} closing the file in case
- * of I/O error<br>
- *
- * @param positionInFile
- * @throws HeapException
- * if an I/O error occurs
- * @throws HeapRuntimeException
- * file closed
- */
- void seek(long positionInFile) throws HeapException;
-
- /**
- * delegate to {@link RandomAccessFile#read(byte[])} closing the file in
- * case of I/O error<br>
- *
- * Reads up to <code>data.length</code> bytes of data from this file into an
- * array of bytes.
- *
- * @param data
- * where store data read
- * @return number of bytes read
- * @throws HeapException
- * if an I/O error occurs
- * @throws HeapRuntimeException
- * file closed
- */
- int read(byte[] ioBuffer) throws HeapException;
-
- /**
- * delegate to {@link RandomAccessFile#write(byte[]))} closing the file in
- * case of I/O error<br>
- *
- * @param data
- * @throws HeapException
- * if an I/O error occurs
- * @throws HeapRuntimeException
- * file closed
- */
- void write(byte[] ioBuffer) throws HeapException;
-
- void write(ToBackupRecord toBackupRecord) throws HeapException;
-}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -27,8 +27,8 @@
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
import net.sf.joafip.heapfile.record.service.HeapElementManager;
-import net.sf.joafip.heapfile.service.FileForStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.redblacktree.service.RBTException;
@NotStorableClass
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -23,8 +23,8 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.entity.AbstractFileStorable;
-import net.sf.joafip.heapfile.service.FileForStorable;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
@NotStorableClass
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -23,8 +23,8 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
-import net.sf.joafip.heapfile.entity.AbstractFileStorable;
-import net.sf.joafip.heapfile.service.FileForStorable;
+import net.sf.joafip.kvstore.entity.AbstractFileStorable;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
@NotStorableClass
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -25,8 +25,8 @@
import net.sf.joafip.TestException;
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.service.FileForStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -26,8 +26,8 @@
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.service.FileForStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.entity.IRBTNode;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -27,9 +27,9 @@
import net.sf.joafip.heapfile.record.entity.HeapHeader;
import net.sf.joafip.heapfile.record.entity.HeapIdNode;
import net.sf.joafip.heapfile.record.entity.HeapRecord;
-import net.sf.joafip.heapfile.service.FileForStorable;
import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
import net.sf.joafip.kvstore.record.service.IDataRecordKeyManager;
+import net.sf.joafip.kvstore.service.FileForStorable;
import net.sf.joafip.kvstore.service.HeapException;
import net.sf.joafip.redblacktree.service.RBTException;
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-17 05:00:49 UTC (rev 3011)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -2,8 +2,9 @@
import java.io.File;
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
+import net.sf.joafip.kvstore.entity.ToBackupRecord;
import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.IFileForStorable;
public class FileForStorableBridge implements IFileForStorable {
Copied: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java (from rev 3010, trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java)
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java (rev 0)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -0,0 +1,423 @@
+/*
+ * 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.kvstore.entity;
+
+import java.util.Arrays;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.IFileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.logger.JoafipLogger;
+
+/**
+ * all that is common to storable in file using {@link FileForStorable}:<br>
+ * <ul>
+ * <li>the {@link FileForStorable} manager to use</li>
+ * <li>position of data in file</li>
+ * <li>flags for first creation and state change</li>
+ * <li>primitive type read and write in file</li>
+ * <li>crc32 compute and check for data integrity check</li>
+ * </ul>
+ *
+ * by extension make able to create mutable or immutable object, immutable are
+ * for file record unique representation, mutable make able to change the file
+ * record represented<br>
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public abstract class AbstractFileStorable implements IFileStorable {
+
+ protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
+
+ private static final String ALREADY_READ = "already read";
+
+ private static final String RECORD_INTEGRITY_ERROR = "record integrity error";
+
+ private static final String NO_VALUE_CHANGE_TO_WRITE = "no value change to write";
+
+ private static final String READING_ERASE_VALUE_CHANGE = "reading erase value change";
+
+ /** position in file of this in marshallized forms */
+ protected final long positionInFile;
+
+ /** to read/write this in file */
+ protected final IFileForStorable fileForStorable;
+
+ /** to compute crc32 record header */
+ private transient int crc32;
+
+ /** current number of byte read or wrote */
+ private transient int numberOfByteReadWrote = 0;
+
+ /** input output buffer */
+ private transient byte[] ioBuffer;
+
+ private transient int readInIoBuffer;
+
+ /**
+ * true if this value changed, creation implies no value to save since not
+ * read and not write
+ */
+ protected boolean valueChangedToSave = false;
+
+ /** true if just created in memory, never read from file */
+ protected boolean justCreated = true;
+
+ /**
+ * @param fileForStorable
+ * @param positionInFile
+ */
+ public AbstractFileStorable(final IFileForStorable fileForStorable,
+ final long positionInFile) {
+ super();
+ this.fileForStorable = fileForStorable;
+ this.positionInFile = positionInFile;
+ }
+
+ public void clear() {
+ valueChangedToSave = false;
+ justCreated = true;
+ }
+
+ public long getPositionInFile() {
+ return positionInFile;
+ }
+
+ public void readFromFile() throws HeapException {
+ // ASSERTX
+ assert justCreated : ALREADY_READ;
+ // ASSERTX
+ assert !valueChangedToSave : READING_ERASE_VALUE_CHANGE;
+ fileForStorable.seek(positionInFile);
+ crc32 = 0;
+ ioBuffer = null;// NOPMD
+ unmarshallImpl();
+ ioBuffer = null;// NOPMD
+ justCreated = false;
+ }
+
+ public byte[] writeToFile() throws HeapException {
+ // ASSERTX
+ assert valueChangedToSave : NO_VALUE_CHANGE_TO_WRITE;
+ fileForStorable.seek(positionInFile);
+ crc32 = 0;
+ numberOfByteReadWrote = 0;
+ ioBuffer = new byte[toMarshallSize()];
+ marshallImpl();
+ fileForStorable.write(ioBuffer);
+ valueChangedToSave = false;
+ final byte[] result = ioBuffer;
+ ioBuffer = null;// NOPMD discard
+ return result;
+ }
+
+ /**
+ *
+ * @return number of byte to marshal
+ * @throws HeapException
+ */
+ protected abstract int toMarshallSize() throws HeapException;
+
+ /**
+ * Unmarshalling implementation for read<br>
+ * {@link #crc32} is set to zero<br>
+ *
+ * @throws HeapException
+ */
+ protected abstract void unmarshallImpl() throws HeapException;
+
+ /**
+ * marshaling implementation for write<br>
+ * {@link #crc32} is set to zero<br>
+ *
+ * @throws HeapException
+ */
+ protected abstract void marshallImpl() throws HeapException;
+
+ /**
+ *
+ * @return true if just created ( not read from file and not setted )
+ */
+ public boolean isJustCreated() {
+ return justCreated;
+ }
+
+ /**
+ * to know if the value state change
+ *
+ * @return true if value changed
+ */
+ public boolean isValueChangedToSave() {
+ return valueChangedToSave;
+ }
+
+ /**
+ * set this record have value changed, so to save
+ *
+ * @throws HeapException
+ */
+ public void setValueIsChangedValueToSave() throws HeapException {
+ if (!valueChangedToSave) {
+ valueChangedToSave = true;
+ justCreated = false;
+ valueChangedAction();
+ }
+ }
+
+ protected abstract void valueChangedAction() throws HeapException;
+
+ public void setValueIsNotChanged() {
+ valueChangedToSave = false;
+ }
+
+ /**
+ * update crc32 with byte value in buffer
+ *
+ * @param buffer
+ * bytes for crc32 update
+ */
+ private void updateCrc32(final byte[] buffer) {
+ updateCrc32(buffer, 0, buffer.length);
+ }
+
+ private void updateCrc32(final byte[] buffer, final int start,
+ final int length) {
+
+ for (int i = 0; i < length; i++) {
+ final byte byteValue = buffer[start + i];
+ updateCrc32(byteValue);
+ }
+
+ }
+
+ private void updateCrc32(final byte byteValue) {
+ for (int j = 0; j < 8; j++) {
+ final int testbit = ((crc32 >> 31) & 1) ^ ((byteValue >> j) & 1);
+ crc32 <<= 2;
+ if (testbit != 0) {
+ crc32 ^= 0x8005; /* 32 bit crc */
+ }
+ }
+ }
+
+ protected void clearCrc32() {
+ crc32 = 0;
+ }
+
+ protected int getCrc32() {
+ return crc32;
+ }
+
+ protected int readFileToIoBuffer(final int size) throws HeapException {
+ ioBuffer = new byte[size];
+ readInIoBuffer = fileForStorable.read(ioBuffer);
+ numberOfByteReadWrote = 0;
+ return readInIoBuffer;
+ }
+
+ /**
+ * read extending ioBuffer
+ *
+ * @param newSize
+ * ioBuffer new size
+ * @throws HeapException
+ */
+ protected void readFileAppendToIoBuffer(final int newSize)
+ throws HeapException {
+ if (newSize > ioBuffer.length) {
+ ioBuffer = Arrays.copyOf(ioBuffer, newSize);
+ final int appendSize = newSize - readInIoBuffer;
+ final byte[] tempBuffer = new byte[appendSize];
+ // FIXMELUC _________________use of additional read
+ // read(iobuffer,readInIoBuffer/*offset*/,appendSize/*length*/);
+ fileForStorable.read(tempBuffer);
+ System.arraycopy(tempBuffer, 0, ioBuffer, readInIoBuffer,
+ appendSize);
+ }
+ }
+
+ /**
+ * read and check CRC32
+ *
+ * @throws HeapException
+ * read error crc32 error in record
+ */
+ protected void readAndCheckCrc32() throws HeapException {
+ final int computedCrc32 = crc32;
+ final int readCrc32 = readInteger();
+ if (computedCrc32 != readCrc32) {
+ throw new HeapException(RECORD_INTEGRITY_ERROR
+ + " record position=" + positionInFile + " read="
+ + readCrc32 + " computed=" + computedCrc32 + " nb rd/wr="
+ + numberOfByteReadWrote, EnumFileState.STATE_CORRUPTED);
+ }
+ }
+
+ /**
+ * read bytes
+ *
+ * @param length
+ * number of bytes to read
+ * @return the bytes read
+ * @throws HeapException
+ */
+ protected byte[] readBytes(final int length) throws HeapException {
+ final byte[] dataByteArray = new byte[length];
+ System.arraycopy(ioBuffer, numberOfByteReadWrote, dataByteArray, 0,
+ length);
+ numberOfByteReadWrote += length;
+ updateCrc32(dataByteArray);
+ return dataByteArray;
+ }
+
+ /**
+ * unmarshal from byte array current {@link #dataByteArrayIndex} index to
+ * long<br>
+ * {@link #dataByteArrayIndex} is updated to next data to read position<br>
+ *
+ * @param dataByteArray
+ * @return the unmarshaled value
+ * @throws HeapException
+ */
+ protected long readLong() throws HeapException {
+ long value = 0;
+ for (int byteIndex = 7; byteIndex >= 0; byteIndex--) {
+ final byte byteValue = ioBuffer[numberOfByteReadWrote + byteIndex];
+ value = (value << 8) | (((long) byteValue) & 0xff);
+ }
+ updateCrc32(ioBuffer, numberOfByteReadWrote, 8);
+ numberOfByteReadWrote += 8;
+ return value;
+ }
+
+ protected int readInteger() throws HeapException {
+ int value = 0;
+ for (int byteIndex = 3; byteIndex >= 0; byteIndex--) {
+ final byte byteValue = ioBuffer[numberOfByteReadWrote + byteIndex];
+ value = (value << 8) | (((int) byteValue) & 0xff);
+ }
+ updateCrc32(ioBuffer, numberOfByteReadWrote, 4);
+ numberOfByteReadWrote += 4;
+ return value;
+ }
+
+ protected boolean readBoolean() throws HeapException {
+ final byte byteValue = ioBuffer[numberOfByteReadWrote++];
+ updateCrc32(byteValue);
+ return byteValue == 0 ? false : true;
+ }
+
+ protected byte readByte() throws HeapException {
+ final byte byteValue = ioBuffer[numberOfByteReadWrote++];
+ updateCrc32(byteValue);
+ return byteValue;
+ }
+
+ /**
+ * write bytes
+ *
+ * @param dataByteArray
+ * bytes to write
+ * @throws HeapException
+ */
+ protected void writeBytes(final byte[] dataByteArray) throws HeapException {
+ System.arraycopy(dataByteArray, 0, ioBuffer, numberOfByteReadWrote,
+ dataByteArray.length);
+ numberOfByteReadWrote += dataByteArray.length;
+ updateCrc32(dataByteArray);
+ }
+
+ /**
+ * Marshal long value to byte array current {@link #dataByteArrayIndex}
+ * index<br>
+ * {@link #dataByteArrayIndex} is updated to next data to write position<br>
+ *
+ * @param value
+ * the value to marshal
+ * @throws HeapException
+ */
+ protected void writeLong(final long value) throws HeapException {
+ long localValue = value;
+ for (int byteIndex = 0; byteIndex < 8; byteIndex++) {
+ updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) localValue);
+ localValue >>= 8;
+ }
+ }
+
+ protected void writeInteger(final int value) throws HeapException {
+ int localValue = value;
+ for (int byteIndex = 0; byteIndex < 4; byteIndex++) {
+ updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) localValue);
+ localValue >>= 8;
+ }
+ }
+
+ protected void writeCrc32() throws HeapException {
+ int localValue = crc32;
+ for (int byteIndex = 0; byteIndex < 4; byteIndex++) {
+ ioBuffer[numberOfByteReadWrote++] = (byte) localValue;
+ localValue >>= 8;
+ }
+ }
+
+ protected void writeBoolean(final boolean value) throws HeapException {
+ updateCrc32(ioBuffer[numberOfByteReadWrote++] = (byte) (value ? 1 : 0));
+ }
+
+ protected void writeByte(final byte value) throws HeapException {
+ updateCrc32(ioBuffer[numberOfByteReadWrote++] = value);
+ }
+
+ @Override
+ public int hashCode() {
+ return (int) (positionInFile ^ (positionInFile >>> 32));
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ final boolean equals;
+ if (obj == this) {
+ equals = true;
+ } else {
+ assert obj != null : "do no accept null parameter";
+ assert obj instanceof AbstractFileStorable : "must be instance of AbstractFileStorable";
+ final AbstractFileStorable storable = (AbstractFileStorable) obj;
+ equals = positionInFile == storable.positionInFile;
+ }
+ return equals;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("AbstractFileStorable ");
+ builder.append(super.toString());
+ builder.append(" [fileForStorable=");
+ builder.append(fileForStorable);
+ builder.append(", justCreated=");
+ builder.append(justCreated);
+ builder.append(", positionInFile=");
+ builder.append(positionInFile);
+ builder.append(", valueChangedToSave=");
+ builder.append(valueChangedToSave);
+ builder.append("]");
+ return builder.toString();
+ }
+}
Copied: trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java (from rev 3010, trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java)
===================================================================
--- trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java (rev 0)
+++ trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java 2012-04-17 05:05:53 UTC (rev 3012)
@@ -0,0 +1,51 @@
+/*
+ * 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.kvstore.entity;
+
+import net.sf.joafip.kvstore.service.FileForStorable;
+import net.sf.joafip.kvstore.service.HeapException;
+
+/**
+ * class implementing this can be store in file using {@link FileForStorable}<br>
+ *
+ * @author luc peuvrier
+ *
+ */
+public interface IFileStorable {
+
+ /**
+ *
+ * @return position in file of this file storable
+ */
+ long getPositionInFile();
+
+ /**
+ * write this file storable to file
+...
[truncated message content] |
|
From: <luc...@us...> - 2012-04-17 05:05:59
|
Revision: 3012
http://joafip.svn.sourceforge.net/joafip/?rev=3012&view=rev
Author: luc_peuvrier
Date: 2012-04-17 05:05:53 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
for for storable management moved to joafip-kvstore project
Modified Paths:
--------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapHeader.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/HeapRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/HeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/service/IHeapElementManager.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/HeapFileDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/TestIdNode.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestAbstractFileStorable.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/entity/TestMarshall.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapElementManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestHeapRecordManage.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/record/service/TestStoreRestore.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/FileForStorableBridge.java
Added Paths:
-----------
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/AbstractFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/IFileStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/entity/ToBackupRecord.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/FileForStorable.java
trunk/joafip-kvstore/src/main/java/net/sf/joafip/kvstore/service/IFileForStorable.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/AbstractFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/entity/IFileStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/record/entity/ToBackupRecord.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/IFileForStorable.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 05:00:56
|
Revision: 3011
http://joafip.svn.sourceforge.net/joafip/?rev=3011&view=rev
Author: luc_peuvrier
Date: 2012-04-17 05:00:49 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
no more joafip-jdbm and joafip-babudb projects
Modified Paths:
--------------
trunk/joafip-parent/pom.xml
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 05:00:55
|
Revision: 3011
http://joafip.svn.sourceforge.net/joafip/?rev=3011&view=rev
Author: luc_peuvrier
Date: 2012-04-17 05:00:49 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
no more joafip-jdbm and joafip-babudb projects
Modified Paths:
--------------
trunk/joafip-parent/pom.xml
Modified: trunk/joafip-parent/pom.xml
===================================================================
--- trunk/joafip-parent/pom.xml 2012-04-17 04:52:03 UTC (rev 3010)
+++ trunk/joafip-parent/pom.xml 2012-04-17 05:00:49 UTC (rev 3011)
@@ -350,8 +350,7 @@
<module>../joafip-collection</module>
<module>../joafip-kvstore</module>
<module>../joafip-heapfile</module>
- <module>../joafip-jdbm</module>
- <module>../joafip-babudb</module>
+ <module>../joafip-btreeplus</module>
<module>../joafip-pmap</module>
<module>../joafip-callback</module>
<module>../joafip-java-agent</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 04:52:13
|
Revision: 3010
http://joafip.svn.sourceforge.net/joafip/?rev=3010&view=rev
Author: luc_peuvrier
Date: 2012-04-17 04:52:03 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
useless abstract removed
Modified Paths:
--------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -1,358 +0,0 @@
-/*
- * 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.heapfile.service;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.file.service.IRandomAccessFile;
-import net.sf.joafip.file.service.RandomAccessFileDirectNio;
-import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * abstract file management
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public abstract class AbstractFileFor implements IFileForStorable {// NOPMD
- // abstract
- // class
- // without
- // abstract
- // method
-
- private static final String FILE_IS_OPENED = "file is opened";
-
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
- protected static final String FILE_ALREADY_CLOSED = "file already closed";
-
- protected static final String FILE_NOT_OPENNED = "file not opened";
-
- private static final String FILE_ALREADY_OPENED = "file already opened";
-
- protected static final String FAILED_DELETE_FILE = "failed delete file ";
-
- /** the file object for file heap */
- private final File file;
-
- /** for random read write file access */
- protected IRandomAccessFile randomAccessFile;
-
- /** true if file opened */
- private boolean opened = false;
-
- private Exception opennerTrace;
-
- private Exception closerTrace = new Exception("closer trace");
-
- /**
- * setup file to manage at construction, do not use cache<br>
- *
- * @param fileName
- * the file to manage name
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final String fileName, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this(fileName == null ? null : new File(fileName), maxRetry,
- retryMsDelay);
- }
-
- /**
- * setup file to manage at construction, do not use cache<br>
- *
- * @param file
- * the file to manage
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final File file, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this.file = file;
- randomAccessFile = new RandomAccessFileDirectNio(file, maxRetry,
- retryMsDelay);
- }
-
- /**
- * setup file to manage and read/write cache at construction<br>
- *
- * @param fileName
- * the file to manage name
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final String fileName, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this(fileName == null ? null : new File(fileName), pageSize, maxPage,
- maxRetry, retryMsDelay);
- }
-
- /**
- * setup file to manage and read/write cache at construction<br>
- *
- * @param file
- * the file to manage
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final File file, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, maxRetry,
- retryMsDelay);
- }
-
- /**
- * setup file to manage and read/write cache at construction<br>
- *
- * @param file
- * the file to manage
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param haveReadCache
- * true if have read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final File file, final int pageSize,
- final int maxPage, final boolean haveReadCache, final int maxRetry,
- final int retryMsDelay) {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, haveReadCache);
- }
-
- @Override
- public void open() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_ALREADY_OPENED, opennerTrace);
- } else {
- try {
- randomAccessFile.open();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- opened = true;
- opennerTrace = new Exception("openner trace");
- }
- }
-
- @Override
- public void close() throws HeapException {
- if (opened) {
- opened = false;
- closerTrace = new Exception("closer trace");
- try {
- randomAccessFile.close();
- } catch (FileIOException e) {
- throw new HeapException(e);
- }
- } else {
- throw new HeapException(FILE_ALREADY_CLOSED, closerTrace);
- }
- }
-
- @Override
- public void flush() throws HeapException {
- assertOpened();
- try {
- randomAccessFile.flush();
- } catch (FileIOException e) {
- throw new HeapException(e);
- }
- }
-
- @Override
- public void resetFileSize() throws HeapException {
- assertOpened();
- try {
- randomAccessFile.setLength(0);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public void deleteFileIfExists() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_IS_OPENED);
- }
- if (logger.debugEnabled) {
- logger.debug("delete " + file);
- }
- try {
- randomAccessFile.deleteIfExists();
- } catch (FileIOException exception) {
- throw new HeapException(FAILED_DELETE_FILE + file, exception);
- }
- }
-
- @Override
- public void deleteFileIfExistsRenaming() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_IS_OPENED);
- }
- if (logger.debugEnabled) {
- logger.debug("delete " + file);
- }
- try {
- randomAccessFile.deleteIfExistsRenaming();
- } catch (FileIOException exception) {
- throw new HeapException(FAILED_DELETE_FILE + file, exception);
- }
- }
-
- /**
- * @throws HeapException
- *
- */
- private void assertOpened() throws HeapException {
- if (!opened) {
- throw new HeapException(FILE_NOT_OPENNED, closerTrace);
- }
- }
-
- public boolean isOpened() {
- return opened;
- }
-
- @Override
- public void seek(final long positionInFile) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.seek(positionInFile);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public int read(final byte[] data) throws HeapException {
- assertOpened();
- try {
- return randomAccessFile.read(data);// NOPMD
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public void write(final byte[] data) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.write(data);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public File getFile() {
- return file;
- }
-
- @Override
- public long getFileSize() throws HeapException {
- long size;
- assertOpened();
- try {
- size = randomAccessFile.length();
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- return size;
- }
-
- /**
- * set the size of this file
- *
- * @param newSize
- * the file new size
- * @throws HeapException
- * if an I/O error occurs.
- */
- public void setFileSize(final long newSize) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.setLength(newSize);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- /**
- * close after io exception
- */
- protected HeapException closeAfterIOException(
- final FileIOException exception) throws HeapException {
- final HeapException fileForStorageException =
- /**/new HeapException(exception);
- try {
- close();
- } catch (HeapException exception2) {
- logger.warn("closing after exception", exception2);
- }
- return fileForStorageException;
- }
-
- public void copy(final String fileName) throws FileIOException {
- randomAccessFile.copy(fileName);
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("AbstractFileFor [file=");
- builder.append(file);
- builder.append(", opened=");
- builder.append(opened);
- builder.append("]");
- return builder.toString();
- }
-}
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -1,158 +0,0 @@
-/*
- * 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.heapfile.service;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.heapfile.entity.IFileStorable;
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- * to read/write class implementing {@link IFileStorable} to/from file.<br>
- * {@link #open()} and {@link #close()}<br>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class FileForStorable extends AbstractFileFor {
-
- /**
- * create a file to read from and write to {@link IFileStorable} object.<br>
- * no cache used for file management<br>
- *
- * @param fileName
- * the file name of file to use for object storing
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final String fileName, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- super(fileName, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * no cache used for file management<br>
- *
- * @param file
- * the file to use for object storing
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final File file, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- super(file, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param file
- * the file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- super(file, pageSize, maxPage, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param file
- * the file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param haveReadCache
- * true if have read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final boolean haveReadCache, final int maxRetry,
- final int retryMsDelay) {
- super(file, pageSize, maxPage, haveReadCache, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param fileName
- * the file name of file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final String fileName, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- super(fileName, pageSize, maxPage, maxRetry, retryMsDelay);
- }
-
- /**
- * copy this file to an other file
- *
- * @param fileForStorable
- * @throws HeapException
- */
- public void copy(final FileForStorable fileForStorable)
- throws HeapException {
- try {
- randomAccessFile.copy(fileForStorable.getFile().getAbsolutePath());
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
-
- @Override
- public void write(final ToBackupRecord toBackupRecord) throws HeapException {
- try {
- randomAccessFile.seek(toBackupRecord.getPositionInFile());
- randomAccessFile.write(toBackupRecord.getData());
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
-}
Copied: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java (from rev 2999, trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java)
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java (rev 0)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -0,0 +1,387 @@
+/*
+ * 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.heapfile.service;
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.file.service.FileIOException;
+import net.sf.joafip.file.service.IRandomAccessFile;
+import net.sf.joafip.file.service.RandomAccessFileDirectNio;
+import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
+import net.sf.joafip.heapfile.entity.IFileStorable;
+import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.logger.JoafipLogger;
+
+/**
+ * to read/write class implementing {@link IFileStorable} to/from file.<br>
+ * {@link #open()} and {@link #close()}<br>
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class FileForStorable implements IFileForStorable {
+
+ private static final String FILE_IS_OPENED = "file is opened";
+
+ protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
+
+ protected static final String FILE_ALREADY_CLOSED = "file already closed";
+
+ protected static final String FILE_NOT_OPENNED = "file not opened";
+
+ private static final String FILE_ALREADY_OPENED = "file already opened";
+
+ protected static final String FAILED_DELETE_FILE = "failed delete file ";
+
+ /** the file object for file heap */
+ private final File file;
+
+ /** for random read write file access */
+ protected IRandomAccessFile randomAccessFile;
+
+ /** true if file opened */
+ private boolean opened = false;
+
+ private Exception opennerTrace;
+
+ private Exception closerTrace = new Exception("closer trace");
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object.<br>
+ * no cache used for file management<br>
+ *
+ * @param fileName
+ * the file name of file to use for storing storable object
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ * if an I/O error occurs while opening the file
+ */
+ public FileForStorable(final String fileName, final int maxRetry,
+ final int retryMsDelay) throws HeapException {
+ this(fileName == null ? null : new File(fileName), maxRetry,
+ retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ * no cache used for file management<br>
+ *
+ * @param file
+ * the file to use for storable object storing
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ * if an I/O error occurs while opening the file
+ */
+ public FileForStorable(final File file, final int maxRetry,
+ final int retryMsDelay) throws HeapException {
+ this.file = file;
+ randomAccessFile = new RandomAccessFileDirectNio(file, maxRetry,
+ retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ * file management use read/write cache<br>
+ *
+ * @param fileName
+ * the file name of file to use for object storing
+ * @param pageSize
+ * page size ( number of byte ), must be greater or equals to
+ * 1024
+ * @param maxPage
+ * maximum number of page for read cache
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ */
+ public FileForStorable(final String fileName, final int pageSize,
+ final int maxPage, final int maxRetry, final int retryMsDelay)
+ throws HeapException {
+ this(fileName == null ? null : new File(fileName), pageSize, maxPage,
+ maxRetry, retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ *
+ * @param file
+ * the file to use for storable object storing
+ * @param pageSize
+ * page size ( number of byte ), must be greater or equals to
+ * 1024
+ * @param maxPage
+ * maximum number of page for read cache
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ */
+ public FileForStorable(final File file, final int pageSize,
+ final int maxPage, final int maxRetry, final int retryMsDelay)
+ throws HeapException {
+ this.file = file;
+ final RandomAccessFileDirectNio randomAccessFileDirect =
+ /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
+ randomAccessFile = new RandomAccessFileReadWriteCache(
+ randomAccessFileDirect, pageSize, maxPage, maxRetry,
+ retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ * file management use read/write cache<br>
+ *
+ * @param file
+ * the file to use for storable object storing
+ * @param pageSize
+ * page size ( number of byte ), must be greater or equals to
+ * 1024
+ * @param maxPage
+ * maximum number of page for read cache
+ * @param haveReadCache
+ * true if have read cache
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ */
+ public FileForStorable(final File file, final int pageSize,
+ final int maxPage, final boolean haveReadCache, final int maxRetry,
+ final int retryMsDelay) {
+ this.file = file;
+ final RandomAccessFileDirectNio randomAccessFileDirect =
+ /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
+ randomAccessFile = new RandomAccessFileReadWriteCache(
+ randomAccessFileDirect, pageSize, maxPage, haveReadCache);
+ }
+
+ @Override
+ public void open() throws HeapException {
+ if (opened) {
+ throw new HeapException(FILE_ALREADY_OPENED, opennerTrace);
+ } else {
+ try {
+ randomAccessFile.open();
+ } catch (FileIOException exception) {
+ throw new HeapException(exception);
+ }
+ opened = true;
+ opennerTrace = new Exception("openner trace");
+ }
+ }
+
+ @Override
+ public void close() throws HeapException {
+ if (opened) {
+ opened = false;
+ closerTrace = new Exception("closer trace");
+ try {
+ randomAccessFile.close();
+ } catch (FileIOException e) {
+ throw new HeapException(e);
+ }
+ } else {
+ throw new HeapException(FILE_ALREADY_CLOSED, closerTrace);
+ }
+ }
+
+ @Override
+ public void flush() throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.flush();
+ } catch (FileIOException e) {
+ throw new HeapException(e);
+ }
+ }
+
+ @Override
+ public void resetFileSize() throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.setLength(0);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public void deleteFileIfExists() throws HeapException {
+ if (opened) {
+ throw new HeapException(FILE_IS_OPENED);
+ }
+ if (logger.debugEnabled) {
+ logger.debug("delete " + file);
+ }
+ try {
+ randomAccessFile.deleteIfExists();
+ } catch (FileIOException exception) {
+ throw new HeapException(FAILED_DELETE_FILE + file, exception);
+ }
+ }
+
+ @Override
+ public void deleteFileIfExistsRenaming() throws HeapException {
+ if (opened) {
+ throw new HeapException(FILE_IS_OPENED);
+ }
+ if (logger.debugEnabled) {
+ logger.debug("delete " + file);
+ }
+ try {
+ randomAccessFile.deleteIfExistsRenaming();
+ } catch (FileIOException exception) {
+ throw new HeapException(FAILED_DELETE_FILE + file, exception);
+ }
+ }
+
+ /**
+ * @throws HeapException
+ *
+ */
+ private void assertOpened() throws HeapException {
+ if (!opened) {
+ throw new HeapException(FILE_NOT_OPENNED, closerTrace);
+ }
+ }
+
+ public boolean isOpened() {
+ return opened;
+ }
+
+ @Override
+ public void seek(final long positionInFile) throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.seek(positionInFile);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public int read(final byte[] data) throws HeapException {
+ assertOpened();
+ try {
+ return randomAccessFile.read(data);// NOPMD
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public void write(final byte[] data) throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.write(data);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public void write(final ToBackupRecord toBackupRecord) throws HeapException {
+ try {
+ randomAccessFile.seek(toBackupRecord.getPositionInFile());
+ randomAccessFile.write(toBackupRecord.getData());
+ } catch (FileIOException exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ public File getFile() {
+ return file;
+ }
+
+ @Override
+ public long getFileSize() throws HeapException {
+ long size;
+ assertOpened();
+ try {
+ size = randomAccessFile.length();
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ return size;
+ }
+
+ /**
+ * set the size of this file
+ *
+ * @param newSize
+ * the file new size
+ * @throws HeapException
+ * if an I/O error occurs.
+ */
+ public void setFileSize(final long newSize) throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.setLength(newSize);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ /**
+ * copy this file to an other file
+ *
+ * @param fileForStorable
+ * @throws HeapException
+ */
+ public void copy(final FileForStorable fileForStorable)
+ throws HeapException {
+ try {
+ randomAccessFile.copy(fileForStorable.getFile().getAbsolutePath());
+ } catch (FileIOException exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ /**
+ * close after io exception
+ */
+ protected HeapException closeAfterIOException(
+ final FileIOException exception) throws HeapException {
+ final HeapException fileForStorageException =
+ /**/new HeapException(exception);
+ try {
+ close();
+ } catch (HeapException exception2) {
+ logger.warn("closing after exception", exception2);
+ }
+ return fileForStorageException;
+ }
+
+ public void copy(final String fileName) throws FileIOException {
+ randomAccessFile.copy(fileName);
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("AbstractFileFor [file=");
+ builder.append(file);
+ builder.append(", opened=");
+ builder.append(opened);
+ builder.append("]");
+ return builder.toString();
+ }
+}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -617,10 +617,10 @@
heapDataManager.flush();
identifier = heapDataManager.removeFirstDataRecord();
assertNotNull("must deleted first data record", identifier);
- assertEquals(BAD_VALUE,0L, identifier.value);
+ assertEquals(BAD_VALUE, 0L, identifier.value);
identifier = heapDataManager.removeFirstDataRecord();
assertNotNull("must deleted first data record", identifier);
- assertEquals(BAD_VALUE,1L, identifier.value);
+ assertEquals(BAD_VALUE, 1L, identifier.value);
assertNull(MUST_NOT_HAVE_DATA_RECORD,
heapDataManager.removeFirstDataRecord());
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -373,7 +373,8 @@
@Override
public void setDataRecordKeyComparator(
- final IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
+ final IDataRecordKeyManager dataRecordKeyComparator)
+ throws HeapException {
firstDataManager.setDataRecordKeyComparator(dataRecordKeyComparator);
secondDataManager.setDataRecordKeyComparator(dataRecordKeyComparator);
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -58,7 +58,7 @@
assertTrue("must found 'A'", heapDataManager.hasDataRecord(keyA));
final byte[] readDataA = heapDataManager.readDataRecord(keyA);
assertNotNull("must read 'A' data", readDataA);
- assertEquals("bad value","valueA", new String(readDataA));
+ assertEquals("bad value", "valueA", new String(readDataA));
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-17 04:52:10
|
Revision: 3010
http://joafip.svn.sourceforge.net/joafip/?rev=3010&view=rev
Author: luc_peuvrier
Date: 2012-04-17 04:52:03 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
useless abstract removed
Modified Paths:
--------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:07:13
|
Revision: 3009
http://joafip.svn.sourceforge.net/joafip/?rev=3009&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:07:06 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
initial commit, empty project
Added Paths:
-----------
trunk/joafip-btreeplus/pom.xml
trunk/joafip-btreeplus/src/
trunk/joafip-btreeplus/src/main/
trunk/joafip-btreeplus/src/main/java/
trunk/joafip-btreeplus/src/main/resources/
trunk/joafip-btreeplus/src/test/
trunk/joafip-btreeplus/src/test/java/
trunk/joafip-btreeplus/src/test/resources/
Property Changed:
----------------
trunk/joafip-btreeplus/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:07:12
|
Revision: 3009
http://joafip.svn.sourceforge.net/joafip/?rev=3009&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:07:06 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
initial commit, empty project
Added Paths:
-----------
trunk/joafip-btreeplus/pom.xml
trunk/joafip-btreeplus/src/
trunk/joafip-btreeplus/src/main/
trunk/joafip-btreeplus/src/main/java/
trunk/joafip-btreeplus/src/main/resources/
trunk/joafip-btreeplus/src/test/
trunk/joafip-btreeplus/src/test/java/
trunk/joafip-btreeplus/src/test/resources/
Property Changed:
----------------
trunk/joafip-btreeplus/
Property changes on: trunk/joafip-btreeplus
___________________________________________________________________
Added: svn:ignore
+ .settings
.classpath
.project
Added: trunk/joafip-btreeplus/pom.xml
===================================================================
--- trunk/joafip-btreeplus/pom.xml (rev 0)
+++ trunk/joafip-btreeplus/pom.xml 2012-04-16 03:07:06 UTC (rev 3009)
@@ -0,0 +1,51 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-parent</artifactId>
+ <version>1.0.0</version>
+ <relativePath>../joafip-parent</relativePath>
+ </parent>
+ <!-- <groupId>net.sf.joafip</groupId> -->
+ <artifactId>joafip-btreeplus</artifactId>
+ <packaging>jar</packaging>
+ <version>4.0.0b8</version>
+ <url>http://joafip.sourceforge.net/</url>
+ <name>Joafip storage using btree+</name>
+
+ <!-- <sourceDirectory>src_maven/main/java</sourceDirectory> <testSourceDirectory>src_maven/test/java</testSourceDirectory>
+ <resources><resource><directory>src_maven/main/resource</directory></resource></resources> -->
+
+ <dependencies>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-common</artifactId>
+ <version>4.0.0b8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-common</artifactId>
+ <version>4.0.0b8</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-kvstore</artifactId>
+ <version>4.0.0b8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-log4j</artifactId>
+ <version>4.0.0b8</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:03:40
|
Revision: 3008
http://joafip.svn.sourceforge.net/joafip/?rev=3008&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:03:34 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
Initial import.
Added Paths:
-----------
trunk/joafip-btreeplus/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:03:40
|
Revision: 3008
http://joafip.svn.sourceforge.net/joafip/?rev=3008&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:03:34 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
Initial import.
Added Paths:
-----------
trunk/joafip-btreeplus/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:01:24
|
Revision: 3007
http://joafip.svn.sourceforge.net/joafip/?rev=3007&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:01:18 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
was for test
Removed Paths:
-------------
trunk/joafip-jdbm/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:01:24
|
Revision: 3007
http://joafip.svn.sourceforge.net/joafip/?rev=3007&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:01:18 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
was for test
Removed Paths:
-------------
trunk/joafip-jdbm/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:00:53
|
Revision: 3006
http://joafip.svn.sourceforge.net/joafip/?rev=3006&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:00:46 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
was for test
Removed Paths:
-------------
trunk/joafip-babudb/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <luc...@us...> - 2012-04-16 03:00:53
|
Revision: 3006
http://joafip.svn.sourceforge.net/joafip/?rev=3006&view=rev
Author: luc_peuvrier
Date: 2012-04-16 03:00:46 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
was for test
Removed Paths:
-------------
trunk/joafip-babudb/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|