View Javadoc
1   /*
2   Copyright (c) 2014 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  
21  import com.healthmarketscience.jackcess.PropertyMap;
22  import com.healthmarketscience.jackcess.complex.ComplexColumnInfo;
23  import com.healthmarketscience.jackcess.complex.ComplexDataType;
24  import com.healthmarketscience.jackcess.complex.ComplexValue;
25  import com.healthmarketscience.jackcess.impl.complex.ComplexColumnInfoImpl;
26  import com.healthmarketscience.jackcess.impl.complex.MultiValueColumnInfoImpl;
27  import com.healthmarketscience.jackcess.impl.complex.MultiValueColumnPropertyMap;
28  
29  /**
30   * ColumnImpl subclass which is used for complex data types.
31   * 
32   * @author James Ahlborn
33   * @usage _advanced_class_
34   */
35  class ComplexColumnImpl extends ColumnImpl 
36  {
37    /** additional information specific to complex columns */
38    private final ComplexColumnInfo<? extends ComplexValue> _complexInfo;
39    /** properties for multi-value column */
40    private PropertyMap _mvProps;
41  
42    ComplexColumnImpl(InitArgs args) throws IOException
43    {
44      super(args);
45      _complexInfo = ComplexColumnSupport.create(this, args.buffer, args.offset);
46    }
47  
48    @Override
49    void postTableLoadInit() throws IOException {
50      if(_complexInfo != null) {
51        ((ComplexColumnInfoImpl<? extends ComplexValue>)_complexInfo)
52          .postTableLoadInit();
53      }
54      super.postTableLoadInit();
55    }
56  
57    @Override
58    public PropertyMap getProperties() throws IOException {
59      if(_complexInfo.getType() == ComplexDataType.MULTI_VALUE) {
60        if(_mvProps == null) {
61          PropertyMap primaryProps = super.getProperties();
62          PropertyMap complexProps = ((MultiValueColumnInfoImpl)_complexInfo)
63            .getValueColumn().getProperties();
64          _mvProps = new MultiValueColumnPropertyMap(primaryProps, complexProps);
65        }
66        return _mvProps;
67      }
68      return super.getProperties();
69    }
70  
71    @Override
72    public ComplexColumnInfo<? extends ComplexValue> getComplexInfo() {
73      return _complexInfo;
74    }
75  }