private Joiner(Index fromIndex, IndexCursor toCursor) { _fromIndex = fromIndex; _fromCols = _fromIndex.getColumns(); _entryValues = new Object[_fromCols.size()]; _toCursor = toCursor; }
private void loadTableIndexesNotUK(String tn) throws IOException, SQLException { Table t = dbIO.getTable(tn); UcanaccessTable table = new UcanaccessTable(t, tn); if (!skipIndexes && t != null) { for (Index idx : table.getIndexes()) { if (!idx.isForeignKey() && !idx.isPrimaryKey() && !idx.isUnique()) { loadIndex(idx, tn); } } } }
public String getName() { if(_name == null) { if(_indexes.size() == 1) { _name = _indexes.get(0).getName(); } else if(!_indexes.isEmpty()) { List<String> names = new ArrayList<String>(_indexes.size()); for(Index idx : _indexes) { names.add(idx.getName()); } _name = names.toString(); } else { _name = String.valueOf(_number); } } return _name; }
//broken, 'cos we don't generate these with names in SchemaExport subIter = table.getIndexIterator(); while ( subIter.hasNext() ) { Index index = (Index) subIter.next(); if ( !index.isForeignKey() || !dialect.hasImplicitIndexForForeignKey() ) { if ( tableInfo==null || tableInfo.getIndexMetadata( index.getFilterName() ) == null ) { script.add( index.sqlCreateString(dialect, mapping) ); } } } //broken, 'cos we don't generate these with names in SchemaExport subIter = table.getUniqueKeyIterator(); while ( subIter.hasNext() ) { UniqueKey uk = (UniqueKey) subIter.next(); if ( tableInfo==null || tableInfo.getIndexMetadata( uk.getFilterName() ) == null ) { script.add( uk.sqlCreateString(dialect, mapping) ); } }
/** * Adds a logical index which this data is backing. */ void addIndex(Index index) { // we keep foreign key indexes at the back of the list. this way the // primary index will be a non-foreign key index (if any) if(index.isForeignKey()) { _indexes.add(index); } else { int pos = _indexes.size(); while(pos > 0) { if(!_indexes.get(pos - 1).isForeignKey()) { break; } --pos; } _indexes.add(pos, index); // also, keep track of whether or not this is a primary key index _primaryKey |= index.isPrimaryKey(); } // force name to be regenerated _name = null; }
public Index getBestIndex() { if (this.bestIndex == null) { List<? extends Index> li = table.getIndexes(); for (Index idx : li) { if (idx.isPrimaryKey()) { this.bestIndex = idx; this.primaryCursor = true; break; } } if (this.bestIndex == null) { for (Index idx : li) { if (idx.isUnique()) { this.bestIndex = idx; break; } } } if (this.bestIndex == null && li.size() == 1) { this.bestIndex = li.get(0); } } return this.bestIndex; }
return; String nin = idx.getName(); nin = escapeIdentifier(tn + "_" + nin); 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); return; if (idx.isUnique()) { 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));
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; }
public static boolean hasPrimaryKey(Table _table) { for (Index idx : _table.getIndexes()) { if (idx.isPrimaryKey()) { return true; } } return false; }
public Table getFromTable() { return getFromIndex().getTable(); }
/** * Creates a new Joiner based on the given index which backs a foreign-key * relationship. The table of the given index will be the "from" table and * the table on the other end of the relationship will be the "to" table. * * @param fromIndex the index backing one side of a foreign-key relationship */ public static Joiner create(Index fromIndex) throws IOException { Index toIndex = fromIndex.getReferencedIndex(); IndexCursor toCursor = CursorBuilder.createCursor(toIndex); // text lookups are always case-insensitive toCursor.setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE); return new Joiner(fromIndex, toCursor); }
/** * Creates an indexed cursor for the given table. * <p> * Note, index based table traversal may not include all rows, as certain * types of indexes do not include all entries (namely, some indexes ignore * null entries, see {@link Index#shouldIgnoreNulls}). * * @param index index for the table which will define traversal order as * well as enhance certain lookups */ public static IndexCursor createCursor(Index index) throws IOException { return index.getTable().newCursor().setIndex(index).toIndexCursor(); }
List<? extends Index.Column> toCols = _toCursor.getIndex().getColumns(); sb.append(toCols.get(0).getName()); for(int i = 1; i < toCols.size(); ++i) {
private void loadTableIndexesUK(String tn) throws IOException, SQLException { Table t = dbIO.getTable(tn); UcanaccessTable table = new UcanaccessTable(t, tn); if (t != null) { for (Index idx : table.getIndexes()) { if (!idx.isForeignKey() && (idx.isPrimaryKey() || idx.isUnique())) { loadIndex(idx, tn); } } } }
names.add(toLookupName(idx.getName()));
/** * Creates an indexed cursor for the given table, narrowed to the given * range. * <p> * Note, index based table traversal may not include all rows, as certain * types of indexes do not include all entries (namely, some indexes ignore * null entries, see {@link Index#shouldIgnoreNulls}). * * @param index index for the table which will define traversal order as * well as enhance certain lookups * @param startRow the first row of data for the cursor (inclusive), or * {@code null} for the first entry * @param endRow the last row of data for the cursor (inclusive), or * {@code null} for the last entry */ public static IndexCursor createCursor(Index index, Object[] startRow, Object[] endRow) throws IOException { return index.getTable().newCursor().setIndex(index) .setStartRow(startRow) .setEndRow(endRow) .toIndexCursor(); }
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; } }
throws IOException return index.getTable().newCursor().setIndex(index) .setStartRow(startRow) .setStartRowInclusive(startInclusive)
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)); } }