View Javadoc
1   /*
2   Copyright (c) 2013 James Ahlborn
3   
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7   
8       http://www.apache.org/licenses/LICENSE-2.0
9   
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16  
17  package com.healthmarketscience.jackcess.impl;
18  
19  import java.io.IOException;
20  import java.util.LinkedHashMap;
21  import java.util.Date;
22  import java.math.BigDecimal;
23  
24  import com.healthmarketscience.jackcess.Row;
25  import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
26  import com.healthmarketscience.jackcess.util.OleBlob;
27  
28  
29  /**
30   * A row of data as column->value pairs.
31   * </p>
32   * Note that the {@link #equals} and {@link #hashCode} methods work on the row
33   * contents <i>only</i> (i.e. they ignore the id).
34   *
35   * @author James Ahlborn
36   */
37  public class RowImpl extends LinkedHashMap<String,Object> implements Row
38  {
39    private static final long serialVersionUID = 20130314L;  
40  
41    private final RowIdImpl _id;
42  
43    public RowImpl(RowIdImpl id) {
44      _id = id;
45    }
46  
47    public RowImpl(RowIdImpl id, int expectedSize) {
48      super(expectedSize);
49      _id = id;
50    }
51  
52    public RowImpl(Row row) {
53      super(row);
54      _id = (RowIdImpl)row.getId();
55    }
56  
57    public RowIdImpl getId() {
58      return _id;
59    }
60  
61    public String getString(String name) {
62      return (String)get(name);
63    }
64  
65    public Boolean getBoolean(String name) {
66      return (Boolean)get(name);
67    }
68  
69    public Byte getByte(String name) {
70      return (Byte)get(name);
71    }
72  
73    public Short getShort(String name) {
74      return (Short)get(name);
75    }
76  
77    public Integer getInt(String name) {
78      return (Integer)get(name);
79    }
80  
81    public BigDecimal getBigDecimal(String name) {
82      return (BigDecimal)get(name);
83    }
84  
85    public Float getFloat(String name) {
86      return (Float)get(name);
87    }
88  
89    public Double getDouble(String name) {
90      return (Double)get(name);
91    }
92  
93    public Date getDate(String name) {
94      return (Date)get(name);
95    }
96  
97    public byte[] getBytes(String name) {
98      return (byte[])get(name);
99    }
100 
101   public ComplexValueForeignKey getForeignKey(String name) {
102     return (ComplexValueForeignKey)get(name);
103   }
104 
105   public OleBlob getBlob(String name) throws IOException {
106     byte[] bytes = getBytes(name);
107     return ((bytes != null) ? OleBlob.Builder.fromInternalData(bytes) : null);
108   }
109 
110   @Override
111   public String toString() {
112     return CustomToStringStyle.valueBuilder("Row[" + _id + "]")
113       .append(null, this)
114       .toString();
115   }
116 }