01: /*
02: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
03:
04: This file is part of the JODB (Java Objects Database) open source project.
05:
06: JODB is free software; you can redistribute it and/or modify it under
07: the terms of version 2 of the GNU General Public License as published
08: by the Free Software Foundation.
09:
10: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
11: WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: for more details.
14:
15: You should have received a copy of the GNU General Public License along
16: with this program; if not, write to the Free Software Foundation, Inc.,
17: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package com.mobixess.jodb.core.io.buffers;
20:
21: import java.io.File;
22: import java.io.IOException;
23:
24: import com.mobixess.jodb.core.io.IRandomAccessBufferFactory;
25: import com.mobixess.jodb.core.io.IRandomAccessDataBuffer;
26:
27: public class RandomAccessFileBufferFactory implements
28: IRandomAccessBufferFactory {
29:
30: private final static String TRANSACTION_TEMP_FILE_EXT = ".jotm";
31: private final static String TRANSACTION_TEMP_FILE_PREFIX = "jodbtrans";
32: private final static String TRANSACTION_ROLLBACK_TEMP_FILE_EXT = ".rbk";
33: private final static String TRANSACTION_REPLACEMENTS_TEMP_FILE_EXT = ".rpl";
34:
35: private static RandomAccessFileBufferFactory _instance = new RandomAccessFileBufferFactory();
36:
37: private RandomAccessFileBufferFactory() {
38: }
39:
40: public IRandomAccessDataBuffer createBuffer(String name,
41: BUFFER_TYPE type, boolean write) throws IOException {
42: File file;
43: switch (type) {
44: case MAIN:
45: file = new File(name);
46: break;
47: case NEW_DATA:
48: file = File.createTempFile(TRANSACTION_TEMP_FILE_PREFIX,
49: TRANSACTION_TEMP_FILE_EXT);
50: break;
51: case REPLACEMENTS:
52: file = File.createTempFile(TRANSACTION_TEMP_FILE_PREFIX,
53: TRANSACTION_REPLACEMENTS_TEMP_FILE_EXT);
54: break;
55: case ROLLBACK:
56: file = File.createTempFile(TRANSACTION_TEMP_FILE_PREFIX,
57: TRANSACTION_ROLLBACK_TEMP_FILE_EXT);
58: break;
59: case CLIENT_TEMP_FILE:
60: case SERVER_TEMP_BUFFER:
61: file = File
62: .createTempFile(TRANSACTION_TEMP_FILE_PREFIX, "");
63: break;
64: default:
65: throw new IOException();
66: }
67: return new RandomAccessFileTransactionBuffer(file, write);
68: }
69:
70: public static RandomAccessFileBufferFactory getInstance() {
71: return _instance;
72: }
73:
74: }
|