/* HeliDB -- A simple database for Java, http://www.helidb.org
* Copyright (C) 2008, 2009 Karl Gustafsson
*
* This file is a part of HeliDB.
*
* HeliDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeliDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.helidb.resources.perf;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.entityfs.Directory;
import org.entityfs.ReadWritableFile;
import org.entityfs.fs.FSRWFileSystemBuilder;
import org.entityfs.support.log.LogAdapterHolder;
import org.entityfs.util.io.ReadWritableFileAdapter;
import org.helidb.Database;
import org.helidb.backend.DatabaseBackendFactory;
import org.helidb.backend.heap.HeapBackendFactory;
import org.helidb.impl.txn.sc.ShadowCopyTransactionalDatabase;
import org.helidb.impl.txn.sc.SingleFileManager;
import org.helidb.lang.serializer.StringSerializer;
import org.helidb.test.support.FileSupport;
public class ShadowCopyTransactionalDatabaseHeapConfiguration extends AbstractTestConfiguration implements VRSTestConfiguration
{
private Collection<ShadowCopyTransactionalDatabase<String, String, Long>> m_databases;
private Map<Integer, File[]> m_dbFiles;
public ShadowCopyTransactionalDatabaseHeapConfiguration(int noOfDatabases, int noOfBaseRecords, int noOfAdditionalRecords)
{
super(noOfDatabases, noOfBaseRecords, noOfAdditionalRecords);
}
public String getGraphFileNamePrefix()
{
return "sct_h_";
}
public String getDatabaseImplementationName()
{
return "ShadowCopyTxnDatabase";
}
public String[] getBackendImplementationNames()
{
return new String[] { "HeapBackend" };
}
public String getAdditionalInfo()
{
return null;
}
public Collection<? extends Database<String, String>> getDatabases()
{
return m_databases;
}
public String getHeader()
{
return "Shadow copy transactional database with heap backend";
}
public void setup(LogAdapterHolder lah)
{
final int noOfDatabases = getNoOfDatabases();
m_databases = new ArrayList<ShadowCopyTransactionalDatabase<String, String, Long>>(noOfDatabases);
m_dbFiles = new HashMap<Integer, File[]>(noOfDatabases);
for (int i = 0; i < noOfDatabases; i++)
{
File f = FileSupport.createTempFile();
ReadWritableFile ff = new ReadWritableFileAdapter(f);
File tmpDir = FileSupport.createTempDirectory();
Directory tmpDirD = new FSRWFileSystemBuilder().setRoot(tmpDir).create().getRootDirectory();
DatabaseBackendFactory<String, String, Long> baf = new HeapBackendFactory<String, String>(StringSerializer.INSTANCE, StringSerializer.INSTANCE, lah);
ShadowCopyTransactionalDatabase<String, String, Long> db = new ShadowCopyTransactionalDatabase<String, String, Long>(new SingleFileManager(ff, tmpDirD), baf, false, lah);
m_dbFiles.put(System.identityHashCode(db), new File[] { f, tmpDir });
m_databases.add(db);
}
}
public void tearDown()
{
for (Database<?, ?> db : m_databases)
{
db.close();
deleteFile(m_dbFiles.get(System.identityHashCode(db))[0]);
deleteFile(m_dbFiles.get(System.identityHashCode(db))[1]);
}
m_dbFiles = null;
m_databases = null;
}
}