You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/19 23:35:07 UTC
svn commit: r423615 [8/44] - in /incubator/openjpa/trunk: ./ openjpa-jdbc-5/
openjpa-jdbc-5/src/ openjpa-jdbc-5/src/main/ openjpa-jdbc-5/src/main/java/
openjpa-jdbc-5/src/main/java/org/ openjpa-jdbc-5/src/main/java/org/apache/
openjpa-jdbc-5/src/main/j...
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Tests whether a value is IN a map value collection.
+ *
+ * @author Abe White
+ */
+class InValueExpression
+ extends InExpression {
+
+ /**
+ * Constructor. Supply the value to test and the constant to obtain
+ * the parameters from.
+ */
+ public InValueExpression(Val val, Const constant) {
+ super(val, constant);
+ }
+
+ /**
+ * Return the collection to test for containment with.
+ */
+ protected Collection getCollection() {
+ Map map = (Map) getConst().getValue();
+ return (map == null) ? null : map.values();
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.sql.SQLException;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.Result;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.kernel.Filters;
+import org.apache.openjpa.meta.ClassMetaData;
+
+/**
+ * Find the index of one string within another.
+ *
+ * @author Abe White
+ */
+class IndexOf
+ extends AbstractVal
+ implements Val {
+
+ private final Val _val1;
+ private final Val _val2;
+ private Joins _joins = null;
+ private ClassMetaData _meta = null;
+ private Class _cast = null;
+
+ /**
+ * Constructor. Provide the strings to operate on.
+ */
+ public IndexOf(Val val1, Val val2) {
+ _val1 = val1;
+ _val2 = val2;
+ }
+
+ public ClassMetaData getMetaData() {
+ return _meta;
+ }
+
+ public void setMetaData(ClassMetaData meta) {
+ _meta = meta;
+ }
+
+ public boolean isVariable() {
+ return false;
+ }
+
+ public Class getType() {
+ if (_cast != null)
+ return _cast;
+ return int.class;
+ }
+
+ public void setImplicitType(Class type) {
+ _cast = type;
+ }
+
+ public void initialize(Select sel, JDBCStore store, boolean nullTest) {
+ _val1.initialize(sel, store, false);
+ _val2.initialize(sel, store, false);
+ _joins = sel.and(_val1.getJoins(), _val2.getJoins());
+ }
+
+ public Joins getJoins() {
+ return _joins;
+ }
+
+ public Object toDataStoreValue(Object val, JDBCStore store) {
+ return val;
+ }
+
+ public void select(Select sel, JDBCStore store, Object[] params,
+ boolean pks, JDBCFetchState fetchState) {
+ sel.select(newSQLBuffer(sel, store, params, fetchState), this);
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _val1.selectColumns(sel, store, params, true, fetchState);
+ _val2.selectColumns(sel, store, params, true, fetchState);
+ }
+
+ public void groupBy(Select sel, JDBCStore store, Object[] params,
+ JDBCFetchState fetchState) {
+ sel.groupBy(newSQLBuffer(sel, store, params, fetchState), false);
+ }
+
+ public void orderBy(Select sel, JDBCStore store, Object[] params,
+ boolean asc, JDBCFetchState fetchState) {
+ sel.orderBy(newSQLBuffer(sel, store, params, fetchState), asc, false);
+ }
+
+ private SQLBuffer newSQLBuffer(Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ calculateValue(sel, store, params, null, fetchState);
+ SQLBuffer buf = new SQLBuffer(store.getDBDictionary());
+ appendTo(buf, 0, sel, store, params, fetchState);
+ clearParameters();
+ return buf;
+ }
+
+ public Object load(Result res, JDBCStore store,
+ JDBCFetchState fetchState)
+ throws SQLException {
+ return Filters.convert(res.getObject(this,
+ JavaSQLTypes.JDBC_DEFAULT, null), getType());
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _val1.hasVariable(var) || _val2.hasVariable(var);
+ }
+
+ public void calculateValue(Select sel, JDBCStore store,
+ Object[] params, Val other, JDBCFetchState fetchState) {
+ _val1.calculateValue(sel, store, params, null, fetchState);
+ _val2.calculateValue(sel, store, params, null, fetchState);
+ }
+
+ public void clearParameters() {
+ _val1.clearParameters();
+ _val2.clearParameters();
+ }
+
+ public int length() {
+ return 1;
+ }
+
+ public void appendTo(SQLBuffer sql, int index, Select sel,
+ JDBCStore store, Object[] params, JDBCFetchState fetchState) {
+ FilterValue str = new FilterValueImpl(_val1, sel, store, params,
+ fetchState);
+ FilterValue search;
+ FilterValue start = null;
+ if (_val2 instanceof Args) {
+ Val[] args = ((Args) _val2).getVals();
+ search =
+ new FilterValueImpl(args[0], sel, store, params, fetchState);
+ start =
+ new FilterValueImpl(args[1], sel, store, params, fetchState);
+ } else
+ search = new FilterValueImpl(_val2, sel, store, params, fetchState);
+
+ store.getDBDictionary().indexOf(sql, str, search, start);
+ }
+}
+
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.Discriminator;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.MappingRepository;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.meta.JavaTypes;
+
+/**
+ * Tests whether the given path is an instance of the given class.
+ *
+ * @author Abe White
+ */
+class InstanceofExpression
+ implements Exp {
+
+ private final PCPath _path;
+ private final Class _cls;
+ private Joins _joins = null;
+ private Discriminator _dsc = null;
+ private Class _relCls = null;
+ private ClassMapping _mapping = null;
+
+ /**
+ * Constructor. Supply path and class to test for.
+ */
+ public InstanceofExpression(PCPath path, Class cls) {
+ _path = path;
+ _cls = cls;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ Object[] params, Map contains) {
+ // note that we tell the path to go ahead and join to its related
+ // object (if any) in order to access its class indicator
+ _path.initialize(sel, store, false);
+ _path.joinRelation();
+ _joins = _path.getJoins();
+
+ // does this path represent a relation? if not, what class
+ // is the field?
+ ClassMapping rel = _path.getClassMapping();
+ if (rel == null) {
+ FieldMapping field = _path.getFieldMapping();
+ switch (field.getTypeCode()) {
+ case JavaTypes.MAP:
+ if (_path.isKey())
+ _relCls = field.getKey().getDeclaredType();
+ // no break
+ case JavaTypes.ARRAY:
+ case JavaTypes.COLLECTION:
+ _relCls = field.getElement().getDeclaredType();
+ break;
+ default:
+ _relCls = field.getDeclaredType();
+ }
+ } else
+ _relCls = rel.getDescribedType();
+
+ // if the path represents a relation, get its class indicator and
+ // make sure it's joined down to its base type
+ _dsc = (rel == null || !rel.getDescribedType().isAssignableFrom(_cls))
+ ? null : rel.getDiscriminator();
+ if (_dsc != null) {
+ // cache mapping for cast
+ MappingRepository repos = store.getConfiguration().
+ getMappingRepository();
+ _mapping = repos.getMapping(_cls, store.getContext().
+ getClassLoader(), false);
+
+ // if not looking for a PC, don't bother with indicator
+ if (_mapping == null)
+ _dsc = null;
+ else {
+ ClassMapping owner = _dsc.getClassMapping();
+ ClassMapping from, to;
+ if (rel.getDescribedType().isAssignableFrom
+ (owner.getDescribedType())) {
+ from = owner;
+ to = rel;
+ } else {
+ from = rel;
+ to = owner;
+ }
+
+ for (; from != null && from != to;
+ from = from.getJoinablePCSuperclassMapping())
+ _joins = from.joinSuperclass(_joins, false);
+ }
+ }
+ }
+
+ public void appendTo(SQLBuffer sql, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ // if no class indicator or a final class, just append true or false
+ // depending on whether the cast matches the expected type
+ if (_dsc == null) {
+ if (_cls.isAssignableFrom(_relCls))
+ sql.append("1 = 1");
+ else
+ sql.append("1 <> 1");
+ } else {
+ store.loadSubclasses(_dsc.getClassMapping());
+ SQLBuffer buf = _dsc.getClassConditions(store, sel, _joins,
+ _mapping, true);
+ if (buf == null)
+ sql.append("1 = 1");
+ else
+ sql.append(buf);
+ }
+ sel.append(sql, _joins);
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ if (_dsc != null)
+ sel.select(_dsc.getColumns(), _joins);
+ }
+
+ public Joins getJoins() {
+ return _joins;
+ }
+
+ public boolean hasContainsExpression() {
+ return false;
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _path.hasVariable(var);
+ }
+}
+
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Tests whether the given value is empty.
+ *
+ * @author Abe White
+ */
+class IsEmptyExpression
+ implements Exp {
+
+ private final Val _val;
+
+ /**
+ * Constructor. Supply value to test.
+ */
+ public IsEmptyExpression(Val val) {
+ _val = val;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ Object[] params, Map contains) {
+ _val.initialize(sel, store, true);
+ }
+
+ public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ _val.calculateValue(sel, store, params, null, fetchState);
+ _val.appendIsEmpty(buf, sel, store, params, fetchState);
+ sel.append(buf, _val.getJoins());
+ _val.clearParameters();
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _val.selectColumns(sel, store, params, true, fetchState);
+ }
+
+ public Joins getJoins() {
+ return _val.getJoins();
+ }
+
+ public boolean hasContainsExpression() {
+ return false;
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _val.hasVariable(var);
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Tests whether the given value is not empty.
+ *
+ * @author Marc Prud'hommeaux
+ */
+class IsNotEmptyExpression
+ implements Exp {
+
+ private final Val _val;
+
+ /**
+ * Constructor. Supply value to test.
+ */
+ public IsNotEmptyExpression(Val val) {
+ _val = val;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ Object[] params, Map contains) {
+ _val.initialize(sel, store, true);
+ }
+
+ public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ _val.calculateValue(sel, store, params, null, fetchState);
+ _val.appendIsNotEmpty(buf, sel, store, params, fetchState);
+ sel.append(buf, _val.getJoins());
+ _val.clearParameters();
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _val.selectColumns(sel, store, params, true, fetchState);
+ }
+
+ public Joins getJoins() {
+ return _val.getJoins();
+ }
+
+ public boolean hasContainsExpression() {
+ return false;
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _val.hasVariable(var);
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCAggregateListener.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCAggregateListener.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCAggregateListener.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCAggregateListener.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.kernel.exps.AggregateListener;
+
+/**
+ * JDBC extension to the {@link AggregateListener}.
+ *
+ * @author Abe White
+ */
+public interface JDBCAggregateListener
+ extends AggregateListener {
+
+ /**
+ * Append the SQL for this aggregate.
+ *
+ * @param buf the SQL buffer to append to
+ * @param args the values of the arguments given in the filter, or
+ * null if this listener doesn't expect arguments
+ * @param mapping the class mapping for the query's candidate class
+ * @param store the store that owns the query
+ */
+ public void appendTo(SQLBuffer buf, FilterValue[] args,
+ ClassMapping mapping, JDBCStore store);
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCAggregateListener.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,450 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.commons.collections.map.LinkedMap;
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStoreQuery;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.kernel.exps.AggregateListener;
+import org.apache.openjpa.kernel.exps.Arguments;
+import org.apache.openjpa.kernel.exps.Expression;
+import org.apache.openjpa.kernel.exps.ExpressionFactory;
+import org.apache.openjpa.kernel.exps.FilterListener;
+import org.apache.openjpa.kernel.exps.Literal;
+import org.apache.openjpa.kernel.exps.Parameter;
+import org.apache.openjpa.kernel.exps.Path;
+import org.apache.openjpa.kernel.exps.QueryExpressions;
+import org.apache.openjpa.kernel.exps.Subquery;
+import org.apache.openjpa.kernel.exps.Value;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.util.ImplHelper;
+import org.apache.openjpa.util.UserException;
+
+/**
+ * Expression factory implementation that can be used to execute queries
+ * via SQL.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
+public class JDBCExpressionFactory
+ implements ExpressionFactory {
+
+ private static final int CACHE_NULL = 0;
+ private static final int CACHE_JOINS = 1;
+ private static final int CACHE_FULL = 2;
+
+ private static final Val NULL = new Null();
+ private static final Val CURRENT_DATE =
+ new CurrentDate(CurrentDate.DATE);
+ private static final Val CURRENT_TIME =
+ new CurrentDate(CurrentDate.TIME);
+ private static final Val CURRENT_TIMESTAMP =
+ new CurrentDate(CurrentDate.TIMESTAMP);
+
+ private static final Localizer _loc = Localizer.forPackage
+ (JDBCExpressionFactory.class);
+
+ private final ClassMapping _type;
+ private final SelectConstructor _cons = new SelectConstructor();
+
+ /**
+ * Constructor. Supply the type we're querying against.
+ */
+ public JDBCExpressionFactory(ClassMapping type) {
+ _type = type;
+ }
+
+ /**
+ * Evaluate the expression, returning a SQL select with the proper
+ * conditions. Use {@link #select} to then select the data.
+ * This method returns null if there is no query criteria. It is
+ * synchronized because factories may be cached and used by multiple
+ * queries at the same time.
+ */
+ public synchronized Select evaluate(JDBCStoreQuery q,
+ JDBCFetchState fetchState, QueryExpressions exps, Object[] params) {
+ // figure out proper cache level based on parameters
+ int level = getCacheLevel(q, params);
+ return _cons.evaluate(q.getStore(), null, null, exps, params,
+ level, fetchState);
+ }
+
+ /**
+ * Return the cache level for this query. The level depends on whether
+ * the query uses any params, as well as the types and values of those
+ * params.
+ */
+ private int getCacheLevel(JDBCStoreQuery q, Object[] params) {
+ // if there are no parameters, we can cache the full SQL
+ if (params.length == 0)
+ return SelectConstructor.CACHE_FULL;
+
+ // if there is a null PC parameter, we have to cache differently
+ // since it affects joins
+ LinkedMap types = null;
+ Class type;
+ for (int i = 0; i < params.length; i++) {
+ if (params[i] != null)
+ continue;
+
+ if (types == null)
+ types = q.getContext().getParameterTypes();
+
+ type = (Class) types.getValue(i);
+ if (type != null && ImplHelper.isManagedType(type))
+ return SelectConstructor.CACHE_NULL;
+ }
+ return SelectConstructor.CACHE_JOINS;
+ }
+
+ /**
+ * Select the data for this query.
+ */
+ public void select(JDBCStoreQuery q, ClassMapping mapping,
+ boolean subclasses, Select sel, QueryExpressions exps,
+ Object[] params, JDBCFetchState fetchState, int eager) {
+ _cons.select(q.getStore(), mapping, subclasses, sel, exps,
+ params, fetchState, eager);
+ }
+
+ public Expression emptyExpression() {
+ return new EmptyExpression();
+ }
+
+ public Expression asExpression(Value v) {
+ return equal(v, newLiteral(Boolean.TRUE, Literal.TYPE_BOOLEAN));
+ }
+
+ public Expression equal(Value v1, Value v2) {
+ // if we're comparing an unaccessed bound variable, like in:
+ // coll.contains (var) && var == x, then translate into:
+ // coll.contains (x)
+ if (v1 instanceof PCPath && ((PCPath) v1).isUnaccessedVariable())
+ return contains(v1, v2);
+ if (v2 instanceof PCPath && ((PCPath) v2).isUnaccessedVariable())
+ return contains(v2, v1);
+ return new EqualExpression((Val) v1, (Val) v2);
+ }
+
+ public Expression notEqual(Value v1, Value v2) {
+ return new NotEqualExpression((Val) v1, (Val) v2);
+ }
+
+ public Expression lessThan(Value v1, Value v2) {
+ return new CompareExpression((Val) v1, (Val) v2,
+ CompareExpression.LESS);
+ }
+
+ public Expression greaterThan(Value v1, Value v2) {
+ return new CompareExpression((Val) v1, (Val) v2,
+ CompareExpression.GREATER);
+ }
+
+ public Expression lessThanEqual(Value v1, Value v2) {
+ return new CompareExpression((Val) v1, (Val) v2,
+ CompareExpression.LESS_EQUAL);
+ }
+
+ public Expression greaterThanEqual(Value v1, Value v2) {
+ return new CompareExpression((Val) v1, (Val) v2,
+ CompareExpression.GREATER_EQUAL);
+ }
+
+ public Expression isEmpty(Value val) {
+ return new IsEmptyExpression((Val) val);
+ }
+
+ public Expression isNotEmpty(Value val) {
+ return new IsNotEmptyExpression((Val) val);
+ }
+
+ public Expression contains(Value v1, Value v2) {
+ if (v1 instanceof Const)
+ return new InExpression((Val) v2, (Const) v1);
+ if (v1 instanceof SubQ)
+ return new InSubQExpression((Val) v2, (SubQ) v1);
+ return new ContainsExpression((Val) v1, (Val) v2);
+ }
+
+ public Expression containsKey(Value v1, Value v2) {
+ if (v1 instanceof Const)
+ return new InKeyExpression((Val) v2, (Const) v1);
+ return new ContainsKeyExpression((Val) v1, (Val) v2);
+ }
+
+ public Expression containsValue(Value v1, Value v2) {
+ if (v1 instanceof Const)
+ return new InValueExpression((Val) v2, (Const) v1);
+ return new ContainsExpression((Val) v1, (Val) v2);
+ }
+
+ public Expression isInstance(Value val, Class c) {
+ if (val instanceof Const)
+ return new ConstInstanceofExpression((Const) val, c);
+ return new InstanceofExpression((PCPath) val, c);
+ }
+
+ public Expression and(Expression exp1, Expression exp2) {
+ if (exp1 instanceof BindVariableExpression)
+ return new BindVariableAndExpression((BindVariableExpression) exp1,
+ (Exp) exp2);
+ if (exp2 instanceof BindVariableExpression)
+ return new BindVariableAndExpression((BindVariableExpression) exp2,
+ (Exp) exp1);
+ return new AndExpression((Exp) exp1, (Exp) exp2);
+ }
+
+ public Expression or(Expression exp1, Expression exp2) {
+ return new OrExpression((Exp) exp1, (Exp) exp2);
+ }
+
+ public Expression not(Expression exp) {
+ Exp e = (Exp) exp;
+ if (e.hasContainsExpression())
+ return new NotContainsExpression(e);
+ return new NotExpression(e);
+ }
+
+ public Expression bindVariable(Value var, Value val) {
+ // handle the strange case of using a constant path to bind a
+ // variable; in these cases the variable acts like an unbound
+ // variable that we limit by using an IN clause on the constant
+ // value collection
+ if (val instanceof Const) {
+ PCPath path = new PCPath(_type, (Variable) var);
+ path.setMetaData(var.getMetaData());
+ return new InExpression(path, (Const) val);
+ }
+ return new BindVariableExpression((Variable) var, (PCPath) val, false);
+ }
+
+ public Expression bindKeyVariable(Value var, Value val) {
+ // handle the strange case of using a constant path to bind a
+ // variable; in these cases the variable acts like an unbound
+ // variable that we limit by using an IN clause on the constant
+ // value collection
+ if (val instanceof Const) {
+ PCPath path = new PCPath(_type, (Variable) var);
+ path.setMetaData(var.getMetaData());
+ return new InKeyExpression(path, (Const) val);
+ }
+ return new BindVariableExpression((Variable) var, (PCPath) val, true);
+ }
+
+ public Expression bindValueVariable(Value var, Value val) {
+ return bindVariable(var, val);
+ }
+
+ public Expression startsWith(Value v1, Value v2) {
+ return new StartsWithExpression((Val) v1, (Val) v2);
+ }
+
+ public Expression endsWith(Value v1, Value v2) {
+ return new EndsWithExpression((Val) v1, (Val) v2);
+ }
+
+ public Expression notMatches(Value v1, Value v2,
+ String single, String multi, String esc) {
+ return not(matches(v1, v2, single, multi, esc));
+ }
+
+ public Expression matches(Value v1, Value v2,
+ String single, String multi, String esc) {
+ if (!(v2 instanceof Const))
+ throw new UserException(_loc.get("const-only", "matches"));
+ return new MatchesExpression((Val) v1, (Const) v2, single, multi,
+ esc != null ? esc : _type.getMappingRepository().
+ getDBDictionary().searchStringEscape);
+ }
+
+ public Subquery newSubquery(ClassMetaData candidate, boolean subs,
+ String alias) {
+ DBDictionary dict = _type.getMappingRepository().getDBDictionary();
+ dict.assertSupport(dict.supportsSubselect, "SupportsSubselect");
+ return new SubQ((ClassMapping) candidate, subs, alias);
+ }
+
+ public Path newPath() {
+ return new PCPath(_type);
+ }
+
+ public Path newPath(Value val) {
+ if (val instanceof Const)
+ return new ConstPath((Const) val);
+ if (val instanceof SubQ)
+ return new PCPath((SubQ) val);
+ return new PCPath(_type, (Variable) val);
+ }
+
+ public Literal newLiteral(Object val, int ptype) {
+ return new Lit(val, ptype);
+ }
+
+ public Value getThis() {
+ return new PCPath(_type);
+ }
+
+ public Value getNull() {
+ return NULL;
+ }
+
+ public Value getCurrentDate() {
+ return CURRENT_DATE;
+ }
+
+ public Value getCurrentTime() {
+ return CURRENT_TIME;
+ }
+
+ public Value getCurrentTimestamp() {
+ return CURRENT_TIMESTAMP;
+ }
+
+ public Parameter newParameter(String name, Class type) {
+ return new Param(name, type);
+ }
+
+ public Value newExtension(FilterListener listener, Value target,
+ Value arg) {
+ return new Extension((JDBCFilterListener) listener,
+ (Val) target, (Val) arg, _type);
+ }
+
+ public Value newAggregate(AggregateListener listener, Value arg) {
+ return new Aggregate((JDBCAggregateListener) listener,
+ (Val) arg, _type);
+ }
+
+ public Arguments newArgumentList(Value v1, Value v2) {
+ return new Args((Val) v1, (Val) v2);
+ }
+
+ public Value newUnboundVariable(String name, Class type) {
+ return new Variable(name, type);
+ }
+
+ public Value newBoundVariable(String name, Class type) {
+ return newUnboundVariable(name, type);
+ }
+
+ public Value cast(Value val, Class cls) {
+ val.setImplicitType(cls);
+ return val;
+ }
+
+ public Value add(Value v1, Value v2) {
+ return new Math((Val) v1, (Val) v2, Math.ADD);
+ }
+
+ public Value subtract(Value v1, Value v2) {
+ return new Math((Val) v1, (Val) v2, Math.SUBTRACT);
+ }
+
+ public Value multiply(Value v1, Value v2) {
+ return new Math((Val) v1, (Val) v2, Math.MULTIPLY);
+ }
+
+ public Value divide(Value v1, Value v2) {
+ return new Math((Val) v1, (Val) v2, Math.DIVIDE);
+ }
+
+ public Value mod(Value v1, Value v2) {
+ return new Math((Val) v1, (Val) v2, Math.MOD);
+ }
+
+ public Value abs(Value val) {
+ return new Abs((Val) val);
+ }
+
+ public Value indexOf(Value v1, Value v2) {
+ return new IndexOf((Val) v1, (Val) v2);
+ }
+
+ public Value concat(Value v1, Value v2) {
+ return new Concat((Val) v1, (Val) v2);
+ }
+
+ public Value stringLength(Value str) {
+ return new StringLength((Val) str);
+ }
+
+ public Value trim(Value str, Value trimChar, Boolean where) {
+ return new Trim((Val) str, (Val) trimChar, where);
+ }
+
+ public Value sqrt(Value val) {
+ return new Sqrt((Val) val);
+ }
+
+ public Value substring(Value v1, Value v2) {
+ return new Substring((Val) v1, (Val) v2);
+ }
+
+ public Value toUpperCase(Value val) {
+ return new ToUpperCase((Val) val);
+ }
+
+ public Value toLowerCase(Value val) {
+ return new ToLowerCase((Val) val);
+ }
+
+ public Value avg(Value val) {
+ return new Avg((Val) val);
+ }
+
+ public Value count(Value val) {
+ return new Count((Val) val);
+ }
+
+ public Value distinct(Value val) {
+ return new Distinct((Val) val);
+ }
+
+ public Value max(Value val) {
+ return new Max((Val) val);
+ }
+
+ public Value min(Value val) {
+ return new Min((Val) val);
+ }
+
+ public Value sum(Value val) {
+ return new Sum((Val) val);
+ }
+
+ public Value any(Value val) {
+ return new Any((Val) val);
+ }
+
+ public Value all(Value val) {
+ return new All((Val) val);
+ }
+
+ public Value size(Value val) {
+ return new Size((Val) val);
+ }
+
+ public Value getObjectId(Value val) {
+ if (val instanceof Const)
+ return new ConstGetObjectId((Const) val);
+ return new GetObjectId((PCPath) val);
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCFilterListener.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCFilterListener.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCFilterListener.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCFilterListener.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.kernel.exps.FilterListener;
+
+/**
+ * JDBC extension to the {@link FilterListener}.
+ *
+ * @author Abe White
+ */
+public interface JDBCFilterListener
+ extends FilterListener {
+
+ /**
+ * Append the SQL for this expression or value.
+ *
+ * @param buf the SQL buffer to append to
+ * @param target the target to act on, or null if the listener
+ * doesn't expect a target
+ * @param args the values of the arguments given in the filter, or
+ * null if this listener doesn't expect arguments
+ * @param mapping the class mapping for the query's candidate class
+ * @param store the store that owns the query
+ */
+ public void appendTo(SQLBuffer buf, FilterValue target, FilterValue[] args,
+ ClassMapping mapping, JDBCStore store);
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCFilterListener.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCPath.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCPath.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCPath.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCPath.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.kernel.exps.Path;
+
+/**
+ * A path represents a traversal into fields of a candidate object.
+ *
+ * @author Abe White
+ */
+interface JDBCPath
+ extends Path, Val {
+
+ public void getKey();
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCPath.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCStringContains.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCStringContains.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCStringContains.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCStringContains.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.kernel.exps.StringContains;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.util.UserException;
+
+/**
+ * Tests if the target contains the given argument. The argument must be
+ * a constant.
+ * Examples:<br />
+ * <code> "address.street.ext:stringContains (\"main\")"
+ * </code>
+ *
+ * @nojavadoc
+ * @deprecated Use <code>matches()</code> instead.
+ */
+public class JDBCStringContains
+ extends StringContains
+ implements JDBCFilterListener {
+
+ private static final Localizer _loc = Localizer.forPackage
+ (JDBCStringContains.class);
+
+ public void appendTo(SQLBuffer buf, FilterValue target, FilterValue[] args,
+ ClassMapping type, JDBCStore store) {
+ if (!args[0].isConstant())
+ throw new UserException(_loc.get("const-only", TAG));
+
+ Object val = args[0].getValue();
+ target.appendTo(buf);
+ if (val == null)
+ buf.append(" IS ").appendValue(null);
+ else
+ buf.append(" LIKE ").appendValue("%" + val + "%");
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCStringContains.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCWildcardMatch.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCWildcardMatch.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCWildcardMatch.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCWildcardMatch.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.kernel.exps.WildcardMatch;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.util.UserException;
+
+/**
+ * Tests if the target matches the wildcard expression given in the
+ * argument. The wildcard '?' is used to represent any single character,
+ * while '*' is used to represent any series of 0 or more characters.
+ * Examples:<br />
+ * <code> "address.street.ext:wildcardMatch (\"?ain*reet\")"
+ * </code>
+ *
+ * @nojavadoc
+ * @deprecated Use <code>matches()</code> instead.
+ */
+public class JDBCWildcardMatch
+ extends WildcardMatch
+ implements JDBCFilterListener {
+
+ private static final Localizer _loc = Localizer.forPackage
+ (JDBCWildcardMatch.class);
+
+ public void appendTo(SQLBuffer sql, FilterValue target, FilterValue[] args,
+ ClassMapping type, JDBCStore store) {
+ if (!args[0].isConstant())
+ throw new UserException(_loc.get("const-only", TAG));
+
+ Object val = args[0].getValue();
+ target.appendTo(sql);
+ if (val == null)
+ sql.append(" IS ").appendValue(null);
+ else {
+ // create a DB wildcard string by replacing '*' with '%' and
+ // '?' with '_'
+ String wild = val.toString().replace('*', '%').replace('?', '_');
+ sql.append(" LIKE ").appendValue(wild);
+ }
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCWildcardMatch.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.kernel.Filters;
+import org.apache.openjpa.kernel.exps.Literal;
+
+/**
+ * A literal value in a filter.
+ *
+ * @author Abe White
+ */
+class Lit
+ extends Const
+ implements Literal {
+
+ private Object _val;
+ private int _ptype;
+ private Object _sqlVal = null;
+ private int _otherLen = 0;
+
+ /**
+ * Constructor. Supply literal value.
+ */
+ public Lit(Object val, int ptype) {
+ _val = val;
+ _ptype = ptype;
+ }
+
+ public Class getType() {
+ return (_val == null) ? Object.class : _val.getClass();
+ }
+
+ public void setImplicitType(Class type) {
+ _val = Filters.convert(_val, type);
+ }
+
+ public int getParseType() {
+ return _ptype;
+ }
+
+ public Object getValue() {
+ return _val;
+ }
+
+ public void setValue(Object val) {
+ _val = val;
+ }
+
+ public void calculateValue(Select sel, JDBCStore store,
+ Object[] params, Val other, JDBCFetchState fetchState) {
+ super.calculateValue(sel, store, params, other, fetchState);
+ if (other != null) {
+ _sqlVal = other.toDataStoreValue(_val, store);
+ _otherLen = other.length();
+ } else
+ _sqlVal = _val;
+ }
+
+ public void appendTo(SQLBuffer sql, int index, Select sel,
+ JDBCStore store, Object[] params, JDBCFetchState fetchState) {
+ if (_otherLen > 1)
+ sql.appendValue(((Object[]) _sqlVal)[index], getColumn(index));
+ else
+ sql.appendValue(_sqlVal, getColumn(index));
+ }
+
+ public void clearParameters() {
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+import serp.util.Strings;
+
+/**
+ * Test if a string matches a regexp.
+ *
+ * @author Abe White
+ */
+class MatchesExpression
+ implements Exp {
+
+ private final Val _val;
+ private final Const _const;
+ private final String _single;
+ private final String _multi;
+ private final String _escape;
+ private Joins _joins = null;
+
+ /**
+ * Constructor. Supply values.
+ */
+ public MatchesExpression(Val val, Const con,
+ String single, String multi, String escape) {
+ _val = val;
+ _const = con;
+ _single = single;
+ _multi = multi;
+ _escape = escape;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ Object[] params, Map contains) {
+ _val.initialize(sel, store, false);
+ _const.initialize(sel, store, false);
+ _joins = sel.and(_val.getJoins(), _const.getJoins());
+ }
+
+ public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ _val.calculateValue(sel, store, params, _const, fetchState);
+ _const.calculateValue(sel, store, params, _val, fetchState);
+
+ Column col = null;
+ if (_val instanceof PCPath) {
+ Column[] cols = ((PCPath) _val).getColumns();
+ if (cols.length == 1)
+ col = cols[0];
+ }
+
+ Object o = _const.getValue();
+ if (o == null)
+ buf.append("1 <> 1");
+ else {
+ // look for ignore case flag and strip it out if present
+ boolean ignoreCase = false;
+ String str = o.toString();
+ int idx = str.indexOf("(?i)");
+ if (idx != -1) {
+ ignoreCase = true;
+ if (idx + 4 < str.length())
+ str = str.substring(0, idx) + str.substring(idx + 4);
+ else
+ str = str.substring(0, idx);
+ str = str.toLowerCase();
+ }
+
+ // append target
+ if (ignoreCase)
+ buf.append("LOWER(");
+ _val.appendTo(buf, 0, sel, store, params, fetchState);
+ if (ignoreCase)
+ buf.append(")");
+
+ // create a DB wildcard string by replacing the
+ // multi token (e.g., '.*') and the single token (e.g., ".")
+ // with '%' and '.' with '_'
+ str = Strings.replace(str, _multi, "%");
+ str = Strings.replace(str, _single, "_");
+
+ buf.append(" LIKE ").appendValue(str, col);
+
+ // escape out characters by using the database's escape sequence
+ if (_escape != null)
+ buf.append(" ESCAPE '").append(_escape).append("'");
+ }
+ sel.append(buf, _joins);
+
+ _val.clearParameters();
+ _const.clearParameters();
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _val.selectColumns(sel, store, params, true, fetchState);
+ _const.selectColumns(sel, store, params, true, fetchState);
+ }
+
+ public Joins getJoins() {
+ return _joins;
+ }
+
+ public boolean hasContainsExpression() {
+ return false;
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _val.hasVariable(var) || _const.hasVariable(var);
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.sql.SQLException;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.Result;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.kernel.Filters;
+import org.apache.openjpa.meta.ClassMetaData;
+
+/**
+ * Value produced by a mathematical operation on two values.
+ *
+ * @author Abe White
+ */
+class Math
+ extends AbstractVal
+ implements Val {
+
+ public static final String ADD = "+";
+ public static final String SUBTRACT = "-";
+ public static final String MULTIPLY = "*";
+ public static final String DIVIDE = "/";
+ public static final String MOD = "MOD";
+
+ private final Val _val1;
+ private final Val _val2;
+ private final String _op;
+ private Joins _joins = null;
+ private ClassMetaData _meta = null;
+ private Class _cast = null;
+
+ /**
+ * Constructor. Provide the values to operate on, and the operator.
+ */
+ public Math(Val val1, Val val2, String op) {
+ _val1 = val1;
+ _val2 = val2;
+ _op = op;
+ }
+
+ public ClassMetaData getMetaData() {
+ return _meta;
+ }
+
+ public void setMetaData(ClassMetaData meta) {
+ _meta = meta;
+ }
+
+ public boolean isVariable() {
+ return false;
+ }
+
+ public Class getType() {
+ if (_cast != null)
+ return _cast;
+ Class c1 = _val1.getType();
+ Class c2 = _val2.getType();
+ return Filters.promote(c1, c2);
+ }
+
+ public void setImplicitType(Class type) {
+ _cast = type;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ boolean nullTest) {
+ _val1.initialize(sel, store, false);
+ _val2.initialize(sel, store, false);
+ _joins = sel.and(_val1.getJoins(), _val2.getJoins());
+ }
+
+ public Joins getJoins() {
+ return _joins;
+ }
+
+ public Object toDataStoreValue(Object val, JDBCStore store) {
+ return val;
+ }
+
+ public void select(Select sel, JDBCStore store, Object[] params,
+ boolean pks, JDBCFetchState fetchState) {
+ sel.select(newSQLBuffer(sel, store, params, fetchState), this);
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _val1.selectColumns(sel, store, params, true, fetchState);
+ _val2.selectColumns(sel, store, params, true, fetchState);
+ }
+
+ public void groupBy(Select sel, JDBCStore store, Object[] params,
+ JDBCFetchState fetchState) {
+ sel.groupBy(newSQLBuffer(sel, store, params, fetchState), false);
+ }
+
+ public void orderBy(Select sel, JDBCStore store, Object[] params,
+ boolean asc, JDBCFetchState fetchState) {
+ sel.orderBy(newSQLBuffer(sel, store, params, fetchState), asc, false);
+ }
+
+ private SQLBuffer newSQLBuffer(Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ calculateValue(sel, store, params, null, fetchState);
+ SQLBuffer buf = new SQLBuffer(store.getDBDictionary());
+ appendTo(buf, 0, sel, store, params, fetchState);
+ clearParameters();
+ return buf;
+ }
+
+ public Object load(Result res, JDBCStore store,
+ JDBCFetchState fetchState)
+ throws SQLException {
+ return Filters.convert(res.getObject(this,
+ JavaSQLTypes.JDBC_DEFAULT, null), getType());
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _val1.hasVariable(var) || _val2.hasVariable(var);
+ }
+
+ public void calculateValue(Select sel, JDBCStore store,
+ Object[] params, Val other, JDBCFetchState fetchState) {
+ _val1.calculateValue(sel, store, params, _val2, fetchState);
+ _val2.calculateValue(sel, store, params, _val1, fetchState);
+ }
+
+ public void clearParameters() {
+ _val1.clearParameters();
+ _val2.clearParameters();
+ }
+
+ public int length() {
+ return 1;
+ }
+
+ public void appendTo(SQLBuffer sql, int index, Select sel,
+ JDBCStore store, Object[] params, JDBCFetchState fetchState) {
+ store.getDBDictionary().mathFunction(sql, _op,
+ new FilterValueImpl(_val1, sel, store, params, fetchState),
+ new FilterValueImpl(_val2, sel, store, params, fetchState));
+ }
+}
+
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Max.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Max.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Max.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Max.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+/**
+ * Maximum.
+ *
+ * @author Abe White
+ */
+class Max
+ extends UnaryOp {
+
+ /**
+ * Constructor. Provide the value to operate on.
+ */
+ public Max(Val val) {
+ super(val);
+ }
+
+ protected String getOperator() {
+ return "MAX";
+ }
+
+ protected boolean isAggregate() {
+ return true;
+ }
+}
+
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Max.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Min.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Min.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Min.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Min.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+/**
+ * Minimum.
+ *
+ * @author Abe White
+ */
+class Min
+ extends UnaryOp {
+
+ /**
+ * Constructor. Provide the value to operate on.
+ */
+ public Min(Val val) {
+ super(val);
+ }
+
+ protected String getOperator() {
+ return "MIN";
+ }
+
+ protected boolean isAggregate() {
+ return true;
+ }
+}
+
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Min.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Negates a contains expression using a subselect to make sure no
+ * elements meet the criteria.
+ *
+ * @author Abe White
+ */
+class NotContainsExpression
+ implements Exp {
+
+ private final Exp _exp;
+ private Map _contains = null;
+
+ /**
+ * Constructor. Supply the expression to negate.
+ */
+ public NotContainsExpression(Exp exp) {
+ _exp = exp;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ Object[] params, Map contains) {
+ _contains = contains;
+ }
+
+ public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ DBDictionary dict = store.getDBDictionary();
+ dict.assertSupport(dict.supportsSubselect, "SupportsSubselect");
+
+ Select sub = store.getSQLFactory().newSelect();
+ sub.setParent(sel, null);
+ _exp.initialize(sub, store, params, _contains);
+ sub.where(sub.and(null, _exp.getJoins()));
+
+ SQLBuffer where = new SQLBuffer(dict).append("(");
+ _exp.appendTo(where, sub, store, params, fetchState);
+ if (where.getSQL().length() > 1)
+ sub.where(where.append(")"));
+
+ buf.append("0 = ");
+ buf.appendCount(sub, fetchState.getJDBCFetchConfiguration());
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _exp.selectColumns(sel, store, params, true, fetchState);
+ }
+
+ public Joins getJoins() {
+ return null;
+ }
+
+ public boolean hasContainsExpression() {
+ return false;
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _exp.hasVariable(var);
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Compares two values.
+ *
+ * @author Abe White
+ */
+class NotEqualExpression
+ extends CompareEqualExpression {
+
+ /**
+ * Constructor. Supply values to compare.
+ */
+ public NotEqualExpression(Val val1, Val val2) {
+ super(val1, val2);
+ }
+
+ public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState, boolean val1Null,
+ boolean val2Null) {
+ if (val1Null && val2Null)
+ buf.appendValue(null).append(" IS NOT ").appendValue(null);
+ else if (val1Null || val2Null) {
+ Val val = (val1Null) ? getValue2() : getValue1();
+ if (!isDirectComparison()) {
+ int len = val.length();
+ for (int i = 0; i < len; i++) {
+ if (i > 0)
+ buf.append(" AND ");
+ val.appendTo(buf, i, sel, store, params, fetchState);
+ buf.append(" IS NOT ").appendValue(null);
+ }
+ } else
+ val.appendIsNotNull(buf, sel, store, params, fetchState);
+ } else {
+ Val val1 = getValue1();
+ Val val2 = getValue2();
+ if (val1.length() == 1 && val2.length() == 1) {
+ store.getDBDictionary().comparison(buf, "<>",
+ new FilterValueImpl(val1, sel, store, params, fetchState),
+ new FilterValueImpl(val2, sel, store, params, fetchState));
+ } else {
+ int len = java.lang.Math.max(val1.length(), val2.length());
+ buf.append("(");
+ for (int i = 0; i < len; i++) {
+ if (i > 0)
+ buf.append(" OR ");
+ val1.appendTo(buf, i, sel, store, params, fetchState);
+ buf.append(" <> ");
+ val2.appendTo(buf, i, sel, store, params, fetchState);
+ }
+ buf.append(")");
+ }
+ }
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Negates an expression.
+ *
+ * @author Abe White
+ */
+class NotExpression
+ implements Exp {
+
+ private final Exp _exp;
+ private Joins _joins = null;
+
+ /**
+ * Constructor. Supply the expression to negate.
+ */
+ public NotExpression(Exp exp) {
+ _exp = exp;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ Object[] params, Map contains) {
+ _exp.initialize(sel, store, params, contains);
+ _joins = sel.or(_exp.getJoins(), null);
+ }
+
+ public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ buf.append("NOT (");
+ _exp.appendTo(buf, sel, store, params, fetchState);
+ buf.append(")");
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _exp.selectColumns(sel, store, params, pks, fetchState);
+ }
+
+ public Joins getJoins() {
+ return _joins;
+ }
+
+ public boolean hasContainsExpression() {
+ return _exp.hasContainsExpression();
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _exp.hasVariable(var);
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * A literal null value in a filter.
+ *
+ * @author Abe White
+ */
+class Null
+ extends Const {
+
+ public Class getType() {
+ return Object.class;
+ }
+
+ public void setImplicitType(Class type) {
+ }
+
+ public Object getValue() {
+ return null;
+ }
+
+ public void calculateValue(Select sel, JDBCStore store,
+ Object[] params, Val other, JDBCFetchState fetchState) {
+ }
+
+ public void appendTo(SQLBuffer sql, int index, Select sel,
+ JDBCStore store, Object[] params, JDBCFetchState fetchState) {
+ sql.appendValue(null);
+ }
+
+ public void clearParameters() {
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.kernel.exps;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.Joins;
+import org.apache.openjpa.jdbc.sql.SQLBuffer;
+import org.apache.openjpa.jdbc.sql.Select;
+
+/**
+ * Combines two expressions.
+ *
+ * @author Abe White
+ */
+class OrExpression
+ implements Exp {
+
+ private final Exp _exp1;
+ private final Exp _exp2;
+ private Joins _joins = null;
+
+ /**
+ * Constructor. Supply the expressions to combine.
+ */
+ public OrExpression(Exp exp1, Exp exp2) {
+ _exp1 = exp1;
+ _exp2 = exp2;
+ }
+
+ public void initialize(Select sel, JDBCStore store,
+ Object[] params, Map contains) {
+ // when OR'ing expressions each expression gets its own copy of the
+ // contains counts, cause it's OK for each to use the same aliases
+ Map contains2 = null;
+ if (contains != null)
+ contains2 = new HashMap(contains);
+
+ _exp1.initialize(sel, store, params, contains);
+ _exp2.initialize(sel, store, params, contains2);
+ _joins = sel.or(_exp1.getJoins(), _exp2.getJoins());
+ if (contains == null)
+ return;
+
+ // combine the contains counts from the copy into the main map
+ Map.Entry entry;
+ Integer val1, val2;
+ for (Iterator itr = contains2.entrySet().iterator();
+ itr.hasNext();) {
+ entry = (Map.Entry) itr.next();
+ val2 = (Integer) entry.getValue();
+ val1 = (Integer) contains.get(entry.getKey());
+ if (val1 == null || val2.intValue() > val1.intValue())
+ contains.put(entry.getKey(), val2);
+ }
+ }
+
+ public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
+ Object[] params, JDBCFetchState fetchState) {
+ boolean paren = _joins != null && !_joins.isEmpty();
+ if (paren)
+ buf.append("(");
+
+ _exp1.appendTo(buf, sel, store, params, fetchState);
+ buf.append(" OR ");
+ _exp2.appendTo(buf, sel, store, params, fetchState);
+
+ if (paren)
+ buf.append(")");
+ sel.append(buf, _joins);
+ }
+
+ public void selectColumns(Select sel, JDBCStore store,
+ Object[] params, boolean pks, JDBCFetchState fetchState) {
+ _exp1.selectColumns(sel, store, params, pks, fetchState);
+ _exp2.selectColumns(sel, store, params, pks, fetchState);
+ }
+
+ public Joins getJoins() {
+ return _joins;
+ }
+
+ public boolean hasContainsExpression() {
+ return _exp1.hasContainsExpression() || _exp2.hasContainsExpression();
+ }
+
+ public boolean hasVariable(Variable var) {
+ return _exp1.hasVariable(var) || _exp2.hasVariable(var);
+ }
+}
Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java
------------------------------------------------------------------------------
svn:executable = *