use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestVDBStatusChecker method testDataSourceReplaced.
@Test
public void testDataSourceReplaced() throws Exception {
final VDBRepository repo = new VDBRepository();
repo.setSystemFunctionManager(RealMetadataFactory.SFM);
repo.start();
VDBStatusChecker vsc = new VDBStatusChecker() {
@Override
public VDBRepository getVDBRepository() {
return repo;
}
@Override
public Executor getExecutor() {
return null;
}
};
VDBTranslatorMetaData factory = new VDBTranslatorMetaData();
factory.setExecutionFactoryClass(ExecutionFactory.class);
assertFalse(vsc.dataSourceReplaced("x", "1", "y", "z", "t", "dsName"));
MetadataStore metadataStore = RealMetadataFactory.exampleBQTCached().getMetadataStore();
VDBMetaData vdb = TestCompositeVDB.createVDBMetadata(metadataStore, "bqt");
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
cmr.setProvider(new ExecutionFactoryProvider() {
@Override
public ExecutionFactory<Object, Object> getExecutionFactory(String name) throws ConnectorManagerException {
return new ExecutionFactory<Object, Object>();
}
});
ExecutionFactory ef1 = new ExecutionFactory();
ConnectorManager mgr = new ConnectorManager("oracle", "dsName", ef1);
cmr.addConnectorManager("BQT1", mgr);
repo.addVDB(vdb, metadataStore, null, null, cmr);
assertTrue(vsc.dataSourceReplaced("bqt", "1", "BQT1", "BQT1", "oracle", "dsName1"));
ExecutionFactory ef = cmr.getConnectorManager("BQT1").getExecutionFactory();
assertSame(ef, ef1);
assertFalse(vsc.dataSourceReplaced("bqt", "1", "BQT1", "BQT1", "sqlserver", "dsName1"));
ExecutionFactory ef2 = cmr.getConnectorManager("BQT1").getExecutionFactory();
assertNotNull(ef2);
assertNotSame(ef, ef2);
assertTrue(vsc.dataSourceReplaced("bqt", "1", "BQT1", "BQT1", "oracle", "dsName2"));
ef = cmr.getConnectorManager("BQT1").getExecutionFactory();
assertNotNull(ef);
assertNotSame(ef, ef2);
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class AbstractVDBDeployer method processVDBDDL.
private void processVDBDDL(final VDBMetaData vdb, final MetadataStore vdbMetadataStore, final ConnectorManagerRepository cmr, final VDBResources vdbResources) {
if (vdb.getStatus() == Status.FAILED) {
return;
}
String ddl = vdb.getPropertyValue(VDBMetaData.TEIID_DDL);
if (ddl != null) {
final Database database = DatabaseUtil.convert(vdb, vdbMetadataStore);
CompositeMetadataStore compositeStore = new CompositeMetadataStore(vdbMetadataStore);
final TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, null, getVDBRepository().getSystemFunctionManager().getSystemFunctions(), null);
DeploymentBasedDatabaseStore deploymentStore = new DeploymentBasedDatabaseStore(getVDBRepository()) {
@Override
protected TransformationMetadata getTransformationMetadata() {
return metadata;
}
@Override
public void importSchema(String schemaName, String serverType, String serverName, String foreignSchemaName, List<String> includeTables, List<String> excludeTables, Map<String, String> properties) {
ModelMetaData model = vdb.getModel(schemaName);
MetadataFactory factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
if (!includeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.includeTables", StringUtil.join(includeTables, ","));
}
if (!excludeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.excludeTables", StringUtil.join(excludeTables, ","));
}
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
MetadataRepository baseRepo = model.getAttachment(MetadataRepository.class);
MetadataRepository metadataRepository;
try {
metadataRepository = getMetadataRepository(serverType);
if (metadataRepository == null) {
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), serverType));
}
} catch (VirtualDatabaseException e1) {
throw new MetadataException(e1);
}
metadataRepository = new ChainingMetadataRepository(Arrays.asList(new MetadataRepositoryWrapper(metadataRepository, null), baseRepo));
ExecutionFactory ef = null;
Object cf = null;
Exception te = null;
for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
if (te != null) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
te = null;
}
try {
if (cm != null) {
ef = cm.getExecutionFactory();
cf = cm.getConnectionFactory();
}
} catch (TranslatorException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
}
try {
metadataRepository.loadMetadata(factory, ef, cf);
break;
} catch (Exception e) {
te = e;
factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
}
}
if (te != null) {
if (te instanceof RuntimeException) {
throw (RuntimeException) te;
}
throw new MetadataException(te);
}
}
};
deploymentStore.startEditing(false);
deploymentStore.databaseCreated(database);
deploymentStore.databaseSwitched(database.getName(), database.getVersion());
deploymentStore.setMode(Mode.SCHEMA);
try {
QueryParser.getQueryParser().parseDDL(deploymentStore, new StringReader(ddl));
} finally {
deploymentStore.stopEditing();
}
DatabaseUtil.copyDatabaseGrantsAndRoles(database, vdb);
}
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class EmbeddedServer method loadMetadata.
/**
* TODO: consolidate this logic more into the abstract deployer
*/
@Override
protected void loadMetadata(VDBMetaData vdb, ModelMetaData model, ConnectorManagerRepository cmr, MetadataRepository metadataRepository, MetadataStore store, AtomicInteger loadCount, VDBResources vdbResources) throws TranslatorException {
MetadataFactory factory = createMetadataFactory(vdb, store, model, vdbResources == null ? Collections.EMPTY_MAP : vdbResources.getEntriesPlusVisibilities());
ExecutionFactory ef = null;
Object cf = null;
Exception te = null;
for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
if (te != null) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
te = null;
}
try {
if (cm != null) {
ef = cm.getExecutionFactory();
cf = cm.getConnectionFactory();
}
} catch (TranslatorException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
}
try {
metadataRepository.loadMetadata(factory, ef, cf);
break;
} catch (Exception e) {
te = e;
factory = createMetadataFactory(vdb, store, model, vdbResources == null ? Collections.EMPTY_MAP : vdbResources.getEntriesPlusVisibilities());
}
}
if (te != null) {
if (te instanceof TranslatorException) {
throw (TranslatorException) te;
}
if (te instanceof RuntimeException) {
throw (RuntimeException) te;
}
throw new TranslatorException(te);
}
metadataLoaded(vdb, model, store, loadCount, factory, true, cmr, vdbResources);
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestDynamicImportedMetaData method testDroppedFk.
@Test
public void testDroppedFk() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.addSourceMetadata("ddl", "create foreign table x (y integer primary key);" + "create foreign table z (y integer, foreign key (y) references x)");
mmd.setName("foo");
mmd.addSourceMapping("x", "x", "x");
server.addTranslator("x", new ExecutionFactory());
server.deployVDB("vdb", mmd);
// $NON-NLS-1$
Connection conn = server.createConnection("jdbc:teiid:vdb");
Properties importProperties = new Properties();
importProperties.setProperty("importer.importKeys", "true");
// only import z and not the referenced table x
importProperties.setProperty("importer.tableNamePattern", "z");
MetadataFactory mf = getMetadata(importProperties, conn);
Table t = mf.asMetadataStore().getSchemas().get("test").getTables().get("vdb.foo.z");
List<ForeignKey> fks = t.getForeignKeys();
assertEquals(0, fks.size());
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestDynamicImportedMetaData method testMultiSourceImportError.
@Test
public void testMultiSourceImportError() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.addSourceMetadata("ddl", "create foreign table x (y integer primary key);");
mmd.setName("foo");
mmd.addSourceMapping("x", "x", "x");
server.addTranslator("x", new ExecutionFactory());
server.deployVDB("vdb", mmd);
TeiidExecutionFactory tef = new TeiidExecutionFactory() {
@Override
public void closeConnection(Connection connection, DataSource factory) {
}
};
tef.start();
server.addTranslator("teiid", tef);
DataSource ds = Mockito.mock(DataSource.class);
Connection c = server.getDriver().connect("jdbc:teiid:vdb", null);
// bad databasemetadata
DatabaseMetaData dbmd = (DatabaseMetaData) SimpleMock.createSimpleMock(new Object[] { new BadMetadata(), c.getMetaData() }, new Class[] { DatabaseMetaData.class });
Connection mock = Mockito.mock(Connection.class);
Mockito.stub(mock.getMetaData()).toReturn(dbmd);
Mockito.stub(ds.getConnection()).toReturn(mock);
DataSource ds1 = Mockito.mock(DataSource.class);
Mockito.stub(ds1.getConnection()).toReturn(server.getDriver().connect("jdbc:teiid:vdb", null));
server.addConnectionFactory("teiid1", ds);
server.addConnectionFactory("teiid2", ds1);
server.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("multi.xml")));
}
Aggregations