1 16 17 package org.springframework.jdbc.core; 18 19 import java.sql.PreparedStatement ; 20 import java.sql.SQLException ; 21 import java.sql.Types ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 25 import org.springframework.dao.InvalidDataAccessApiUsageException; 26 27 33 class ArgTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer { 34 35 private final Object [] args; 36 37 private final int[] argTypes; 38 39 40 45 public ArgTypePreparedStatementSetter(Object [] args, int[] argTypes) { 46 if ((args != null && argTypes == null) || (args == null && argTypes != null) || 47 (args != null && args.length != argTypes.length)) { 48 throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match"); 49 } 50 this.args = args; 51 this.argTypes = argTypes; 52 } 53 54 55 public void setValues(PreparedStatement ps) throws SQLException { 56 int argIndx = 1; 57 if (this.args != null) { 58 for (int i = 0; i < this.args.length; i++) { 59 Object arg = this.args[i]; 60 if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) { 61 Collection entries = (Collection ) arg; 62 for (Iterator it = entries.iterator(); it.hasNext();) { 63 Object entry = it.next(); 64 StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], null, entry); 65 } 66 } 67 else { 68 StatementCreatorUtils.setParameterValue(ps, argIndx++, this.argTypes[i], null, arg); 69 } 70 } 71 } 72 } 73 74 public void cleanupParameters() { 75 StatementCreatorUtils.cleanupParameters(this.args); 76 } 77 78 } 79 | Popular Tags |