1 2 12 package com.versant.core.jdbc.fetch; 13 14 import com.versant.core.metadata.ClassMetaData; 15 import com.versant.core.metadata.MDStatics; 16 import com.versant.core.jdbc.sql.exp.SelectExp; 17 import com.versant.core.jdbc.sql.exp.SqlExp; 18 import com.versant.core.jdbc.metadata.JdbcClass; 19 import com.versant.core.jdbc.metadata.JdbcColumn; 20 import com.versant.core.jdbc.metadata.JdbcTable; 21 import com.versant.core.jdbc.JdbcOID; 22 import com.versant.core.common.OID; 23 24 import java.sql.ResultSet ; 25 import java.sql.SQLException ; 26 27 33 public class FopGetOID extends FetchOp { 34 35 private final FetchOpData src; 36 private final ClassMetaData cmd; 37 private final Data data; 38 39 private int firstColIndex; 41 45 public class Data extends FetchOpDataProxy { 46 47 public Data(FetchOpData src) { 48 super(src); 49 } 50 51 public void setOID(FetchResultImp fetchResult, OID oid) { 52 fetchResult.setData(FopGetOID.this, oid); 53 } 54 55 public OID getOID(FetchResultImp fetchResult) { 56 return (OID)fetchResult.getData(FopGetOID.this); 57 } 58 59 public String getDescription() { 60 return " [" + getIndex() + "]"; 61 } 62 } 63 64 public FetchOpData getOutputData() { 65 return data; 66 } 67 68 71 public FopGetOID(FetchSpec spec, FetchOpData src, ClassMetaData cmd) { 72 super(spec); 73 this.src = src; 74 this.cmd = cmd.top; 75 data = new Data(src); 76 } 77 78 83 public SqlExp init(SelectExp root, int firstColIndex) { 84 this.firstColIndex = firstColIndex; 85 JdbcClass jdbcClass = (JdbcClass)cmd.storeClass; 86 JdbcTable table = jdbcClass.table; 87 return JdbcColumn.toSqlExp(table.pk, root); 88 } 89 90 public void fetch(FetchResultImp fetchResult) throws SQLException { 91 ResultSet rs = src.getResultSet(fetchResult); 92 if (rs == null) { 93 return; } 95 JdbcOID oid = (JdbcOID)cmd.createOID(!cmd.isInHeirachy()); 96 if (oid.copyKeyFields(rs, firstColIndex)) { 97 data.setOID(fetchResult, oid); 98 } 99 } 100 101 public String getDescription() { 102 return cmd.qname + src.getDescription(); 103 } 104 105 public int getResultType() { 106 return MDStatics.OID; 107 } 108 109 public Object getResult(FetchResultImp fetchResult) { 110 return data.getOID(fetchResult); 111 } 112 113 } 114 115 | Popular Tags |