Back to the Main Page
All Selects
Pretty much all of the selects.
package au.id.medge.daotester.testsuite;
import au.id.medge.dao.BaseDatabaseObject;
import au.id.medge.dao.DAO;
import au.id.medge.dao.annotations.daoproperty;
import au.id.medge.dao.annotations.daotable;
import au.id.medge.dao.query.AggregatedObject;
import au.id.medge.dao.query.Filter;
import au.id.medge.dao.query.ListFilter;
import au.id.medge.dao.query.OrderBy;
import au.id.medge.dao.query.PropertyFilter;
import au.id.medge.dao.query.SelectColumn;
import au.id.medge.dao.utilities.DAOException;
import au.id.medge.tutorial.ContactInfo;
import au.id.medge.tutorial.Country;
import au.id.medge.tutorial.Person;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class FullSelectTest extends AbstractTestSuite {
private static final String TEST_SURNAME = "Jones";
private static final String OTHER_TEST_SURNAME = "Smith";
private static final String TEST_GIVENS = "Colin";
private static final String OTHER_TEST_GIVENS = "Fred";
private static final String TEST_COUNTRY_ID = "AUSTRALIA";
public FullSelectTest() {
super("Full Select Tests");
}
private void testSelectClass() {
try {
List resultSet = getDAO().select(Person.class);
if (resultSet.isEmpty()) {
reportFailure("Select class failed");
} else {
reportSuccess("Select class succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectDAOTable() {
try {
daotable table = getDAO().getTable(Person.class);
List resultSet = getDAO().select(table);
if (resultSet.isEmpty()) {
reportFailure("Select daotable failed");
} else {
reportSuccess("Select daotable succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectObject() {
try {
Person person = new Person();
List resultSet = getDAO().select(person);
if (resultSet.isEmpty()) {
reportFailure("Select all objects failed");
} else {
reportSuccess("Select all objects succeeded");
}
int allCount = resultSet.size();
person.setSurname(TEST_SURNAME);
resultSet = getDAO().select(person);
if (resultSet.isEmpty()) {
reportFailure("Select some objects failed");
} else {
reportSuccess("Select some objects succeeded");
}
if (resultSet.size() > allCount) {
reportFailure("Select some objects failed to filter");
} else {
reportSuccess("Select some objects succeeded with filter");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectObjectSort() {
try {
Person person = new Person();
person.setSurname(TEST_SURNAME);
daoproperty property = getDAO().getProperty(Person.class, Person.GIVENS);
OrderBy orderBy = new OrderBy(property);
List resultSet = getDAO().select(person, orderBy);
Person firstPerson = resultSet.get(0);
Person secondPerson = resultSet.get(1);
if (firstPerson.getGivens().compareTo(secondPerson.getGivens()) > 0) {
reportFailure("Select objects sorted failed");
} else {
reportSuccess("Select objects sorted succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectTableSelect() {
try {
daotable table = getDAO().getTable(Person.class);
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
List resultSet = getDAO().select(table, column1, column2);
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
if (!hasOnlySelectColumns) {
reportFailure("Select table select specific columns failed");
} else {
reportSuccess("Select table select specific columns succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectClassSelect() {
try {
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
List resultSet = getDAO().select(Person.class, column1, column2);
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
if (!hasOnlySelectColumns) {
reportFailure("Select class select specific columns failed");
} else {
reportSuccess("Select class select specific columns succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectTableSelectSort() {
try {
daotable table = getDAO().getTable(Person.class);
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
OrderBy orderBy = new OrderBy(property1);
List resultSet = getDAO().select(table, new SelectColumn[]{column1, column2}, orderBy);
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
boolean inRightOrder = true;
for (int i = 1; i < resultSet.size(); i++) {
Person firstPerson = resultSet.get(i - 1);
Person secondPerson = resultSet.get(i);
inRightOrder &= (firstPerson.getSurname().compareTo(secondPerson.getSurname()) <= 0);
}
if (!hasOnlySelectColumns) {
reportFailure("Select table select specific columns sort [columns] failed");
} else {
reportSuccess("Select table select specific columns sort [columns] succeeded");
}
if (!inRightOrder) {
reportFailure("Select table select specific columns sort [sort] failed");
} else {
reportSuccess("Select table select specific columns sort [sort]succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectClassSelectSort() {
try {
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
OrderBy orderBy = new OrderBy(property1);
List resultSet = getDAO().select(Person.class, new SelectColumn[]{column1, column2}, orderBy);
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
boolean inRightOrder = true;
for (int i = 1; i < resultSet.size(); i++) {
Person firstPerson = resultSet.get(i - 1);
Person secondPerson = resultSet.get(i);
inRightOrder &= (firstPerson.getSurname().compareTo(secondPerson.getSurname()) <= 0);
}
if (!hasOnlySelectColumns) {
reportFailure("Select class select specific columns sort [columns] failed");
} else {
reportSuccess("Select class select specific columns sort [columns] succeeded");
}
if (!inRightOrder) {
reportFailure("Select class select specific columns sort [sort] failed");
} else {
reportSuccess("Select class select specific columns sort [sort]succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectTableSelectSorts() {
try {
daotable table = getDAO().getTable(Person.class);
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
OrderBy orderBy1 = new OrderBy(property1);
OrderBy orderBy2 = new OrderBy(property2);
List resultSet = getDAO().select(table, new SelectColumn[]{column1, column2}, new OrderBy[]{orderBy1, orderBy2});
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
boolean inRightOrder = true;
for (int i = 1; i < resultSet.size(); i++) {
Person firstPerson = resultSet.get(i - 1);
Person secondPerson = resultSet.get(i);
inRightOrder &= (firstPerson.getSurname().compareTo(secondPerson.getSurname()) <= 0);
if (firstPerson.getSurname().compareTo(secondPerson.getSurname()) == 0) {
inRightOrder &= (firstPerson.getGivens().compareTo(secondPerson.getGivens()) <= 0);
}
}
if (!hasOnlySelectColumns) {
reportFailure("Select table select specific columns sorts [columns] failed");
} else {
reportSuccess("Select table select specific columns sorts [columns] succeeded");
}
if (!inRightOrder) {
reportFailure("Select table select specific columns sorts [sort] failed");
} else {
reportSuccess("Select table select specific columns sorts [sort]succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectClassSelectSorts() {
try {
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
OrderBy orderBy1 = new OrderBy(property1);
OrderBy orderBy2 = new OrderBy(property2);
List resultSet = getDAO().select(Person.class, new SelectColumn[]{column1, column2}, new OrderBy[]{orderBy1, orderBy2});
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
boolean inRightOrder = true;
for (int i = 1; i < resultSet.size(); i++) {
Person firstPerson = resultSet.get(i - 1);
Person secondPerson = resultSet.get(i);
inRightOrder &= (firstPerson.getSurname().compareTo(secondPerson.getSurname()) <= 0);
if (firstPerson.getSurname().compareTo(secondPerson.getSurname()) == 0) {
inRightOrder &= (firstPerson.getGivens().compareTo(secondPerson.getGivens()) <= 0);
}
}
if (!hasOnlySelectColumns) {
reportFailure("Select class select specific columns sorts [columns] failed");
} else {
reportSuccess("Select class select specific columns sorts [columns] succeeded");
}
if (!inRightOrder) {
reportFailure("Select class select specific columns sorts [sort] failed");
} else {
reportSuccess("Select class select specific columns sorts [sort]succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectTableSelectFilter() {
try {
daotable table = getDAO().getTable(Person.class);
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
Filter filter = new PropertyFilter(table, property1, TEST_SURNAME);
List resultSet = getDAO().select(table, new SelectColumn[]{column1, column2}, filter);
boolean hasOnlySelectColumns = true;
boolean hasOnlyOneSurname = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
for (Person person : resultSet) {
hasOnlyOneSurname &= (person.getSurname().equalsIgnoreCase(TEST_SURNAME));
}
if (!hasOnlySelectColumns) {
reportFailure("Select table select specific columns filter [columns] failed");
} else {
reportSuccess("Select table select specific columns filter [columns] succeeded");
}
if (!hasOnlyOneSurname) {
reportFailure("Select table select specific columns filter [filter] failed");
} else {
reportSuccess("Select table select specific columns filter [filter] succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectClassSelectFilter() {
try {
daotable table = getDAO().getTable(Person.class);
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
Filter filter = new PropertyFilter(table, property1, TEST_SURNAME);
List resultSet = getDAO().select(Person.class, new SelectColumn[]{column1, column2}, filter);
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
boolean hasOnlyOneSurname = true;
for (Person person : resultSet) {
hasOnlyOneSurname &= (person.getSurname().equalsIgnoreCase(TEST_SURNAME));
}
if (!hasOnlySelectColumns) {
reportFailure("Select class select specific columns filter [columns] failed");
} else {
reportSuccess("Select class select specific columns filter [columns] succeeded");
}
if (!hasOnlyOneSurname) {
reportFailure("Select class select specific columns filter [filter] failed");
} else {
reportSuccess("Select class select specific columns filter [filter] succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectTableSelectSortsFilter() {
try {
daotable table = getDAO().getTable(Person.class);
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
OrderBy orderBy2 = new OrderBy(property2);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
Filter filter = new PropertyFilter(table, property1, TEST_SURNAME);
List resultSet = getDAO().select(table, new SelectColumn[]{column1, column2}, new OrderBy[]{orderBy2}, filter);
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
boolean hasOnlyOneSurname = true;
for (Person person : resultSet) {
hasOnlyOneSurname &= (person.getSurname().equalsIgnoreCase(TEST_SURNAME));
}
boolean inRightOrder = true;
for (int i = 1; i < resultSet.size(); i++) {
Person firstPerson = resultSet.get(i - 1);
Person secondPerson = resultSet.get(i);
inRightOrder &= (firstPerson.getGivens().compareTo(secondPerson.getGivens()) <= 0);
}
if (!hasOnlySelectColumns) {
reportFailure("Select table select specific columns sort filter [columns] failed");
} else {
reportSuccess("Select table select specific columns sort filter [columns] succeeded");
}
if (!hasOnlyOneSurname) {
reportFailure("Select table select specific columns sort filter [filter] failed");
} else {
reportSuccess("Select table select specific columns sort filter [filter] succeeded");
}
if (!inRightOrder) {
reportFailure("Select table select specific columns sort filter [sort] failed");
} else {
reportSuccess("Select table select specific columns sort filter [sort]succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectClassSelectSortsFilter() {
try {
daotable table = getDAO().getTable(Person.class);
daoproperty property1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty property2 = getDAO().getProperty(Person.class, Person.GIVENS);
OrderBy orderBy2 = new OrderBy(property2);
SelectColumn column1 = new SelectColumn(property1);
SelectColumn column2 = new SelectColumn(property2);
Filter filter = new PropertyFilter(table, property1, TEST_SURNAME);
List resultSet = getDAO().select(Person.class, new SelectColumn[]{column1, column2}, new OrderBy[]{orderBy2}, filter);
boolean hasOnlySelectColumns = true;
for (Person person : resultSet) {
hasOnlySelectColumns &= (person.getGivens() != null && person.getPersonId() == null);
}
boolean hasOnlyOneSurname = true;
for (Person person : resultSet) {
hasOnlyOneSurname &= (person.getSurname().equalsIgnoreCase(TEST_SURNAME));
}
boolean inRightOrder = true;
for (int i = 1; i < resultSet.size(); i++) {
Person firstPerson = resultSet.get(i - 1);
Person secondPerson = resultSet.get(i);
inRightOrder &= (firstPerson.getGivens().compareTo(secondPerson.getGivens()) <= 0);
}
if (!hasOnlySelectColumns) {
reportFailure("Select class select specific columns sort filter [columns] failed");
} else {
reportSuccess("Select class select specific columns sort filter [columns] succeeded");
}
if (!hasOnlyOneSurname) {
reportFailure("Select class select specific columns sort filter [filter] failed");
} else {
reportSuccess("Select class select specific columns sort filter [filter] succeeded");
}
if (!inRightOrder) {
reportFailure("Select class select specific columns sort filter [sort] failed");
} else {
reportSuccess("Select class select specific columns sort filter [sort]succeeded");
}
} catch (DAOException ex) {
reportFailure("DAO Failed", ex);
} catch (SQLException ex) {
reportFailure("SQL Failed", ex);
}
}
private void testSelectClassSelectsMultiTable() {
try {
daotable tableA = getDAO().getTable(Person.class);
daotable tableB = getDAO().getTable(ContactInfo.class);
daoproperty propertyA1 = getDAO().getProperty(Person.class, Person.SURNAME);
daoproperty propertyA2 = getDAO().getProperty(Person.class, Person.GIVENS);
daoproperty propertyB1 = getDAO().getProperty(ContactInfo.class, ContactInfo.CONTACTINFOTYPE);
daoproperty propertyB2 = getDAO().getProperty(ContactInfo.class, ContactInfo.CONTACTINFO);
SelectColumn columnA1 = new SelectColumn(tableA, propertyA1);
SelectColumn columnA2 = new SelectColumn(propertyA2);
SelectColumn columnB1 = new SelectColumn(tableB, propertyB1);
SelectColumn columnB2 = new SelectColumn(tableB, propertyB2);
Filter filter = new PropertyFilter(tableA, propertyA1, TEST_SURNAME);
OrderBy orderByA2 = new OrderBy(propertyA2);
OrderBy orderByB1 = new OrderBy(tableB, propertyB1);
SelectColumn[] selectColumns = new SelectColumn[]{columnA1, columnA2, columnB1, columnB2};
OrderBy[] orderBys = new OrderBy[]{orderByA2, orderByB1};
List
Back to the Main Page