Java Code Examples for com.healthmarketscience.sqlbuilder.Condition

The following examples show how to use com.healthmarketscience.sqlbuilder.Condition. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: olaper   Source File: SqlQuery.java    License: MIT License 6 votes vote down vote up
protected void filterLayer(LevelMemberSet layer) throws OlapException {
	OlapOp func =layer.getFunction();
	if(func!=null){
		SetSubquery sub_query = func.query(mapping, layer);
		if(sub_query!=null){
			
			Condition condition = sub_query.condition();
			if(condition!=null)
				addCondition(condition);

			Condition having_condition = sub_query.havingCondition();
			if(having_condition!=null)
				addHavingCondition(having_condition);
			
		}
			

	}
}
 
Example 2
Source Project: deep-spark   Source File: JdbcReaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNoConditionsAddedIfNotPartitioning() throws Exception {
    PowerMockito.mockStatic(DriverManager.class);
    SelectQuery selectQuery = PowerMockito.mock(SelectQuery.class);
    ComboCondition comboCondition = PowerMockito.mock(ComboCondition.class);

    when(selectQuery.getWhereClause()).thenReturn(comboCondition);
    when(comboCondition.addCondition(any(Condition.class))).thenReturn(comboCondition);
    when(config.getDriverClass()).thenReturn(JDBC_CELL_EXTRACTOR_CLASSNAME_CONSTANT);
    when(config.getConnectionUrl()).thenReturn(WHATEVER_CONSTANT);
    when(config.getUsername()).thenReturn(WHATEVER_CONSTANT);
    when(config.getPassword()).thenReturn(WHATEVER_CONSTANT);
    when(config.getQuery()).thenReturn(selectQuery);
    when(DriverManager.getConnection(anyString(), anyString(), anyString())).thenReturn(conn);
    when(conn.createStatement()).thenReturn(statement);
    when(statement.executeQuery(anyString())).thenReturn(resultSet);
    when(resultSet.next()).thenReturn(true);

    JdbcReader reader = new JdbcReader(config);

    reader.init(partition);

    verify(comboCondition, times(0)).addCondition(any((BinaryCondition.class)));

}
 
Example 3
Source Project: deep-spark   Source File: JdbcReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testConditionIsAddedForPartitioning() throws Exception {

    PowerMockito.mockStatic(DriverManager.class);
    SelectQuery selectQuery = PowerMockito.mock(SelectQuery.class);
    ComboCondition comboCondition = PowerMockito.mock(ComboCondition.class);

    when(selectQuery.getWhereClause()).thenReturn(comboCondition);
    when(comboCondition.addCondition(any(Condition.class))).thenReturn(comboCondition);
    when(config.getDriverClass()).thenReturn(JDBC_CELL_EXTRACTOR_CLASSNAME_CONSTANT);
    when(config.getConnectionUrl()).thenReturn(WHATEVER_CONSTANT);
    when(config.getUsername()).thenReturn(WHATEVER_CONSTANT);
    when(config.getPassword()).thenReturn(WHATEVER_CONSTANT);
    when(config.getPartitionKey()).thenReturn(PowerMockito.mock(DbColumn.class));
    when(config.getNumPartitions()).thenReturn(NUM_PARTITIONS);
    when(config.getQuery()).thenReturn(selectQuery);
    when(DriverManager.getConnection(anyString(), anyString(), anyString())).thenReturn(conn);
    when(partition.lower()).thenReturn(0L);
    when(partition.upper()).thenReturn(100L);
    when(conn.createStatement()).thenReturn(statement);
    when(statement.executeQuery(anyString())).thenReturn(resultSet);
    when(resultSet.next()).thenReturn(true);

    JdbcReader reader = new JdbcReader(config);

    reader.init(partition);

    verify(comboCondition, times(2)).addCondition(any((BinaryCondition.class)));
}
 
Example 4
Source Project: olaper   Source File: SetSubquery.java    License: MIT License 4 votes vote down vote up
public Condition condition() {
	
	if((values==null || values.size()==0) && from_value==null && to_value==null){
		if(except==null)
			return null;
		else
			return new NotCondition(except.condition());
	}
		
	DimensionTable dim_table = join.getDimensionTable();
	
	SelectQuery dim_query = new SelectQuery().
			addFromTable(dim_table.getDbTable()).
			addColumns(dim_table.getDbKey());
	
	if(from_value!=null){
		dim_query = dim_query.addCondition(BinaryCondition.greaterThan(column.getDbColumn(), from_value, true));
	}

	if(to_value!=null){
		dim_query = dim_query.addCondition(BinaryCondition.lessThan(column.getDbColumn(), to_value, true));
	}

	
	if(values!=null && values.size()>0){
		if(values.size()==1){
			String value = values.iterator().next();
			if(LevelMember.NULL_MEMBER.equals(value))
				dim_query = dim_query.addCondition(UnaryCondition.isNull(column.getDbColumn()));
			else		
				dim_query = dim_query.addCondition(BinaryCondition.equalTo(column.getDbColumn(), value));
		}else{ 
			
			if(values.contains(LevelMember.NULL_MEMBER)){
				Set<String> values_without_null = new HashSet<String>(values);
				values_without_null.remove(LevelMember.NULL_MEMBER);
				dim_query = dim_query.addCondition(ComboCondition.or(
						UnaryCondition.isNull(column.getDbColumn()),
						new InCondition(column.getDbColumn(), values_without_null)));
			}else{
				dim_query = dim_query.addCondition(new InCondition(column.getDbColumn(), values));	
			}
			
		}
	}
	
	Condition myCondition = new InCondition(join.getForeign_key(), new Subquery(dim_query) );
	
	if(except!=null)
		myCondition = ComboCondition.and(myCondition, new NotCondition(except.condition()) );

	if(exists!=null)
		myCondition = ComboCondition.and(myCondition, exists.condition());
	
	return myCondition;
	 
	
}
 
Example 5
Source Project: olaper   Source File: SetSubquery.java    License: MIT License 4 votes vote down vote up
public Condition havingCondition(){
	
	if(having_expression==null){
		if(except == null || except.having_expression==null)
			return null;
		else
			return new NotCondition(except.havingCondition());
	}
	
	Condition myCondition = new CustomCondition(having_expression);
	
	if(except!=null && except.having_expression!=null)
		myCondition = ComboCondition.and(myCondition, new NotCondition(except.havingCondition()) );
	
	if(exists!=null && exists.having_expression!=null)
		myCondition = ComboCondition.and(myCondition, exists.havingCondition() );
	
	
	return myCondition;
	
	
}
 
Example 6
Source Project: olaper   Source File: SqlQuery.java    License: MIT License 4 votes vote down vote up
private void addCondition(Condition condition){
	conditions.add(condition);
}
 
Example 7
Source Project: olaper   Source File: SqlQuery.java    License: MIT License 4 votes vote down vote up
private void addHavingCondition(Condition having_condition) {
	having_conditions.add(having_condition);
}
 
Example 8
Source Project: sqlbuilder   Source File: DbCheckConstraint.java    License: Apache License 2.0 4 votes vote down vote up
public DbCheckConstraint(DbColumn parent, String name, Condition condition) {
  super(parent, name, Type.CHECK);
  _condition = condition;
}
 
Example 9
Source Project: sqlbuilder   Source File: DbCheckConstraint.java    License: Apache License 2.0 4 votes vote down vote up
public DbCheckConstraint(DbTable parent, String name, Condition condition) {
  super(parent, name, Type.CHECK, (DbColumn[])null);
  _condition = condition;
}
 
Example 10
Source Project: sqlbuilder   Source File: DbCheckConstraint.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Condition getCondition() {
  return _condition;
}
 
Example 11
Source Project: sqlbuilder   Source File: CheckConstraint.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @return the check condition for this constraint
 */
public Condition getCondition();
 
Example 12
Source Project: sqlbuilder   Source File: DbColumn.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates and adds check constraint with the given parameters to this
 * table.
 * <p>
 * Note, no effort is made to make sure the given name is unique.
 * @param condition the check condition
 */
public DbCheckConstraint checkCondition(String name, Condition condition) {
  DbCheckConstraint constraint = getSpec().createColumnCheckConstraint(
      this, name, condition);
  return addConstraint(constraint);
}
 
Example 13
Source Project: sqlbuilder   Source File: DbTable.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates and adds check constraint with the given parameters to this
 * table.
 * <p>
 * Note, no effort is made to make sure the given name is unique.
 * @param condition the check condition
 */
public DbCheckConstraint checkCondition(String name, Condition condition) {
  DbCheckConstraint constraint = getSpec().createTableCheckConstraint(
      this, name, condition);
  return addConstraint(constraint);
}
 
Example 14
Source Project: sqlbuilder   Source File: DbSpec.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates and returns a new column {@link DbCheckConstraint} with the given
 * parameters.
 * <p>
 * This method can be overriden to utilize custom model subclasses.
 */
public DbCheckConstraint createColumnCheckConstraint(
    DbColumn parent, String name, Condition condition)
{
  return new DbCheckConstraint(parent, name, condition);
}
 
Example 15
Source Project: sqlbuilder   Source File: DbSpec.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates and returns a new table {@link DbCheckConstraint} with the given
 * parameters.
 * <p>
 * This method can be overriden to utilize custom model subclasses.
 */
public DbCheckConstraint createTableCheckConstraint(
    DbTable parent, String name, Condition condition)
{
  return new DbCheckConstraint(parent, name, condition);
}