*** empty log message ***
[IRC.git] / Robust / Transactions / mytuplesoup / src / com / solidosystems / tuplesoup / core / Table.java
1 /*
2  * Copyright (c) 2007, Solido Systems
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * Neither the name of Solido Systems nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31  
32 package com.solidosystems.tuplesoup.core;
33  
34 import java.io.*;
35 import java.util.*;
36 import java.nio.channels.*;
37 import com.solidosystems.tuplesoup.filter.*;
38
39 /**
40  * The table stores a group of rows.
41  * Every row must have a unique id within a table.
42  */
43 public interface Table{
44     // Index type constants
45     public static final int MEMORY=0;
46     public static final int FLAT=1;
47     public static final int PAGED=2;
48      
49     // Row location constants
50     public static final int FILEA=0;
51     public static final int FILEB=1;
52     public static final int DELETE=2;
53     public static final int INDEX=3;
54      
55     /**
56      * Return the current values of the statistic counters and reset them.
57      * The current counters are:
58      * <ul>
59      *   <li>stat_table_add
60      *   <li>stat_table_update
61      *   <li>stat_table_delete
62      *   <li>stat_table_add_size
63      *   <li>stat_table_update_size
64      *   <li>stat_table_read_size
65      *   <li>stat_table_read
66      *   <li>stat_table_cache_hit
67      *   <li>stat_table_cache_miss
68      *   <li>stat_table_cache_drop
69      * </ul>
70      * Furthermore, the index will be asked to deliver separate index specific counters
71      */
72     public Hashtable<String,Long> readStatistics();
73
74     /**
75      * Set the maximal allowable size of the index cache.
76      */ 
77     public void setIndexCacheSize(int newsize);
78
79     /**
80      * Close all open file streams
81      */
82     public void close();
83
84     /** 
85      * Returns the name of this table
86      */ 
87     public String getTitle();
88     
89     /**
90      * Returns the location of this tables datafiles
91      */ 
92     public String getLocation();
93     
94     /**
95      * Delete the files created by this table object.
96      * Be aware that this will delete any data stored in this table!
97      */ 
98     public void deleteFiles();
99      
100     /**
101      * Adds a row of data to this table.
102      */
103     public void addRow(Row row) throws IOException;
104     
105      /**
106       * Adds a row to this table if it doesn't already exist, if it does it updates the row instead.
107       * This method is much slower than directly using add or update, so only use it if you don't know wether or not the row already exists.
108       */
109      public void addOrUpdateRow(Row row) throws IOException;
110      
111      /**
112       * Updates a row stored in this table.
113       */
114      public void updateRow(Row row) throws IOException;
115      
116      /**
117       * Marks a row as deleted in the index.
118       * Be aware that the space consumed by the row is not actually reclaimed.
119       */
120      public void deleteRow(Row row) throws IOException;
121      
122      /**
123       * Returns a tuplestream containing the given list of rows
124       */
125      public TupleStream getRows(List<String> rows) throws IOException;
126      
127      /**
128       * Returns a tuplestream containing the rows matching the given rowmatcher
129       */
130      public TupleStream getRows(RowMatcher matcher) throws IOException;
131      
132      /**
133       * Returns a tuplestream containing those rows in the given list that matches the given RowMatcher
134       */
135      public TupleStream getRows(List<String> rows,RowMatcher matcher) throws IOException;
136      
137      /**
138       * Returns a tuplestream of all rows in this table.
139       */
140      public TupleStream getRows() throws IOException;
141      
142      /**
143       * Returns a single row stored in this table.
144       * If the row does not exist in the table, null will be returned.
145       */
146      public Row getRow(String id) throws IOException;
147  }