public static boolean hasPrimaryKey(Table _table) { for (Index idx : _table.getIndexes()) { if (idx.isPrimaryKey()) { return true; } } return false; }
/** * 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; }
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; }
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();
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); } } } }
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); } } } }