All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.teiid.maven.PluginDatabaseStore Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.teiid.maven;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.metadata.Database;
import org.teiid.metadata.Datatype;
import org.teiid.query.metadata.DatabaseStore;
import org.teiid.query.parser.QueryParser;

public class PluginDatabaseStore extends DatabaseStore {
    private List vdbImports = new ArrayList<>();
    private  Map typeMap;
    private  Map> importMap = new HashMap>();

    static class ImportSchema {
        String schemaName;
        String serverType;
        String serverName;
        String foreignSchemaName;
        List includeTables;
        List excludeTables;
        Map properties;
    }


    public PluginDatabaseStore ( Map typeMap) {
        this.typeMap = typeMap;
    }

    public List getVdbImports() {
        return vdbImports;
    }

    @Override
    public Map getRuntimeTypes() {
        return typeMap;
    }

    @Override
    public void importSchema(String schemaName, String serverType, String serverName, String foreignSchemaName,
            List includeTables, List excludeTables, Map properties) {
        ImportSchema is = new ImportSchema();
        is.schemaName = schemaName;
        is.serverType = serverType;
        is.serverName = serverName;
        is.foreignSchemaName = foreignSchemaName;
        is.includeTables = includeTables;
        is.excludeTables = excludeTables;
        is.properties = properties;

        List imports = this.importMap.get(schemaName);
        if (imports == null) {
            imports = new ArrayList();
            this.importMap.put(schemaName, imports);
        }
        imports.add(is);
    }

    public List getImportSchemas(String schema) {
        return this.importMap.get(schema);
    }

    @Override
    public Database getCurrentDatabase() {
        return super.getCurrentDatabase();
    }

    @Override
    public void importDatabase(String dbName, String version, boolean importPolicies) {
        VdbImport vdb = new VdbImport();
        vdb.setDbName(dbName);
        vdb.setVersion(version);
        vdb.setImportPolicies(importPolicies);
        vdbImports.add(vdb);
    }

    public Database parse(File vdbfile) throws IOException {
        String vdbStr = ObjectConverterUtil.convertToString(new FileInputStream(vdbfile));
        StringReader reader = new StringReader(vdbStr);
        try {
            startEditing(false);
            setMode(Mode.ANY);
            QueryParser.getQueryParser().parseDDL(this, reader);
            return getDatabases().get(0);
        } finally {
            reader.close();
            stopEditing();
        }
    }

    public Database db() {
        return getDatabases().get(0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy