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