001: /*
002: * $Id: BaseConstraint.java,v 1.16 2005/12/20 18:32:46 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.constraints;
042:
043: import org.axiondb.AxionException;
044: import org.axiondb.Constraint;
045: import org.axiondb.Database;
046: import org.axiondb.TableIdentifier;
047: import org.axiondb.event.RowEvent;
048: import org.axiondb.util.StringIdentifierGenerator;
049:
050: /**
051: * Abstract base {@link Constraint} implementation.
052: *
053: * @version $Revision: 1.16 $ $Date: 2005/12/20 18:32:46 $
054: * @author Rodney Waldhoff
055: * @author James Strachan
056: * @author Ahimanikya Satapathy
057: */
058: public abstract class BaseConstraint implements Constraint {
059: /**
060: * Creates a {@link Constraint} with the
061: * given <i>name</i> and <i>type</i>.
062: * @param name the name of this constraint (see {@link #setName})
063: * which may be <code>null</code>
064: * @param type the type of this constraint (see {@link #getType}),
065: * which should not be <code>null</code>
066: */
067: public BaseConstraint(String name, String type) {
068: setName(name);
069: _type = type;
070: }
071:
072: public abstract boolean evaluate(RowEvent event)
073: throws AxionException;
074:
075: /** This base implementation is a no-op. */
076: public void resolve(Database db, TableIdentifier table)
077: throws AxionException {
078: }
079:
080: public String getName() {
081: return _name;
082: }
083:
084: /**
085: * Sets the name of this constraint. When <i>name </i> is <code>null</code> a unique
086: * name is programatically generated.
087: */
088: public void setName(String name) {
089: if (null == name) {
090: _name = StringIdentifierGenerator.INSTANCE
091: .next16DigitIdentifier("C");
092: } else {
093: _name = name;
094: }
095: }
096:
097: public String getType() {
098: return _type;
099: }
100:
101: public boolean isDeferred() {
102: return _deferred;
103: }
104:
105: public void setDeferred(boolean deferred) throws AxionException {
106: if (deferred && !_deferrable) {
107: throw new AxionException("Not deferrable.");
108: }
109: _deferred = deferred;
110: }
111:
112: public boolean isDeferrable() {
113: return _deferrable;
114: }
115:
116: public void setDeferrable(boolean deferrable) {
117: _deferrable = deferrable;
118: if (!_deferrable) {
119: _deferred = false;
120: }
121: }
122:
123: protected TableIdentifier[] toArray(TableIdentifier table) {
124: TableIdentifier[] tables = null;
125: if (null != table) {
126: tables = new TableIdentifier[1];
127: tables[0] = table;
128: } else {
129: tables = new TableIdentifier[0];
130: }
131: return tables;
132: }
133:
134: private String _name;
135: private String _type;
136: private boolean _deferred = false;
137: private boolean _deferrable = false;
138:
139: private static final long serialVersionUID = 4423282446007162270L;
140: }
|