001/**
002 * Copyright 2005-2018 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.platform;
017
018import org.apache.ojb.broker.PersistenceBroker;
019
020import java.sql.Connection;
021import java.util.regex.Pattern;
022
023/**
024 * DatabasePlatform implementation that generates Derby-compliant SQL
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 */
027public class DerbyDatabasePlatform extends ANSISqlDatabasePlatform {
028
029        private static final Pattern APOS_PAT = Pattern.compile("'");
030        
031    public String getLockRouteHeaderQuerySQL(String documentId, boolean wait) {
032        return "SELECT DOC_HDR_ID FROM KREW_DOC_HDR_T WHERE DOC_HDR_ID=?";
033    }
034
035    private static long nextVal = 1000;
036    
037        public String getCurTimeFunction() {
038                return "CURRENT_TIMESTAMP";
039        }
040
041        public String getDateFormatString(String dateFormatString) {
042                return "'" + dateFormatString + "'";
043        }
044    
045        public String getStrToDateFunction() {
046                return null;
047        }
048
049    @Override
050    protected Long getNextValSqlOjb(String sequenceName, PersistenceBroker persistenceBroker) {
051        return nextVal++;
052    }
053
054    @Override
055    protected Long getNextValSqlJdbc(String sequenceName, Connection connection) {
056        return nextVal++;
057    }
058
059    public String toString() {
060        return "[Derby]";
061    }
062
063    public String getSelectForUpdateSuffix(long waitMillis) {
064        throw new UnsupportedOperationException("Implement me!");
065    }
066
067    /**
068     * Performs Derby-specific escaping of String parameters.
069     * 
070     * @see DatabasePlatform#escapeString(java.lang.String)
071     */
072    public String escapeString(String sqlString) {
073        return (sqlString != null) ? APOS_PAT.matcher(sqlString).replaceAll("''") : null;
074    }
075
076    @Override
077    public String applyLimitSql(Integer limit) {
078        // derby has no such concept
079        return null;
080    }
081
082    @Override
083    public String getValidationQuery() {
084        return "values 1";
085    }
086
087}