1 2 12 package com.versant.core.jdbc; 13 14 import com.versant.core.common.OID; 15 import com.versant.core.metadata.FetchGroupField; 16 import com.versant.core.jdbc.metadata.JdbcCollectionField; 17 import com.versant.core.jdbc.metadata.JdbcField; 18 import com.versant.core.jdbc.metadata.JdbcRefField; 19 import com.versant.core.jdbc.metadata.JdbcClass; 20 import com.versant.core.jdbc.sql.exp.SelectExp; 21 22 import java.sql.PreparedStatement ; 23 import java.sql.ResultSet ; 24 import java.sql.SQLException ; 25 26 35 public class ColFieldHolder { 36 37 41 public ResultSet rs; 42 public PreparedStatement ps; 43 public OID[] lastOIDs = new OID[2]; 44 public int returnState; 45 46 49 public ColFieldHolder parent; 50 53 public JoinStructure js; 54 55 public JoinStructure valueJs; 56 57 public JoinStructure keyJs; 58 63 public final boolean valueJoinToParent; 64 public boolean crossJoinedField; 65 66 public ColFieldHolder(ColFieldHolder parent, 67 boolean valueJoinToParent, JoinStructure js) { 68 this.parent = parent; 69 this.valueJoinToParent = valueJoinToParent; 70 this.js = js; 71 } 72 73 public void close() { 74 if (rs != null) { 75 try { 76 rs.close(); 77 } catch (SQLException e) { 78 } 80 } 81 82 if (ps != null) { 83 try { 84 ps.close(); 85 } catch (SQLException e) { 86 } 88 } 89 } 90 91 private SelectExp createSelectExpImp(JdbcStorageManager sm, 92 FetchGroupField fgField, SelectExp inSe, 93 boolean valueJoin, boolean justJoin, 94 SelectExp root, boolean addRootJoin) { 95 final JdbcField jdbcField = (JdbcField)fgField.fmd.storeField; 96 if (jdbcField instanceof JdbcRefField) { 97 JdbcRefField refField = (JdbcRefField)jdbcField; 98 99 SelectExp se = new SelectExp(); 100 se.table = ((JdbcClass)refField.targetClass.storeClass).table; 101 se.jdbcField = refField; 102 inSe.addJoin(refField.cols, se.table.pk, se); 103 104 inSe = se; 105 } else { 106 if (justJoin) { 107 inSe = ((JdbcCollectionField)jdbcField).getSelectFilterJoinExp( 108 valueJoin, 109 inSe, root, addRootJoin); 110 } else { 111 final JdbcCollectionField jdbcCollectionField = 112 (JdbcCollectionField)fgField.fmd.storeField; 113 SelectExp se = jdbcCollectionField.getSelectFilterExp(sm, fgField, 114 this); 115 inSe.addJoin(inSe.table.pk, jdbcCollectionField.ourPkColumns, 116 se); 117 return se; 118 } 119 } 120 return inSe; 121 } 122 123 133 private SelectExp createSEImp(JdbcStorageManager sm, SelectExp joinToExp, 134 SelectExp rootExp, boolean valueJoin, boolean addRootJoin) { 135 if (parent != null) { 137 joinToExp = parent.createSEImp(sm, joinToExp, rootExp, 138 valueJoinToParent, false); 139 } 140 141 return appendJoins(sm, joinToExp, valueJoin, true, rootExp, addRootJoin); 143 } 144 145 150 private SelectExp appendJoins(JdbcStorageManager sm, SelectExp joinToExp, 151 boolean valueJoin, boolean justJoin, SelectExp root, 152 boolean addRootJoin) { 153 FetchGroupField[] fgFields = js.fgFields; 154 for (int i = 0; i < fgFields.length; i++) { 155 joinToExp = createSelectExpImp(sm, fgFields[i], joinToExp, valueJoin, 156 justJoin, root, addRootJoin); 157 } 158 return joinToExp; 159 } 160 161 164 public SelectExp createSE(JdbcStorageManager sm, SelectExp root) { 165 SelectExp rhSe = root; 166 if (parent != null) { 167 rhSe = parent.createSEImp(sm, rhSe, root, valueJoinToParent, true); 168 } 169 170 return appendJoins(sm, rhSe, true, false, root, false); 171 } 172 173 public String toString() { 174 return this.getClass().getName() + "@" 175 + System.identityHashCode(this) 176 + "field " + js.fgField.fmd.name 177 + " --> " + parent; 178 179 } 180 } 181 | Popular Tags |