Move use of Glom.build_sql*() into a new SqlUtils class.
[online-glom:gwt-glom.git] / src / main / java / org / glom / web / server / SqlUtils.java
1 /*
2  * Copyright (C) 2012 Openismus GmbH
3  *
4  * This file is part of GWT-Glom.
5  *
6  * GWT-Glom is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with GWT-Glom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package org.glom.web.server;
21
22 import org.glom.libglom.Field;
23 import org.glom.libglom.Glom;
24 import org.glom.libglom.LayoutFieldVector;
25 import org.glom.libglom.Relationship;
26 import org.glom.libglom.SortClause;
27 import org.glom.libglom.SqlBuilder;
28 import org.glom.libglom.SqlExpr;
29 import org.glom.libglom.Value;
30
31 /**
32  * @author Ben Konrath <ben@bagu.org>
33  * 
34  */
35 public class SqlUtils {
36
37         // TODO: Change to final ArrayList<LayoutItem_Field> fieldsToGet
38         public static String build_sql_select_with_key(final String tableName, final LayoutFieldVector fieldsToGet,
39                         final Field primaryKey, final Value gdaPrimaryKeyValue) {
40                 final SqlBuilder builder = Glom.build_sql_select_with_key(tableName, fieldsToGet, primaryKey,
41                                 gdaPrimaryKeyValue);
42                 return Glom.sqlbuilder_get_full_query(builder);
43         }
44
45         public static String build_sql_select_with_where_clause(final String tableName,
46                         final LayoutFieldVector fieldsToGet, final SqlExpr whereClause, final SortClause sortClause) {
47                 final Relationship extraJoin = new Relationship(); // Ignored.
48                 final SqlBuilder builder = Glom.build_sql_select_with_where_clause(tableName, fieldsToGet, whereClause,
49                                 extraJoin, sortClause);
50                 return Glom.sqlbuilder_get_full_query(builder);
51         }
52
53         public static String build_sql_count_select_with_where_clause(final String tableName,
54                         final LayoutFieldVector fieldsToGet) {
55                 final SqlBuilder builder_inner = Glom.build_sql_select_with_where_clause(tableName, fieldsToGet);
56                 final SqlBuilder builder = Glom.build_sql_select_count_rows(builder_inner);
57                 return Glom.sqlbuilder_get_full_query(builder);
58         }
59
60         public static String build_sql_count_select_with_where_clause(final String tableName,
61                         final LayoutFieldVector fieldsToGet, final SqlExpr whereClause) {
62                 final SqlBuilder builder_inner = Glom.build_sql_select_with_where_clause(tableName, fieldsToGet, whereClause);
63                 final SqlBuilder builder = Glom.build_sql_select_count_rows(builder_inner);
64                 return Glom.sqlbuilder_get_full_query(builder);
65         }
66
67 }