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.complex;
18  
19  import java.io.IOException;
20  import java.io.ObjectStreamException;
21  import java.time.LocalDateTime;
22  import java.util.Date;
23  import java.util.List;
24  import java.util.Map;
25  
26  import com.healthmarketscience.jackcess.Column;
27  import com.healthmarketscience.jackcess.DateTimeType;
28  
29  
30  /**
31   * Value which is returned for a complex column.  This value corresponds to a
32   * foreign key in a secondary table which contains the actual complex data for
33   * this row (which could be 0 or more complex values for a given row).  This
34   * class contains various convenience methods for interacting with the actual
35   * complex values.
36   * <p>
37   * This class will cache the associated complex values returned from one of
38   * the lookup methods.  The various modification methods will clear this cache
39   * automatically.  The {@link #reset} method may be called manually to clear
40   * this internal cache.
41   *
42   * @author James Ahlborn
43   */
44  public abstract class ComplexValueForeignKey extends Number
45  {
46    private static final long serialVersionUID = 20130319L;
47  
48    @Override
49    public byte byteValue() {
50      return (byte)get();
51    }
52  
53    @Override
54    public short shortValue() {
55      return (short)get();
56    }
57  
58    @Override
59    public int intValue() {
60      return get();
61    }
62  
63    @Override
64    public long longValue() {
65      return get();
66    }
67  
68    @Override
69    public float floatValue() {
70      return get();
71    }
72  
73    @Override
74    public double doubleValue() {
75      return get();
76    }
77  
78    protected final Object writeReplace() throws ObjectStreamException {
79      // if we are going to serialize this ComplexValueForeignKey, convert it
80      // back to a normal Integer (in case it is restored outside of the context
81      // of jackcess)
82      return Integer.valueOf(get());
83    }
84  
85    @Override
86    public int hashCode() {
87      return get();
88    }
89  
90    @Override
91    public boolean equals(Object o) {
92      return ((this == o) ||
93              ((o != null) && (getClass() == o.getClass()) &&
94               (get() == ((ComplexValueForeignKey)o).get())));
95    }
96  
97    @Override
98    public String toString() {
99      return String.valueOf(get());
100   }
101 
102   public abstract int get();
103 
104   public abstract Column getColumn();
105 
106   public abstract ComplexDataType getComplexType();
107 
108   public abstract int countValues() throws IOException;
109 
110   public abstract List<? extends ComplexValue> getValues() throws IOException;
111 
112   public abstract List<Version> getVersions() throws IOException;
113 
114   public abstract List<Attachment> getAttachments()
115     throws IOException;
116 
117   public abstract List<SingleValue> getMultiValues()
118     throws IOException;
119 
120   public abstract List<UnsupportedValue> getUnsupportedValues()
121     throws IOException;
122 
123   public abstract void reset();
124 
125   public abstract Version addVersion(String value)
126     throws IOException;
127 
128   /**
129    * @deprecated see {@link DateTimeType} for details
130    */
131   @Deprecated
132   public abstract Version addVersion(String value, Date modifiedDate)
133     throws IOException;
134 
135   public abstract Version addVersion(String value, LocalDateTime modifiedDate)
136     throws IOException;
137 
138   public abstract Attachment addAttachment(byte[] data)
139     throws IOException;
140 
141   /**
142    * @deprecated see {@link DateTimeType} for details
143    */
144   @Deprecated
145   public abstract Attachment addAttachment(
146       String url, String name, String type, byte[] data,
147       Date timeStamp, Integer flags)
148     throws IOException;
149 
150   public abstract Attachment addAttachment(
151       String url, String name, String type, byte[] data,
152       LocalDateTime timeStamp, Integer flags)
153     throws IOException;
154 
155   public abstract Attachment addEncodedAttachment(byte[] encodedData)
156     throws IOException;
157 
158   /**
159    * @deprecated see {@link DateTimeType} for details
160    */
161   @Deprecated
162   public abstract Attachment addEncodedAttachment(
163       String url, String name, String type, byte[] encodedData,
164       Date timeStamp, Integer flags)
165     throws IOException;
166 
167   public abstract Attachment addEncodedAttachment(
168       String url, String name, String type, byte[] encodedData,
169       LocalDateTime timeStamp, Integer flags)
170     throws IOException;
171 
172   public abstract Attachment/com/healthmarketscience/jackcess/complex/Attachment.html#Attachment">Attachment updateAttachment(Attachment attachment)
173     throws IOException;
174 
175   public abstract Attachment/com/healthmarketscience/jackcess/complex/Attachment.html#Attachment">Attachment deleteAttachment(Attachment attachment)
176     throws IOException;
177 
178   public abstract SingleValue addMultiValue(Object value)
179     throws IOException;
180 
181   public abstract SingleValuecom/healthmarketscience/jackcess/complex/SingleValue.html#SingleValue">SingleValue updateMultiValue(SingleValue value)
182     throws IOException;
183 
184   public abstract SingleValuecom/healthmarketscience/jackcess/complex/SingleValue.html#SingleValue">SingleValue deleteMultiValue(SingleValue value)
185     throws IOException;
186 
187   public abstract UnsupportedValue addUnsupportedValue(Map<String,?> values)
188     throws IOException;
189 
190   public abstract UnsupportedValuearketscience/jackcess/complex/UnsupportedValue.html#UnsupportedValue">UnsupportedValue updateUnsupportedValue(UnsupportedValue value)
191     throws IOException;
192 
193   public abstract UnsupportedValuearketscience/jackcess/complex/UnsupportedValue.html#UnsupportedValue">UnsupportedValue deleteUnsupportedValue(UnsupportedValue value)
194     throws IOException;
195 
196   public abstract void deleteAllValues()
197     throws IOException;
198 
199 }