Java源码示例:com.healthmarketscience.jackcess.Column

示例1
public VersionHistoryColumnInfoImpl(Column column, int complexId,
                                    Table typeObjTable, Table flatTable)
  throws IOException
{
  super(column, complexId, typeObjTable, flatTable);

  Column valueCol = null;
  Column modifiedCol = null;
  for(Column col : getTypeColumns()) {
    switch(col.getType()) {
    case SHORT_DATE_TIME:
      modifiedCol = col;
      break;
    case MEMO:
      valueCol = col;
      break;
    default:
      // ignore
    }
  }

  _valueCol = valueCol;
  _modifiedCol = modifiedCol;
}
 
示例2
private static void updateSecondaryValues(Joiner joiner, Object[] oldFromRow,
                                          Object[] newFromRow)
  throws IOException
{
  IndexCursor toCursor = joiner.getToCursor();
  List<? extends Index.Column> fromCols = joiner.getColumns();
  List<? extends Index.Column> toCols = joiner.getToIndex().getColumns();
  Object[] toRow = new Object[joiner.getToTable().getColumnCount()];

  for(Iterator<Row> iter = joiner.findRows(oldFromRow)
        .setColumnNames(Collections.<String>emptySet())
        .iterator(); iter.hasNext(); ) {
    iter.next();

    // create update row for "to" table
    Arrays.fill(toRow, Column.KEEP_VALUE);
    for(int i = 0; i < fromCols.size(); ++i) {
      Object val = fromCols.get(i).getColumn().getRowValue(newFromRow);
      toCols.get(i).getColumn().setRowValue(toRow, val);
    }

    toCursor.updateCurrentRow(toRow);
  }
}
 
示例3
private static void nullSecondaryValues(Joiner joiner, Object[] oldFromRow)
  throws IOException
{
  IndexCursor toCursor = joiner.getToCursor();
  List<? extends Index.Column> fromCols = joiner.getColumns();
  List<? extends Index.Column> toCols = joiner.getToIndex().getColumns();
  Object[] toRow = new Object[joiner.getToTable().getColumnCount()];

  for(Iterator<Row> iter = joiner.findRows(oldFromRow)
        .setColumnNames(Collections.<String>emptySet())
        .iterator(); iter.hasNext(); ) {
    iter.next();

    // create update row for "to" table
    Arrays.fill(toRow, Column.KEEP_VALUE);
    for(int i = 0; i < fromCols.size(); ++i) {
      toCols.get(i).getColumn().setRowValue(toRow, null);
    }

    toCursor.updateCurrentRow(toRow);
  }
}
 
示例4
@SuppressWarnings("unchecked")
private static void replaceColumn(Table t, String colName) throws Exception
{
  Field colsField = TableImpl.class.getDeclaredField("_columns");
  colsField.setAccessible(true);
  List<Column> cols = (List<Column>)colsField.get(t);

  Column srcCol = null;
  ColumnImpl destCol = new BogusColumn(t, colName);
  for(int i = 0; i < cols.size(); ++i) {
    srcCol = cols.get(i);
    if(srcCol.getName().equals(colName)) {
      cols.set(i, destCol);
      break;
    }
  }

  // copy fields from source to dest
  for(Field f : Column.class.getDeclaredFields()) {
    if(!Modifier.isFinal(f.getModifiers())) {
      f.setAccessible(true);
      f.set(destCol, f.get(srcCol));
    }
  }
  
}
 
示例5
public void testImportFromFileWithOnlyHeaders() throws Exception
{
  for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
    Database db = create(fileFormat);
    String tableName = new ImportUtil.Builder(db, "test")
      .setDelimiter("\\t")
      .importFile(new File("src/test/data/sample-input-only-headers.tab"));

    Table t = db.getTable(tableName);

    List<String> colNames = new ArrayList<String>();
    for(Column c : t.getColumns()) {
      colNames.add(c.getName());
    }
    assertEquals(Arrays.asList(
                     "RESULT_PHYS_ID", "FIRST", "MIDDLE", "LAST", "OUTLIER",
                     "RANK", "CLAIM_COUNT", "PROCEDURE_COUNT",
                     "WEIGHTED_CLAIM_COUNT", "WEIGHTED_PROCEDURE_COUNT"),
                 colNames);

    db.close();
  }
}
 
示例6
@Override
public Object handleRowError(Column column, byte[] columnData,
                             Location location, Exception error)
  throws IOException
{
  return _replacement;
}
 
示例7
@Override
public Object handleRowError(Column column, byte[] columnData,
                             Location location, Exception error)
  throws IOException
{
  // really can only be RuntimeException or IOException
  if(error instanceof IOException) {
    throw (IOException)error;
  }
  throw (RuntimeException)error;
}
 
示例8
@Override
public Object handleRowError(Column column, byte[] columnData, 
                             Location location, Exception error)
  throws IOException
{
  if(LOG.isDebugEnabled()) {
    LOG.debug("Failed reading column " + column + ", row " +
              location + ", bytes " +
              ((columnData != null) ?
               ByteUtil.toHexString(columnData) : "null"),
              error);
  }

  return super.handleRowError(column, columnData, location, error);
}
 
示例9
public EntryIterableBuilder addColumns(Iterable<? extends Column> cols) {
  if(cols != null) {
    for(Column col : cols) {
      addColumnName(col.getName());
    }
  }
  return this;
}
 
示例10
/**
 * Creates a filter based on a single value row pattern.
 *
 * @param columnPattern column to be matched
 * @param valuePattern value to be matched.
 *                     A table row will match the target if
 *                     {@code Objects.equals(valuePattern, row.get(columnPattern.getName()))}.
 * @return a filter which matches table rows which match the value in the
 *         row pattern
 */
public static RowFilter matchPattern(final Column columnPattern,
                                     final Object valuePattern)
{
  return new RowFilter() {
      @Override
      public boolean matches(Row row)
      {
        return Objects.equals(valuePattern, columnPattern.getRowValue(row));
      }
    };
}
 
示例11
public IterableBuilder addColumns(Iterable<? extends Column> cols) {
  if(cols != null) {
    for(Column col : cols) {
      addColumnName(col.getName());
    }
  }
  return this;
}
 
示例12
public IterableBuilder setMatchPattern(Column columnPattern, 
                                       Object valuePattern) {
  _type = Type.COLUMN_MATCH;
  _matchPattern = new AbstractMap.SimpleImmutableEntry<Column,Object>(
      columnPattern, valuePattern);
  return this;
}
 
示例13
@Override
protected Object internalValidate(Column col, Object val)
  throws IOException
{
  if(val == null) {
    throw new InvalidValueException(
        ((ColumnImpl)col).withErrorContext(
            "Missing value for required column"));
  }
  return val;
}
 
示例14
@Override
protected Object internalValidate(Column col, Object val)
  throws IOException
{
  CharSequence valStr = ColumnImpl.toCharSequence(val);
  // oddly enough null is allowed for non-zero len strings
  if((valStr != null) && valStr.length() == 0) {
    throw new InvalidValueException(
        ((ColumnImpl)col).withErrorContext(
            "Zero length string is not allowed"));
  }
  return valStr;
}
 
示例15
private Object convert( Object obj, AccessInputField field, int index ) throws Exception {
  // Get column
  Column c = data.t.getColumn( field.getColumn() );
  // Find out field type
  ValueMetaAndData sourceValueMetaAndData = AccessInputMeta.getValueMetaAndData( c, field.getName(), obj );

  // DO CONVERSIONS...
  //
  ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( data.totalpreviousfields + index );
  return targetValueMeta.convertData( sourceValueMetaAndData.getValueMeta(), sourceValueMetaAndData
    .getValueData() );
}
 
示例16
public void setCurrentRowValue(ColumnImpl column, Object value)
  throws IOException
{
  Object[] row = new Object[_table.getColumnCount()];
  Arrays.fill(row, Column.KEEP_VALUE);
  column.setRowValue(row, value);
  _table.updateRow(_rowState, _curPos.getRowId(), row);
}
 
示例17
ColumnValidator toColumnValidator(ColumnValidator delegate) {
  return new InternalColumnValidator(delegate) {
    @Override
    protected Object internalValidate(Column col, Object val)
      throws IOException {
      return ColValidatorEvalContext.this.validate(val);
    }
    @Override
    protected void appendToString(StringBuilder sb) {
      sb.append("expression=").append(ColValidatorEvalContext.this);
    }
  };
}
 
示例18
/**
 * Update the given column's value for the given row id.  Provided RowId
 * must have previously been returned from this Table.
 * @throws IllegalStateException if the given row is not valid, or deleted.
 * @usage _intermediate_method_
 */
public void updateValue(Column column, RowId rowId, Object value)
  throws IOException
{
  Object[] row = new Object[_columns.size()];
  Arrays.fill(row, Column.KEEP_VALUE);
  column.setRowValue(row, value);

  updateRow(rowId, row);
}
 
示例19
/**
 * Optionally get the input autonumber row value for the given column from
 * the given row if one was provided.
 */
private static Object getInputAutoNumberRowValue(
    boolean enableInsert, ColumnImpl col, Object[] row)
{
  if(!enableInsert) {
    return null;
  }

  Object inRowValue = col.getRowValue(row);
  if((inRowValue == Column.KEEP_VALUE) || (inRowValue == Column.AUTO_NUMBER)) {
    // these "special" values both behave like nothing was given
    inRowValue = null;
  }
  return inRowValue;
}
 
示例20
public RelationshipImpl(String name, Table fromTable, Table toTable, int flags,
                        int numCols)
{
  this(name, fromTable, toTable, flags, 
       Collections.nCopies(numCols, (Column)null),
       Collections.nCopies(numCols, (Column)null));
}
 
示例21
public RelationshipImpl(String name, Table fromTable, Table toTable, int flags,
                        List<? extends Column> fromCols,
                        List<? extends Column> toCols)
{
  _name = name;
  _fromTable = fromTable;
  _fromColumns = new ArrayList<Column>(fromCols);
  _toTable = toTable;
  _toColumns = new ArrayList<Column>(toCols);
  _flags = flags;
}
 
示例22
protected ComplexColumnInfoImpl(Column column, int complexTypeId,
                                Table typeObjTable, Table flatTable)
  throws IOException
{
  _column = column;
  _complexTypeId = complexTypeId;
  _flatTable = flatTable;
  
  // 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<Column> typeCols = new ArrayList<Column>();
  List<Column> otherCols = new ArrayList<Column>();
  diffFlatColumns(typeObjTable, flatTable, typeCols, otherCols);

  _typeCols = Collections.unmodifiableList(typeCols);

  Column pkCol = null;
  Column complexValFkCol = null;
  for(Column col : otherCols) {
    if(col.isAutoNumber()) {
      pkCol = col;
    } else if(col.getType() == DataType.LONG) {
      complexValFkCol = col;
    }
  }

  if((pkCol == null) || (complexValFkCol == null)) {
    throw new IOException("Could not find expected columns in flat table " +
                          flatTable.getName() + " for complex column with id "
                          + complexTypeId);
  }
  _pkCol = pkCol;
  _complexValFkCol = complexValFkCol;
}
 
示例23
protected Object[] asRow(Object[] row, V value) 
  throws IOException
{
ComplexValue.Id id = value.getId();
  _pkCol.setRowValue(
      row, ((id != INVALID_ID) ? id : Column.AUTO_NUMBER));
  ComplexValueForeignKey cFk = value.getComplexValueForeignKey();
  _complexValFkCol.setRowValue(
      row, ((cFk != INVALID_FK) ? cFk : Column.AUTO_NUMBER));
  return row;
}
 
示例24
protected static void diffFlatColumns(Table typeObjTable, 
                                      Table flatTable,
                                      List<Column> typeCols,
                                      List<Column> otherCols)
{
  // each "flat"" table has the columns from the "type" table, plus some
  // others.  separate the "flat" columns into these 2 buckets
  for(Column col : flatTable.getColumns()) {
    if(((TableImpl)typeObjTable).hasColumn(col.getName())) {
      typeCols.add(col);
    } else {
      otherCols.add(col);
    }  
  } 
}
 
示例25
public MultiValueColumnInfoImpl(Column column, int complexId,
                                Table typeObjTable, Table flatTable) 
  throws IOException
{
  super(column, complexId, typeObjTable, flatTable);

  _valueCol = getTypeColumns().get(0);
}
 
示例26
@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);
}
 
示例27
@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;
}
 
示例28
@Override
public void postTableLoadInit() throws IOException {
  super.postTableLoadInit();

  // link up with the actual versioned column.  it should have the same name
  // as the "value" column in the type table.
  Column versionedCol = getColumn().getTable().getColumn(
      getValueColumn().getName());
  ((ColumnImpl)versionedCol).setVersionHistoryColumn((ColumnImpl)getColumn());
}
 
示例29
private static boolean anyUpdates(Joiner joiner,Object[] oldRow, 
                                  Object[] newRow)
{
  Table fromTable = joiner.getFromTable();
  for(Index.Column iCol : joiner.getColumns()) {
    Column col = iCol.getColumn();
    if(!MATCHER.matches(fromTable, col.getName(),
                        col.getRowValue(oldRow), col.getRowValue(newRow))) {
      return true;
    }
  }
  return false;
}
 
示例30
/**
 * Returns kettle type from Microsoft Access database
 *
 * @param : MS Access column
 * @return valuemeta
 */
public static ValueMetaInterface getValueMeta( Column c ) {
  // get value
  ValueMetaAndData vmd = getValueMetaAndData( c, null, null );
  if ( vmd != null ) {
    // returns meta
    return vmd.getValueMeta();
  }
  return null;
}