@Override public Object getPrimaryKey(Object metadataID) { Table table = (Table)metadataID; return table.getPrimaryKey(); }
@Override public Object getPrimaryKey(Object metadataID) { Table table = (Table)metadataID; return table.getPrimaryKey(); }
@Override public Object getPrimaryKey(Object metadataID) { Table table = (Table)metadataID; return table.getPrimaryKey(); }
static KeyRecord getIdentifier(Table table) { if (table.getPrimaryKey() != null) { return table.getPrimaryKey(); } for (KeyRecord key:table.getUniqueKeys()) { return key; } return null; }
boolean hasCompositePrimaryKey(Table table) { KeyRecord pk = table.getPrimaryKey(); return pk.getColumns().size() > 1; }
public Collection<KeyRecord> getUniqueKeysInGroup(final Object groupID) throws TeiidComponentException, QueryMetadataException { Table tableRecordImpl = (Table)groupID; ArrayList<KeyRecord> result = new ArrayList<KeyRecord>(tableRecordImpl.getUniqueKeys()); if (tableRecordImpl.getPrimaryKey() != null) { result.add(tableRecordImpl.getPrimaryKey()); } for (KeyRecord key : tableRecordImpl.getIndexes()) { if (key.getType() == KeyRecord.Type.Unique) { result.add(key); } } return result; }
public Collection<KeyRecord> getAllKeys() { Collection<KeyRecord> keys = new LinkedList<KeyRecord>(); if (getPrimaryKey() != null) { keys.add(getPrimaryKey()); } keys.addAll(getForeignKeys()); keys.addAll(getAccessPatterns()); keys.addAll(getIndexes()); keys.addAll(getUniqueKeys()); return keys; }
KeyRecord getPKorUnique(Table table) { KeyRecord pk = table.getPrimaryKey(); if (pk == null && !table.getUniqueKeys().isEmpty()) { pk = table.getUniqueKeys().get(0); } return pk; }
static boolean isPartOfPrimaryKey(Table table, String columnName) { KeyRecord pk = table.getPrimaryKey(); if (pk != null) { for (Column column:pk.getColumns()) { if (getRecordName(column).equals(columnName)) { return true; } } } return false; }
public boolean isPartOfPrimaryKey(String columnName) { KeyRecord pk = this.table.getPrimaryKey(); if (pk != null) { for (Column column:pk.getColumns()) { if (column.getName().equals(columnName)) { return true; } } } return false; }
private boolean matchesWithPkOrUnique(List<String> names, Table table) { if (keyMatches(names, table.getPrimaryKey())) { return true; } for (KeyRecord record:table.getUniqueKeys()) { if (keyMatches(names, record)) { return true; } } return false; }
static boolean isPartOfPrimaryKey(Table table, String columnName) { KeyRecord pk = table.getPrimaryKey(); if (hasColumn(pk, columnName)) { return true; } for (KeyRecord key:table.getUniqueKeys()) { if (hasColumn(key, columnName)) { return true; } } return false; }
private boolean isJoinOrPkColumn(Column column) { boolean joinColumn = Boolean.valueOf(column.getProperty(ODataMetadataProcessor.JOIN_COLUMN, false)); if (!joinColumn) { Table table = (Table)column.getParent(); return (table.getPrimaryKey().getColumnByName(column.getName()) != null); } return false; }
static boolean isPartOfPrimaryKey(Table table, String columnName) { KeyRecord pk = table.getPrimaryKey(); if (hasColumn(pk, columnName)) { return true; } for (KeyRecord key:table.getUniqueKeys()) { if (hasColumn(key, columnName)) { return true; } } return false; }
final public AbstractMetadataRecord primaryKey(MetadataFactory factory, Table table, String name) throws ParseException { List<String> columnNames = null; Column column = null; KeyRecord key = null; jj_consume_token(PRIMARY); jj_consume_token(KEY); columnNames = columnList(true, false); if (table.getPrimaryKey() != null){ {if (true) throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));} } {if (true) return factory.addPrimaryKey(name!=null?name:"PK", columnNames, table);} throw new Error("Missing return statement in function"); }
final public AbstractMetadataRecord primaryKey(MetadataFactory factory, Table table, String name) throws ParseException { List<String> columnNames = null; Column column = null; KeyRecord key = null; jj_consume_token(PRIMARY); jj_consume_token(KEY); columnNames = columnList(true, false); if (table.getPrimaryKey() != null){ {if (true) throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));} } {if (true) return factory.addPrimaryKey(name!=null?name:"PK", columnNames, table);} throw new Error("Missing return statement in function"); }
private boolean isJoinOrPkColumn(Column column) { Table table = (Table)column.getParent(); boolean isKey = (table.getPrimaryKey().getColumnByName(column.getName()) != null); if (!isKey) { for(ForeignKey fk:table.getForeignKeys()) { if (fk.getColumnByName(column.getName()) != null) { isKey = true; } } } return isKey; } }
@Test public void testAlterAddPK() throws Exception { String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date); ALTER TABLE G1 ADD PRIMARY KEY (e1, e2);"; Schema s = helpParse(ddl, "model").getSchema(); Map<String, Table> tableMap = s.getTables(); assertTrue("Table not found", tableMap.containsKey("G1")); Table table = tableMap.get("G1"); assertEquals(table.getColumns().subList(0, 2), table.getPrimaryKey().getColumns()); }
@Test public void testMultiKeyPK() throws Exception { String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, PRIMARY KEY (e1, e2))"; Schema s = helpParse(ddl, "model").getSchema(); Map<String, Table> tableMap = s.getTables(); assertTrue("Table not found", tableMap.containsKey("G1")); Table table = tableMap.get("G1"); assertEquals(table.getColumns().subList(0, 2), table.getPrimaryKey().getColumns()); }
@Test public void testEmptyKey() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));"; buildModel("pm1", true, this.vdb, this.store, ddl); buildTransformationMetadata(); this.store.getSchema("pm1").getTable("G1").getPrimaryKey().getColumns().clear(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }