Search in sources :

Example 6 with Datatype

use of org.teiid.metadata.Datatype in project teiid by teiid.

the class AbstractVDBDeployer method createMetadataFactory.

protected MetadataFactory createMetadataFactory(VDBMetaData vdb, MetadataStore store, ModelMetaData model, Map<String, ? extends VDBResource> vdbResources) {
    Map<String, Datatype> datatypes = store.getDatatypes();
    MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), datatypes, model);
    factory.getSchema().setPhysical(model.isSource());
    // for thread safety each factory gets it's own instance.
    factory.setParser(new QueryParser());
    factory.setVdbResources(vdbResources);
    return factory;
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) MetadataFactory(org.teiid.metadata.MetadataFactory) Datatype(org.teiid.metadata.Datatype)

Example 7 with Datatype

use of org.teiid.metadata.Datatype in project teiid by teiid.

the class TestTransformationMetadata method testAmbiguousTableWithPrivateModel.

@Test
public void testAmbiguousTableWithPrivateModel() throws Exception {
    Map<String, Datatype> datatypes = new HashMap<String, Datatype>();
    Datatype dt = new Datatype();
    dt.setName(DataTypeManager.DefaultDataTypes.STRING);
    dt.setJavaClassName(String.class.getCanonicalName());
    datatypes.put(DataTypeManager.DefaultDataTypes.STRING, dt);
    // $NON-NLS-1$
    MetadataFactory mf = new MetadataFactory(null, 1, "x", datatypes, new Properties(), null);
    // $NON-NLS-1$
    mf.addTable("y");
    // $NON-NLS-1$
    MetadataFactory mf1 = new MetadataFactory(null, 1, "x1", datatypes, new Properties(), null);
    // $NON-NLS-1$
    mf1.addTable("y");
    CompositeMetadataStore cms = new CompositeMetadataStore(Arrays.asList(mf.asMetadataStore(), mf1.asMetadataStore()));
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("foo");
    vdb.setVersion(1);
    ModelMetaData model = new ModelMetaData();
    model.setName("x1");
    vdb.addModel(model);
    ModelMetaData model2 = new ModelMetaData();
    model2.setName("x");
    model2.setVisible(true);
    vdb.addModel(model2);
    TransformationMetadata tm = new TransformationMetadata(vdb, cms, null, RealMetadataFactory.SFM.getSystemFunctions(), null);
    // $NON-NLS-1$
    Collection result = tm.getGroupsForPartialName("y");
    assertEquals(2, result.size());
    RealMetadataFactory.buildWorkContext(tm, vdb);
    model.setVisible(false);
    tm = new TransformationMetadata(vdb, cms, null, RealMetadataFactory.SFM.getSystemFunctions(), null);
    // $NON-NLS-1$
    result = tm.getGroupsForPartialName("y");
    assertEquals(1, result.size());
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) HashMap(java.util.HashMap) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Collection(java.util.Collection) Properties(java.util.Properties) Datatype(org.teiid.metadata.Datatype) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 8 with Datatype

use of org.teiid.metadata.Datatype in project teiid by teiid.

the class TestTransformationMetadata method exampleTransformationMetadata.

private TransformationMetadata exampleTransformationMetadata() throws TranslatorException {
    Map<String, Datatype> datatypes = new HashMap<String, Datatype>();
    Datatype dt = new Datatype();
    dt.setName(DataTypeManager.DefaultDataTypes.STRING);
    dt.setJavaClassName(String.class.getCanonicalName());
    datatypes.put(DataTypeManager.DefaultDataTypes.STRING, dt);
    // $NON-NLS-1$
    MetadataFactory mf = new MetadataFactory(null, 1, "x", datatypes, new Properties(), null);
    // $NON-NLS-1$
    mf.addProcedure("y");
    Table t = mf.addTable("foo");
    mf.addColumn("col", DataTypeManager.DefaultDataTypes.STRING, t);
    // $NON-NLS-1$
    MetadataFactory mf1 = new MetadataFactory(null, 1, "x1", datatypes, new Properties(), null);
    // $NON-NLS-1$
    mf1.addProcedure("y");
    Table table = mf1.addTable("doc");
    table.setSchemaPaths(Arrays.asList("../../x.xsd"));
    table.setResourcePath("/a/b/doc.xmi");
    HashMap<String, VDBResources.Resource> resources = new HashMap<String, VDBResources.Resource>();
    resources.put("/x.xsd", new VDBResources.Resource(VFS.getRootVirtualFile()));
    CompositeMetadataStore cms = new CompositeMetadataStore(Arrays.asList(mf.asMetadataStore(), mf1.asMetadataStore()));
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("vdb");
    vdb.setVersion(1);
    vdb.addModel(buildModel("x"));
    vdb.addModel(buildModel("x1"));
    vdb.addModel(buildModel("y"));
    return new TransformationMetadata(vdb, cms, resources, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
Also used : Table(org.teiid.metadata.Table) HashMap(java.util.HashMap) Properties(java.util.Properties) Datatype(org.teiid.metadata.Datatype) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData)

Example 9 with Datatype

use of org.teiid.metadata.Datatype in project teiid by teiid.

the class TestTransformationMetadata method testTypeCorrection.

@Test
public void testTypeCorrection() throws Exception {
    // $NON-NLS-1$
    MetadataFactory mf = new MetadataFactory(null, 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    // $NON-NLS-1$
    Table t = mf.addTable("y");
    mf.addColumn("test", "string", t);
    mf.addColumn("array", "string[]", t);
    Datatype unknown = new Datatype();
    unknown.setName("unknown");
    Column col = mf.addColumn("arg", "string", t);
    col.setDatatype(unknown, false, 0);
    MetadataFactory mf1 = UnitTestUtil.helpSerialize(mf);
    Column column = mf1.getSchema().getTable("y").getColumns().get(0);
    Datatype dt = column.getDatatype();
    assertNotSame(mf.getDataTypes().get(dt.getName()), column.getDatatype());
    assertEquals(1, mf1.getSchema().getTable("y").getColumns().get(1).getArrayDimensions());
    mf1.correctDatatypes(mf.getDataTypes());
    assertSame(mf.getDataTypes().get(dt.getName()), column.getDatatype());
    assertEquals(1, mf1.getSchema().getTable("y").getColumns().get(1).getArrayDimensions());
}
Also used : Table(org.teiid.metadata.Table) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Properties(java.util.Properties) Datatype(org.teiid.metadata.Datatype) Test(org.junit.Test)

Example 10 with Datatype

use of org.teiid.metadata.Datatype in project teiid by teiid.

the class VDBService method loadMetadata.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void loadMetadata(final VDBMetaData vdb, final ModelMetaData model, final ConnectorManagerRepository cmr, final MetadataRepository metadataRepo, final MetadataStore vdbMetadataStore, final AtomicInteger loadCount, final VDBResources vdbResources) {
    String msg = IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50029, vdb.getName(), vdb.getVersion(), model.getName(), SimpleDateFormat.getInstance().format(new Date()));
    model.setMetadataStatus(Model.MetadataStatus.LOADING);
    model.addRuntimeMessage(Severity.INFO, msg);
    LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
    final Runnable job = new Runnable() {

        @Override
        public void run() {
            boolean cached = false;
            Exception ex = null;
            TranslatorException te = null;
            // if this is not the first time trying to load metadata
            if (model.getMetadataStatus() != Model.MetadataStatus.LOADING) {
                model.setMetadataStatus(Model.MetadataStatus.RETRYING);
            }
            // designer based models define data types based on their built in data types, which are system vdb data types
            Map<String, Datatype> datatypes = vdbMetadataStore.getDatatypes();
            final File cachedFile = getSerializer().buildModelFile(vdb, model.getName());
            MetadataFactory factory = getSerializer().loadSafe(cachedFile, MetadataFactory.class);
            if (factory != null) {
                factory.correctDatatypes(datatypes);
                cached = true;
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                LogManager.logDetail(LogConstants.CTX_RUNTIME, "Model ", model.getName(), "in VDB ", vdb.getName(), " was loaded from cached metadata");
            } else {
                factory = createMetadataFactory(vdb, vdbMetadataStore, model, vdbResources.getEntriesPlusVisibilities());
                ExecutionFactory ef = null;
                Object cf = null;
                for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
                    if (ex != null) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_RUNTIME, ex, "Failed to get metadata, trying next source.");
                        ex = null;
                        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.");
                        te = e;
                    }
                    ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
                    try {
                        LogManager.logDetail(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50104, vdb.getName(), vdb.getVersion(), model.getName(), cm != null ? cm.getTranslatorName() : null, cm != null ? cm.getConnectionName() : null));
                        Thread.currentThread().setContextClassLoader(metadataRepo.getClass().getClassLoader());
                        metadataRepo.loadMetadata(factory, ef, cf);
                        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50030, vdb.getName(), vdb.getVersion(), model.getName(), SimpleDateFormat.getInstance().format(new Date())));
                        break;
                    } catch (Exception e) {
                        factory = createMetadataFactory(vdb, vdbMetadataStore, model, vdbResources.getEntriesPlusVisibilities());
                        ex = e;
                    } finally {
                        Thread.currentThread().setContextClassLoader(originalCL);
                    }
                }
            }
            synchronized (vdb) {
                VDBStatusChecker marked = model.removeAttachment(VDBStatusChecker.class);
                if (ex == null) {
                    if (!cached) {
                        // cache the schema to disk
                        cacheMetadataStore(model, factory);
                    }
                    metadataLoaded(vdb, model, vdbMetadataStore, loadCount, factory, true, cmr, vdbResources);
                } else {
                    String errorMsg = ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage();
                    if (te != null) {
                        // $NON-NLS-1$
                        errorMsg += ": " + te.getMessage();
                    }
                    model.addRuntimeError(errorMsg);
                    model.setMetadataStatus(Model.MetadataStatus.FAILED);
                    LogManager.logWarning(LogConstants.CTX_RUNTIME, ex, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50036, vdb.getName(), vdb.getVersion(), model.getName(), errorMsg));
                    if (ex instanceof RuntimeException) {
                        metadataLoaded(vdb, model, vdbMetadataStore, loadCount, factory, false, cmr, vdbResources);
                    } else {
                        if (marked != null) {
                            getExecutor().execute(this);
                        } else {
                            // defer the load to the status checker if/when a source is available/redeployed
                            model.addAttchment(Runnable.class, this);
                        }
                    }
                }
            }
        }
    };
    Executor executor = getExecutor();
    // wrap the runnable to trap exceptions that may be caused by an asynch deployment issue
    executor.execute(new Runnable() {

        @Override
        public void run() {
            try {
                job.run();
            } catch (IllegalStateException e) {
                if (vdb.getStatus() != Status.FAILED && vdb.getStatus() != Status.REMOVED) {
                    throw e;
                }
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Could not load metadata for a removed or failed deployment.");
            }
        }
    });
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) VDBStatusChecker(org.teiid.deployers.VDBStatusChecker) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) Date(java.util.Date) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) XMLStreamException(javax.xml.stream.XMLStreamException) OperationFailedException(org.jboss.as.controller.OperationFailedException) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) StartException(org.jboss.msc.service.StartException) IOException(java.io.IOException) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) Datatype(org.teiid.metadata.Datatype) Executor(java.util.concurrent.Executor) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslatorException(org.teiid.translator.TranslatorException) File(java.io.File)

Aggregations

Datatype (org.teiid.metadata.Datatype)10 MetadataFactory (org.teiid.metadata.MetadataFactory)5 Column (org.teiid.metadata.Column)4 Properties (java.util.Properties)3 Test (org.junit.Test)3 Table (org.teiid.metadata.Table)3 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)3 HashMap (java.util.HashMap)2 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)2 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 TranslatorException (org.teiid.translator.TranslatorException)2 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 StringTokenizer (java.util.StringTokenizer)1 Executor (java.util.concurrent.Executor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1