[Joafip-svn] SF.net SVN: joafip:[3148] trunk/joafip
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2012-11-18 10:04:05
|
Revision: 3148
http://joafip.svn.sourceforge.net/joafip/?rev=3148&view=rev
Author: luc_peuvrier
Date: 2012-11-18 10:03:58 +0000 (Sun, 18 Nov 2012)
Log Message:
-----------
added persistent data record identifier set
Modified Paths:
--------------
trunk/joafip/pom.xml
trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/PersistantDataRecordIdentifierSetQue.java
Added Paths:
-----------
trunk/joafip/src/main/java/net/sf/joafip/util/PersistantDataRecordIdentifierSet.java
trunk/joafip/src/test/java/net/sf/joafip/util/TestPersistantDataRecordIdentifierSet.java
Modified: trunk/joafip/pom.xml
===================================================================
--- trunk/joafip/pom.xml 2012-11-17 16:23:40 UTC (rev 3147)
+++ trunk/joafip/pom.xml 2012-11-18 10:03:58 UTC (rev 3148)
@@ -42,6 +42,13 @@
<dependency>
<groupId>net.sf.joafip</groupId>
+ <artifactId>joafip-collection</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.joafip</groupId>
<artifactId>joafip-kvstore</artifactId>
</dependency>
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/PersistantDataRecordIdentifierSetQue.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/PersistantDataRecordIdentifierSetQue.java 2012-11-17 16:23:40 UTC (rev 3147)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/out/PersistantDataRecordIdentifierSetQue.java 2012-11-18 10:03:58 UTC (rev 3148)
@@ -51,10 +51,10 @@
private final byte[] minusOne;
public PersistantDataRecordIdentifierSetQue(
- final String temporaryDirectoryName) throws HeapException {
+ final String directoryName) throws HeapException {
super();
- final File dataFile = new File(temporaryDirectoryName + "/set");
+ final File dataFile = new File(directoryName + "/set");
final HeapFileSetup setup = new HeapFileSetup(
EnumFileAccessMode.MAPPED_RANDOM_FILE_ACCESS, dataFile,
false/* crashSafeMode */, true/* useCacheMode */,
Added: trunk/joafip/src/main/java/net/sf/joafip/util/PersistantDataRecordIdentifierSet.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/util/PersistantDataRecordIdentifierSet.java (rev 0)
+++ trunk/joafip/src/main/java/net/sf/joafip/util/PersistantDataRecordIdentifierSet.java 2012-11-18 10:03:58 UTC (rev 3148)
@@ -0,0 +1,133 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.util.AbstractSet;
+import java.util.Iterator;
+
+import net.sf.joafip.heapfile.service.AutoSaveHeapFileDataManager;
+import net.sf.joafip.kvstore.entity.EnumFileAccessMode;
+import net.sf.joafip.kvstore.entity.HeapFileSetup;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.HeapRuntimeException;
+import net.sf.joafip.kvstore.service.IHeapDataManager;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class PersistantDataRecordIdentifierSet extends
+ AbstractSet<DataRecordIdentifier> {
+
+ private static final int MAX_RECORDS = 1000;
+
+ private static final byte[] DATA = new byte[0];
+
+ private final IHeapDataManager heapDataManagerForSet;
+
+ public PersistantDataRecordIdentifierSet(final String filePath)
+ throws HeapException {
+ super();
+ final File dataFile = new File(filePath);
+ final HeapFileSetup setup = new HeapFileSetup(
+ EnumFileAccessMode.MAPPED_RANDOM_FILE_ACCESS, dataFile,
+ false/* crashSafeMode */, true/* useCacheMode */,
+ false/* deleteRenaming */, false/* clearResizeFile */,
+ 1/* maxFileOperationRetry */, 0/* fileOperationRetryMsDelay */,
+ null/* openFileTraceFile */);
+ setup.cacheSetup(1024/* pageSize */, 1024/* maxPage */);
+ setup.fileBufferSetup(8 * 1024/* maxBufferSize */, 32/* maxNumberOfBuffer */);
+ heapDataManagerForSet = new AutoSaveHeapFileDataManager(setup, false,
+ MAX_RECORDS);
+ }
+
+ public void startService(final boolean removeFiles) throws HeapException {
+ heapDataManagerForSet.startService(removeFiles);
+ }
+
+ public void stopService() throws HeapException {
+ heapDataManagerForSet.stopService();
+ }
+
+ @Override
+ public Iterator<DataRecordIdentifier> iterator() {
+ try {
+ return heapDataManagerForSet.dataRecordIterator();
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ }
+
+ @Override
+ public int size() {
+ try {
+ return heapDataManagerForSet.getNumberOfDataRecord();
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ }
+
+ @Override
+ public boolean contains(final Object object) {
+ final DataRecordIdentifier dataRecordIdentifier = (DataRecordIdentifier) object;
+ try {
+ return heapDataManagerForSet.hasDataRecord(dataRecordIdentifier);
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ }
+
+ @Override
+ public boolean add(final DataRecordIdentifier dataRecordIdentifier) {
+ try {
+ return heapDataManagerForSet.writeDataRecord(dataRecordIdentifier,
+ DATA);
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ }
+
+ @Override
+ public boolean remove(final Object object) {
+ final DataRecordIdentifier dataRecordIdentifier = (DataRecordIdentifier) object;
+ try {
+ return heapDataManagerForSet.deleteDataRecord(dataRecordIdentifier);
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ }
+
+ @Override
+ public void clear() {
+ try {
+ heapDataManagerForSet.clear();
+ } catch (HeapException exception) {
+ throw new HeapRuntimeException(exception);
+ }
+ }
+
+}
Property changes on: trunk/joafip/src/main/java/net/sf/joafip/util/PersistantDataRecordIdentifierSet.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/joafip/src/test/java/net/sf/joafip/util/TestPersistantDataRecordIdentifierSet.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/util/TestPersistantDataRecordIdentifierSet.java (rev 0)
+++ trunk/joafip/src/test/java/net/sf/joafip/util/TestPersistantDataRecordIdentifierSet.java 2012-11-18 10:03:58 UTC (rev 3148)
@@ -0,0 +1,261 @@
+/*
+ * 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.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import net.sf.joafip.NoStorableAccess;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.TestException;
+import net.sf.joafip.java.util.AbstractSetTest;
+import net.sf.joafip.kvstore.record.entity.DataRecordIdentifier;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.kvstore.service.HeapRuntimeException;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+@NoStorableAccess
+public class TestPersistantDataRecordIdentifierSet extends AbstractSetTest {
+
+ private AdapterSet adapterSet;
+
+ public TestPersistantDataRecordIdentifierSet() throws TestException {
+ super();
+ }
+
+ public TestPersistantDataRecordIdentifierSet(final String name)
+ throws TestException {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ adapterSet = new AdapterSet();
+ set = adapterSet;
+ adapterSet.startService(true);
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ try {
+ adapterSet.clear();
+ } catch (Exception exception) {
+ // ignore error
+ }
+ try {
+ adapterSet.stopService();
+ } catch (Exception exception) {
+ // ignore error
+ }
+ super.tearDown();
+ }
+
+ @Override
+ protected boolean concurrentAccess() {
+ return false;
+ }
+
+ @Override
+ protected boolean acceptNullElement() {
+ return false;
+ }
+
+ @Override
+ public void testEquals() throws InstantiationException,
+ IllegalAccessException {
+ // TODO Auto-generated method stub
+ // super.testEquals();
+ }
+
+ @NotStorableClass
+ @NoStorableAccess
+ private class AdapterSet implements Set<String> {
+
+ private final PersistantDataRecordIdentifierSet set;
+
+ public AdapterSet() throws HeapException {
+ super();
+ set = new PersistantDataRecordIdentifierSet("runtime/set");
+ }
+
+ public void startService(final boolean removeFiles)
+ throws HeapException {
+ set.startService(removeFiles);
+ }
+
+ public void stopService() throws HeapException {
+ set.stopService();
+ }
+
+ @Override
+ public int size() {
+ return set.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return set.isEmpty();
+ }
+
+ @Override
+ public boolean contains(final Object object) {
+ return set.contains(dataRecordIdentifier((String) object));
+ }
+
+ @Override
+ public Iterator<String> iterator() {
+ return new Iterator<String>() {
+
+ private final Iterator<DataRecordIdentifier> iterator = set
+ .iterator();
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public String next() {
+ DataRecordIdentifier dataRecordIdentifier = iterator.next();
+ return string(dataRecordIdentifier);
+ }
+
+ @Override
+ public void remove() {
+ iterator.remove();
+ }
+ };
+ }
+
+ @Override
+ public Object[] toArray() {
+ final Object[] objects = set.toArray();
+ final String result[] = new String[objects.length];
+ int index = 0;
+ for (Object object : objects) {
+ result[index++] = string((DataRecordIdentifier) object);
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T[] toArray(T[] array) {
+ final DataRecordIdentifier[] objects = new DataRecordIdentifier[set
+ .size()];
+ set.toArray(objects);
+ int index = 0;
+ final T[] rarray;
+ if (array.length != set.size()) {
+ rarray = (T[]) new String[set.size()];
+ } else {
+ rarray = array;
+ }
+ for (DataRecordIdentifier object : objects) {
+ rarray[index++] = (T) string(object);
+ }
+ return rarray;
+ }
+
+ @Override
+ public boolean add(final String element) {
+ return set.add(dataRecordIdentifier(element));
+ }
+
+ @Override
+ public boolean remove(Object object) {
+ final String element = (String) object;
+ return set.remove(dataRecordIdentifier(element));
+ }
+
+ @Override
+ public boolean containsAll(final Collection<?> collection) {
+ final List<DataRecordIdentifier> list = new LinkedList<DataRecordIdentifier>();
+ for (Object string : collection) {
+ list.add(dataRecordIdentifier((String) string));
+ }
+ return set.containsAll(list);
+ }
+
+ @Override
+ public boolean addAll(final Collection<? extends String> collection) {
+ final List<DataRecordIdentifier> list = new LinkedList<DataRecordIdentifier>();
+ for (String string : collection) {
+ list.add(dataRecordIdentifier(string));
+ }
+ return set.addAll(list);
+ }
+
+ @Override
+ public boolean retainAll(final Collection<?> collection) {
+ final List<DataRecordIdentifier> list = new LinkedList<DataRecordIdentifier>();
+ for (Object string : collection) {
+ list.add(dataRecordIdentifier((String) string));
+ }
+ return set.retainAll(list);
+ }
+
+ @Override
+ public boolean removeAll(final Collection<?> collection) {
+ final List<DataRecordIdentifier> list = new LinkedList<DataRecordIdentifier>();
+ for (Object string : collection) {
+ list.add(dataRecordIdentifier((String) string));
+ }
+ return set.removeAll(list);
+ }
+
+ @Override
+ public void clear() {
+ set.clear();
+ }
+
+ private DataRecordIdentifier dataRecordIdentifier(final String value) {
+ if (value.length() != 1) {
+ throw new HeapRuntimeException("bad value \"" + value + "\"");
+ }
+ return new DataRecordIdentifier(value.charAt(0));
+ }
+
+ private String string(final DataRecordIdentifier dataRecordIdentifier) {
+ final String string;
+ if (dataRecordIdentifier == null) {
+ string = null;
+ } else {
+ final char[] value = new char[1];
+ value[0] = (char) dataRecordIdentifier.value;
+ string = new String(value);
+ }
+ return string;
+ }
+ }
+}
Property changes on: trunk/joafip/src/test/java/net/sf/joafip/util/TestPersistantDataRecordIdentifierSet.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|