summaryrefslogtreecommitdiff
path: root/sqlelements/src/main/java/org/israfil/sqlelements/SimpleColumn.java
blob: d5919aa56ddae53910e2386316be245a3c4ae748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * SQLElements object-oriented SQL parsing and generation library
 * 
 * Copyright (c) 2003, 2004, 2005 Israfil Consulting Services Corporation
 * Copyright (c) 2003, 2004, 2005 Christian Edward Gruber
 * All Rights Reserved
 * 
 *  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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 * OF SUCH DAMAGE.
 *
 *  You should have received a copy of the GNU Lesser General Public License 
 *  along with this library; if not, please visit http://www.gnu.org/licenses/lgpl.html
 *
 * $Id: SimpleColumn.java 25 2005-12-15 23:36:26Z cgruber $
 */
package org.israfil.sqlelements;

import org.israfil.sqlelements.render.SQLRenderContext;

/** 
 * A simple implementation of a Column which takes a name and a table.  The table
 * can be any Table object.
 *
 * @author <a href="mailto:cgruber@israfil.net">Christian Edward Gruber </a>
 * @author Latest: $Author: cgruber $
 * @version $Revision: 25 $ 
 */
public class SimpleColumn extends AbstractAliasedSQLElement implements Column
{
    
        protected Table table;
        public Table getTable() { return table;  }

        protected String name;
        public String getName() { return name;  }

        /**
         * Constructs a Column implementation instance
         * 
         * @param table A Table object of which this Column is a field.
         * @param colName The name of this column
         */
        public SimpleColumn(Table table, String colName) {
        	this(table,colName,null);
        }

        /**
         * Constructs a Column implementation instance
         * 
         * @param table A Table object of which this Column is a field.
         * @param colName The name of this column
         * @param alias An alternate designation for this column - usually shorter
         */
        public SimpleColumn(Table table, String colName, String alias) 
        {
        	super(alias);
            this.table = table;
            this.name = colName;
        }

        public String render(SQLRenderContext context)
        {
            return this.name;
        }

        /**
         * Convenience method to create batches of SimpleColumns from an array
         * of names.  Note: this cannot be used to create SimpleColumns with 
         * aliases.
         * 
         * @param table A table, within whom the columns will be created.
         * @param names An array of column names
         * @return an array of SimpleColumns
         */
        public static SimpleColumn[] createColumns(Table table, String ... names) 
        {   
            SimpleColumn[] result = new SimpleColumn[names.length];
            for (int i = 0; i < names.length; i++)
                result[i] = new SimpleColumn(table,names[i]);
            return result;
        }

        public String toString()
        {
            return "SimpleColumn[" + table + "," + name + "]";
        }

}