RandomAccessTestFileBufferFactory.java :  » Database-DBMS » JODB » com » mobixess » jodb » tests » io » buffers » Java Open Source

Java Open Source » Database DBMS » JODB 
JODB » com » mobixess » jodb » tests » io » buffers » RandomAccessTestFileBufferFactory.java
/*
Copyright (C) 2007  Mobixess Inc. http://www.java-objects-database.com

This file is part of the JODB (Java Objects Database) open source project.

JODB is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation.

JODB 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, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
*/
package com.mobixess.jodb.tests.io.buffers;

import java.io.File;
import java.io.IOException;

import com.mobixess.jodb.core.io.IRandomAccessBufferFactory;
import com.mobixess.jodb.core.io.IRandomAccessDataBuffer;

public abstract class RandomAccessTestFileBufferFactory implements IRandomAccessBufferFactory{
    
    private final static String TRANSACTION_TEMP_FILE_EXT = ".jotm";
    private final static String TRANSACTION_TEMP_FILE_PREFIX = "jodbtrans";
    private final static String TRANSACTION_ROLLBACK_TEMP_FILE_EXT = ".rbk";
    private final static String TRANSACTION_REPLACEMENTS_TEMP_FILE_EXT = ".rpl";
    
    public RandomAccessTestFileBufferFactory() {
    }

    public IRandomAccessDataBuffer createBuffer(String name, BUFFER_TYPE type, boolean write) throws IOException {
        File file;
        switch (type) {
        case MAIN:
            file = new File(name);
            break;
        case NEW_DATA:
            file = File.createTempFile(TRANSACTION_TEMP_FILE_PREFIX, TRANSACTION_TEMP_FILE_EXT);
            break;
        case REPLACEMENTS:
            file = File.createTempFile(TRANSACTION_TEMP_FILE_PREFIX, TRANSACTION_REPLACEMENTS_TEMP_FILE_EXT);
            break;
        case ROLLBACK:
            file = File.createTempFile(TRANSACTION_TEMP_FILE_PREFIX, TRANSACTION_ROLLBACK_TEMP_FILE_EXT);
            break;
        case CLIENT_TEMP_FILE:
        case SERVER_TEMP_BUFFER:
            file = File.createTempFile(TRANSACTION_TEMP_FILE_PREFIX, "");
            break;
        default:
            throw new IOException();
        }
        return createBuffer(file, type, write);
    }
    
    protected abstract IRandomAccessDataBuffer createBuffer(File name, BUFFER_TYPE type, boolean write) throws IOException;
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.