private Joiner(Index fromIndex, IndexCursor toCursor) { _fromIndex = fromIndex; _fromCols = _fromIndex.getColumns(); _entryValues = new Object[_fromCols.size()]; _toCursor = toCursor; }
boolean uk = idx.isUnique(); boolean pk = idx.isPrimaryKey(); if (!uk && !pk && idx.getColumns().size() == 1) { Column cl = idx.getColumns().get(0).getColumn(); if (this.alreadyIndexed.contains(cl)) { return; if (uk && idx.getColumns().size() == 1) { Column cl = idx.getColumns().get(0).getColumn(); DataType dt = cl.getType(); if (dt.equals(DataType.COMPLEX_TYPE)) { String colsIdx = commaSeparated(idx.getColumns(), true); if (pk) { ci.append(" ADD PRIMARY KEY ").append(colsIdx); for (Index.Column cd : idx.getColumns()) { if (cd.getColumn().getType().equals(DataType.COMPLEX_TYPE)) { return; loadedIndexes.add(pre + " on " + tn + " Columns:" + commaSeparated(idx.getColumns(), false));
List<? extends Index.Column> toCols = _toCursor.getIndex().getColumns(); sb.append(toCols.get(0).getName()); for(int i = 1; i < toCols.size(); ++i) {
public BlobKey(Table _table, String _columnName, Row _row) { this.tableName = _table.getName(); this.columnName = _columnName; if (hasPrimaryKey(_table)) { List<? extends Index.Column> cl = _table.getPrimaryKeyIndex().getColumns(); HashMap<String, Object> keyMap = new HashMap<String, Object>(); for (Index.Column c : cl) { keyMap.put(c.getName(), _row.get(c.getName())); } this.key = keyMap; } }
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); } }
public BlobAction(Table _table, Object[] newValues) throws SQLException { this.table = _table; if (!BlobKey.hasPrimaryKey(_table)) { return; } Index pk = _table.getPrimaryKeyIndex(); HashSet<String> hsKey = new HashSet<String>(); for (Index.Column icl : pk.getColumns()) { hsKey.add(icl.getName()); } HashSet<String> hsBlob = new HashSet<String>(); int i = 0; HashMap<String, Object> keyMap = new HashMap<String, Object>(); for (Column cl : _table.getColumns()) { if (cl.getType().equals(DataType.OLE) && newValues[i] != null) { containsBlob = true; hsBlob.add(cl.getName()); } if (hsKey.contains(cl.getName())) { keyMap.put(cl.getName(), newValues[i]); } ++i; } for (String cln : hsBlob) { keys.add(new BlobKey(keyMap, table.getName(), cln)); } }
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); } }
private boolean isPrimaryColumn(String tableName, com.healthmarketscience.jackcess.Column originalColumn) throws IOException { for (Index index : jackcessDatabase.getTable(tableName).getIndexes()) { if (index.isPrimaryKey()) { for (Index.Column indexColumn : index.getColumns()) { if (indexColumn.getName().equals(originalColumn.getName())) { return true; } } } } boolean hasPrimaryKey = false; for (Index index : jackcessDatabase.getTable(tableName).getIndexes()) { if (index.isPrimaryKey()) { hasPrimaryKey = true; } } return originalColumn.isAutoNumber() && !hasPrimaryKey; }
@Override protected Schema getMainSchema() throws MetaModelException { MutableSchema schema = new MutableSchema(_file.getName()); Database db = getDatabase(); for (com.healthmarketscience.jackcess.Table mdbTable : db) { final MutableTable table = new MutableTable(mdbTable.getName(), TableType.TABLE, schema); try { int i = 0; for (com.healthmarketscience.jackcess.Column mdbColumn : mdbTable.getColumns()) { final ColumnType columnType = ColumnType.convertColumnType(mdbColumn.getSQLType()); final MutableColumn column = new MutableColumn(mdbColumn.getName(), columnType, table, i, null); column.setColumnSize((int) mdbColumn.getLength()); column.setNativeType(mdbColumn.getType().name()); table.addColumn(column); i++; } final Index primaryKeyIndex = mdbTable.getPrimaryKeyIndex(); final List<ColumnDescriptor> columnDescriptors = primaryKeyIndex.getColumns(); for (ColumnDescriptor columnDescriptor : columnDescriptors) { final String name = columnDescriptor.getColumn().getName(); final MutableColumn column = (MutableColumn) table.getColumnByName(name); column.setPrimaryKey(true); } schema.addTable(table); } catch (Exception e) { throw new MetaModelException(e); } } return schema; }