METAMODEL-1205: Fixed CassandraUnit, Guava, Hadoop for JDK9+
[metamodel.git] / hbase / src / main / java / org / apache / metamodel / hbase / HBaseColumn.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.metamodel.hbase;
20
21 import org.apache.metamodel.schema.ColumnType;
22 import org.apache.metamodel.schema.MutableColumn;
23 import org.apache.metamodel.schema.Table;
24
25 final class HBaseColumn extends MutableColumn {
26
27 private static final long serialVersionUID = 1L;
28
29 public static final ColumnType DEFAULT_COLUMN_TYPE_FOR_ID_COLUMN = ColumnType.BINARY;
30 public static final ColumnType DEFAULT_COLUMN_TYPE_FOR_COLUMN_FAMILIES = ColumnType.LIST;
31
32 private final String columnFamily;
33 private final String qualifier;
34
35 public HBaseColumn(final String columnFamily, final Table table) {
36 this(columnFamily, null, table, -1, null);
37 }
38
39 public HBaseColumn(final String columnFamily, final String qualifier, final Table table) {
40 this(columnFamily, qualifier, table, -1, null);
41 }
42
43 public HBaseColumn(final String columnFamily, final String qualifier, final Table table, final int columnNumber,
44 final ColumnType columnType) {
45 super(getName(columnFamily, qualifier), table);
46 if (columnFamily == null) {
47 throw new IllegalArgumentException("Column family isn't allowed to be null.");
48 } else if (table == null || !(table instanceof HBaseTable)) {
49 throw new IllegalArgumentException("Table is null or isn't a HBaseTable.");
50 }
51
52 this.columnFamily = columnFamily;
53 this.qualifier = qualifier;
54
55 setColumnNumber(columnNumber);
56 setPrimaryKey(HBaseDataContext.FIELD_ID.equals(columnFamily));
57
58 // Set the columnType
59 if (columnType != null) {
60 setType(columnType);
61 } else {
62 if (isPrimaryKey() || qualifier != null) {
63 setType(DEFAULT_COLUMN_TYPE_FOR_ID_COLUMN);
64 } else {
65 setType(DEFAULT_COLUMN_TYPE_FOR_COLUMN_FAMILIES);
66 }
67 }
68 }
69
70 public String getColumnFamily() {
71 return columnFamily;
72 }
73
74 public String getQualifier() {
75 return qualifier;
76 }
77
78 private static String getName(final String columnFamily, final String qualifier) {
79 if (qualifier == null) {
80 return columnFamily;
81 }
82 return columnFamily + ":" + qualifier;
83 }
84
85 @Override
86 public Boolean isNullable() {
87 return !isPrimaryKey();
88 }
89
90 @Override
91 public String getRemarks() {
92 return null;
93 }
94
95 @Override
96 public Integer getColumnSize() {
97 return null;
98 }
99
100 @Override
101 public String getNativeType() {
102 // TODO: maybe change if no qualifier is present (and not identifier column).
103 return "byte[]";
104 }
105
106 @Override
107 public boolean isIndexed() {
108 return false;
109 }
110
111 @Override
112 public String getQuote() {
113 return null;
114 }
115 }