001/*
002 * Copyright 2002-2017 the original author or authors.
003 *
004 * Licensed under the Apache 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 *      https://www.apache.org/licenses/LICENSE-2.0
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 */
016
017package org.springframework.jdbc.core.metadata;
018
019import java.sql.DatabaseMetaData;
020import java.sql.SQLException;
021
022import org.springframework.lang.Nullable;
023
024/**
025 * Sybase specific implementation for the {@link CallMetaDataProvider} interface.
026 * This class is intended for internal use by the Simple JDBC classes.
027 *
028 * @author Thomas Risberg
029 * @since 2.5
030 */
031public class SybaseCallMetaDataProvider extends GenericCallMetaDataProvider {
032
033        private static final String REMOVABLE_COLUMN_PREFIX = "@";
034
035        private static final String RETURN_VALUE_NAME = "RETURN_VALUE";
036
037
038        public SybaseCallMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
039                super(databaseMetaData);
040        }
041
042
043        @Override
044        @Nullable
045        public String parameterNameToUse(@Nullable String parameterName) {
046                if (parameterName == null) {
047                        return null;
048                }
049                else if (parameterName.length() > 1 && parameterName.startsWith(REMOVABLE_COLUMN_PREFIX)) {
050                        return super.parameterNameToUse(parameterName.substring(1));
051                }
052                else {
053                        return super.parameterNameToUse(parameterName);
054                }
055        }
056
057        @Override
058        public boolean byPassReturnParameter(String parameterName) {
059                return (RETURN_VALUE_NAME.equals(parameterName) ||
060                                RETURN_VALUE_NAME.equals(parameterNameToUse(parameterName)));
061        }
062
063}