1 2 12 package com.versant.core.jdbc.metadata; 13 14 import com.versant.core.common.State; 15 import com.versant.core.metadata.ClassMetaData; 16 import com.versant.core.metadata.FetchGroupField; 17 import com.versant.core.metadata.parser.JdoElement; 18 import com.versant.core.metadata.parser.JdoExtension; 19 import com.versant.core.common.OID; 20 import com.versant.core.common.*; 21 import com.versant.core.server.StateContainer; 22 import com.versant.core.jdbc.*; 23 import com.versant.core.jdbc.sql.exp.SelectExp; 24 import com.versant.core.util.CharBuf; 25 26 import java.io.PrintStream ; 27 import java.sql.Connection ; 28 import java.sql.ResultSet ; 29 import java.sql.SQLException ; 30 import java.sql.Statement ; 31 32 import com.versant.core.common.BindingSupportImpl; 33 34 37 public abstract class JdbcCollectionField extends JdbcField { 38 39 public static int STATUS_CLOSED = 1; 40 public static int STATUS_VALID_ROWS = 2; 41 public static int STATUS_DATA_ADDED = 4; 42 43 public static final Object [] EMPTY_OBJECT_ARRAY = new Object [0]; 44 public static final OID[] EMPTY_OID_ARRAY = new OID[0]; 45 public static final Object [] PRE_GEN_EMPTY_OBJECT_ARRAY = new Object [0]; 46 47 51 public JdbcColumn[] ourPkColumns; 52 56 public JdbcColumn sequenceColumn; 57 58 public void dump(PrintStream out, String indent) { 59 super.dump(out, indent); 60 String is = indent + " "; 61 if (ourPkColumns == null) { 62 out.println(is + "ourPkColumns null"); 63 } else { 64 for (int i = 0; i < ourPkColumns.length; i++) { 65 out.println(is + "ourPkColumns[" + i + "] " + ourPkColumns[i]); 66 } 67 } 68 out.println(is + "sequenceColumn " + sequenceColumn); 69 } 70 71 75 public void processMetaData(JdoElement context, JdbcMetaDataBuilder mdb, 76 boolean quiet) { 77 fmd.primaryField = false; 78 fmd.secondaryField = true; 79 80 JdoExtension[] a = fmd.jdoField == null ? null : fmd.jdoField.extensions; 84 if (a != null) { 85 for (int i = 0; i < a.length; i++) { 86 if (a[i].isJdbc()) { 87 fmd.addError(BindingSupportImpl.getInstance().runtime("Unexpected extension: " + a[i] + "\n" + 88 context.getContext()), quiet); 89 } 90 } 91 } 92 } 93 94 public void deletePass2Block(DeletePacket graph, int blockStart, 95 int blockEnd, CharBuf s, Connection con, boolean batch) 96 throws SQLException { 97 } 99 100 103 protected boolean updateForFirstRow(FetchInfo fetchInfo, 104 boolean mustBreak, ResultSet rs, 105 int colIndex, OID oid) throws SQLException { 106 fetchInfo.onNextRow = false; 107 if (fetchInfo.breakStatus == FetchInfo.BREAK_STATUS_NULL) { 110 mustBreak = true; 112 fetchInfo.breakStatus = FetchInfo.BREAK_STATUS_DEFAULT; 113 } else if (fetchInfo.breakStatus == FetchInfo.BREAK_STATUS_DEFAULT) { 114 mustBreak = checkKeyOid(rs, colIndex, fetchInfo, mustBreak, oid); 116 } 117 return mustBreak; 118 } 119 120 protected boolean checkKeyOid(ResultSet rs, int colIndex, 121 FetchInfo fetchInfo, boolean mustBreak, 122 OID oid) throws SQLException { 123 OID keyOid; 124 keyOid = fmd.classMetaData.createOID(false); 125 126 if (!((JdbcOID)keyOid).copyKeyFields(rs, colIndex)) { 127 fetchInfo.breakStatus = FetchInfo.BREAK_STATUS_NULL; 128 fetchInfo.nextOid = null; 129 mustBreak = true; 130 } 131 132 if (!oid.equals(keyOid)) { 133 fetchInfo.breakStatus = FetchInfo.BREAK_STATUS_VALID; 134 fetchInfo.nextOid = keyOid; 135 fetchInfo.onNextRow = true; 136 mustBreak = true; 137 } 138 return mustBreak; 139 } 140 141 145 public abstract void fillStateWithEmpty(FetchGroupField field, State state); 146 147 150 public abstract int fetch(JdbcStorageManager sm, OID oid, State state, 151 FetchGroupField field, boolean forUpdate, 152 StateContainer container, boolean fetchPass2Fields, 153 ColFieldHolder colFHolder) 154 throws SQLException ; 155 156 public abstract int fetchFrom(ResultSet rs, OID oid, 157 State state, 158 FetchGroupField field, boolean forUpdate, 159 StateContainer container, boolean fetchPass2Fields, int colIndex, 160 FetchInfo fetchInfo, JdbcStorageManager sm) 161 throws SQLException ; 162 163 166 public abstract int fetchWithFilter(JdbcStorageManager sm, 167 StateContainer oidStates, 168 FetchGroupField field, ResultSet rs, boolean forUpdate, 169 OID oidToCheckOn, 170 OID[] lastReadStateOID, ClassMetaData cmd, 171 ColFieldHolder colFHolder) 172 throws SQLException ; 173 174 177 public abstract SelectExp getSelectFilterExp(JdbcStorageManager sm, 178 FetchGroupField field, ColFieldHolder colFHolder); 179 180 public abstract SelectExp getSelectExpFrom(JdbcStorageManager sm, 181 SelectExp joinToExp, FetchGroupField field, FgDs owningFgDs); 182 183 186 public abstract SelectExp getSelectFilterJoinExp(boolean value, 187 SelectExp lhSe, 188 SelectExp rootSe, 189 boolean addRootJoin); 190 191 protected void cleanup(Statement s) { 192 if (s != null) { 193 try { 194 s.close(); 195 } catch (SQLException x) { 196 } 198 } 199 } 200 201 protected void cleanup(ResultSet rs) { 202 if (rs != null) { 203 try { 204 rs.close(); 205 } catch (SQLException x) { 206 } 208 } 209 } 210 } 211 212 | Popular Tags |