From 6faae316016729fdad25572fe14e4573dabaffdc Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 12 Mar 2013 22:13:37 +0000 Subject: [PATCH] clean up complex column classes git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jackcess-2@679 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/ColumnImpl.java | 17 +- .../jackcess/ComplexColumnSupport.java | 189 ++++++++++++++++++ .../complex/AttachmentColumnInfo.java | 90 +++------ .../jackcess/complex/ComplexColumnInfo.java | 123 +++--------- .../complex/ComplexValueForeignKey.java | 8 +- .../complex/MultiValueColumnInfo.java | 27 +-- .../complex/UnsupportedColumnInfo.java | 14 +- .../complex/VersionHistoryColumnInfo.java | 52 ++--- 8 files changed, 273 insertions(+), 247 deletions(-) create mode 100644 src/java/com/healthmarketscience/jackcess/ComplexColumnSupport.java diff --git a/src/java/com/healthmarketscience/jackcess/ColumnImpl.java b/src/java/com/healthmarketscience/jackcess/ColumnImpl.java index db84233..7443c6b 100644 --- a/src/java/com/healthmarketscience/jackcess/ColumnImpl.java +++ b/src/java/com/healthmarketscience/jackcess/ColumnImpl.java @@ -199,7 +199,7 @@ public class ColumnImpl implements Column, Comparable { /** the auto number generator for this column (if autonumber column) */ private final AutoNumberGenerator _autoNumberGenerator; /** additional information specific to complex columns */ - private ComplexColumnInfo _complexInfo; + private final ComplexColumnInfo _complexInfo; /** properties for this column, if any */ private PropertyMap _props; @@ -229,6 +229,7 @@ public class ColumnImpl implements Column, Comparable { _displayIndex = colNumber; _fixedDataOffset = fixedOffset; _varLenTableIndex = varLenIndex; + _complexInfo = null; } /** @@ -302,8 +303,10 @@ public class ColumnImpl implements Column, Comparable { // load complex info if(_type == DataType.COMPLEX_TYPE) { - _complexInfo = ComplexColumnInfo.create(this, buffer, offset); - } + _complexInfo = ComplexColumnSupport.create(this, buffer, offset); + } else { + _complexInfo = null; + } } /** @@ -408,14 +411,6 @@ public class ColumnImpl implements Column, Comparable { return _textInfo._sortOrder; } - /** - * @usage _advanced_method_ - */ - public void setTextSortOrder(SortOrder newTextSortOrder) { - modifyTextInfo(); - _textInfo._sortOrder = newTextSortOrder; - } - /** * @usage _intermediate_method_ */ diff --git a/src/java/com/healthmarketscience/jackcess/ComplexColumnSupport.java b/src/java/com/healthmarketscience/jackcess/ComplexColumnSupport.java new file mode 100644 index 0000000..82313f6 --- /dev/null +++ b/src/java/com/healthmarketscience/jackcess/ComplexColumnSupport.java @@ -0,0 +1,189 @@ +/* +Copyright (c) 2013 James Ahlborn + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA +*/ + +package com.healthmarketscience.jackcess; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.healthmarketscience.jackcess.complex.AttachmentColumnInfo; +import com.healthmarketscience.jackcess.complex.ComplexColumnInfo; +import com.healthmarketscience.jackcess.complex.ComplexValue; +import com.healthmarketscience.jackcess.complex.MultiValueColumnInfo; +import com.healthmarketscience.jackcess.complex.UnsupportedColumnInfo; +import com.healthmarketscience.jackcess.complex.VersionHistoryColumnInfo; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author James Ahlborn + */ +public class ComplexColumnSupport +{ + private static final Log LOG = LogFactory.getLog(ComplexColumnSupport.class); + + private static final String COL_COMPLEX_TYPE_OBJECT_ID = "ComplexTypeObjectID"; + private static final String COL_TABLE_ID = "ConceptualTableID"; + private static final String COL_FLAT_TABLE_ID = "FlatTableID"; + + private static final Set MULTI_VALUE_TYPES = EnumSet.of( + DataType.BYTE, DataType.INT, DataType.LONG, DataType.FLOAT, + DataType.DOUBLE, DataType.GUID, DataType.NUMERIC, DataType.TEXT); + + + /** + * Creates a ComplexColumnInfo for a complex column. + */ + public static ComplexColumnInfo create( + ColumnImpl column, ByteBuffer buffer, int offset) + throws IOException + { + int complexTypeId = buffer.getInt( + offset + column.getFormat().OFFSET_COLUMN_COMPLEX_ID); + + DatabaseImpl db = column.getDatabase(); + TableImpl complexColumns = db.getSystemComplexColumns(); + IndexCursor cursor = CursorBuilder.createCursor( + complexColumns, complexColumns.getPrimaryKeyIndex()); + if(!cursor.findFirstRowByEntry(complexTypeId)) { + throw new IOException( + "Could not find complex column info for complex column with id " + + complexTypeId); + } + Map cColRow = cursor.getCurrentRow(); + int tableId = (Integer)cColRow.get(COL_TABLE_ID); + if(tableId != column.getTable().getTableDefPageNumber()) { + throw new IOException( + "Found complex column for table " + tableId + " but expected table " + + column.getTable().getTableDefPageNumber()); + } + int flatTableId = (Integer)cColRow.get(COL_FLAT_TABLE_ID); + int typeObjId = (Integer)cColRow.get(COL_COMPLEX_TYPE_OBJECT_ID); + + TableImpl typeObjTable = db.getTable(typeObjId); + TableImpl flatTable = db.getTable(flatTableId); + + if((typeObjTable == null) || (flatTable == null)) { + throw new IOException( + "Could not find supporting tables (" + typeObjId + ", " + flatTableId + + ") for complex column with id " + complexTypeId); + } + + // we inspect the structore of the "type table" to determine what kind of + // complex info we are dealing with + if(isMultiValueColumn(typeObjTable)) { + return new MultiValueColumnInfo(column, complexTypeId, typeObjTable, + flatTable); + } else if(isAttachmentColumn(typeObjTable)) { + return new AttachmentColumnInfo(column, complexTypeId, typeObjTable, + flatTable); + } else if(isVersionHistoryColumn(typeObjTable)) { + return new VersionHistoryColumnInfo(column, complexTypeId, typeObjTable, + flatTable); + } + + LOG.warn("Unsupported complex column type " + typeObjTable.getName()); + return new UnsupportedColumnInfo(column, complexTypeId, typeObjTable, + flatTable); + } + + + public static boolean isMultiValueColumn(Table typeObjTable) { + // if we found a single value of a "simple" type, then we are dealing with + // a multi-value column + List typeCols = typeObjTable.getColumns(); + return ((typeCols.size() == 1) && + MULTI_VALUE_TYPES.contains(typeCols.get(0).getType())); + } + + public static boolean isAttachmentColumn(Table typeObjTable) { + // attachment data has these columns FileURL(MEMO), FileName(TEXT), + // FileType(TEXT), FileData(OLE), FileTimeStamp(SHORT_DATE_TIME), + // FileFlags(LONG) + List typeCols = typeObjTable.getColumns(); + if(typeCols.size() < 6) { + return false; + } + + int numMemo = 0; + int numText = 0; + int numDate = 0; + int numOle= 0; + int numLong = 0; + + for(Column col : typeCols) { + switch(col.getType()) { + case TEXT: + ++numText; + break; + case LONG: + ++numLong; + break; + case SHORT_DATE_TIME: + ++numDate; + break; + case OLE: + ++numOle; + break; + case MEMO: + ++numMemo; + break; + default: + // ignore + } + } + + // be flexible, allow for extra columns... + return((numMemo >= 1) && (numText >= 2) && (numOle >= 1) && + (numDate >= 1) && (numLong >= 1)); + } + + public static boolean isVersionHistoryColumn(Table typeObjTable) { + // version history data has these columns (MEMO), + // (SHORT_DATE_TIME) + List typeCols = typeObjTable.getColumns(); + if(typeCols.size() < 2) { + return false; + } + + int numMemo = 0; + int numDate = 0; + + for(Column col : typeCols) { + switch(col.getType()) { + case SHORT_DATE_TIME: + ++numDate; + break; + case MEMO: + ++numMemo; + break; + default: + // ignore + } + } + + // be flexible, allow for extra columns... + return((numMemo >= 1) && (numDate >= 1)); + } +} diff --git a/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java index 7cdc45f..ef05e3c 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java +++ b/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java @@ -21,12 +21,11 @@ package com.healthmarketscience.jackcess.complex; import java.io.IOException; import java.util.Date; -import java.util.List; import java.util.Map; import com.healthmarketscience.jackcess.ByteUtil; -import com.healthmarketscience.jackcess.ColumnImpl; -import com.healthmarketscience.jackcess.TableImpl; +import com.healthmarketscience.jackcess.Column; +import com.healthmarketscience.jackcess.Table; /** @@ -39,27 +38,27 @@ public class AttachmentColumnInfo extends ComplexColumnInfo private static final String FILE_NAME_COL_NAME = "FileName"; private static final String FILE_TYPE_COL_NAME = "FileType"; - private final ColumnImpl _fileUrlCol; - private final ColumnImpl _fileNameCol; - private final ColumnImpl _fileTypeCol; - private final ColumnImpl _fileDataCol; - private final ColumnImpl _fileTimeStampCol; - private final ColumnImpl _fileFlagsCol; + private final Column _fileUrlCol; + private final Column _fileNameCol; + private final Column _fileTypeCol; + private final Column _fileDataCol; + private final Column _fileTimeStampCol; + private final Column _fileFlagsCol; - public AttachmentColumnInfo(ColumnImpl column, int complexId, - TableImpl typeObjTable, TableImpl flatTable) + public AttachmentColumnInfo(Column column, int complexId, + Table typeObjTable, Table flatTable) throws IOException { super(column, complexId, typeObjTable, flatTable); - ColumnImpl fileUrlCol = null; - ColumnImpl fileNameCol = null; - ColumnImpl fileTypeCol = null; - ColumnImpl fileDataCol = null; - ColumnImpl fileTimeStampCol = null; - ColumnImpl fileFlagsCol = null; + Column fileUrlCol = null; + Column fileNameCol = null; + Column fileTypeCol = null; + Column fileDataCol = null; + Column fileTimeStampCol = null; + Column fileFlagsCol = null; - for(ColumnImpl col : getTypeColumns()) { + for(Column col : getTypeColumns()) { switch(col.getType()) { case TEXT: if(FILE_NAME_COL_NAME.equalsIgnoreCase(col.getName())) { @@ -100,27 +99,27 @@ public class AttachmentColumnInfo extends ComplexColumnInfo _fileFlagsCol = fileFlagsCol; } - public ColumnImpl getFileUrlColumn() { + public Column getFileUrlColumn() { return _fileUrlCol; } - public ColumnImpl getFileNameColumn() { + public Column getFileNameColumn() { return _fileNameCol; } - public ColumnImpl getFileTypeColumn() { + public Column getFileTypeColumn() { return _fileTypeCol; } - public ColumnImpl getFileDataColumn() { + public Column getFileDataColumn() { return _fileDataCol; } - public ColumnImpl getFileTimeStampColumn() { + public Column getFileTimeStampColumn() { return _fileTimeStampCol; } - public ColumnImpl getFileFlagsColumn() { + public Column getFileFlagsColumn() { return _fileFlagsCol; } @@ -183,49 +182,6 @@ public class AttachmentColumnInfo extends ComplexColumnInfo } - public static boolean isAttachmentColumn(TableImpl typeObjTable) { - // attachment data has these columns FileURL(MEMO), FileName(TEXT), - // FileType(TEXT), FileData(OLE), FileTimeStamp(SHORT_DATE_TIME), - // FileFlags(LONG) - List typeCols = typeObjTable.getColumns(); - if(typeCols.size() < 6) { - return false; - } - - int numMemo = 0; - int numText = 0; - int numDate = 0; - int numOle= 0; - int numLong = 0; - - for(ColumnImpl col : typeCols) { - switch(col.getType()) { - case TEXT: - ++numText; - break; - case LONG: - ++numLong; - break; - case SHORT_DATE_TIME: - ++numDate; - break; - case OLE: - ++numOle; - break; - case MEMO: - ++numMemo; - break; - default: - // ignore - } - } - - // be flexible, allow for extra columns... - return((numMemo >= 1) && (numText >= 2) && (numOle >= 1) && - (numDate >= 1) && (numLong >= 1)); - } - - private static class AttachmentImpl extends ComplexValueImpl implements Attachment { diff --git a/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java index 800d189..05bd308 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java +++ b/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java @@ -20,7 +20,6 @@ USA package com.healthmarketscience.jackcess.complex; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -29,16 +28,11 @@ import java.util.List; import java.util.Map; import com.healthmarketscience.jackcess.Column; -import com.healthmarketscience.jackcess.ColumnImpl; import com.healthmarketscience.jackcess.CursorBuilder; import com.healthmarketscience.jackcess.DataType; -import com.healthmarketscience.jackcess.DatabaseImpl; +import com.healthmarketscience.jackcess.Database; import com.healthmarketscience.jackcess.IndexCursor; -import com.healthmarketscience.jackcess.JetFormat; -import com.healthmarketscience.jackcess.PageChannel; -import com.healthmarketscience.jackcess.TableImpl; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import com.healthmarketscience.jackcess.Table; /** * Base class for the additional information tracked for complex columns. @@ -47,27 +41,21 @@ import org.apache.commons.logging.LogFactory; */ public abstract class ComplexColumnInfo { - private static final Log LOG = LogFactory.getLog(ComplexColumnInfo.class); - public static final int INVALID_ID = -1; public static final ComplexValueForeignKey INVALID_COMPLEX_VALUE_ID = new ComplexValueForeignKey(null, INVALID_ID); - - private static final String COL_COMPLEX_TYPE_OBJECT_ID = "ComplexTypeObjectID"; - private static final String COL_TABLE_ID = "ConceptualTableID"; - private static final String COL_FLAT_TABLE_ID = "FlatTableID"; - private final ColumnImpl _column; + private final Column _column; private final int _complexTypeId; - private final TableImpl _flatTable; - private final List _typeCols; - private final ColumnImpl _pkCol; - private final ColumnImpl _complexValFkCol; + private final Table _flatTable; + private final List _typeCols; + private final Column _pkCol; + private final Column _complexValFkCol; private IndexCursor _pkCursor; private IndexCursor _complexValIdCursor; - protected ComplexColumnInfo(ColumnImpl column, int complexTypeId, - TableImpl typeObjTable, TableImpl flatTable) + protected ComplexColumnInfo(Column column, int complexTypeId, + Table typeObjTable, Table flatTable) throws IOException { _column = column; @@ -77,15 +65,15 @@ public abstract class ComplexColumnInfo // the flat table has all the "value" columns and 2 extra columns, a // primary key for each row, and a LONG value which is essentially a // foreign key to the main table. - List typeCols = new ArrayList(); - List otherCols = new ArrayList(); + List typeCols = new ArrayList(); + List otherCols = new ArrayList(); diffFlatColumns(typeObjTable, flatTable, typeCols, otherCols); _typeCols = Collections.unmodifiableList(typeCols); - ColumnImpl pkCol = null; - ColumnImpl complexValFkCol = null; - for(ColumnImpl col : otherCols) { + Column pkCol = null; + Column complexValFkCol = null; + for(Column col : otherCols) { if(col.isAutoNumber()) { pkCol = col; } else if(col.getType() == DataType.LONG) { @@ -102,88 +90,27 @@ public abstract class ComplexColumnInfo _complexValFkCol = complexValFkCol; } - public static ComplexColumnInfo create( - ColumnImpl column, ByteBuffer buffer, int offset) - throws IOException - { - int complexTypeId = buffer.getInt( - offset + column.getFormat().OFFSET_COLUMN_COMPLEX_ID); - - DatabaseImpl db = column.getDatabase(); - TableImpl complexColumns = db.getSystemComplexColumns(); - IndexCursor cursor = CursorBuilder.createCursor( - complexColumns, complexColumns.getPrimaryKeyIndex()); - if(!cursor.findFirstRowByEntry(complexTypeId)) { - throw new IOException( - "Could not find complex column info for complex column with id " + - complexTypeId); - } - Map cColRow = cursor.getCurrentRow(); - int tableId = (Integer)cColRow.get(COL_TABLE_ID); - if(tableId != column.getTable().getTableDefPageNumber()) { - throw new IOException( - "Found complex column for table " + tableId + " but expected table " + - column.getTable().getTableDefPageNumber()); - } - int flatTableId = (Integer)cColRow.get(COL_FLAT_TABLE_ID); - int typeObjId = (Integer)cColRow.get(COL_COMPLEX_TYPE_OBJECT_ID); - - TableImpl typeObjTable = db.getTable(typeObjId); - TableImpl flatTable = db.getTable(flatTableId); - - if((typeObjTable == null) || (flatTable == null)) { - throw new IOException( - "Could not find supporting tables (" + typeObjId + ", " + flatTableId - + ") for complex column with id " + complexTypeId); - } - - // we inspect the structore of the "type table" to determine what kind of - // complex info we are dealing with - if(MultiValueColumnInfo.isMultiValueColumn(typeObjTable)) { - return new MultiValueColumnInfo(column, complexTypeId, typeObjTable, - flatTable); - } else if(AttachmentColumnInfo.isAttachmentColumn(typeObjTable)) { - return new AttachmentColumnInfo(column, complexTypeId, typeObjTable, - flatTable); - } else if(VersionHistoryColumnInfo.isVersionHistoryColumn(typeObjTable)) { - return new VersionHistoryColumnInfo(column, complexTypeId, typeObjTable, - flatTable); - } - - LOG.warn("Unsupported complex column type " + typeObjTable.getName()); - return new UnsupportedColumnInfo(column, complexTypeId, typeObjTable, - flatTable); - } - public void postTableLoadInit() throws IOException { // nothing to do in base class } - public ColumnImpl getColumn() { + public Column getColumn() { return _column; } - public DatabaseImpl getDatabase() { + public Database getDatabase() { return getColumn().getDatabase(); } - - public JetFormat getFormat() { - return getDatabase().getFormat(); - } - - public PageChannel getPageChannel() { - return getDatabase().getPageChannel(); - } - public ColumnImpl getPrimaryKeyColumn() { + public Column getPrimaryKeyColumn() { return _pkCol; } - public ColumnImpl getComplexValueForeignKeyColumn() { + public Column getComplexValueForeignKeyColumn() { return _complexValFkCol; } - protected List getTypeColumns() { + protected List getTypeColumns() { return _typeCols; } @@ -371,14 +298,14 @@ public abstract class ComplexColumnInfo return rtn.toString(); } - protected static void diffFlatColumns(TableImpl typeObjTable, - TableImpl flatTable, - List typeCols, - List otherCols) + protected static void diffFlatColumns(Table typeObjTable, + Table flatTable, + List typeCols, + List otherCols) { // each "flat"" table has the columns from the "type" table, plus some // others. separate the "flat" columns into these 2 buckets - for(ColumnImpl col : flatTable.getColumns()) { + for(Column col : flatTable.getColumns()) { boolean found = false; try { typeObjTable.getColumn(col.getName()); @@ -434,7 +361,7 @@ public abstract class ComplexColumnInfo _complexValueFk = complexValueFk; } - public ColumnImpl getColumn() { + public Column getColumn() { return _complexValueFk.getColumn(); } diff --git a/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java b/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java index b1b83a3..80735e3 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java +++ b/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java @@ -25,7 +25,7 @@ import java.util.Date; import java.util.List; import java.util.Map; -import com.healthmarketscience.jackcess.ColumnImpl; +import com.healthmarketscience.jackcess.Column; /** * Value which is returned for a complex column. This value corresponds to a @@ -45,11 +45,11 @@ public class ComplexValueForeignKey extends Number { private static final long serialVersionUID = 20110805L; - private transient final ColumnImpl _column; + private transient final Column _column; private final int _value; private transient List _values; - public ComplexValueForeignKey(ColumnImpl column, int value) { + public ComplexValueForeignKey(Column column, int value) { _column = column; _value = value; } @@ -58,7 +58,7 @@ public class ComplexValueForeignKey extends Number return _value; } - public ColumnImpl getColumn() { + public Column getColumn() { return _column; } diff --git a/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java index f0f449a..76f60bd 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java +++ b/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java @@ -20,14 +20,10 @@ USA package com.healthmarketscience.jackcess.complex; import java.io.IOException; -import java.util.EnumSet; -import java.util.List; import java.util.Map; -import java.util.Set; -import com.healthmarketscience.jackcess.ColumnImpl; -import com.healthmarketscience.jackcess.DataType; -import com.healthmarketscience.jackcess.TableImpl; +import com.healthmarketscience.jackcess.Column; +import com.healthmarketscience.jackcess.Table; /** * Complex column info for a column holding multiple values per row. @@ -36,14 +32,10 @@ import com.healthmarketscience.jackcess.TableImpl; */ public class MultiValueColumnInfo extends ComplexColumnInfo { - private static final Set VALUE_TYPES = EnumSet.of( - DataType.BYTE, DataType.INT, DataType.LONG, DataType.FLOAT, - DataType.DOUBLE, DataType.GUID, DataType.NUMERIC, DataType.TEXT); - - private final ColumnImpl _valueCol; + private final Column _valueCol; - public MultiValueColumnInfo(ColumnImpl column, int complexId, - TableImpl typeObjTable, TableImpl flatTable) + public MultiValueColumnInfo(Column column, int complexId, + Table typeObjTable, Table flatTable) throws IOException { super(column, complexId, typeObjTable, flatTable); @@ -57,7 +49,7 @@ public class MultiValueColumnInfo extends ComplexColumnInfo return ComplexDataType.MULTI_VALUE; } - public ColumnImpl getValueColumn() { + public Column getValueColumn() { return _valueCol; } @@ -88,13 +80,6 @@ public class MultiValueColumnInfo extends ComplexColumnInfo return new SingleValueImpl(INVALID_ID, complexValueFk, value); } - public static boolean isMultiValueColumn(TableImpl typeObjTable) { - // if we found a single value of a "simple" type, then we are dealing with - // a multi-value column - List typeCols = typeObjTable.getColumns(); - return ((typeCols.size() == 1) && - VALUE_TYPES.contains(typeCols.get(0).getType())); - } private static class SingleValueImpl extends ComplexValueImpl implements SingleValue diff --git a/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java index 6af1557..03bd8b1 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java +++ b/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java @@ -24,8 +24,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import com.healthmarketscience.jackcess.ColumnImpl; -import com.healthmarketscience.jackcess.TableImpl; +import com.healthmarketscience.jackcess.Column; +import com.healthmarketscience.jackcess.Table; /** * Complex column info for an unsupported complex type. @@ -35,14 +35,14 @@ import com.healthmarketscience.jackcess.TableImpl; public class UnsupportedColumnInfo extends ComplexColumnInfo { - public UnsupportedColumnInfo(ColumnImpl column, int complexId, TableImpl typeObjTable, - TableImpl flatTable) + public UnsupportedColumnInfo(Column column, int complexId, Table typeObjTable, + Table flatTable) throws IOException { super(column, complexId, typeObjTable, flatTable); } - public List getValueColumns() { + public List getValueColumns() { return getTypeColumns(); } @@ -60,7 +60,7 @@ public class UnsupportedColumnInfo extends ComplexColumnInfo int id = (Integer)getPrimaryKeyColumn().getRowValue(rawValue); Map values = new LinkedHashMap(); - for(ColumnImpl col : getValueColumns()) { + for(Column col : getValueColumns()) { col.setRowValue(values, col.getRowValue(rawValue)); } @@ -72,7 +72,7 @@ public class UnsupportedColumnInfo extends ComplexColumnInfo super.asRow(row, value); Map values = value.getValues(); - for(ColumnImpl col : getValueColumns()) { + for(Column col : getValueColumns()) { col.setRowValue(row, col.getRowValue(values)); } diff --git a/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java index 1ef3d09..1895271 100644 --- a/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java +++ b/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java @@ -25,8 +25,9 @@ import java.util.Date; import java.util.List; import java.util.Map; +import com.healthmarketscience.jackcess.Column; import com.healthmarketscience.jackcess.ColumnImpl; -import com.healthmarketscience.jackcess.TableImpl; +import com.healthmarketscience.jackcess.Table; /** * Complex column info for a column which tracking the version history of an @@ -41,18 +42,18 @@ import com.healthmarketscience.jackcess.TableImpl; */ public class VersionHistoryColumnInfo extends ComplexColumnInfo { - private final ColumnImpl _valueCol; - private final ColumnImpl _modifiedCol; + private final Column _valueCol; + private final Column _modifiedCol; - public VersionHistoryColumnInfo(ColumnImpl column, int complexId, - TableImpl typeObjTable, TableImpl flatTable) + public VersionHistoryColumnInfo(Column column, int complexId, + Table typeObjTable, Table flatTable) throws IOException { super(column, complexId, typeObjTable, flatTable); - ColumnImpl valueCol = null; - ColumnImpl modifiedCol = null; - for(ColumnImpl col : getTypeColumns()) { + Column valueCol = null; + Column modifiedCol = null; + for(Column col : getTypeColumns()) { switch(col.getType()) { case SHORT_DATE_TIME: modifiedCol = col; @@ -75,16 +76,16 @@ public class VersionHistoryColumnInfo extends ComplexColumnInfo // link up with the actual versioned column. it should have the same name // as the "value" column in the type table. - ColumnImpl versionedCol = getColumn().getTable().getColumn( + Column versionedCol = getColumn().getTable().getColumn( getValueColumn().getName()); - versionedCol.setVersionHistoryColumn(getColumn()); + ((ColumnImpl)versionedCol).setVersionHistoryColumn((ColumnImpl)getColumn()); } - public ColumnImpl getValueColumn() { + public Column getValueColumn() { return _valueCol; } - public ColumnImpl getModifiedDateColumn() { + public Column getModifiedDateColumn() { return _modifiedCol; } @@ -151,33 +152,6 @@ public class VersionHistoryColumnInfo extends ComplexColumnInfo return new VersionImpl(INVALID_ID, complexValueFk, value, modifiedDate); } - public static boolean isVersionHistoryColumn(TableImpl typeObjTable) { - // version history data has these columns (MEMO), - // (SHORT_DATE_TIME) - List typeCols = typeObjTable.getColumns(); - if(typeCols.size() < 2) { - return false; - } - - int numMemo = 0; - int numDate = 0; - - for(ColumnImpl col : typeCols) { - switch(col.getType()) { - case SHORT_DATE_TIME: - ++numDate; - break; - case MEMO: - ++numMemo; - break; - default: - // ignore - } - } - - // be flexible, allow for extra columns... - return((numMemo >= 1) && (numDate >= 1)); - } private static class VersionImpl extends ComplexValueImpl implements Version { -- 2.39.5