1 2 12 package com.versant.core.jdbc; 13 14 import com.versant.core.common.GenericOID; 15 import com.versant.core.common.OID; 16 import com.versant.core.metadata.ClassMetaData; 17 import com.versant.core.jdbc.metadata.JdbcColumn; 18 import com.versant.core.jdbc.metadata.JdbcField; 19 import com.versant.core.jdbc.metadata.JdbcClass; 20 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.sql.PreparedStatement ; 24 25 28 public class JdbcGenericOID extends GenericOID implements JdbcOID { 29 30 public JdbcGenericOID() { 31 } 32 33 public JdbcGenericOID(ClassMetaData cmd, boolean resolved) { 34 super(cmd, resolved); 35 } 36 37 45 public boolean copyKeyFields(ResultSet rs, int firstCol) 46 throws SQLException { 47 JdbcColumn[] pkc = ((JdbcClass)cmd.storeClass).table.pk; 48 for (int i = 0; i < pkc.length; i++) { 49 JdbcColumn c = pkc[i]; 50 if (c.converter != null) { 51 pk[i] = c.converter.get(rs, firstCol++, c); 52 } else { 53 pk[i] = JdbcUtils.get(rs, firstCol++, c.javaTypeCode, c.scale); 54 } 55 if (rs.wasNull()) return false; 56 } 57 return true; 58 } 59 60 63 public boolean copyKeyFields(ResultSet rs, JdbcField[] pks, int[] pkFieldIndexs) 64 throws SQLException { 65 for (int j = 0; j < pkFieldIndexs.length; j++) { 66 JdbcColumn c = pks[pkFieldIndexs[j]].mainTableCols[0]; 67 if (c.converter != null) { 68 pk[j] = c.converter.get(rs, pkFieldIndexs[j] + 1, c); 69 } else { 70 pk[j] = JdbcUtils.get(rs, pkFieldIndexs[j] + 1, c.javaTypeCode, c.scale); 71 } 72 if (rs.wasNull()) return false; 73 } 74 return true; 75 } 76 77 80 public boolean validateKeyFields(ResultSet rs, int firstCol) throws SQLException { 81 JdbcColumn[] pkc = ((JdbcClass)cmd.storeClass).table.pk; 82 for (int i = 0; i < pkc.length; i++) { 83 JdbcColumn c = pkc[i]; 84 if (c.converter != null) { 85 c.converter.get(rs, firstCol++, c); 86 } else { 87 JdbcUtils.get(rs, firstCol++, c.javaTypeCode, c.scale); 88 } 89 if (rs.wasNull()) return false; 90 } 91 return true; 92 } 93 94 102 public int setParams(PreparedStatement ps, int firstParam) 103 throws SQLException { 104 JdbcColumn[] pkc = ((JdbcClass)cmd.storeClass).table.pk; 105 for (int i = 0; i < pkc.length; i++) { 106 JdbcColumn c = pkc[i]; 107 if (c.converter != null) { 108 c.converter.set(ps, firstParam++, c, pk[i]); 109 } else { 110 JdbcUtils.set(ps, firstParam++, pk[i], c.javaTypeCode, 111 c.jdbcType); 112 } 113 } 114 return firstParam; 115 } 116 117 121 public int setParams(PreparedStatement ps, int firstParam, 122 JdbcColumn[] pkc) 123 throws SQLException { 124 for (int i = 0; i < pkc.length; i++) { 125 JdbcColumn c = pkc[i]; 126 if (c.isForUpdate()) { 127 if (c.converter != null) { 128 c.converter.set(ps, firstParam++, c, pk[i]); 129 } else { 130 JdbcUtils.set(ps, firstParam++, pk[i], c.javaTypeCode, 131 c.jdbcType); 132 } 133 } 134 } 135 return firstParam; 136 } 137 138 141 public static int setNullParams(PreparedStatement ps, 142 int firstParam, ClassMetaData cmd) throws SQLException { 143 JdbcColumn[] pkc = ((JdbcClass)cmd.storeClass).table.pk; 144 for (int i = 0; i < pkc.length; i++) { 145 ps.setNull(firstParam++, pkc[i].jdbcType); 146 } 147 return firstParam; 148 } 149 150 protected GenericOID newInstance() { 151 return new JdbcGenericOID(); 152 } 153 154 public String toSString() { 155 StringBuffer s = new StringBuffer (); 156 s.append("GenericOID@"); 157 s.append(Integer.toHexString(System.identityHashCode(this))); 158 s.append(' '); 159 if (cmd == null) { 160 s.append("classIndex "); 161 s.append(cmd.index); 162 } else { 163 String n = cmd.qname; 164 int i = n.lastIndexOf('.'); 165 if (i >= 0) n = n.substring(i + 1); 166 s.append(n); 167 s.append(' '); 168 JdbcColumn[] pkc = ((JdbcClass)cmd.storeClass).table.pk; 169 for (i = 0; i < pkc.length; i++) { 170 JdbcColumn c = pkc[i]; 171 s.append(c.name); 172 s.append('='); 173 s.append(pk[i]); 174 } 175 } 176 if (!isResolved()) s.append(" NOTRES "); 177 return s.toString(); 178 } 179 180 } 181 182 | Popular Tags |