/*
* Copyright (c) 2008, Jan Stender, Bjoern Kolbeck, Mikael Hoegqvist,
* Felix Hupfeld, Zuse Institute Berlin
*
* Licensed under the BSD License, see LICENSE file for details.
*
*/
package de.mxro.thrd.babudb05.lsmdb;
import de.mxro.thrd.babudb05.BabuDBRequestResultImpl;
import de.mxro.thrd.babudb05.api.database.UserDefinedLookup;
import de.mxro.thrd.babudb05.lsmdb.LSMDBWorker.RequestOperation;
/**
*
* @author bjko
* @param <T>
*/
public class LSMDBRequest<T> {
private final BabuDBRequestResultImpl<T> listener;
private final LSMDatabase database;
private final int indexId;
private final RequestOperation operation;
private final InsertRecordGroup insertData;
private final byte[] lookupKey;
private byte[] from;
private byte[] to;
private boolean ascending;
private final UserDefinedLookup udLookup;
/**
* Lock worker request.
*
* @param listener
*/
public LSMDBRequest(BabuDBRequestResultImpl<T> listener) {
this.operation = RequestOperation.LOCK;
this.listener = listener;
this.udLookup = null;
this.lookupKey = null;
this.insertData = null;
this.indexId = -1;
this.database = null;
}
public LSMDBRequest(LSMDatabase database, BabuDBRequestResultImpl<T> listener,
InsertRecordGroup insert) {
this.operation = RequestOperation.INSERT;
this.database = database;
this.indexId = 0;
this.insertData = insert;
this.lookupKey = null;
this.listener = listener;
this.udLookup = null;
}
public LSMDBRequest(LSMDatabase database, int indexId,
BabuDBRequestResultImpl<T> listener, byte[] key) {
this.operation = RequestOperation.LOOKUP;
this.database = database;
this.indexId = indexId;
this.lookupKey = key;
this.insertData = null;
this.listener = listener;
this.udLookup = null;
}
public LSMDBRequest(LSMDatabase database, int indexId,
BabuDBRequestResultImpl<T> listener, byte[] prefix,
boolean ascending) {
this.operation = RequestOperation.PREFIX_LOOKUP;
this.database = database;
this.indexId = indexId;
this.lookupKey = prefix;
this.insertData = null;
this.listener = listener;
this.udLookup = null;
this.ascending = ascending;
}
public LSMDBRequest(LSMDatabase database, int indexId,
BabuDBRequestResultImpl<T> listener, byte[] from, byte[] to,
boolean ascending) {
this.operation = RequestOperation.RANGE_LOOKUP;
this.database = database;
this.indexId = indexId;
this.from = from;
this.to = to;
this.lookupKey = null;
this.insertData = null;
this.listener = listener;
this.udLookup = null;
this.ascending = ascending;
}
public LSMDBRequest(LSMDatabase database,
BabuDBRequestResultImpl<T> listener, UserDefinedLookup udLookup) {
this.operation = RequestOperation.USER_DEFINED_LOOKUP;
this.database = database;
this.indexId = 0;
this.lookupKey = null;
this.insertData = null;
this.listener = listener;
this.udLookup = udLookup;
}
public LSMDatabase getDatabase() {
return database;
}
public int getIndexId() {
return indexId;
}
public RequestOperation getOperation() {
return operation;
}
public InsertRecordGroup getInsertData() {
return insertData;
}
public byte[] getLookupKey() {
return lookupKey;
}
public byte[] getFrom() {
return from;
}
public byte[] getTo() {
return to;
}
public boolean isAscending() {
return ascending;
}
public BabuDBRequestResultImpl<T> getListener() {
return listener;
}
public UserDefinedLookup getUserDefinedLookup() {
return this.udLookup;
}
}