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  import java.time.LocalDateTime;
24  
25  import com.healthmarketscience.jackcess.Row;
26  import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
27  import com.healthmarketscience.jackcess.util.OleBlob;
28  
29  
30  /**
31   * A row of data as column->value pairs.
32   * <p>
33   * Note that the {@link #equals} and {@link #hashCode} methods work on the row
34   * contents <i>only</i> (i.e. they ignore the id).
35   *
36   * @author James Ahlborn
37   */
38  public class RowImpl extends LinkedHashMap<String,Object> implements Row
39  {
40    private static final long serialVersionUID = 20130314L;
41  
42    private final RowIdImpl _id;
43  
44    public RowImpl(RowIdImpl id) {
45      _id = id;
46    }
47  
48    public RowImpl(RowIdImpl id, int expectedSize) {
49      super(expectedSize);
50      _id = id;
51    }
52  
53    public RowImpl(Row row) {
54      super(row);
55      _id = (RowIdImpl)row.getId();
56    }
57  
58    @Override
59    public RowIdImpl getId() {
60      return _id;
61    }
62  
63    @Override
64    public String getString(String name) {
65      return (String)get(name);
66    }
67  
68    @Override
69    public Boolean getBoolean(String name) {
70      return (Boolean)get(name);
71    }
72  
73    @Override
74    public Byte getByte(String name) {
75      return (Byte)get(name);
76    }
77  
78    @Override
79    public Short getShort(String name) {
80      return (Short)get(name);
81    }
82  
83    @Override
84    public Integer getInt(String name) {
85      return (Integer)get(name);
86    }
87  
88    @Override
89    public BigDecimal getBigDecimal(String name) {
90      return (BigDecimal)get(name);
91    }
92  
93    @Override
94    public Float getFloat(String name) {
95      return (Float)get(name);
96    }
97  
98    @Override
99    public Double getDouble(String name) {
100     return (Double)get(name);
101   }
102 
103   @Override
104   @SuppressWarnings("deprecation")
105   public Date getDate(String name) {
106     return (Date)get(name);
107   }
108 
109   @Override
110   public LocalDateTime getLocalDateTime(String name) {
111     return (LocalDateTime)get(name);
112   }
113 
114   @Override
115   public byte[] getBytes(String name) {
116     return (byte[])get(name);
117   }
118 
119   @Override
120   public ComplexValueForeignKey getForeignKey(String name) {
121     return (ComplexValueForeignKey)get(name);
122   }
123 
124   @Override
125   public OleBlob getBlob(String name) throws IOException {
126     byte[] bytes = getBytes(name);
127     return ((bytes != null) ? OleBlob.Builder.fromInternalData(bytes) : null);
128   }
129 
130   @Override
131   public String toString() {
132     return CustomToStringStyle.valueBuilder("Row[" + _id + "]")
133       .append(null, this)
134       .toString();
135   }
136 }