1 2 12 package com.versant.core.jdbc.fetch; 13 14 import com.versant.core.metadata.FetchGroup; 15 import com.versant.core.metadata.ClassMetaData; 16 import com.versant.core.jdbc.sql.exp.SelectExp; 17 import com.versant.core.jdbc.sql.exp.SqlExp; 18 import com.versant.core.common.State; 19 import com.versant.core.common.OID; 20 21 import java.sql.SQLException ; 22 23 26 public class FopGetState extends FetchOp { 27 28 private final FetchOpData src; 29 private final FetchGroup fg; 30 private final boolean includeSubClasses; 31 private final Data data; 32 33 private int firstColIndex; 35 39 public class Data extends FetchOpDataProxy { 40 41 public Data(FetchOpData src) { 42 super(src); 43 } 44 45 public void setState(FetchResultImp fetchResult, State state) { 46 fetchResult.setData(FopGetState.this, state); 47 } 48 49 public State getState(FetchResultImp fetchResult) { 50 return (State)fetchResult.getData(FopGetState.this); 51 } 52 53 public String getDescription() { 54 return " [" + getIndex() + "]"; 55 } 56 } 57 58 63 public FopGetState(FetchSpec spec, FetchOpData src, FetchGroup fg, 64 boolean includeSubClasses) { 65 super(spec); 66 this.src = src; 67 this.fg = fg; 68 this.includeSubClasses = includeSubClasses 69 && fg.classMetaData.pcSubclasses != null; 70 data = new Data(src); 71 } 72 73 public FetchOpData getOutputData() { 74 return data; 75 } 76 77 84 public SqlExp init(SelectExp root, int firstColIndex) { 85 this.firstColIndex = firstColIndex; 86 ClassMetaData cmd = fg.classMetaData; 87 if (cmd.isInHeirachy()) { 88 throw notImplemented(); 90 } 91 for (FetchGroup g = fg; g != null; g = g.superFetchGroup) { 93 processFetchGroup(g); 94 } 95 if (includeSubClasses) { 97 processSubFetchGroups(fg.subFetchGroups); 98 } 99 return null; 100 } 101 102 private void processFetchGroup(FetchGroup g) { 103 spec.addFetchOp(new FopGetFetchGroup(spec, data, g), false); 104 } 105 106 private void processSubFetchGroups(FetchGroup[] subs) { 107 if (subs != null) { 108 int n = subs.length; 109 for (int i = 0; i < n; i++) { 110 processFetchGroup(subs[i]); 111 } 112 for (int i = 0; i < n; i++) { 113 processSubFetchGroups(subs[i].subFetchGroups); 114 } 115 } 116 } 117 118 public void fetch(FetchResultImp fetchResult) throws SQLException { 119 OID oid = src.getOID(fetchResult); 120 if (oid == null) { 121 return; } 123 ClassMetaData cmd = fg.classMetaData; 124 if (cmd.isInHeirachy()) { 125 throw notImplemented(); 127 } 128 State state = cmd.createState(); 129 oid.resolve(state); 130 data.setState(fetchResult, state); 131 } 132 133 public String getDescription() { 134 return fg.classMetaData.qname + 135 (includeSubClasses ? " and subclasses" : "") + 136 src.getDescription(); 137 } 138 139 public int getResultType() { 140 return 0; 141 } 142 143 public Object getResult(FetchResultImp fetchResult) { 144 return data.getState(fetchResult); 145 } 146 147 } 148 149 | Popular Tags |