001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.core.framework.persistence.ojb; 017 018import org.apache.commons.lang.exception.ExceptionUtils; 019import org.apache.ojb.broker.accesslayer.sql.SelectStatement; 020import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl; 021import org.apache.ojb.broker.metadata.ClassDescriptor; 022import org.apache.ojb.broker.platforms.Platform; 023import org.apache.ojb.broker.query.Query; 024import org.apache.ojb.broker.util.logging.Logger; 025import org.apache.ojb.broker.util.logging.LoggerFactory; 026 027/** 028 * SqlGeneratorDefaultImpl subclass that replaced the vanilla SqlSelectStatement implementation 029 * with a new {@link SuffixedSqlSelectStatement} that is {@link SuffixableQueryByCriteria} - aware. 030 * This class needs to be specified as the SqlGenerator implementation in the OJB properties, to replace 031 * the SqlGeneratorDefaultImpl. 032 * This is a hack to introduce select-for-update functionality into OJB so the same ORM/Criteria abstractions 033 * can be retained for select-for-update queries. Select for update appears to have been added in the OJB 034 * source repository, so maybe a forthcoming release will include this functionality and these kludges can be 035 * removed. 036 * @see SuffixedSqlSelectStatement 037 * @author Kuali Rice Team (rice.collab@kuali.org) 038 */ 039@Deprecated 040public class SqlGeneratorSuffixableImpl extends SqlGeneratorDefaultImpl { 041 private Logger logger = LoggerFactory.getLogger(SqlGeneratorSuffixableImpl.class); 042 043 public SqlGeneratorSuffixableImpl(Platform platform) { 044 super(platform); 045 } 046 047 @Override 048 public SelectStatement getPreparedSelectStatement(Query query, ClassDescriptor cld) { 049 SelectStatement sql = new SuffixedSqlSelectStatement(getPlatform(), cld, query, logger); 050 if (logger.isDebugEnabled()) { 051 boolean masochisticSqlLogging = true; 052 if ( masochisticSqlLogging ) { 053 logger.debug("SQL: " + sql.getStatement() + "\n" + query.getCriteria() + "\nFor platform: " + getPlatform().getClass().toString() + "\n" + ExceptionUtils.getStackTrace(new Throwable())); 054 } else { 055 logger.debug("SQL: " + sql.getStatement() ); 056 } 057 } 058 return sql; 059 } 060}