org.opencms.db.CmsSelectQuery Maven / Gradle / Ivy
Show all versions of opencms-test Show documentation
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.db;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
/**
* A class for generating SQL SELECT statements.
*
* @since 8.0.0
*/
public class CmsSelectQuery implements I_CmsQueryFragment {
/**
* Helper class which wraps a table alias.
*/
public class TableAlias {
/** The table alias. */
String m_name;
/**
* Creates a new instance.
*
* @param name the table alias
*/
public TableAlias(String name) {
m_name = name;
}
/**
* Adds the table alias before a column name.
*
* @param colName the column name
*
* @return the column name, qualified by the table alias
*/
public String column(String colName) {
return m_name + "." + colName;
}
/**
* Returns the name of the table alias.
*
* @return the name of the table alias
*/
public String getName() {
return m_name;
}
}
/** The columns of the result. */
private CmsCompositeQueryFragment m_columns = new CmsCompositeQueryFragment();
/** The conditions for the WHERE clause. */
private CmsCompositeQueryFragment m_conditions = new CmsCompositeQueryFragment();
/** The result ordering. */
private I_CmsQueryFragment m_ordering;
/** SQL clauses which will be added after the other ones. */
private CmsCompositeQueryFragment m_otherClauses = new CmsCompositeQueryFragment();
/** The tables from which the data should be fetched. */
private List m_tables = Lists.newArrayList();
/** The table aliases which have already been used. */
private Set m_usedAliases = new HashSet();
/**
* Creates a new instance.
*/
public CmsSelectQuery() {
// always use 1 = 1 as a condition so we don't have to worry about whether we need a "WHERE" keyword
m_conditions.add(new CmsSimpleQueryFragment("1 = 1", Collections.