本文整理汇总了Java中org.apache.metamodel.schema.Schema.getTables方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.getTables方法的具体用法?Java Schema.getTables怎么用?Java Schema.getTables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.metamodel.schema.Schema
的用法示例。
在下文中一共展示了Schema.getTables方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeBlockingly
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void executeBlockingly() {
if (!isNeeded()) {
return;
}
final Schema schema = (Schema) _schemaNode.getUserObject();
final List<Table> tables = schema.getTables();
for (final Table table : tables) {
final String name = table.getName();
logger.debug("Building table node: {}", name);
final DefaultMutableTreeNode tableNode = new DefaultMutableTreeNode(table);
final DefaultMutableTreeNode loadingColumnsNode = new DefaultMutableTreeNode(LOADING_COLUMNS_STRING);
tableNode.add(loadingColumnsNode);
_schemaNode.add(tableNode);
}
_schemaNode.remove(0);
}
示例2: addTablesOfSchema
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
private void addTablesOfSchema(Schema rawSchema, MSchema mSchema, UpdateLogger upLog) throws MetaException {
for (Table rawTable : rawSchema.getTables()) {
String tableName = rawTable.getName();
TableType tableType = rawTable.getType();
LOG.debug("add table. tableName=" + tableName);
// TODO: handle table type (SYSTEM_TABLE, ALIAS, SYNONYM etc...)
MTable mTable = new MTable(tableName, tableType.name(), mSchema);
pm.makePersistent(mTable);
if (upLog != null)
upLog.create(null, tableName);
addColumnsOfTable(rawTable, mTable);
}
}
示例3: doInBackground
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
@Override
protected Void doInBackground() throws Exception {
final Schema schema = (Schema) _schemaNode.getUserObject();
final List<Table> tables = schema.getTables();
for (final Table table : tables) {
final String name = table.getName();
logger.debug("Publishing table name: {}", name);
publish(table);
}
return null;
}
示例4: convertToTable
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public Table convertToTable(String schemaName, String tableName) {
final Schema schema;
if (schemaName == null) {
schema = getDefaultSchema();
} else {
schema = getSchemaByName(schemaName);
}
if (schema == null) {
throw new IllegalArgumentException("Schema " + schemaName + " not found. Available schema names are: "
+ Arrays.toString(dataContext.getSchemaNames()));
}
final Table table;
if (tableName == null) {
if (schema.getTableCount() == 1) {
table = schema.getTables()[0];
} else {
throw new IllegalArgumentException(
"No table name specified, and multiple options exist. Available table names are: "
+ Arrays.toString(schema.getTableNames()));
}
} else {
table = schema.getTableByName(tableName);
}
if (table == null) {
throw new IllegalArgumentException("Table not found. Available table names are: "
+ Arrays.toString(schema.getTableNames()));
}
return table;
}
示例5: testGetDatastoreConnection
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testGetDatastoreConnection() throws Exception {
FixedWidthDatastore ds = new FixedWidthDatastore("example datastore",
"src/test/resources/employees-fixed-width.txt", "UTF-8", 19, false);
try (DatastoreConnection con = ds.openConnection()) {
Schema schema = con.getDataContext().getDefaultSchema();
assertEquals("resources", schema.getName());
Table table = schema.getTables()[0];
assertEquals("employees-fixed-width.txt", table.getName());
assertEquals("[name, email]", Arrays.toString(table.getColumnNames()));
}
}
示例6: serializeAnalyzerBeansConfigurationDataStores
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public static String serializeAnalyzerBeansConfigurationDataStores(
AnalyzerBeansConfiguration analyzerBeansConfiguration) {
StringBuilder datastoresOutputBuilder = new StringBuilder();
DatastoreCatalog datastoreCatalog = analyzerBeansConfiguration
.getDatastoreCatalog();
for (String datastoreName : analyzerBeansConfiguration
.getDatastoreCatalog().getDatastoreNames()) {
Datastore datastore = datastoreCatalog.getDatastore(datastoreName);
Schema schema = datastore.openConnection().getDataContext()
.getDefaultSchema();
for (Table table : schema.getTables()) {
datastoresOutputBuilder.append(datastoreName);
datastoresOutputBuilder.append(",");
datastoresOutputBuilder.append(schema.getName());
datastoresOutputBuilder.append(",");
datastoresOutputBuilder.append(table.getName());
datastoresOutputBuilder.append(",");
String[] columnNames = table.getColumnNames();
for (int i = 0; i < columnNames.length; i++) {
datastoresOutputBuilder.append(columnNames[i]);
if (i == columnNames.length - 1)
datastoresOutputBuilder.append("\n");
else
datastoresOutputBuilder.append(",");
}
}
}
return datastoresOutputBuilder.toString();
}
示例7: testSerializeDeserializeDatastores
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
@Test
public void testSerializeDeserializeDatastores() {
String csv = ConfigurationSerializer.serializeAnalyzerBeansConfigurationDataStores(analyzerBeansConfiguration);
logger.info("Csv: " + csv);
AnalyzerBeansConfiguration deserialized = ConfigurationSerializer.deserializeAnalyzerBeansDatastores(csv);
for (String datastoreName : analyzerBeansConfiguration.getDatastoreCatalog().getDatastoreNames()) {
logger.info("Datastore: " + datastoreName);
Datastore datastore = analyzerBeansConfiguration.getDatastoreCatalog().getDatastore(datastoreName);
Datastore deserializedDatastore = deserialized.getDatastoreCatalog().getDatastore(datastoreName);
Assert.assertNotNull(deserializedDatastore);
SchemaNavigator schemaNavigator = datastore.openConnection().getSchemaNavigator();
SchemaNavigator deserializedSchemaNavigator = deserializedDatastore.openConnection().getSchemaNavigator();
for (Schema schema : schemaNavigator.getSchemas()) {
String schemaName = schema.getName();
logger.info("\tSchema: " + schemaName);
Schema deserializedSchema = deserializedSchemaNavigator.getSchemaByName(schemaName);
Assert.assertNotNull(deserializedSchema);
for (Table table : schema.getTables()) {
String tableName = table.getName();
logger.info("\t\tTable: " + tableName);
Table deserializedTable = deserializedSchema.getTableByName(tableName);
Assert.assertNotNull(deserializedTable);
for (Column column : table.getColumns()) {
String columnName = column.getName();
logger.info("\t\t\tColumn: " + columnName);
Column deserializedColumn = deserializedTable.getColumnByName(columnName);
Assert.assertNotNull(deserializedColumn);
}
}
}
}
}
示例8: generate
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
@Override
public void generate() {
try {
//Get current execution path
final String dir = System.getProperty("user.dir");
System.out.println("Excuting in directory: " + dir);
Database database = this.project.getDatabase();
String db = database.getSchema();
Connection conn = ConnectionFactory.create(database);
DataContext dataContext = new JdbcDataContext(conn);
List<Schema> schemaList = new ArrayList<>();
List<Table> tableList = new ArrayList<>();
List<Column> columnList = new ArrayList<>();
//Traverse database
Schema[] schemas = dataContext.getSchemas();
schemaList = Arrays.asList(schemas);
for (Schema schema : schemas) {
System.out.println("Schema: " + schema.getName());
if (schema.getName().equals(db)) {
Table[] tables = schema.getTables();
tableList = Arrays.asList(tables);
for (Table table : tables) {
System.out.println(" Table: " + table.getName());
Column[] columns = table.getColumns();
columnList = Arrays.asList(columns);
for (Column column : columns) {
System.out.println(" Column: " + column.getName() + "Type: " + column.getType());
}
}
}
}
System.out.println("table list: " + tableList.size());
Writer writer = WriterFactory.createWriter(this.project, tableList);
writer.write();
} catch (IOException ex) {
Logger.getLogger(DefaultGenerator.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例9: getTables
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public Table[] getTables(String database) throws Exception{
Schema schema = dataContext.getDefaultSchema();
Table[] tables = schema.getTables();
return tables;
}
示例10: createPojoDatastore
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
/**
* Creates a serialized POJO copy of a datastore.
*
* @param datastore
* the datastore to copy
* @param columns
* the columns to include, or null if all tables/columns should
* be included.
* @param maxRowsToQuery
* the maximum number of records to query and include in the
* datastore copy. Keep this number reasonably low, or else the
* copy might cause out-of-memory issues (Both while reading and
* writing).
* @return
*/
public AbstractDatastoreType createPojoDatastore(final Datastore datastore, final Set<Column> columns,
final int maxRowsToQuery) {
final PojoDatastoreType datastoreType = new PojoDatastoreType();
datastoreType.setName(datastore.getName());
datastoreType.setDescription(datastore.getDescription());
try (DatastoreConnection con = datastore.openConnection()) {
final DataContext dataContext = con.getDataContext();
final Schema schema;
final List<Table> tables;
if (columns == null || columns.isEmpty()) {
schema = dataContext.getDefaultSchema();
tables = schema.getTables();
} else {
tables = Arrays.asList(MetaModelHelper.getTables(columns));
// TODO: There's a possibility that tables span multiple
// schemas, but we cannot currently support that in a
// PojoDatastore, so we just pick the first and cross our
// fingers.
schema = tables.get(0).getSchema();
}
datastoreType.setSchemaName(schema.getName());
for (final Table table : tables) {
final List<Column> usedColumns;
if (columns == null || columns.isEmpty()) {
usedColumns = table.getColumns();
} else {
usedColumns = Arrays.asList(MetaModelHelper.getTableColumns(table, columns));
}
final PojoTableType tableType = createPojoTable(dataContext, table, usedColumns, maxRowsToQuery);
datastoreType.getTable().add(tableType);
}
}
return datastoreType;
}
示例11: setModel
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void setModel(final Datastore datastore, final boolean retainSelection) {
final Column previousItem = getSelectedItem();
setTable(null);
if (datastore == null) {
setDatastoreConnection(null);
setModel(new DefaultComboBoxModel<>(new String[1]));
} else {
final DatastoreConnection con = setDatastoreConnection(datastore.openConnection());
int selectedIndex = 0;
final List<Object> comboBoxList = new ArrayList<>();
comboBoxList.add(null);
final Schema[] schemas = con.getSchemaNavigator().getSchemas();
Arrays.sort(schemas, new SchemaComparator());
for (final Schema schema : schemas) {
comboBoxList.add(schema);
if (!MetaModelHelper.isInformationSchema(schema)) {
final List<Table> tables = schema.getTables();
for (final Table table : tables) {
try {
final List<Column> columns = table.getColumns();
if (columns != null && !columns.isEmpty()) {
comboBoxList.add(table);
for (final Column column : columns) {
comboBoxList.add(column);
if (column == previousItem) {
selectedIndex = comboBoxList.size() - 1;
}
}
}
} catch (final Exception e) {
// errors can occur for experimental datastores (or
// something like SAS datastores where not all SAS
// files are supported). Ignore.
logger.error("Error occurred getting columns of table: {}", table);
}
}
}
}
final ComboBoxModel<Object> model = new DefaultComboBoxModel<>(comboBoxList.toArray());
setModel(model);
if (retainSelection) {
setSelectedIndex(selectedIndex);
}
}
}
示例12: createPojoDatastore
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
/**
* Creates a serialized POJO copy of a datastore.
*
* @param datastore
* the datastore to copy
* @param columns
* the columns to include, or null if all tables/columns should
* be included.
* @param maxRowsToQuery
* the maximum number of records to query and include in the
* datastore copy. Keep this number reasonably low, or else the
* copy might cause out-of-memory issues (Both while reading and
* writing).
* @return
*/
public AbstractDatastoreType createPojoDatastore(final Datastore datastore, final Set<Column> columns,
final int maxRowsToQuery) {
final PojoDatastoreType datastoreType = new PojoDatastoreType();
datastoreType.setName(datastore.getName());
datastoreType.setDescription(datastore.getDescription());
try (final DatastoreConnection con = datastore.openConnection()) {
final DataContext dataContext = con.getDataContext();
final Schema schema;
final Table[] tables;
if (columns == null || columns.isEmpty()) {
schema = dataContext.getDefaultSchema();
tables = schema.getTables();
} else {
tables = MetaModelHelper.getTables(columns);
// TODO: There's a possibility that tables span multiple
// schemas, but we cannot currently support that in a
// PojoDatastore, so we just pick the first and cross our
// fingers.
schema = tables[0].getSchema();
}
datastoreType.setSchemaName(schema.getName());
for (final Table table : tables) {
final Column[] usedColumns;
if (columns == null || columns.isEmpty()) {
usedColumns = table.getColumns();
} else {
usedColumns = MetaModelHelper.getTableColumns(table, columns);
}
final PojoTableType tableType = createPojoTable(dataContext, table, usedColumns, maxRowsToQuery);
datastoreType.getTable().add(tableType);
}
}
return datastoreType;
}
示例13: testErrorHandlingToTempFile
import org.apache.metamodel.schema.Schema; //导入方法依赖的package包/类
public void testErrorHandlingToTempFile() throws Exception {
final InsertIntoTableAnalyzer insertIntoTable = new InsertIntoTableAnalyzer();
insertIntoTable.datastore = jdbcDatastore;
insertIntoTable.tableName = "test_table";
insertIntoTable.columnNames = new String[] { "foo", "bar" };
insertIntoTable.errorHandlingOption = ErrorHandlingOption.SAVE_TO_FILE;
insertIntoTable._componentContext = EasyMock.createMock(ComponentContext.class);
InputColumn<Object> col1 = new MockInputColumn<Object>("in1", Object.class);
InputColumn<Object> col2 = new MockInputColumn<Object>("in2", Object.class);
insertIntoTable.values = new InputColumn[] { col1, col2 };
insertIntoTable.validate();
insertIntoTable.init();
// a valid row
insertIntoTable.run(new MockInputRow().put(col1, "hello world").put(col2, 123), 1);
// null values - should be accepted
insertIntoTable.run(new MockInputRow().put(col1, null).put(col2, null), 1);
// invalid types, they should be automatically converted
insertIntoTable.run(new MockInputRow().put(col1, 123).put(col2, "123"), 1);
// invalid and unconvertable types!
insertIntoTable.run(new MockInputRow().put(col2, "hey I am a string in a number field"), 1);
// another valid row (after the failing one)
insertIntoTable.run(new MockInputRow().put(col1, "foo bar").put(col2, 3123), 1);
WriteDataResult result = insertIntoTable.getResult();
// assertions about succes rows
assertEquals(4, result.getWrittenRowCount());
assertEquals(jdbcDatastore, result.getDatastore(null));
Table table = result.getPreviewTable(jdbcDatastore);
assertEquals("TEST_TABLE", table.getName());
// make assertions about error rows
assertEquals(1, result.getErrorRowCount());
FileDatastore errorDatastore = result.getErrorDatastore();
assertNotNull(errorDatastore);
DatastoreConnection errorCon = errorDatastore.openConnection();
Schema errorSchema = errorCon.getDataContext().getDefaultSchema();
assertEquals(1, errorSchema.getTableCount());
Table errorTable = errorSchema.getTables()[0];
assertEquals("[foo, bar, insert_into_table_error_message]", Arrays.toString(errorTable.getColumnNames()));
DataSet ds = errorCon.getDataContext().query().from(errorTable).select("foo").and("bar")
.and("insert_into_table_error_message").execute();
assertTrue(ds.next());
assertEquals("Row[values=[, hey I am a string in a number field, "
+ "Could not convert hey I am a string in a number field to number]]", ds.getRow().toString());
assertFalse(ds.next());
errorCon.close();
String filename = errorDatastore.getFilename();
assertEquals("4 inserts executed\n" + " - WARNING! 1 record failed, written to file: " + filename,
result.toString());
}