|                                                                                                              1
 10
 11  package com.triactive.jdo.store;
 12
 13  import javax.jdo.JDOUserException;
 14  import java.util.Iterator
  ; 15  import java.util.Set
  ; 16
 17
 18
 26
 27  class SetLiteral extends SetExpression
 28  {
 29      private final Set
  value; 30      private final boolean isEmpty;
 31      private final boolean containsNull;
 32      private final DatabaseAdapter dba;
 33
 34
 35
 41
 42      public SetLiteral(QueryStatement qs, Set
  value) 43      {
 44          super(qs);
 45
 46          this.value = value;
 47
 48          containsNull = (null != value) && value.contains(null);
 49          dba = qs.getStoreManager().getDatabaseAdapter();
 50
 51
 56          isEmpty =
 57              (null == value) ||
 58              (value.isEmpty()) ||
 59              (1 == value.size() && containsNull);
 60
 61
 64          if (!isEmpty)
 65          {
 66              st.append("(");
 67
 68              boolean hadPrev = false;
 69
 70              for (Iterator
  it = value.iterator(); it.hasNext(); ) 71              {
 72                  Object
  current = it.next(); 73
 74                  if (null != current)
 75                  {
 76                      Mapping m = dba.getMapping(current.getClass());
 77                      SQLExpression expr = m.newSQLLiteral(qs, current);
 78
 79
 82                      st.append(hadPrev ? "," : "");
 83                      st.append(expr);
 84
 85                      hadPrev = true;
 86                  }
 87              }
 88
 89              st.append(")");
 90          }
 91      }
 92
 93
 94
 101     public BooleanExpression containsMethod(SQLExpression expr)
 102     {
 103         BooleanExpression returnVal = isEmpty ? new BooleanLiteral(qs, false) : expr.in(this);
 104
 105
 110         if (containsNull)
 111             returnVal = returnVal.ior(expr.eq(new NullLiteral(qs)));
 112
 113         return returnVal;
 114     }
 115
 116
 117     public BooleanExpression isEmptyMethod()
 118     {
 119         return new BooleanLiteral(qs, isEmpty);
 120     }
 121 }
 122
                                                                                                                                                                                                             |                                                                       
 
 
 
 
 
                                                                                   Popular Tags                                                                                                                                                                                              |