1 2 12 package com.versant.core.jdbc.metadata; 13 14 import com.versant.core.metadata.StoreFetchGroup; 15 import com.versant.core.metadata.FetchGroup; 16 import com.versant.core.metadata.FieldMetaData; 17 import com.versant.core.metadata.FetchGroupField; 18 import com.versant.core.jdbc.FgDs; 19 import com.versant.core.common.BindingSupportImpl; 20 21 24 public class JdbcFetchGroup implements StoreFetchGroup { 25 26 public static int OPT_INC_SUBS = 1; 27 public static int OPT_START_OUTER = 2; 28 29 private FetchGroup fg; 30 private FgDs[] fgDses = new FgDs[4]; 31 32 public JdbcFetchGroup() { 33 } 34 35 public void setFetchGroup(FetchGroup fg) { 36 this.fg = fg; 37 } 38 39 public FgDs getFgDs(boolean incSubClasses, boolean outer) { 40 int opts = createOpts(incSubClasses, outer); 41 FgDs fgDs = fgDses[opts]; 42 if (fgDs == null) { 43 fgDs = new FgDs(null, fg, fg.name, opts); 44 } 45 return fgDs; 46 } 47 48 public FgDs getExistingFgDs(boolean incSubClasses, boolean outer) { 49 int opts = createOpts(incSubClasses, outer); 50 FgDs fgDs = fgDses[opts]; 51 if (fgDs == null) { 52 StringBuffer msg = new StringBuffer (); 53 msg.append("FgDs does not exist: " + fg.classMetaData.qname + "." + 54 fg.name + " incSubClasses " + incSubClasses + " outer " + 55 outer); 56 msg.append("\nincSubClasses outer FgDs"); 57 msg.append("\nfalse false " + fgDses[createOpts(false, false)]); 58 msg.append("\nfalse true " + fgDses[createOpts(false, true)]); 59 msg.append("\ntrue false " + fgDses[createOpts(true, false)]); 60 msg.append("\ntrue true " + fgDses[createOpts(true, true)] + "\n"); 61 throw BindingSupportImpl.getInstance().internal(msg.toString()); 62 } 63 return fgDs; 64 } 65 66 public static int createOpts(boolean incSubClasses, boolean outer) { 67 int opt = 0; 68 if (incSubClasses) opt += OPT_INC_SUBS; 69 if (outer) opt += OPT_START_OUTER; 70 return opt; 71 } 72 73 public void setFgDs(FgDs fgDs) { 74 if (!fgDs.isFinished()) { 75 throw BindingSupportImpl.getInstance().internal( 76 "The FetchPlan has not been finished"); 77 } 78 fgDses[fgDs.getOpts()] = fgDs; 79 } 80 81 public void fieldAdded(FieldMetaData fmd) { 82 JdbcField jdbcField = ((JdbcField)fmd.storeField); 83 if (jdbcField.mainTableCols != null) { 84 fg.jdbcTotalCols += jdbcField.mainTableCols.length; 85 } 86 } 87 88 public void finish() { 89 FetchGroupField[] fields = fg.fields; 90 int nf = fields.length; 91 for (int i = nf - 1; i >= 0; i--) { 92 if (fg.crossJoinedCollectionField == null 94 && fields[i].fmd.storeField instanceof JdbcCollectionField 95 && !(fields[i].fmd.storeField instanceof JdbcMapField)) { 96 fg.crossJoinedCollectionField = fields[i]; 97 } 98 } 99 } 100 101 } 102 103 | Popular Tags |