001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.amber.entity;
030:
031: import com.caucho.amber.query.ResultSetCacheChunk;
032: import com.caucho.amber.type.EntityType;
033: import com.caucho.util.L10N;
034: import com.caucho.util.Log;
035:
036: import java.util.logging.Level;
037: import java.util.logging.Logger;
038:
039: /**
040: * Code to update the cache value on the completion of a transaction.
041: */
042: public class RowInvalidateCompletion implements AmberCompletion {
043: private static final L10N L = new L10N(
044: RowInvalidateCompletion.class);
045: private static final Logger log = Log
046: .open(RowInvalidateCompletion.class);
047:
048: private String _table;
049: private Object _key;
050:
051: public RowInvalidateCompletion(String table, Object key) {
052: if (log.isLoggable(Level.FINER))
053: log.log(Level.FINER, L.l(
054: "RowInvalidateCompletion table: {0} key: {1}",
055: table, key));
056:
057: if (table == null || key == null)
058: throw new NullPointerException();
059:
060: _table = table;
061: _key = key;
062: }
063:
064: /**
065: * Code when the transaction completes.
066: *
067: * @return true if the entry should be deleted.
068: */
069: public boolean complete(EntityType entityType, Object key,
070: EntityItem entityItem) {
071: if (log.isLoggable(Level.FINER))
072: log.log(Level.FINER, L
073: .l("RowInvalidateCompletion.complete"));
074:
075: if (entityType.getTable().getName().equals(_table)
076: && _key.equals(key)) {
077: if (log.isLoggable(Level.FINER))
078: log
079: .log(
080: Level.FINER,
081: L
082: .l(
083: "RowInvalidateCompletion expiring table: {0} key: {1}",
084: _table, _key));
085:
086: // jpa/0k20
087: entityItem.expire();
088: } else {
089: entityItem.getEntity().__caucho_invalidate_foreign(_table,
090: key);
091: }
092:
093: return false;
094: }
095:
096: /**
097: * Code to invalidate the query.
098: *
099: * @return true if the entry should be deleted.
100: */
101: public boolean complete(ResultSetCacheChunk chunk) {
102: if (chunk.invalidate(_table, _key)) {
103: chunk.invalidate();
104: return true;
105: }
106:
107: return false;
108: }
109:
110: /**
111: * Returns true for equality.
112: */
113: public boolean equals(Object o) {
114: if (this == o)
115: return true;
116: else if (o == null || o.getClass() != getClass())
117: return false;
118:
119: RowInvalidateCompletion comp = (RowInvalidateCompletion) o;
120:
121: return _table.equals(comp._table) && _key.equals(comp._key);
122: }
123:
124: public String toString() {
125: return "RowInvalidateCompletion[" + _table + "," + _key + "]";
126: }
127: }
|