Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / sql / catalog / TDCacheable.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/catalog/TDCacheable.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/catalog/TDCacheable.java
new file mode 100644 (file)
index 0000000..abba938
--- /dev/null
@@ -0,0 +1,140 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.catalog.TDCacheable\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.catalog;\r
+\r
+import org.apache.derby.iapi.services.cache.Cacheable;\r
+import org.apache.derby.iapi.services.cache.CacheManager;\r
+\r
+import org.apache.derby.iapi.services.monitor.Monitor;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.services.stream.HeaderPrintWriter;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;\r
+\r
+/**\r
+ * This class implements a Cacheable for a DataDictionary cache of\r
+ * table descriptors.  It is an abstract class - there is more than\r
+ * one cache of table descriptors per data dictionary, and this class\r
+ * provides the implementation that's common to all of them.  The lookup\r
+ * key for the cache (the "identity" of the cache item) is provided by\r
+ * the subclass.\r
+ *\r
+ * Another design alternative was to make the table descriptors themselves\r
+ * the cacheable objects.  This was rejected because: we would have only\r
+ * one way of caching table descriptors, and we need at least two (by UUID\r
+ * and by name); the contents of a table descriptor would have to be\r
+ * split out into a separate class, so it could be used as the createParameter\r
+ * to the createIdentity() method; the releasing of the Cacheable would\r
+ * have to be done when at the end of compilation by traversing the tree -\r
+ * by creating a separate Cacheable object, we can release the object within\r
+ * the getTableDescriptor() method after getting the table descriptor out\r
+ * of it.\r
+ */\r
+abstract class TDCacheable implements Cacheable\r
+{\r
+       protected TableDescriptor       td;\r
+       protected final DataDictionaryImpl      dd;\r
+\r
+       TDCacheable(DataDictionaryImpl dd) {\r
+               this.dd = dd;\r
+       }\r
+\r
+       /* Cacheable interface */\r
+\r
+       /** @see Cacheable#clean */\r
+       public void clean(boolean forRemove)\r
+       {\r
+               return;\r
+       }\r
+\r
+       /** @see Cacheable#isDirty */\r
+       public boolean isDirty()\r
+       {\r
+               return false;\r
+       }\r
+\r
+       /**\r
+        * Get the table descriptor that is associated with this Cacheable\r
+        */\r
+       public TableDescriptor getTableDescriptor()\r
+       {\r
+               return td;\r
+       }\r
+\r
+       /**\r
+        * Check the consistency of the table descriptor held by this TDCacheable\r
+        * versus an uncached table descriptor.\r
+        *\r
+        * @param uncachedTD    The uncached descriptor to compare to\r
+        * @param identity              The identity of the table descriptor\r
+        * @param reportInconsistent    A HeaderPrintWriter to send complaints to\r
+        *\r
+        * @return      true if the descriptors are the same, false if they're different\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       protected boolean checkConsistency(TableDescriptor uncachedTD,\r
+                                                                               Object identity,\r
+                                                                               HeaderPrintWriter reportInconsistent)\r
+                       throws StandardException\r
+       {\r
+               boolean retval = true;\r
+\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       if (uncachedTD == null)\r
+                       {\r
+                               reportInconsistent.println(\r
+                                       "Inconsistent NameTDCacheable: identity = " + identity +\r
+                                       ", uncached table descriptor not found.");\r
+                               retval = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               if (\r
+                                       (uncachedTD.getHeapConglomerateId() !=\r
+                                                                               td.getHeapConglomerateId()) ||\r
+                                       ( ! uncachedTD.getUUID().equals(td.getUUID())) ||\r
+                                       ( ! uncachedTD.getSchemaName().equals(td.getSchemaName()))||\r
+                                       ( ! uncachedTD.getName().equals(td.getName())) ||\r
+                                       ( uncachedTD.getTableType() != td.getTableType())\r
+                               )\r
+                               {\r
+                                       reportInconsistent.println(\r
+                                               "Inconsistent NameTDCacheable: identity = " + identity +\r
+                                               ", cached TD = " +\r
+                                               td +\r
+                                               ", uncached TD = " +\r
+                                               uncachedTD);\r
+\r
+                                       retval = false;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               return retval;\r
+       }\r
+}\r