View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.ojb;
17  
18  import org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement;
19  import org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement;
20  import org.apache.ojb.broker.metadata.ClassDescriptor;
21  import org.apache.ojb.broker.platforms.Platform;
22  import org.apache.ojb.broker.query.Query;
23  import org.apache.ojb.broker.util.logging.Logger;
24  
25  /**
26   * A SqlSelectStatement sublclass that is aware of a special {@link SuffixableQueryByCriteria} Criteria
27   * class and will append a suffix specified by that class of criteria to the generated SQL statement.
28   * This is a hack to introduce select-for-update functionality into OJB so the same ORM/Criteria abstractions
29   * can be retained for select-for-update queries.  Select for update appears to have been added in the OJB
30   * source repository, so maybe a forthcoming release will include this functionality and these kludges can be
31   * removed.
32   * @see SqlGeneratorSuffixableImpl
33   * @see SuffixableQueryByCriteria
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class SuffixedSqlSelectStatement extends SqlSelectStatement {
37  
38      public SuffixedSqlSelectStatement(Platform pf, ClassDescriptor cld, Query query, Logger logger) {
39          super(pf, cld, query, logger);
40      }
41  
42      public SuffixedSqlSelectStatement(SqlQueryStatement parent, Platform pf, ClassDescriptor cld, Query query,
43              Logger logger) {
44          super(parent, pf, cld, query, logger);
45      }
46  
47      @Override
48      protected String buildStatement() {
49          String stmt = super.buildStatement();
50          Query query = this.getQuery();
51          if (query instanceof SuffixableQueryByCriteria) {
52              stmt += " " + ((SuffixableQueryByCriteria) query).getQuerySuffix();
53          }
54          return stmt;
55      }
56  }