View Javadoc
1   package org.apache.commons.jcs3.auxiliary.disk.jdbc;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.Serializable;
23  
24  /**
25   * This is used by various elements of the JDBC disk cache to indicate the
26   * status of a table. The MySQL disk cache, for instance, marks the status as
27   * optimizing when a scheduled optimization is taking place. This allows the
28   * cache to balk rather than block during long running optimizations.
29   */
30  public class TableState
31      implements Serializable
32  {
33      /** Don't change. */
34      private static final long serialVersionUID = -6625081552084964885L;
35  
36      /** Name of the table whose state this reflects. */
37      private String tableName;
38  
39      /**
40       * The table is free. It can be accessed and no potentially table locking
41       * jobs are running.
42       */
43      public static final int FREE = 0;
44  
45      /** A potentially table locking deletion is running */
46      public static final int DELETE_RUNNING = 1;
47  
48      /** A table locking optimization is running. */
49      public static final int OPTIMIZATION_RUNNING = 2;
50  
51      /** we might want to add error */
52      private int state = FREE;
53  
54      /**
55       * Construct a usable table state.
56       * <p>
57       * @param tableName
58       */
59      public TableState( final String tableName )
60      {
61          this.setTableName( tableName );
62      }
63  
64      /**
65       * @param tableName
66       *            The tableName to set.
67       */
68      public void setTableName( final String tableName )
69      {
70          this.tableName = tableName;
71      }
72  
73      /**
74       * @return Returns the tableName.
75       */
76      public String getTableName()
77      {
78          return tableName;
79      }
80  
81      /**
82       * @param state
83       *            The state to set.
84       */
85      public void setState( final int state )
86      {
87          this.state = state;
88      }
89  
90      /**
91       * @return Returns the state.
92       */
93      public int getState()
94      {
95          return state;
96      }
97  
98      /**
99       * Write out the values for debugging purposes.
100      * <p>
101      * @return String
102      */
103     @Override
104     public String toString()
105     {
106         final StringBuilder str = new StringBuilder();
107         str.append( "TableState " );
108         str.append( "\n TableName = " + getTableName() );
109         str.append( "\n State = " + getState() );
110         return str.toString();
111     }
112 }