Return-Path: X-Original-To: apmail-cayenne-commits-archive@www.apache.org Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 30A7D9256 for ; Fri, 3 Feb 2012 16:00:16 +0000 (UTC) Received: (qmail 85068 invoked by uid 500); 3 Feb 2012 16:00:16 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 85032 invoked by uid 500); 3 Feb 2012 16:00:15 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 85024 invoked by uid 99); 3 Feb 2012 16:00:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Feb 2012 16:00:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Feb 2012 16:00:13 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id A4D2618BAE8 for ; Fri, 3 Feb 2012 15:59:53 +0000 (UTC) Date: Fri, 3 Feb 2012 15:59:53 +0000 (UTC) From: "Lucas Holt (Updated) (JIRA)" To: commits@cayenne.apache.org Message-ID: <201175534.7795.1328284793677.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <2023652755.7793.1328284675113.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (CAY-1659) PATCH: Ingres limit query support MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAY-1659?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Lucas Holt updated CAY-1659: ---------------------------- Attachment: cay.diff > PATCH: Ingres limit query support > --------------------------------- > > Key: CAY-1659 > URL: https://issues.apache.org/jira/browse/CAY-1659 > Project: Cayenne > Issue Type: Improvement > Components: Database integration > Affects Versions: Short term future > Environment: Developed for Ingres 10 (open source edition) > Reporter: Lucas Holt > Priority: Minor > Labels: patch > Fix For: 3.1M4 > > Attachments: cay.diff > > > 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 ")) { > + buffer.replace(0, 15, "SELECT FIRST " + (offset + limit) + " 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) { > + super(query, adapter, entityResolver); > + } > + > + @Override > + protected SelectTranslator createTranslator(Connection connection) { > + SelectTranslator translator = new IngresSelectTranslator(); > + translator.setQuery(query); > + translator.setAdapter(adapter); > + translator.setEntityResolver(getEntityResolver()); > + translator.setConnection(connection); > + translator.setJdbcEventLogger(adapter.getJdbcEventLogger()); > + return translator; > + } > + > +} > 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 Ingres. > + * DbAdapter implementation for Ingres. > * Sample connection settings to use with Ingres are shown below: > * > *
> @@ -59,6 +62,17 @@
>              @Inject(EXTENDED_TYPE_FACTORY_LIST) List extendedTypeFactories) {
>          super(runtimeProperties, defaultExtendedTypes, userExtendedTypes, extendedTypeFactories);
>      }
> +
> +    /**
> +     * Uses IngresActionBuilder to create the right action.
> +     * 
> +     * @since 1.2
> +     */
> +    @Override
> +    public SQLAction getAction(Query query, DataNode node) {
> +        return query
> +                .createSQLAction(new IngresActionBuilder(this, node.getEntityResolver()));
> +    }
>      
>      @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) {
> +        super(adapter, resolver);
> +    }
> +    
> +    @Override
> +    public SQLAction objectSelectAction(SelectQuery query) {
> +        return new IngresSelectAction(query, adapter, entityResolver);
> +    }    
> +}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira