Java Code Examples for com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable

The following examples show how to use com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable. 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: sqlbuilder   Source File: SqlBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testCustomPrefix() throws Exception
{
  DbTable table = new DbSpec("pre_").addDefaultSchema().addTable("NewTable");
  table.addColumn("col1");
  table.addColumn("col2");

  String sqlStr = new SelectQuery().addAllTableColumns(table)
    .validate().toString();
  checkResult(sqlStr, "SELECT pre_0.* FROM NewTable pre_0");
}
 
Example 2
Source Project: olaper   Source File: DimensionTable.java    License: MIT License 4 votes vote down vote up
public DbTable getDbTable() {
	return dbTable;
}
 
Example 3
Source Project: olaper   Source File: AggregateTable.java    License: MIT License 4 votes vote down vote up
public DbTable getDbTable() {
	return dbTable;
}
 
Example 4
Source Project: olaper   Source File: SqlQuery.java    License: MIT License 4 votes vote down vote up
protected void buildColumns() throws OlapException {
	DbTable fromTable = null;
	for(ResultAxis axis : resultAxes){
		
		for(LevelMemberSet layer : axis.getLayers()){
			
			if(layer.isMeasure()){
				
				for(Member m : layer.getMembers()){
					TableMapping.MeasureMapping mmap = mapping.getMapping((ServerMeasure) m);						
					sql.addAliasedColumn(mmap.column.getExpression(), mmap.alias);
				}
					
			}else if(layer.getLevel() instanceof ServerLevel){
				
				TableMapping.LevelMapping lmap = mapping.getMapping(layer.getLevel());
				fromTable = lmap.name_column.getDbColumn().getTable();			
				sql.addAliasedColumn(lmap.name_column.getDbColumn(), lmap.name_alias);
									
				if(lmap.key_column!=lmap.name_column){
					if(lmap.key_column==null)
						throw new OlapException("Key column for name:"+lmap.name_column.column+" not defined in tables.json, layer "+layer.toString());
					sql.addAliasedColumn(lmap.key_column.getDbColumn(), lmap.key_alias);
					addGroupedBy(lmap.key_column.getDbColumn());
				}

				if(lmap.order_column!=lmap.name_column && lmap.order_column!=lmap.key_column){
					addGroupedBy(lmap.order_column.getDbColumn());
				}
				
				layer.setSorter(new Sorter(lmap.order_column.getDbColumn(), lmap.order_column.sort_direction));
				
				addGroupedBy(lmap.name_column.getDbColumn());
				
				addJoin(lmap.join);					
				
			}
			
		}
		
	}
	
	if(fromTable==null){
		log.debug("Adding from table:"+mapping.getAggregate().getDbTable().getName());
		sql.addFromTable(mapping.getAggregate().getDbTable());
	}
	
}