1 10 11 package com.triactive.jdo.store; 12 13 import javax.jdo.JDOUserException; 14 15 16 26 27 class CandidateSetExpression extends SetExpression 28 { 29 private final QueryStatement.QueryColumn ownerQsc; 30 private final SetStore setStore; 31 private final String fieldName; 32 private final DatabaseAdapter dba; 33 34 35 public CandidateSetExpression(QueryStatement qs, QueryStatement.QueryColumn ownerQsc, SetStore setStore, String fieldName) 36 { 37 super(qs); 38 39 this.ownerQsc = ownerQsc; 40 this.setStore = setStore; 41 this.fieldName = fieldName; 42 43 dba = qs.getStoreManager().getDatabaseAdapter(); 44 } 45 46 47 54 55 public BooleanExpression containsMethod(SQLExpression expr) 56 { 57 58 59 String stJavaName = ownerQsc.te.getRangeVariable().getJavaName() + '.' + fieldName; 60 String etJavaNameBase = qs.getDefaultTableExpression().getRangeVariable().getJavaName(); 61 62 if (expr instanceof UnboundVariable) 63 { 64 UnboundVariable var = (UnboundVariable)expr; 65 String etJavaName = qs.getDefaultTableExpression().getRangeVariable().getJavaName() + '.' + var.getVariableName(); 66 67 TableIdentifier stRangeVar = new TableIdentifier(dba, stJavaName); 68 TableIdentifier etRangeVar = new TableIdentifier(dba, etJavaName); 69 70 var.bindTo(setStore.joinElementsTo(qs, 71 ownerQsc, 72 stRangeVar, 73 var.getVariableType(), 74 etRangeVar)); 75 qs.setDistinctResults(true); 76 77 return new BooleanLiteral(qs, true); 78 } 79 else 80 { 81 TableIdentifier stRangeVar = new TableIdentifier(dba, stJavaName); 82 TableIdentifier etRangeVar; 83 int n = 0; 84 85 do 86 { 87 String etJavaName = stJavaName + '.' + (++n); 88 89 etRangeVar = new TableIdentifier(dba, etJavaName); 90 } while (qs.getTableExpression(etRangeVar) != null); 91 92 QueryStatement.QueryColumn qsc = 93 setStore.joinElementsTo(qs, 94 ownerQsc, 95 stRangeVar, 96 setStore.getElementType(), 97 etRangeVar); 98 qs.setDistinctResults(true); 99 100 SQLExpression elemExpr = dba.getMapping(qsc.column).newSQLExpression(qs, qsc, "" + n); 101 102 return elemExpr.eq(expr); 103 } 104 } 105 106 107 112 public BooleanExpression isEmptyMethod() 113 { 114 115 String stJavaName = ownerQsc.te.getRangeVariable().getJavaName() + '.' + fieldName; 116 TableIdentifier stRangeVar = new TableIdentifier(dba, stJavaName); 117 118 return new ExistsExpression(qs, setStore.getExistsSubquery(ownerQsc, stRangeVar), false); 119 } 120 121 public StatementText toStatementText() 122 { 123 throw new JDOUserException("Cannot reference set object directly: field name = " + fieldName); 124 } 125 } 126 | Popular Tags |