Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
Developed for Ingres 10 (open source edition)
Description
Adds support for Ingres's FIRST keyword to limit select query results. Code is based on existing implementation for Microsoft SQLServer. The behavior is similar although the name of the keyword is FIRST rather than TOP. Note that unlike SQL Server, DISTINCT must come after the limit.
I also updated the URL to Ingres as it's no longer a CA product.
Index: src/main/java/org/apache/cayenne/dba/ingres/IngresSelectTranslator.java
===================================================================
— src/main/java/org/apache/cayenne/dba/ingres/IngresSelectTranslator.java (revision 0)
+++ src/main/java/org/apache/cayenne/dba/ingres/IngresSelectTranslator.java (working copy)
@@ -0,0 +1,46 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cayenne.dba.ingres;
+
+import org.apache.cayenne.access.trans.SelectTranslator;
+import org.apache.cayenne.query.QueryMetadata;
+
+public class IngresSelectTranslator extends SelectTranslator {
+
+ @Override
+ protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
+ QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
+
+ int limit = metadata.getFetchLimit();
+ int offset = metadata.getFetchOffset();
+
+ if (limit > 0) {
+ String sql = buffer.toString();
+
+ // If contains distinct insert first limit before
+ if (sql.startsWith("SELECT DISTINCT "))
else
{ + buffer.replace(0, 6, "SELECT FIRST " + (offset + limit)); + }+ }
+ }
+
+}
\ No newline at end of file
Index: src/main/java/org/apache/cayenne/dba/ingres/IngresSelectAction.java
===================================================================
— src/main/java/org/apache/cayenne/dba/ingres/IngresSelectAction.java (revision 0)
+++ src/main/java/org/apache/cayenne/dba/ingres/IngresSelectAction.java (working copy)
@@ -0,0 +1,47 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cayenne.dba.ingres;
+
+import java.sql.Connection;
+
+import org.apache.cayenne.access.jdbc.SelectAction;
+import org.apache.cayenne.access.trans.SelectTranslator;
+import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.SelectQuery;
+
+public class IngresSelectAction extends SelectAction {
+
+ public IngresSelectAction(SelectQuery query, JdbcAdapter adapter,
+ EntityResolver entityResolver)
+
+ @Override
+ protected SelectTranslator createTranslator(Connection connection)
+
+}
Index: src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
===================================================================
— src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java (revision 1240211)
+++ src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java (working copy)
@@ -29,6 +29,7 @@
import org.apache.cayenne.access.types.ExtendedType;
import org.apache.cayenne.access.types.ExtendedTypeFactory;
import org.apache.cayenne.access.types.ExtendedTypeMap;
+import org.apache.cayenne.access.DataNode;
import org.apache.cayenne.configuration.RuntimeProperties;
import org.apache.cayenne.dba.JdbcAdapter;
import org.apache.cayenne.dba.PkGenerator;
@@ -37,9 +38,11 @@
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.SQLAction;
/**
- * DbAdapter implementation for <a href="http://opensource.ca.com/projects/ingres/">Ingres</a>.
+ * DbAdapter implementation for <a href="http://www.actian.com/products/ingres">Ingres</a>.
- Sample connection settings to use with Ingres are shown below:
- <pre>
@@ -59,6 +62,17 @@
@Inject(EXTENDED_TYPE_FACTORY_LIST) List<ExtendedTypeFactory> extendedTypeFactories) { super(runtimeProperties, defaultExtendedTypes, userExtendedTypes, extendedTypeFactories); }+
{ + return query + .createSQLAction(new IngresActionBuilder(this, node.getEntityResolver())); + }
+ /**
+ * Uses IngresActionBuilder to create the right action.
+ *
+ * @since 1.2
+ */
+ @Override
+ public SQLAction getAction(Query query, DataNode node)
@Override
public QualifierTranslator getQualifierTranslator(QueryAssembler queryAssembler) {
Index: src/main/java/org/apache/cayenne/dba/ingres/IngresActionBuilder.java
===================================================================
— src/main/java/org/apache/cayenne/dba/ingres/IngresActionBuilder.java (revision 0)
+++ src/main/java/org/apache/cayenne/dba/ingres/IngresActionBuilder.java (working copy)
@@ -0,0 +1,45 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cayenne.dba.ingres;
+
+import org.apache.cayenne.access.jdbc.BatchAction;
+import org.apache.cayenne.dba.JdbcActionBuilder;
+import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.BatchQuery;
+import org.apache.cayenne.query.ProcedureQuery;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SQLAction;
+
+
+/**
+ * @since 1.2
+ */
+public class IngresActionBuilder extends JdbcActionBuilder {
+
+ public IngresActionBuilder(JdbcAdapter adapter, EntityResolver resolver)
+
+ @Override
+ public SQLAction objectSelectAction(SelectQuery query)
+}