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.

ComplexValue.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.complex;
  14. import java.io.IOException;
  15. import java.io.ObjectStreamException;
  16. import com.healthmarketscience.jackcess.Column;
  17. import com.healthmarketscience.jackcess.RowId;
  18. import com.healthmarketscience.jackcess.impl.complex.ComplexColumnInfoImpl;
  19. /**
  20. * Base interface for a value in a complex column (where there may be multiple
  21. * values for a single row in the main table).
  22. *
  23. * @author James Ahlborn
  24. */
  25. public interface ComplexValue
  26. {
  27. /**
  28. * Returns the unique identifier of this complex value (this value is unique
  29. * among all values in all rows of the main table).
  30. *
  31. * @return the current id or {@link ComplexColumnInfoImpl#INVALID_ID} for a new,
  32. * unsaved value.
  33. */
  34. public Id getId();
  35. /**
  36. * Called once when a new ComplexValue is saved to set the new unique
  37. * identifier.
  38. */
  39. public void setId(Id newId);
  40. /**
  41. * Returns the foreign key identifier for this complex value (this value is
  42. * the same for all values in the same row of the main table).
  43. *
  44. * @return the current id or {@link ComplexColumnInfoImpl#INVALID_FK}
  45. * for a new, unsaved value.
  46. */
  47. public ComplexValueForeignKey getComplexValueForeignKey();
  48. public void setComplexValueForeignKey(ComplexValueForeignKey complexValueFk);
  49. /**
  50. * @return the column in the main table with which this complex value is
  51. * associated
  52. */
  53. public Column getColumn();
  54. /**
  55. * Writes any updated data for this complex value to the database.
  56. */
  57. public void update() throws IOException;
  58. /**
  59. * Deletes the data for this complex value from the database.
  60. */
  61. public void delete() throws IOException;
  62. /**
  63. * Identifier for a ComplexValue. Only valid for comparing complex values
  64. * for the same column.
  65. */
  66. public abstract class Id extends Number
  67. {
  68. private static final long serialVersionUID = 20130318L;
  69. @Override
  70. public byte byteValue() {
  71. return (byte)get();
  72. }
  73. @Override
  74. public short shortValue() {
  75. return (short)get();
  76. }
  77. @Override
  78. public int intValue() {
  79. return get();
  80. }
  81. @Override
  82. public long longValue() {
  83. return get();
  84. }
  85. @Override
  86. public float floatValue() {
  87. return get();
  88. }
  89. @Override
  90. public double doubleValue() {
  91. return get();
  92. }
  93. @Override
  94. public int hashCode() {
  95. return get();
  96. }
  97. @Override
  98. public boolean equals(Object o) {
  99. return ((this == o) ||
  100. ((o != null) && (getClass() == o.getClass()) &&
  101. (get() == ((Id)o).get())));
  102. }
  103. @Override
  104. public String toString() {
  105. return String.valueOf(get());
  106. }
  107. protected final Object writeReplace() throws ObjectStreamException {
  108. // if we are going to serialize this ComplexValue.Id, convert it back to
  109. // a normal Integer (in case it is restored outside of the context of
  110. // jackcess)
  111. return Integer.valueOf(get());
  112. }
  113. /**
  114. * Returns the unique identifier of this complex value (this value is unique
  115. * among all values in all rows of the main table for the complex column).
  116. */
  117. public abstract int get();
  118. /**
  119. * Returns the rowId of this ComplexValue within the secondary table.
  120. */
  121. public abstract RowId getRowId();
  122. }
  123. }