1 21 package com.db4o.inside.cluster; 22 23 import com.db4o.cluster.*; 24 import com.db4o.foundation.*; 25 import com.db4o.query.*; 26 27 30 public class ClusterConstraint implements Constraint{ 31 32 final Cluster _cluster; 33 final Constraint[] _constraints; 34 35 public ClusterConstraint(Cluster cluster, Constraint[] constraints){ 36 _cluster = cluster; 37 _constraints = constraints; 38 } 39 40 private ClusterConstraint compatible (Constraint with){ 41 if(! (with instanceof ClusterConstraint)){ 42 throw new IllegalArgumentException (); 43 } 44 ClusterConstraint other = (ClusterConstraint)with; 45 if(other._constraints.length != _constraints.length){ 46 throw new IllegalArgumentException (); 47 } 48 return other; 49 } 50 51 public Constraint and(Constraint with) { 52 return join(with, true); 53 } 54 55 public Constraint or(Constraint with) { 56 return join(with, false); 57 } 58 59 private Constraint join(Constraint with, boolean isAnd){ 60 synchronized(_cluster){ 61 ClusterConstraint other = compatible(with); 62 Constraint[] newConstraints = new Constraint[_constraints.length]; 63 for (int i = 0; i < _constraints.length; i++) { 64 newConstraints[i] = isAnd ? _constraints[i].and(other._constraints[i]) : _constraints[i].or(other._constraints[i]); 65 } 66 return new ClusterConstraint(_cluster, newConstraints); 67 } 68 } 69 70 71 public Constraint equal() { 72 synchronized(_cluster){ 73 for (int i = 0; i < _constraints.length; i++) { 74 _constraints[i].equal(); 75 } 76 return this; 77 } 78 } 79 80 public Constraint greater() { 81 synchronized(_cluster){ 82 for (int i = 0; i < _constraints.length; i++) { 83 _constraints[i].greater(); 84 } 85 return this; 86 } 87 } 88 89 public Constraint smaller() { 90 synchronized(_cluster){ 91 for (int i = 0; i < _constraints.length; i++) { 92 _constraints[i].smaller(); 93 } 94 return this; 95 } 96 } 97 98 public Constraint identity() { 99 synchronized(_cluster){ 100 for (int i = 0; i < _constraints.length; i++) { 101 _constraints[i].identity(); 102 } 103 return this; 104 } 105 } 106 107 public Constraint like() { 108 synchronized(_cluster){ 109 for (int i = 0; i < _constraints.length; i++) { 110 _constraints[i].like(); 111 } 112 return this; 113 } 114 } 115 116 public Constraint startsWith(boolean caseSensitive) { 117 synchronized(_cluster){ 118 for (int i = 0; i < _constraints.length; i++) { 119 _constraints[i].startsWith(caseSensitive); 120 } 121 return this; 122 } 123 } 124 125 public Constraint endsWith(boolean caseSensitive) { 126 synchronized(_cluster){ 127 for (int i = 0; i < _constraints.length; i++) { 128 _constraints[i].endsWith(caseSensitive); 129 } 130 return this; 131 } 132 } 133 134 public Constraint contains() { 135 synchronized(_cluster){ 136 for (int i = 0; i < _constraints.length; i++) { 137 _constraints[i].contains(); 138 } 139 return this; 140 } 141 } 142 143 public Constraint not() { 144 synchronized(_cluster){ 145 for (int i = 0; i < _constraints.length; i++) { 146 _constraints[i].not(); 147 } 148 return this; 149 } 150 } 151 152 public Object getObject() { 153 throw new NotSupportedException(); 154 } 155 } 156 | Popular Tags |