public void setTableMetadata(Table tableMetadata) { if (tableMetadata != null) { this.columns = tableMetadata.getColumns(); this.table = new GroupSymbol(tableMetadata.getName()); } this.tableMetadata = tableMetadata; }
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; }
private static void removeTableOption(String key, Table table) { if (table.getProperty(key, false) != null) { table.setProperty(key, null); } removeCommonProperty(key, table); if (key.equals(DDLConstants.MATERIALIZED)) { table.setMaterialized(false); } if (key.equals(DDLConstants.MATERIALIZED_TABLE)) { table.setMaterializedTable(null); } if (key.equals(DDLConstants.UPDATABLE)) { table.setSupportsUpdate(false); } if (key.equals(DDLConstants.CARDINALITY)) { table.setCardinality(-1); } }
static KeyRecord getIdentifier(Table table) { if (table.getPrimaryKey() != null) { return table.getPrimaryKey(); } for (KeyRecord key:table.getUniqueKeys()) { return key; } return null; }
private static String getEntityTypeName(Table t, boolean preserveEntityTypeName) { String entityTypeName = t.getName(); if (preserveEntityTypeName && t.getProperty(ODataMetadataProcessor.ENTITY_TYPE, false) != null) { entityTypeName = t.getProperty(ODataMetadataProcessor.ENTITY_TYPE, false); } return entityTypeName; }
private Table createView(String name) { Table t = addTable(name); t.setSystem(true); t.setSupportsUpdate(false); t.setVirtual(true); t.setTableType(Type.Table); return t; }
private static void setTableOptions(Table table) { Map<String, String> props = table.getProperties(); setCommonProperties(table, props); String value = props.remove(DDLConstants.MATERIALIZED); if (value != null) { table.setMaterialized(isTrue(value)); } value = props.remove(DDLConstants.MATERIALIZED_TABLE); if (value != null) { Table mattable = new Table(); mattable.setName(value); table.setMaterializedTable(mattable); } value = props.remove(DDLConstants.UPDATABLE); if (value != null) { table.setSupportsUpdate(isTrue(value)); } value = props.remove(DDLConstants.CARDINALITY); if (value != null) { table.setCardinality(Long.valueOf(value)); } }
@Test public void testConstraints() throws Exception { String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, " + " PRIMARY KEY (e1, e2), INDEX(e2, e3), ACCESSPATTERN(e1), UNIQUE(e1)," + " ACCESSPATTERN(e2, e3))"; 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()); assertEquals(table.getColumns().subList(1, 3), table.getIndexes().get(0).getColumns()); assertEquals(table.getColumns().subList(0, 1), table.getUniqueKeys().get(0).getColumns()); assertEquals(2, table.getAccessPatterns().size()); assertEquals(table.getColumns().subList(0, 1), table.getAccessPatterns().get(0).getColumns()); assertEquals(table.getColumns().subList(1, 3), table.getAccessPatterns().get(1).getColumns()); }
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; }
Column getColumn(String columnName, Table table) throws MetadataException { Column c = table.getColumnByName(columnName); if (c != null) { return c; } throw new MetadataException(QueryPlugin.Util.getString("SQLParser.no_column", columnName, table.getName())); //$NON-NLS-1$ }
/** * Create a physical group with default settings. * @param name Name of physical group, must match model name * @param model Associated model * @return FakeMetadataObject Metadata object for group */ public static Table createPhysicalGroup(String name, Schema model, boolean fullyQualify) { Table table = new Table(); table.setName(name); model.addTable(table); table.setSupportsUpdate(true); table.setNameInSource((fullyQualify || name.lastIndexOf(".") == -1)? name : name.substring(name.lastIndexOf(".") + 1)); //$NON-NLS-1$ //$NON-NLS-2$ table.setTableType(org.teiid.metadata.Table.Type.Table); return table; }
@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()); }
static Table getComplexTableParentTable(RuntimeMetadata metadata, Table table) throws TranslatorException { for (Column c : table.getColumns()) { if (ODataMetadataProcessor.isPseudo(c)) { ForeignKey fk = table.getForeignKeys().get(0); String tableName = fk.getReferenceTableName(); if (tableName.indexOf('.') == -1) { tableName = fk.getReferenceKey().getParent().getFullName(); } return (Table)metadata.getTable(tableName); } } return table; }
/** * * @param metadataFactory * @param tableCatalog * @param tableSchema * @param tableName * @param remarks * @param fullName * @return */ protected Table addTable(MetadataFactory metadataFactory, String tableCatalog, String tableSchema, String tableName, String remarks, String fullName) { Table table = metadataFactory.addTable(useFullSchemaName?fullName:tableName); table.setNameInSource(getFullyQualifiedName(tableCatalog, tableSchema, tableName, true)); //create a fqn for the table FullyQualifiedName fqn = new FullyQualifiedName(); if (tableCatalog != null && !tableCatalog.isEmpty()) { fqn.append(getCatalogTerm(), tableCatalog); } if (tableSchema != null && !tableSchema.isEmpty()) { fqn.append(getSchemaTerm(), tableSchema); } fqn.append(getTableTerm(), tableName); table.setProperty(FQN, fqn.toString()); table.setSupportsUpdate(true); table.setAnnotation(remarks); return table; }
@Override public Object getPrimaryKey(Object metadataID) { Table table = (Table)metadataID; return table.getPrimaryKey(); }
/** * Adds new table to metadata. * * @param spreadsheet Name of the spreadsheet * @param worksheet Name of the worksheet * @throws TranslatorException */ private void addTable(MetadataFactory mf, Worksheet worksheet) { if (worksheet.getColumnCount() == 0){ return; } Table table = mf.addTable(worksheet.getName()); table.setProperty(FQN, new FullyQualifiedName("worksheet", worksheet.getName()).toString()); //$NON-NLS-1$ table.setNameInSource(worksheet.getName()); if (worksheet.isHeaderEnabled()) { table.setSupportsUpdate(true); } addColumnsToTable(mf, table, worksheet); }
static boolean isPartOfForeignKey(Table table, String columnName) { for (ForeignKey fk : table.getForeignKeys()) { for (Column column : fk.getColumns()) { if (column.getName().equals(columnName)) { return true; } } } return false; }
@Test public void testConstraints2() throws Exception { String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date, " + "ACCESSPATTERN(e1), UNIQUE(e1), ACCESSPATTERN(e2, e3))"; 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, 1), table.getUniqueKeys().get(0).getColumns()); assertEquals(2, table.getAccessPatterns().size()); assertEquals(table.getColumns().subList(0, 1), table.getAccessPatterns().get(0).getColumns()); assertEquals(table.getColumns().subList(1, 3), table.getAccessPatterns().get(1).getColumns()); }
private boolean hasColumns(List<String> columnNames, Table table) { for (String columnName:columnNames) { if (table.getColumnByName(columnName) == null) { return false; } } return true; }
public Collection<Table> getXMLTempGroups(Table tableRecord) { ArrayList<Table> results = new ArrayList<Table>(); String namePrefix = tableRecord.getName() + TransformationMetadata.DELIMITER_STRING; for (Table table : tableRecord.getParent().getTables().values()) { if (table.getTableType() == Type.XmlStagingTable && table.getName().startsWith(namePrefix)) { results.add(table); } } return results; }