PageRenderTime 27ms CodeModel.GetById 9ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.2.0-rc0/src/java/org/apache/hcatalog/data/HCatRecord.java

#
Java | 136 lines | 80 code | 29 blank | 27 comment | 0 complexity | a12327e3bb26df0ccc77193e64de22a8 MD5 | raw file
  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, software
 13 * distributed under the License is distributed on an "AS IS" BASIS,
 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18
 19package org.apache.hcatalog.data;
 20
 21import java.util.List;
 22import java.util.Map;
 23
 24import org.apache.hcatalog.common.HCatException;
 25import org.apache.hcatalog.data.schema.HCatSchema;
 26
 27/**
 28 * Abstract class exposing get and set semantics for basic record usage.
 29 * Note :
 30 *   HCatRecord is designed only to be used as in-memory representation only.
 31 *   Don't use it to store data on the physical device.
 32 */
 33public abstract class HCatRecord implements HCatRecordable {
 34
 35    public abstract Object get(String fieldName, HCatSchema recordSchema) throws HCatException;
 36    public abstract void set(String fieldName, HCatSchema recordSchema, Object value ) throws HCatException;
 37    public abstract void remove(int idx) throws HCatException;
 38
 39    protected Object get(String fieldName, HCatSchema recordSchema, Class clazz) throws HCatException{
 40        // TODO : if needed, verify that recordschema entry for fieldname matches appropriate type.
 41        return get(fieldName,recordSchema);
 42    }
 43
 44    public Boolean getBoolean(String fieldName, HCatSchema recordSchema) throws HCatException {
 45        return (Boolean) get(fieldName, recordSchema, Boolean.class);
 46    }
 47
 48    public void setBoolean(String fieldName, HCatSchema recordSchema, Boolean value) throws HCatException {
 49        set(fieldName,recordSchema,value);
 50    }
 51
 52    public Byte getByte(String fieldName, HCatSchema recordSchema) throws HCatException {
 53        //TINYINT
 54        return (Byte) get(fieldName, recordSchema, Byte.class);
 55    }
 56
 57    public void setByte(String fieldName, HCatSchema recordSchema, Byte value) throws HCatException {
 58        set(fieldName,recordSchema,value);
 59    }
 60
 61    public Short getShort(String fieldName, HCatSchema recordSchema) throws HCatException {
 62        // SMALLINT
 63        return (Short) get(fieldName, recordSchema, Short.class);
 64    }
 65
 66    public void setShort(String fieldName, HCatSchema recordSchema, Short value) throws HCatException {
 67        set(fieldName,recordSchema,value);
 68    }
 69
 70    public Integer getInteger(String fieldName, HCatSchema recordSchema) throws HCatException {
 71        return (Integer) get(fieldName,recordSchema, Integer.class);
 72    }
 73
 74    public void setInteger(String fieldName, HCatSchema recordSchema, Integer value) throws HCatException {
 75        set(fieldName,recordSchema,value);
 76    }
 77
 78    public Long getLong(String fieldName, HCatSchema recordSchema) throws HCatException {
 79        // BIGINT
 80        return (Long) get(fieldName,recordSchema,Long.class);
 81    }
 82
 83    public void setLong(String fieldName, HCatSchema recordSchema, Long value) throws HCatException {
 84        set(fieldName,recordSchema,value);
 85    }
 86
 87    public Float getFloat(String fieldName, HCatSchema recordSchema) throws HCatException {
 88        return (Float) get(fieldName,recordSchema,Float.class);
 89    }
 90
 91    public void setFloat(String fieldName, HCatSchema recordSchema, Float value) throws HCatException {
 92        set(fieldName,recordSchema,value);
 93    }
 94
 95    public Double getDouble(String fieldName, HCatSchema recordSchema) throws HCatException {
 96        return (Double) get(fieldName,recordSchema,Double.class);
 97    }
 98
 99    public void setDouble(String fieldName, HCatSchema recordSchema, Double value) throws HCatException {
100        set(fieldName,recordSchema,value);
101    }
102
103    public String getString(String fieldName, HCatSchema recordSchema) throws HCatException {
104        return (String) get(fieldName,recordSchema,String.class);
105    }
106
107    public void setString(String fieldName, HCatSchema recordSchema, String value) throws HCatException {
108        set(fieldName,recordSchema,value);
109    }
110
111    @SuppressWarnings("unchecked")
112    public List<? extends Object> getStruct(String fieldName, HCatSchema recordSchema) throws HCatException {
113        return (List<? extends Object>) get(fieldName,recordSchema,List.class);
114    }
115
116    public void setStruct(String fieldName, HCatSchema recordSchema, List<? extends Object> value) throws HCatException {
117        set(fieldName,recordSchema,value);
118    }
119
120    public List<?> getList(String fieldName, HCatSchema recordSchema) throws HCatException {
121        return (List<?>) get(fieldName,recordSchema,List.class);
122    }
123
124    public void setList(String fieldName, HCatSchema recordSchema, List<?> value) throws HCatException {
125        set(fieldName,recordSchema,value);
126    }
127
128    public Map<?,?> getMap(String fieldName, HCatSchema recordSchema) throws HCatException {
129        return (Map<?,?>) get(fieldName,recordSchema,Map.class);
130    }
131
132    public void setMap(String fieldName, HCatSchema recordSchema, Map<?,?> value) throws HCatException {
133        set(fieldName,recordSchema,value);
134    }
135
136}