1 10 11 package com.triactive.jdo.store; 12 13 14 class ObjectFieldExpression extends ObjectExpression 15 { 16 private final QueryStatement.QueryColumn qsc; 17 private final String fieldName; 18 private final Class fieldType; 19 private final Class castType; 20 21 public ObjectFieldExpression(QueryStatement qs, 22 QueryStatement.QueryColumn qsc, 23 String fieldName, 24 Class fieldType) 25 { 26 this(qs, qsc, fieldName, fieldType, fieldType); 27 } 28 29 protected ObjectFieldExpression(QueryStatement qs, 30 QueryStatement.QueryColumn qsc, 31 String fieldName, 32 Class fieldType, 33 Class castType) 34 { 35 super(qs, qsc); 36 37 this.qsc = qsc; 38 this.fieldName = fieldName; 39 this.fieldType = fieldType; 40 this.castType = castType; 41 } 42 43 public SQLExpression cast(Class castType) 44 { 45 return new ObjectFieldExpression(qs, qsc, fieldName, fieldType, castType); 46 } 47 48 public SQLExpression accessField(String subfieldName) 49 { 50 StoreManager storeMgr = qs.getStoreManager(); 51 DatabaseAdapter dba = storeMgr.getDatabaseAdapter(); 52 53 54 String jtJavaName = qsc.te.getRangeVariable().getJavaName(); 55 56 if (!fieldName.equals("this")) 57 jtJavaName += '.' + fieldName; 58 59 if (!castType.equals(fieldType)) 60 { 61 String castTypeName = castType.getName(); 62 jtJavaName += '.' + castTypeName.substring(castTypeName.lastIndexOf('.') + 1); 63 } 64 65 TableIdentifier jtRangeVar = new TableIdentifier(dba, jtJavaName); 66 TableExpression jtExpr = qs.getTableExpression(jtRangeVar); 67 68 if (jtExpr == null) 69 { 70 ClassBaseTable jt = storeMgr.getClassBaseTable(castType); 71 jtExpr = qs.newTableExpression(jt, jtRangeVar); 72 73 QueryStatement.QueryColumn jtCol = qs.getColumn(jtExpr, jt.getIDMapping().getColumn()); 74 75 if (qsc.column.isNullable()) 76 qs.leftOuterJoin(qsc, jtCol); 77 else 78 qs.innerJoin(qsc, jtCol); 79 } 80 81 return jtExpr.newFieldExpression(subfieldName); 82 } 83 } 84 | Popular Tags |