001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal.cluster;
022:
023: import com.db4o.cluster.*;
024: import com.db4o.foundation.*;
025: import com.db4o.query.*;
026:
027: /**
028: * @exclude
029: */
030: public class ClusterConstraint implements Constraint {
031:
032: final Cluster _cluster;
033: final Constraint[] _constraints;
034:
035: public ClusterConstraint(Cluster cluster, Constraint[] constraints) {
036: _cluster = cluster;
037: _constraints = constraints;
038: }
039:
040: private ClusterConstraint compatible(Constraint with) {
041: if (!(with instanceof ClusterConstraint)) {
042: throw new IllegalArgumentException();
043: }
044: ClusterConstraint other = (ClusterConstraint) with;
045: if (other._constraints.length != _constraints.length) {
046: throw new IllegalArgumentException();
047: }
048: return other;
049: }
050:
051: public Constraint and(Constraint with) {
052: return join(with, true);
053: }
054:
055: public Constraint or(Constraint with) {
056: return join(with, false);
057: }
058:
059: private Constraint join(Constraint with, boolean isAnd) {
060: synchronized (_cluster) {
061: ClusterConstraint other = compatible(with);
062: Constraint[] newConstraints = new Constraint[_constraints.length];
063: for (int i = 0; i < _constraints.length; i++) {
064: newConstraints[i] = isAnd ? _constraints[i]
065: .and(other._constraints[i]) : _constraints[i]
066: .or(other._constraints[i]);
067: }
068: return new ClusterConstraint(_cluster, newConstraints);
069: }
070: }
071:
072: public Constraint equal() {
073: synchronized (_cluster) {
074: for (int i = 0; i < _constraints.length; i++) {
075: _constraints[i].equal();
076: }
077: return this ;
078: }
079: }
080:
081: public Constraint greater() {
082: synchronized (_cluster) {
083: for (int i = 0; i < _constraints.length; i++) {
084: _constraints[i].greater();
085: }
086: return this ;
087: }
088: }
089:
090: public Constraint smaller() {
091: synchronized (_cluster) {
092: for (int i = 0; i < _constraints.length; i++) {
093: _constraints[i].smaller();
094: }
095: return this ;
096: }
097: }
098:
099: public Constraint identity() {
100: synchronized (_cluster) {
101: for (int i = 0; i < _constraints.length; i++) {
102: _constraints[i].identity();
103: }
104: return this ;
105: }
106: }
107:
108: public Constraint like() {
109: synchronized (_cluster) {
110: for (int i = 0; i < _constraints.length; i++) {
111: _constraints[i].like();
112: }
113: return this ;
114: }
115: }
116:
117: public Constraint startsWith(boolean caseSensitive) {
118: synchronized (_cluster) {
119: for (int i = 0; i < _constraints.length; i++) {
120: _constraints[i].startsWith(caseSensitive);
121: }
122: return this ;
123: }
124: }
125:
126: public Constraint endsWith(boolean caseSensitive) {
127: synchronized (_cluster) {
128: for (int i = 0; i < _constraints.length; i++) {
129: _constraints[i].endsWith(caseSensitive);
130: }
131: return this ;
132: }
133: }
134:
135: public Constraint contains() {
136: synchronized (_cluster) {
137: for (int i = 0; i < _constraints.length; i++) {
138: _constraints[i].contains();
139: }
140: return this ;
141: }
142: }
143:
144: public Constraint not() {
145: synchronized (_cluster) {
146: for (int i = 0; i < _constraints.length; i++) {
147: _constraints[i].not();
148: }
149: return this ;
150: }
151: }
152:
153: public Object getObject() {
154: throw new NotSupportedException();
155: }
156: }
|