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