01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.table;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.result.SortOrder;
11:
12: /**
13: * This represents a column item of an index. This is required because some
14: * indexes support descending sorted columns.
15: */
16: public class IndexColumn {
17: public String columnName;
18: public Column column;
19: public int sortType = SortOrder.ASCENDING;
20:
21: public String getSQL() {
22: StringBuffer buff = new StringBuffer(column.getSQL());
23: if ((sortType & SortOrder.DESCENDING) != 0) {
24: buff.append(" DESC");
25: }
26: if ((sortType & SortOrder.NULLS_FIRST) != 0) {
27: buff.append(" NULLS FIRST");
28: } else if ((sortType & SortOrder.NULLS_LAST) != 0) {
29: buff.append(" NULLS LAST");
30: }
31: return buff.toString();
32: }
33:
34: public static IndexColumn[] wrap(Column[] columns) {
35: IndexColumn[] list = new IndexColumn[columns.length];
36: for (int i = 0; i < list.length; i++) {
37: list[i] = new IndexColumn();
38: list[i].column = columns[i];
39: }
40: return list;
41: }
42:
43: public static void mapColumns(IndexColumn[] indexColumns,
44: Table table) throws SQLException {
45: for (int i = 0; i < indexColumns.length; i++) {
46: IndexColumn col = indexColumns[i];
47: col.column = table.getColumn(col.columnName);
48: }
49: }
50: }
|