123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /*
- Copyright (c) 2011 James Ahlborn
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
- package com.healthmarketscience.jackcess.impl.complex;
-
- import java.io.IOException;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
-
- import com.healthmarketscience.jackcess.Column;
- import com.healthmarketscience.jackcess.Row;
- import com.healthmarketscience.jackcess.Table;
- import com.healthmarketscience.jackcess.complex.ComplexDataType;
- import com.healthmarketscience.jackcess.complex.ComplexValue;
- import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
- import com.healthmarketscience.jackcess.complex.UnsupportedColumnInfo;
- import com.healthmarketscience.jackcess.complex.UnsupportedValue;
-
- /**
- * Complex column info for an unsupported complex type.
- *
- * @author James Ahlborn
- */
- public class UnsupportedColumnInfoImpl
- extends ComplexColumnInfoImpl<UnsupportedValue>
- implements UnsupportedColumnInfo
- {
-
- public UnsupportedColumnInfoImpl(Column column, int complexId,
- Table typeObjTable, Table flatTable)
- throws IOException
- {
- super(column, complexId, typeObjTable, flatTable);
- }
-
- public List<Column> getValueColumns() {
- return getTypeColumns();
- }
-
- @Override
- public ComplexDataType getType()
- {
- return ComplexDataType.UNSUPPORTED;
- }
-
- @Override
- protected UnsupportedValueImpl toValue(
- ComplexValueForeignKey complexValueFk,
- Row rawValue)
- {
- ComplexValue.Id id = getValueId(rawValue);
-
- Map<String,Object> values = new LinkedHashMap<String,Object>();
- for(Column col : getValueColumns()) {
- col.setRowValue(values, col.getRowValue(rawValue));
- }
-
- return new UnsupportedValueImpl(id, complexValueFk, values);
- }
-
- @Override
- protected Object[] asRow(Object[] row, UnsupportedValue value)
- throws IOException
- {
- super.asRow(row, value);
-
- Map<String,Object> values = value.getValues();
- for(Column col : getValueColumns()) {
- col.setRowValue(row, col.getRowValue(values));
- }
-
- return row;
- }
-
- public static UnsupportedValue newValue(Map<String,?> values) {
- return newValue(INVALID_FK, values);
- }
-
- public static UnsupportedValue newValue(
- ComplexValueForeignKey complexValueFk, Map<String,?> values) {
- return new UnsupportedValueImpl(INVALID_ID, complexValueFk,
- new LinkedHashMap<String,Object>(values));
- }
-
- private static class UnsupportedValueImpl extends ComplexValueImpl
- implements UnsupportedValue
- {
- private Map<String,Object> _values;
-
- private UnsupportedValueImpl(Id id, ComplexValueForeignKey complexValueFk,
- Map<String,Object> values)
- {
- super(id, complexValueFk);
- _values = values;
- }
-
- public Map<String,Object> getValues() {
- return _values;
- }
-
- public Object get(String columnName) {
- return getValues().get(columnName);
- }
-
- public void set(String columnName, Object value) {
- getValues().put(columnName, value);
- }
-
- public void update() throws IOException {
- getComplexValueForeignKey().updateUnsupportedValue(this);
- }
-
- public void delete() throws IOException {
- getComplexValueForeignKey().deleteUnsupportedValue(this);
- }
-
- @Override
- public String toString()
- {
- return "UnsupportedValue(" + getComplexValueForeignKey() + "," + getId() +
- ") " + getValues();
- }
- }
- }
|