Package org.geoserver.test.onlineTest.setup

Source Code of org.geoserver.test.onlineTest.setup.ReferenceDataOracleSetup

/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.test.onlineTest.setup;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;

import org.geoserver.test.onlineTest.support.AbstractReferenceDataSetup;
import org.geoserver.test.onlineTest.support.DatabaseUtil;
import org.geotools.data.oracle.OracleNGDataStoreFactory;
import org.geotools.jdbc.JDBCDataStoreFactory;

/**
* Postgis data setup for the data reference set online test
*
* @author Victor Tey, CSIRO Earth Science and Resource Engineering
*/
public class ReferenceDataOracleSetup extends AbstractReferenceDataSetup {
    private final String versiontbl = "data_version".toUpperCase();

    private InputStream script;

    private final double scriptVersion = 1.0;

    @Override
    protected String typeName(String raw) {
        return raw.toUpperCase();
    }

    @Override
    protected String attributeName(String raw) {
        return raw.toUpperCase();
    }

    public ReferenceDataOracleSetup() throws Exception {
        this.script = this.getClass().getResourceAsStream("/RefDataSet/Oracle_Data_ref_set.sql");
    }

    @Override
    public JDBCDataStoreFactory createDataStoreFactory() {
        return new OracleNGDataStoreFactory();
    }

    @Override
    protected Properties createExampleFixture() {
        Properties fixture = new Properties();
        fixture.put("driver", "oracle.jdbc.driver.OracleDriver");
        fixture.put("url", "jdbc:oracle:thin:@192.168.1.200:1521:xe");
        fixture.put("host", "192.168.1.200");
        fixture.put("port", "1521");
        fixture.put("database", "xe");
        fixture.put("username", "geoserver");
        fixture.put("password", "postgis");
        fixture.put("dbtype", "Oracle");
        return fixture;
    }

    private void runSqlInsertScript() throws Exception {
        DatabaseUtil du = new DatabaseUtil();
        ArrayList<String> sqls = du.splitOracleSQLScript(script);
        for (String sql : sqls) {
            System.out.println(sql);
            if (sql.startsWith("CALL")) {
                String formattedSP = "{" + sql + "}";
                System.out.println(formattedSP);
                this.runOracleStoreProcedure(formattedSP);
                continue;
            }
            this.run(sql);
        }
        this.setDataVersion(this.scriptVersion);

    }

    // these private helper class might be useful in the future. feel free to change its access
    // modifier
    private void setDataVersion(double version) throws Exception {
        this.runOracleStoreProcedure("{CALL DROP_TABLE('" + versiontbl + "')}");
        this.run("CREATE TABLE " + versiontbl + " (" + "NAME VARCHAR2(100 BYTE) NOT NULL, "
                + "VERSION NUMBER(25,2)," + "INSERT_DATE DATE)");
        this.run("insert into " + versiontbl
                + "(name,version,insert_date) values('Data reference set'," + version
                + ",current_timestamp)");

    }

    @Override
    public String getDatabaseID() {
        return "oracle";
    }

    @Override
    public void setUp() throws Exception {
        runSqlInsertScript();
    }

}
TOP

Related Classes of org.geoserver.test.onlineTest.setup.ReferenceDataOracleSetup

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.