/* 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.support.log.LogAdapterHolder;
import org.entityfs.util.io.ReadWritableFileAdapter;
import org.helidb.Database;
import org.helidb.backend.heapcrs.ConstantRecordSizeHeapBackend;
import org.helidb.impl.simple.SimpleDatabase;
import org.helidb.lang.serializer.IntegerSerializer;
import org.helidb.lang.serializer.LongSerializer;
import org.helidb.test.support.FileSupport;
public class SimpleDatabaseCRSHeapConfiguration extends AbstractTestConfiguration implements CRSTestConfiguration
{
private Collection<SimpleDatabase<Integer, Long, Long>> m_databases;
private Map<Integer, File> m_dbFiles;
public SimpleDatabaseCRSHeapConfiguration(int noOfDatabases, int noOfBaseRecords, int noOfAdditionalRecords)
{
super(noOfDatabases, noOfBaseRecords, noOfAdditionalRecords);
}
public String getGraphFileNamePrefix()
{
return "s_crsh_";
}
public String getDatabaseImplementationName()
{
return "SimpleDatabase";
}
public String[] getBackendImplementationNames()
{
return new String[] { "CRSHeapBackend" };
}
public String getAdditionalInfo()
{
return null;
}
public Collection<? extends Database<Integer, Long>> getDatabases()
{
return m_databases;
}
public String getHeader()
{
return "Simple database with constant record size heap backend";
}
public void setup(LogAdapterHolder lah)
{
final int noOfDatabases = getNoOfDatabases();
m_databases = new ArrayList<SimpleDatabase<Integer, Long, Long>>(noOfDatabases);
m_dbFiles = new HashMap<Integer, File>(noOfDatabases);
for (int i = 0; i < noOfDatabases; i++)
{
File f = FileSupport.createTempFile();
ConstantRecordSizeHeapBackend<Integer, Long> b = new ConstantRecordSizeHeapBackend<Integer, Long>(new ReadWritableFileAdapter(f), false, IntegerSerializer.INSTANCE, LongSerializer.INSTANCE, 0, 8192, lah);
SimpleDatabase<Integer, Long, Long> db = new SimpleDatabase<Integer, Long, Long>(b, lah);
m_dbFiles.put(System.identityHashCode(db), f);
m_databases.add(db);
}
}
public void tearDown()
{
for (SimpleDatabase<Integer, Long, Long> db : m_databases)
{
db.close();
deleteFile(m_dbFiles.get(System.identityHashCode(db)));
}
m_dbFiles = null;
m_databases = null;
}
}