You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnsupportedColumnInfoImpl.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. Copyright (c) 2011 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.impl.complex;
  14. import java.io.IOException;
  15. import java.util.LinkedHashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. import com.healthmarketscience.jackcess.Column;
  19. import com.healthmarketscience.jackcess.Row;
  20. import com.healthmarketscience.jackcess.Table;
  21. import com.healthmarketscience.jackcess.complex.ComplexDataType;
  22. import com.healthmarketscience.jackcess.complex.ComplexValue;
  23. import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
  24. import com.healthmarketscience.jackcess.complex.UnsupportedColumnInfo;
  25. import com.healthmarketscience.jackcess.complex.UnsupportedValue;
  26. /**
  27. * Complex column info for an unsupported complex type.
  28. *
  29. * @author James Ahlborn
  30. */
  31. public class UnsupportedColumnInfoImpl
  32. extends ComplexColumnInfoImpl<UnsupportedValue>
  33. implements UnsupportedColumnInfo
  34. {
  35. public UnsupportedColumnInfoImpl(Column column, int complexId,
  36. Table typeObjTable, Table flatTable)
  37. throws IOException
  38. {
  39. super(column, complexId, typeObjTable, flatTable);
  40. }
  41. public List<Column> getValueColumns() {
  42. return getTypeColumns();
  43. }
  44. @Override
  45. public ComplexDataType getType()
  46. {
  47. return ComplexDataType.UNSUPPORTED;
  48. }
  49. @Override
  50. protected UnsupportedValueImpl toValue(
  51. ComplexValueForeignKey complexValueFk,
  52. Row rawValue)
  53. {
  54. ComplexValue.Id id = getValueId(rawValue);
  55. Map<String,Object> values = new LinkedHashMap<String,Object>();
  56. for(Column col : getValueColumns()) {
  57. col.setRowValue(values, col.getRowValue(rawValue));
  58. }
  59. return new UnsupportedValueImpl(id, complexValueFk, values);
  60. }
  61. @Override
  62. protected Object[] asRow(Object[] row, UnsupportedValue value)
  63. throws IOException
  64. {
  65. super.asRow(row, value);
  66. Map<String,Object> values = value.getValues();
  67. for(Column col : getValueColumns()) {
  68. col.setRowValue(row, col.getRowValue(values));
  69. }
  70. return row;
  71. }
  72. public static UnsupportedValue newValue(Map<String,?> values) {
  73. return newValue(INVALID_FK, values);
  74. }
  75. public static UnsupportedValue newValue(
  76. ComplexValueForeignKey complexValueFk, Map<String,?> values) {
  77. return new UnsupportedValueImpl(INVALID_ID, complexValueFk,
  78. new LinkedHashMap<String,Object>(values));
  79. }
  80. private static class UnsupportedValueImpl extends ComplexValueImpl
  81. implements UnsupportedValue
  82. {
  83. private Map<String,Object> _values;
  84. private UnsupportedValueImpl(Id id, ComplexValueForeignKey complexValueFk,
  85. Map<String,Object> values)
  86. {
  87. super(id, complexValueFk);
  88. _values = values;
  89. }
  90. public Map<String,Object> getValues() {
  91. return _values;
  92. }
  93. public Object get(String columnName) {
  94. return getValues().get(columnName);
  95. }
  96. public void set(String columnName, Object value) {
  97. getValues().put(columnName, value);
  98. }
  99. public void update() throws IOException {
  100. getComplexValueForeignKey().updateUnsupportedValue(this);
  101. }
  102. public void delete() throws IOException {
  103. getComplexValueForeignKey().deleteUnsupportedValue(this);
  104. }
  105. @Override
  106. public String toString()
  107. {
  108. return "UnsupportedValue(" + getComplexValueForeignKey() + "," + getId() +
  109. ") " + getValues();
  110. }
  111. }
  112. }