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 * Postgres-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 PostgresCallMetaDataProvider extends GenericCallMetaDataProvider { 035 036 private static final String RETURN_VALUE_NAME = "returnValue"; 037 038 039 public PostgresCallMetaDataProvider(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 Types.OTHER; 057 } 058 059 @Override 060 public String metaDataSchemaNameToUse(String schemaName) { 061 // Use public schema if no schema specified 062 return (schemaName == null ? "public" : super.metaDataSchemaNameToUse(schemaName)); 063 } 064 065 @Override 066 public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) { 067 if (meta.getSqlType() == Types.OTHER && "refcursor".equals(meta.getTypeName())) { 068 return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper()); 069 } 070 else { 071 return super.createDefaultOutParameter(parameterName, meta); 072 } 073 } 074 075 @Override 076 public boolean byPassReturnParameter(String parameterName) { 077 return RETURN_VALUE_NAME.equals(parameterName); 078 } 079 080}