private void generateOrder(Sorter sorter, StatementPrototype mainStatement)
	{
		// add order statements for all non-null values
		ObjectStack oStack = new ObjectStack(adapter, sorter.getSortClass(), sorter.getSortObject());
		this.typeIds.nameStack(oStack);
		mainStatement.getIdStatementGenerator().addPropertyTablesToJoin(oStack);
		for (ObjectRepresentation rep : oStack.getAllRepresentations())
		{
			for (Integer index : rep)
			{
				StringBuilder statement = new StringBuilder();
				statement.append(rep.getAsName());
				statement.append(".");
				statement.append(rep.getPropertyName(index));
				statement.append(" ");
				statement.append(sorter.getKeyWord());
				mainStatement.addSortStatement(statement.toString());
			}
		}
		if (sorter.getSortObject() == null)
		{
			// sort on the main class' C__ID column
			StringBuilder statement = new StringBuilder();
			statement.append(oStack.getActualRepresentation().getAsName());
			statement.append(".");
			statement.append(Defaults.ID_COL);
			statement.append(" ");
			statement.append(sorter.getKeyWord());
			mainStatement.addSortStatement(statement.toString());
		}
	}