org.teiid.query.sql.lang.Query.setCriteria()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(463)

本文整理了Java中org.teiid.query.sql.lang.Query.setCriteria方法的一些代码示例,展示了Query.setCriteria的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setCriteria方法的具体详情如下:
包路径:org.teiid.query.sql.lang.Query
类名称:Query
方法名:setCriteria

Query.setCriteria介绍

[英]Set the criteria clause for the query.
[中]设置查询的条件子句。

代码示例

代码示例来源:origin: org.teiid/teiid-engine

/**
 * Constructs an instance of this class given the specified clauses
 * @param select SELECT clause
 * @param from FROM clause
 * @param criteria WHERE clause
 * @param orderBy ORDER BY clause
 * @param option OPTION clause
 */
public Query( Select select, From from, Criteria criteria, OrderBy orderBy, Option option ) {
  super();
  setSelect( select );
  setFrom( from );
  setCriteria( criteria );
  setOrderBy( orderBy );
  setOption( option );
}

代码示例来源:origin: teiid/teiid

/**
 * Constructs an instance of this class given the specified clauses
 * @param select SELECT clause
 * @param from FROM clause
 * @param criteria WHERE clause
 * @param orderBy ORDER BY clause
 * @param option OPTION clause
 */
public Query( Select select, From from, Criteria criteria, OrderBy orderBy, Option option ) {
  super();
  setSelect( select );
  setFrom( from );
  setCriteria( criteria );
  setOrderBy( orderBy );
  setOption( option );
}

代码示例来源:origin: org.teiid/teiid-olingo

private Query buildSubquery(DocumentNode eResource,
    org.teiid.query.sql.symbol.Expression projected) {
  Select s1 = new Select();
  s1.addSymbol(projected); 
  
  Query q = new Query();
  From from = new From();
  from.addGroup(eResource.getGroupSymbol());
  q.setFrom(from);    
  q.setCriteria(DocumentNode.buildJoinCriteria(eResource, this.ctxQuery));
  
  q.setSelect(s1);
  return q;
}

代码示例来源:origin: org.teiid/teiid-olingo

public QueryCommand buildRootSubQuery(String element, DocumentNode resource) {
    Select s1 = new Select();
    s1.addSymbol(new ElementSymbol(element, resource.getGroupSymbol())); 
    From f1 = new From();
    f1.addGroup(resource.getGroupSymbol());
    Query q1 = new Query();
    q1.setSelect(s1);
    q1.setFrom(f1);    
    q1.setCriteria(resource.getCriteria());  
    return q1;
  }
}

代码示例来源:origin: teiid/teiid

@Test public void testAndOrPrecedence_1575() {
  Select s = new Select();
  s.addSymbol(new MultipleElementSymbol());
  From f = new From();
  f.addGroup(new GroupSymbol("m.g1")); //$NON-NLS-1$
  CompareCriteria c1 = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(0))); //$NON-NLS-1$
  CompareCriteria c2 = new CompareCriteria(new ElementSymbol("e2"), CompareCriteria.EQ, new Constant(new Integer(1))); //$NON-NLS-1$
  CompareCriteria c3 = new CompareCriteria(new ElementSymbol("e3"), CompareCriteria.EQ, new Constant(new Integer(3))); //$NON-NLS-1$
  CompoundCriteria cc1 = new CompoundCriteria(CompoundCriteria.AND, c2, c3);        
  CompoundCriteria cc2 = new CompoundCriteria(CompoundCriteria.OR, c1, cc1);
  Query q = new Query();
  q.setSelect(s);
  q.setFrom(f);
  q.setCriteria(cc2);
  
  helpTest("SELECT * FROM m.g1 WHERE e1=0 OR e2=1 AND e3=3", //$NON-NLS-1$
  "SELECT * FROM m.g1 WHERE (e1 = 0) OR ((e2 = 1) AND (e3 = 3))", q);                          //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

public void testHasNoCriteria2() {
  Query query = new Query();
  CompareCriteria crit = new CompareCriteria(new Constant("a"), CompareCriteria.EQ, new Constant("b")); //$NON-NLS-1$ //$NON-NLS-2$
  query.setCriteria(crit);        
  assertEquals("Got incorrect answer checking for no criteria", false, RuleValidateWhereAll.hasNoCriteria(query)); //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

@Test public void testQuery6() {
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  From from = new From();
  from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
  CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
  GroupBy groupBy = new GroupBy();
  groupBy.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
  CompareCriteria having = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.GT, new Constant(new Integer(0))); //$NON-NLS-1$
  
  Query query = new Query();
  query.setSelect(select);
  query.setFrom(from);
  query.setCriteria(cc);
  query.setGroupBy(groupBy);
  query.setHaving(having);
  
  helpTest(query, "SELECT * FROM m.g WHERE e1 = 5 GROUP BY e1 HAVING e1 > 0");		     //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

@Test public void testQuery4() {
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  From from = new From();
  from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
  CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
  CompareCriteria having = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.GT, new Constant(new Integer(0))); //$NON-NLS-1$
  OrderBy orderBy = new OrderBy();
  orderBy.addVariable(new ElementSymbol("e1")); //$NON-NLS-1$
  
  Query query = new Query();
  query.setSelect(select);
  query.setFrom(from);
  query.setCriteria(cc);
  query.setHaving(having);
  query.setOrderBy(orderBy);
  
  helpTest(query, "SELECT * FROM m.g WHERE e1 = 5 HAVING e1 > 0 ORDER BY e1");		     //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

@Test public void testEscapedFunction3() {
  String sql = "SELECT * FROM a.thing WHERE e1 = {fn cast(5 as string)}"; //$NON-NLS-1$
  
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
  query.setFrom(from);           
  Function function = new Function("cast", new Expression[] { new Constant(new Integer(5)), new Constant("string")}); //$NON-NLS-1$ //$NON-NLS-2$
  CompareCriteria crit = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, function); //$NON-NLS-1$
  query.setCriteria(crit);
  helpTest(sql, "SELECT * FROM a.thing WHERE e1 = cast(5 AS string)", query);         //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

@Test public void testEscapedFunction2() {
  String sql = "SELECT * FROM a.thing WHERE e1 = {fn convert(5, string)}"; //$NON-NLS-1$
  
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
  query.setFrom(from);           
  Function function = new Function("convert", new Expression[] { new Constant(new Integer(5)), new Constant("string")}); //$NON-NLS-1$ //$NON-NLS-2$
  CompareCriteria crit = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, function); //$NON-NLS-1$
  query.setCriteria(crit);
  helpTest(sql, 
    "SELECT * FROM a.thing WHERE e1 = convert(5, string)",  //$NON-NLS-1$
    query);        
}

代码示例来源:origin: teiid/teiid

public static SubqueryFromClause example1() {
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
  select.addSymbol(new ElementSymbol("b"));         //$NON-NLS-1$
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
  query.setFrom(from);
  CompareCriteria crit = new CompareCriteria();
  crit.setLeftExpression(new ElementSymbol("a")); //$NON-NLS-1$
  crit.setRightExpression(new Constant(new Integer(5)));
  crit.setOperator(CompareCriteria.EQ);
  query.setCriteria(crit);
  
  return new SubqueryFromClause("temp", query); //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

public static SubqueryFromClause example3() {
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
  select.addSymbol(new ElementSymbol("b"));         //$NON-NLS-1$
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
  query.setFrom(from);
  CompareCriteria crit = new CompareCriteria();
  crit.setLeftExpression(new ElementSymbol("a")); //$NON-NLS-1$
  crit.setRightExpression(new Constant(new Integer(5)));
  crit.setOperator(CompareCriteria.EQ);
  query.setCriteria(crit);
  
  return new SubqueryFromClause("temp2", query); //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

public static SubqueryFromClause example2() {
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new ElementSymbol("c")); //$NON-NLS-1$
  select.addSymbol(new ElementSymbol("d"));         //$NON-NLS-1$
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("m.g2")); //$NON-NLS-1$
  query.setFrom(from);
  CompareCriteria crit = new CompareCriteria();
  crit.setLeftExpression(new ElementSymbol("c")); //$NON-NLS-1$
  crit.setRightExpression(new Constant(new Integer(10)));
  crit.setOperator(CompareCriteria.EQ);
  query.setCriteria(crit);
  
  return new SubqueryFromClause("temp", query); //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

public static SubquerySetCriteria example1() {
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
  select.addSymbol(new ElementSymbol("b"));         //$NON-NLS-1$
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
  query.setFrom(from);
  CompareCriteria crit = new CompareCriteria();
  crit.setLeftExpression(new ElementSymbol("a")); //$NON-NLS-1$
  crit.setRightExpression(new Constant(new Integer(5)));
  crit.setOperator(CompareCriteria.EQ);
  query.setCriteria(crit);                
  
  return new SubquerySetCriteria(new ElementSymbol("temp"), query); //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

public static SubquerySetCriteria example3() {
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new ElementSymbol("a")); //$NON-NLS-1$
  select.addSymbol(new ElementSymbol("b"));         //$NON-NLS-1$
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
  query.setFrom(from);
  CompareCriteria crit = new CompareCriteria();
  crit.setLeftExpression(new ElementSymbol("a")); //$NON-NLS-1$
  crit.setRightExpression(new Constant(new Integer(5)));
  crit.setOperator(CompareCriteria.EQ);
  query.setCriteria(crit);
  
  return new SubquerySetCriteria(new ElementSymbol("temp2"), query); //$NON-NLS-1$
}

代码示例来源:origin: teiid/teiid

/** Select a From db.g Where Not a IS NULL */
@Test public void testNotIsNullCriteria(){
  GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
  From from = new From();
  from.addGroup(g);
  Select select = new Select();
  ElementSymbol a = new ElementSymbol("a");  //$NON-NLS-1$
  select.addSymbol(a);
  Criteria crit = new NotCriteria(new IsNullCriteria(a));
  Query query = new Query();
  query.setSelect(select);
  query.setFrom(from);
  query.setCriteria(crit);
  helpTest("Select a From db.g Where Not a IS NULL",  //$NON-NLS-1$
       "SELECT a FROM db.g WHERE NOT (a IS NULL)",  //$NON-NLS-1$
       query);
}

代码示例来源:origin: teiid/teiid

/** SELECT * FROM model.doc WHERE ab.cd.@ef = 'abc' */
@Test public void testXMLCriteriaWithAttribute() {
  GroupSymbol g = new GroupSymbol("model.doc"); //$NON-NLS-1$
  From from = new From();
  from.addGroup(g);
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  Query query = new Query();
  query.setSelect(select);
  query.setFrom(from);
  
  ElementSymbol elem = new ElementSymbol("ab.cd.@ef"); //$NON-NLS-1$
  query.setCriteria(new CompareCriteria(elem, CompareCriteria.EQ, new Constant("abc"))); //$NON-NLS-1$
  helpTest("SELECT * FROM model.doc WHERE ab.cd.@ef = 'abc'",  //$NON-NLS-1$
       "SELECT * FROM model.doc WHERE ab.cd.@ef = 'abc'",  //$NON-NLS-1$
       query);   
}

代码示例来源:origin: teiid/teiid

@Test public void testUnicode2() {
  String sql = "SELECT * FROM TestDocument.TestDocument WHERE Subject='\u0041\u005a'";  //$NON-NLS-1$
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("TestDocument.TestDocument")); //$NON-NLS-1$
  query.setFrom(from);           
  CompareCriteria crit = new CompareCriteria(new ElementSymbol("Subject"), CompareCriteria.EQ, new Constant("AZ")); //$NON-NLS-1$ //$NON-NLS-2$
  query.setCriteria(crit);
  helpTest(sql, query.toString(), query);
}

代码示例来源:origin: teiid/teiid

@Test public void testEscapedFunction1() {
  String sql = "SELECT * FROM a.thing WHERE e1 = {fn concat('a', 'b')}"; //$NON-NLS-1$
  
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
  query.setFrom(from);           
  Function function = new Function("concat", new Expression[] { new Constant("a"), new Constant("b")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  CompareCriteria crit = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, function); //$NON-NLS-1$
  query.setCriteria(crit);
  helpTest(sql, 
    "SELECT * FROM a.thing WHERE e1 = concat('a', 'b')",  //$NON-NLS-1$
    query);        
}

代码示例来源:origin: teiid/teiid

@Test public void testEscapedFunction4() {
  String sql = "SELECT * FROM a.thing WHERE e1 = {fn concat({fn concat('a', 'b')}, 'c')}"; //$NON-NLS-1$
  
  Query query = new Query();
  Select select = new Select();
  select.addSymbol(new MultipleElementSymbol());
  query.setSelect(select);
  From from = new From();
  from.addGroup(new GroupSymbol("a.thing")); //$NON-NLS-1$
  query.setFrom(from);           
  Function func1 = new Function("concat", new Expression[] { new Constant("a"), new Constant("b")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  Function func2 = new Function("concat", new Expression[] { func1, new Constant("c")}); //$NON-NLS-1$ //$NON-NLS-2$
  CompareCriteria crit = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, func2); //$NON-NLS-1$
  query.setCriteria(crit);
  helpTest(sql, "SELECT * FROM a.thing WHERE e1 = concat(concat('a', 'b'), 'c')", query);         //$NON-NLS-1$
}

相关文章