Search in sources :

Example 1 with GlobalTableStore

use of org.teiid.query.tempdata.GlobalTableStore in project teiid by teiid.

the class CommandContext method setNewVDBState.

public void setNewVDBState(DQPWorkContext newWorkContext) {
    this.vdbState = new VDBState();
    VDBMetaData vdb = newWorkContext.getVDB();
    GlobalTableStore actualGlobalStore = vdb.getAttachment(GlobalTableStore.class);
    this.vdbState.globalTables = actualGlobalStore;
    this.vdbState.session = newWorkContext.getSession();
    this.vdbState.classLoader = vdb.getAttachment(ClassLoader.class);
    this.vdbState.vdbName = vdb.getName();
    this.vdbState.vdbVersion = vdb.getVersion();
    this.vdbState.dqpWorkContext = newWorkContext;
    TempMetadataAdapter metadata = new TempMetadataAdapter(vdb.getAttachment(QueryMetadataInterface.class), globalState.sessionTempTableStore.getMetadataStore());
    metadata.setSession(true);
    this.vdbState.metadata = metadata;
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface)

Example 2 with GlobalTableStore

use of org.teiid.query.tempdata.GlobalTableStore in project teiid by teiid.

the class EmbeddedServer method startVDBRepository.

private void startVDBRepository() {
    this.repo.addListener(new VDBLifeCycleListener() {

        @Override
        public void added(String name, CompositeVDB vdb) {
        }

        @Override
        public void removed(String name, CompositeVDB vdb) {
            if (replicator != null) {
                replicator.stop(vdb.getVDB().getAttachment(GlobalTableStore.class));
            }
            rs.clearForVDB(vdb.getVDBKey());
            ppc.clearForVDB(vdb.getVDBKey());
            for (SessionMetadata session : sessionService.getSessionsLoggedInToVDB(vdb.getVDBKey())) {
                try {
                    sessionService.closeSession(session.getSessionId());
                } catch (InvalidSessionException e) {
                }
            }
        }

        @Override
        public void finishedDeployment(String name, CompositeVDB vdb) {
            if (!vdb.getVDB().getStatus().equals(Status.ACTIVE)) {
                return;
            }
            GlobalTableStore gts = CompositeGlobalTableStore.createInstance(vdb, dqp.getBufferManager(), replicator);
            vdb.getVDB().addAttchment(GlobalTableStore.class, gts);
        }

        @Override
        public void beforeRemove(String name, CompositeVDB vdb) {
        }
    });
    this.repo.setSystemFunctionManager(SystemMetadata.getInstance().getSystemFunctionManager());
    this.repo.start();
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) CompositeVDB(org.teiid.deployers.CompositeVDB) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) CompositeGlobalTableStore(org.teiid.deployers.CompositeGlobalTableStore) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener)

Example 3 with GlobalTableStore

use of org.teiid.query.tempdata.GlobalTableStore in project teiid by teiid.

the class TestCompositeGlobalTableStore method testCompositeGlobalTableStore.

@Test
public void testCompositeGlobalTableStore() throws VirtualDatabaseException {
    CompositeVDB vdb = TestCompositeVDB.createCompositeVDB(new MetadataStore(), "foo");
    GlobalTableStore gts = CompositeGlobalTableStore.createInstance(vdb, BufferManagerFactory.getStandaloneBufferManager(), null);
    assertTrue(gts instanceof GlobalTableStoreImpl);
    vdb.children = new LinkedHashMap<VDBKey, CompositeVDB>();
    MetadataStore ms = new MetadataStore();
    Schema s = new Schema();
    s.setName("x");
    ms.addSchema(s);
    CompositeVDB imported = TestCompositeVDB.createCompositeVDB(ms, "foo");
    GlobalTableStore gts1 = Mockito.mock(GlobalTableStore.class);
    imported.getVDB().addAttchment(GlobalTableStore.class, gts1);
    vdb.getChildren().put(new VDBKey("foo1", 1), imported);
    CompositeGlobalTableStore cgts = (CompositeGlobalTableStore) CompositeGlobalTableStore.createInstance(vdb, BufferManagerFactory.getStandaloneBufferManager(), null);
    assertEquals(gts1, cgts.getStoreForTable(RelationalPlanner.MAT_PREFIX + "X.Y"));
    assertEquals(cgts.getPrimary(), cgts.getStore("Z"));
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) Schema(org.teiid.metadata.Schema) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) Test(org.junit.Test)

Example 4 with GlobalTableStore

use of org.teiid.query.tempdata.GlobalTableStore in project teiid by teiid.

the class AccessInfo method restore.

/**
 * Restore reconnects to the live metadata objects
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
void restore() throws TeiidComponentException, TeiidProcessingException {
    if (this.objectsAccessed != null) {
        return;
    }
    VDBMetaData vdb = DQPWorkContext.getWorkContext().getVDB();
    TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
    GlobalTableStore globalStore = vdb.getAttachment(GlobalTableStore.class);
    if (!externalNames.isEmpty()) {
        this.objectsAccessed = new HashSet<Object>(externalNames.size());
        for (List<String> key : this.externalNames) {
            if (key.size() == 1) {
                String matTableName = key.get(0);
                TempMetadataID id = globalStore.getGlobalTempTableMetadataId(matTableName);
                if (id == null) {
                    // if the id is null, then create a local instance
                    String viewFullName = matTableName.substring(RelationalPlanner.MAT_PREFIX.length());
                    id = globalStore.getGlobalTempTableMetadataId(tm.getGroupID(viewFullName));
                }
                this.objectsAccessed.add(id);
            } else {
                Schema s = tm.getMetadataStore().getSchema(key.get(0));
                Modifiable m = s.getTables().get(key.get(1));
                if (m == null) {
                    m = s.getProcedures().get(key.get(1));
                }
                if (m != null) {
                    this.objectsAccessed.add(m);
                }
            }
        }
    } else {
        this.objectsAccessed = Collections.emptySet();
    }
    this.externalNames = null;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) TempMetadataID(org.teiid.query.metadata.TempMetadataID) DataModifiable(org.teiid.metadata.AbstractMetadataRecord.DataModifiable) Modifiable(org.teiid.metadata.AbstractMetadataRecord.Modifiable)

Example 5 with GlobalTableStore

use of org.teiid.query.tempdata.GlobalTableStore in project teiid by teiid.

the class VDBRepository method finishDeployment.

public void finishDeployment(String name, String version) {
    VDBKey key = new VDBKey(name, version);
    CompositeVDB v = this.vdbRepo.get(key);
    if (v == null) {
        return;
    }
    VDBMetaData metadataAwareVDB = v.getVDB();
    if (v.getOriginalVDB().getStatus() == Status.FAILED) {
        if (v.getOriginalVDB() != metadataAwareVDB && metadataAwareVDB.getStatus() == Status.LOADING) {
            metadataAwareVDB.setStatus(Status.FAILED);
        }
        return;
    }
    synchronized (metadataAwareVDB) {
        try {
            try {
                v.metadataLoadFinished(allowEnv);
            } catch (MetadataException e) {
                // $NON-NLS-1$
                LogManager.logWarning(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, e.getMessage()));
                if (!metadataAwareVDB.isPreview()) {
                    ValidatorReport report = new ValidatorReport();
                    report.addItem(new ValidatorFailure(e.getMessage()));
                    if (!processMetadataValidatorReport(key, report)) {
                        metadataAwareVDB.setStatus(Status.FAILED);
                        notifyFinished(name, version, v);
                        return;
                    }
                }
            }
            MetadataStore store = metadataAwareVDB.removeAttachment(MetadataStore.class);
            ValidatorReport report = new MetadataValidator(store.getDatatypes(), QueryParser.getQueryParser()).validate(metadataAwareVDB, store);
            if (report.hasItems()) {
                LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, report.getItems().iterator().next()));
                if (!metadataAwareVDB.isPreview() && !processMetadataValidatorReport(key, report)) {
                    metadataAwareVDB.setStatus(Status.FAILED);
                    notifyFinished(name, version, v);
                    return;
                }
            }
            validateDataSources(metadataAwareVDB);
            metadataAwareVDB.setStatus(Status.ACTIVE);
            // for  replication of events, temp tables and mat views
            GlobalTableStore gts = CompositeGlobalTableStore.createInstance(v, this.bufferManager, this.objectReplictor);
            metadataAwareVDB.addAttchment(GlobalTableStore.class, gts);
            if (this.databaseStore != null) {
                metadataAwareVDB.addAttchment(DatabaseStore.class, this.databaseStore);
            }
            notifyFinished(name, version, v);
        } finally {
            if (metadataAwareVDB.getStatus() != Status.ACTIVE && metadataAwareVDB.getStatus() != Status.FAILED) {
                // guard against an unexpected exception - probably bad validation logic
                metadataAwareVDB.setStatus(Status.FAILED);
                notifyFinished(name, version, v);
            }
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FunctionMetadataValidator(org.teiid.query.function.metadata.FunctionMetadataValidator) MetadataValidator(org.teiid.query.metadata.MetadataValidator) MetadataException(org.teiid.metadata.MetadataException) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Aggregations

GlobalTableStore (org.teiid.query.tempdata.GlobalTableStore)8 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)5 MetadataStore (org.teiid.metadata.MetadataStore)2 Schema (org.teiid.metadata.Schema)2 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)2 GlobalTableStoreImpl (org.teiid.query.tempdata.GlobalTableStoreImpl)2 VDBKey (org.teiid.vdb.runtime.VDBKey)2 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)1 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)1 InvalidSessionException (org.teiid.client.security.InvalidSessionException)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 CompositeGlobalTableStore (org.teiid.deployers.CompositeGlobalTableStore)1 CompositeVDB (org.teiid.deployers.CompositeVDB)1 VDBLifeCycleListener (org.teiid.deployers.VDBLifeCycleListener)1 DataModifiable (org.teiid.metadata.AbstractMetadataRecord.DataModifiable)1 Modifiable (org.teiid.metadata.AbstractMetadataRecord.Modifiable)1 MetadataException (org.teiid.metadata.MetadataException)1