assertEquals(q.toString(), q.clone().toString());
}
public void testFromItemAlias() throws Exception {
Query q = new Query();
Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
Column nameColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_NAME);
Column countryColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_COUNTRY);
FromItem fromContributor = new FromItem(contributorTable);
q.from(fromContributor);
q.select(nameColumn, countryColumn);
assertEquals("SELECT contributor.name, contributor.country FROM MetaModelSchema.contributor", q.toString());
fromContributor.setAlias("c");
assertEquals("SELECT c.name, c.country FROM MetaModelSchema.contributor c", q.toString());
q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(nameColumn)));
q.groupBy(new GroupByItem(q.getSelectClause().getSelectItem(countryColumn)));
q.select(new SelectItem(FunctionType.COUNT, "*", "total"));
assertEquals(2, q.getGroupByClause().getItems().size());
assertEquals(
"SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c GROUP BY c.name, c.country",
q.toString());
Column contributorIdColumn = contributorTable.getColumnByName(COLUMN_CONTRIBUTOR_CONTRIBUTOR_ID);
q.where(contributorIdColumn, OperatorType.EQUALS_TO, 1);
assertEquals(
"SELECT c.name, c.country, COUNT(*) AS total FROM MetaModelSchema.contributor c WHERE c.contributor_id = 1 GROUP BY c.name, c.country",
q.toString());