1 21 package oracle.toplink.essentials.internal.databaseaccess; 23 24 import java.sql.*; 25 import oracle.toplink.essentials.internal.helper.*; 26 import oracle.toplink.essentials.internal.sessions.AbstractSession; 27 28 public class OutputParameterForCallableStatement extends BindCallCustomParameter { 29 protected boolean isCursor; 31 32 protected int jdbcType; 34 protected String typeName; 35 protected boolean isTypeNameRequired; 36 37 public OutputParameterForCallableStatement(DatabaseField field) { 38 super(field); 39 } 40 41 public OutputParameterForCallableStatement(DatabaseField field, DatabasePlatform platform) { 42 this(field, platform, false); 43 } 44 45 public OutputParameterForCallableStatement(DatabaseField field, DatabasePlatform platform, boolean isCursor) { 46 this(field); 47 this.isCursor = isCursor; 48 prepare(platform); 49 } 50 51 public OutputParameterForCallableStatement(OutputParameterForCallableStatement outParameter) { 52 super(outParameter.obj); 53 this.isCursor = outParameter.isCursor; 54 this.jdbcType = outParameter.jdbcType; 55 this.typeName = outParameter.typeName; 56 this.isTypeNameRequired = outParameter.isTypeNameRequired; 57 } 58 59 protected OutputParameterForCallableStatement() { 60 } 61 62 public void setIsCursor(boolean isCursor) { 63 this.isCursor = isCursor; 64 } 65 66 public boolean isCursor() { 68 return isCursor; 69 } 70 71 public boolean isTypeNameRequired() { 72 return isTypeNameRequired; 73 } 74 75 public int getJdbcType() { 76 return jdbcType; 77 } 78 79 public String getTypeName() { 80 return typeName; 81 } 82 83 public DatabaseField getOutputField() { 84 return (DatabaseField)obj; 85 } 86 87 public void prepare(DatabasePlatform platform) { 88 if (isCursor()) { 89 jdbcType = platform.getCursorCode(); } else { 91 jdbcType = platform.getJDBCType(getOutputField()); 92 isTypeNameRequired = platform.requiresTypeNameToRegisterOutputParameter(); 93 if (isTypeNameRequired) { 94 typeName = platform.getJdbcTypeName(jdbcType); 95 } 96 } 97 } 98 99 public void set(DatabasePlatform platform, PreparedStatement statement, int index, AbstractSession session) throws SQLException { 100 if (isTypeNameRequired) { 101 ((CallableStatement)statement).registerOutParameter(index, jdbcType, typeName); 102 } else { 103 ((CallableStatement)statement).registerOutParameter(index, jdbcType); 104 } 105 } 106 107 public String toString() { 108 return "=> " + getOutputField().getName(); 109 } 110 } 111 | Popular Tags |