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;
021import java.sql.Types;
022
023import org.springframework.jdbc.core.ColumnMapRowMapper;
024import org.springframework.jdbc.core.SqlOutParameter;
025import org.springframework.jdbc.core.SqlParameter;
026import org.springframework.lang.Nullable;
027
028/**
029 * Oracle-specific implementation for the {@link CallMetaDataProvider} interface.
030 * This class is intended for internal use by the Simple JDBC classes.
031 *
032 * @author Thomas Risberg
033 * @since 2.5
034 */
035public class OracleCallMetaDataProvider extends GenericCallMetaDataProvider {
036
037        private static final String REF_CURSOR_NAME = "REF CURSOR";
038
039
040        public OracleCallMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
041                super(databaseMetaData);
042        }
043
044
045        @Override
046        public boolean isReturnResultSetSupported() {
047                return false;
048        }
049
050        @Override
051        public boolean isRefCursorSupported() {
052                return true;
053        }
054
055        @Override
056        public int getRefCursorSqlType() {
057                return -10;
058        }
059
060        @Override
061        @Nullable
062        public String metaDataCatalogNameToUse(@Nullable String catalogName) {
063                // Oracle uses catalog name for package name or an empty string if no package
064                return (catalogName == null ? "" : catalogNameToUse(catalogName));
065        }
066
067        @Override
068        @Nullable
069        public String metaDataSchemaNameToUse(@Nullable String schemaName) {
070                // Use current user schema if no schema specified
071                return (schemaName == null ? getUserName() : super.metaDataSchemaNameToUse(schemaName));
072        }
073
074        @Override
075        public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
076                if (meta.getSqlType() == Types.OTHER && REF_CURSOR_NAME.equals(meta.getTypeName())) {
077                        return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
078                }
079                else {
080                        return super.createDefaultOutParameter(parameterName, meta);
081                }
082        }
083
084}