Search in sources :

Example 1 with PentahoSystemException

use of org.pentaho.platform.api.engine.PentahoSystemException in project pentaho-platform by pentaho.

the class PentahoSystem method init.

public static boolean init(final IApplicationContext pApplicationContext, final Map listenerMap) {
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "PentahoSystem init called");
    }
    if (PentahoSystem.initializedStatus == PentahoSystem.SYSTEM_INITIALIZED_OK) {
        // tests call init more than once without an intervening shutdown().
        try {
            throw new IllegalStateException("'Init' method was run twice without 'shutdown'");
        } catch (IllegalStateException e) {
            Logger.error(PentahoSystem.class, "PentahoSystem was already initialized when init() called again without a preceding shutdown(). " + "This is likely in error", e);
        }
    }
    PentahoSystem.initializedStatus = PentahoSystem.SYSTEM_INITIALIZED_OK;
    // PDI-3438 Scheduled job fails to open a transformation
    // Kettle jobs spawn threads which may require authentication to load transformations from
    // the kettle repository, by using the INHERITABLETHREADLOCAL strategy, spawned threads will
    // enjoy the same SecurityContext as their parent!
    SecurityContextHolder.setStrategyName(securityContextHolderStrategy);
    PentahoSystem.globalAttributes = Collections.synchronizedMap(new HashMap());
    PentahoSystem.globalParameters = new SimpleParameterProvider(PentahoSystem.globalAttributes);
    PentahoSystem.applicationContext = pApplicationContext;
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Setting property path");
    }
    // $NON-NLS-1$
    System.setProperty("pentaho.solutionpath", "solution:");
    if (LocaleHelper.getLocale() == null) {
        LocaleHelper.setLocale(Locale.getDefault());
    }
    if (PentahoSystem.systemSettingsService != null) {
        if (debug) {
            // $NON-NLS-1$
            Logger.debug(PentahoSystem.class, "Reading ACL list from pentaho.xml");
        }
        // Set Up ACL File Extensions by reading pentaho.xml for acl-files
        // 
        // Read the files that are permitted to have ACLs on them from
        // the pentaho.xml.
        // 
        // $NON-NLS-1$ //$NON-NLS-2$
        String aclFiles = PentahoSystem.getSystemSetting("acl-files", "xaction,url");
        // $NON-NLS-1$
        StringTokenizer st = new StringTokenizer(aclFiles, ",");
        String extn;
        while (st.hasMoreElements()) {
            extn = st.nextToken();
            if (!extn.startsWith(".")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                extn = "." + extn;
            }
            PentahoSystem.ACLFileExtensionList.add(extn);
        }
    }
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Set Java System Properties");
    }
    PentahoSystem.setSystemProperties();
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Initialize XML Factories");
    }
    PentahoSystem.initXMLFactories();
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Set Logging Level from pentaho.xml setting");
    }
    PentahoSystem.loggingLevel = ILogger.ERROR;
    if (PentahoSystem.systemSettingsService != null) {
        PentahoSystem.loggingLevel = // $NON-NLS-1$//$NON-NLS-2$
        Logger.getLogLevel(PentahoSystem.systemSettingsService.getSystemSetting("log-level", "ERROR"));
    }
    Logger.setLogLevel(PentahoSystem.loggingLevel);
    // to guarantee hostnames in SSL mode are not being spoofed
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Register host name verifier");
    }
    PentahoSystem.registerHostnameVerifier();
    // $NON-NLS-1$
    assert null != aggObjectFactory : "aggObjectFactory must be non-null";
    try {
        if (debug) {
            // $NON-NLS-1$
            Logger.debug(PentahoSystem.class, "Validating object factory");
        }
        PentahoSystem.validateObjectFactory();
    } catch (PentahoSystemException e1) {
        // this is fatal
        throw new RuntimeException(e1);
    }
    // store a list of the system listeners
    try {
        if (debug) {
            // $NON-NLS-1$
            Logger.debug(PentahoSystem.class, "Start System Listeners");
        }
        PentahoSystem.notifySystemListenersOfStartup();
    } catch (PentahoSystemException e) {
        String msg = e.getLocalizedMessage();
        Logger.error(PentahoSystem.class.getName(), msg, e);
        PentahoSystem.initializedStatus |= PentahoSystem.SYSTEM_LISTENERS_FAILED;
        PentahoSystem.addInitializationFailureMessage(PentahoSystem.SYSTEM_LISTENERS_FAILED, msg);
        return false;
    }
    // once everything else is initialized, start global actions
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "Global startup");
    }
    PentahoSystem.globalStartup();
    if (debug) {
        // $NON-NLS-1$
        Logger.debug(PentahoSystem.class, "PentahoSystem Init Complete");
    }
    return true;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) PentahoSystemException(org.pentaho.platform.api.engine.PentahoSystemException) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 2 with PentahoSystemException

use of org.pentaho.platform.api.engine.PentahoSystemException in project pentaho-platform by pentaho.

the class PentahoSystemExceptionTest method testPentahoSystemException3.

public void testPentahoSystemException3() {
    // info("Expected: A Hitachi Vantara System Exception will be created with Throwable as a parameter"); //$NON-NLS-1$
    // $NON-NLS-1$
    PentahoSystemException pse2 = new PentahoSystemException(new Throwable("This is a throwable exception"));
    // $NON-NLS-1$
    System.out.println("PentahoSystemException" + pse2);
    Assert.assertTrue(true);
}
Also used : PentahoSystemException(org.pentaho.platform.api.engine.PentahoSystemException)

Example 3 with PentahoSystemException

use of org.pentaho.platform.api.engine.PentahoSystemException in project pentaho-platform by pentaho.

the class PentahoSystemExceptionTest method testPentahoSystemException4.

public void testPentahoSystemException4() {
    // info("Expected: Exception will be caught and thrown as a Hitachi Vantara System Exception"); //$NON-NLS-1$
    PentahoSystemException pse3 = // $NON-NLS-1$
    new PentahoSystemException("A test Pentaho System Exception has been thrown", new Throwable());
    // $NON-NLS-1$
    System.out.println("PentahoSystemException :" + pse3);
    Assert.assertTrue(true);
}
Also used : PentahoSystemException(org.pentaho.platform.api.engine.PentahoSystemException)

Example 4 with PentahoSystemException

use of org.pentaho.platform.api.engine.PentahoSystemException in project pentaho-platform by pentaho.

the class SQLConnection method executeQuery.

/**
 * Executes the specified query with the defined parameters
 *
 * @param query
 *          the query to be executed
 * @param scrollType
 * @param concur
 * @return the result set of data for the query
 * @throws SQLException
 *           indicates an error running the query
 * @throws InterruptedException
 *           indicates the query took longer than allowable by the query timeout
 * @throws PentahoSystemException
 */
public IPentahoResultSet executeQuery(final String query, final int scrollType, final int concur) throws SQLException, InterruptedException, PentahoSystemException {
    if (this.getReadOnly()) {
        try {
            nativeConnection.setReadOnly(true);
        } catch (Exception ignored) {
        // ignored
        }
    }
    // Create a statement for a scrollable resultset.
    Statement stmt = null;
    ResultSet resultSet = null;
    try {
        stmt = nativeConnection.createStatement(scrollType, concur);
        stmts.add(stmt);
        enhanceStatement(stmt);
        setStatementLimitations(stmt);
        if (logger != null && logger.getLoggingLevel() == ILogger.DEBUG) {
            // $NON-NLS-1$
            logger.debug("SQLConnection.executeQuery:" + query);
        }
        resultSet = stmt.executeQuery(query);
    } catch (Exception e) {
        // on this connection, then try to fix it up...
        if ((scrollType == ResultSet.TYPE_SCROLL_INSENSITIVE) && (isFallBackToNonscrollableOnError())) {
            // FORCE forward only
            stmt = nativeConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, concur);
            stmts.add(stmt);
            enhanceStatement(stmt);
            setStatementLimitations(stmt);
            if (logger != null && logger.getLoggingLevel() == ILogger.DEBUG) {
                // $NON-NLS-1$
                logger.debug("SQLConnection.executeQuery(e):" + query);
            }
            resultSet = stmt.executeQuery(query);
            setForcedForwardOnly(true);
        }
    }
    sqlResultSet = new SQLResultSet(resultSet, this);
    // add to list of resultsets for cleanup later.
    resultSets.add(sqlResultSet);
    lastQuery = query;
    return sqlResultSet;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) SQLException(java.sql.SQLException) PentahoSystemException(org.pentaho.platform.api.engine.PentahoSystemException)

Example 5 with PentahoSystemException

use of org.pentaho.platform.api.engine.PentahoSystemException in project pentaho-platform by pentaho.

the class PentahoSystemExceptionTest method testPentahoSystemException1.

public void testPentahoSystemException1() {
    // info("Expected: Exception will be caught and thrown as a Hitachi Vantara System Exception"); //$NON-NLS-1$
    PentahoSystemException pse = new PentahoSystemException();
    // $NON-NLS-1$
    System.out.println("PentahoSystemException :" + pse);
    Assert.assertTrue(true);
}
Also used : PentahoSystemException(org.pentaho.platform.api.engine.PentahoSystemException)

Aggregations

PentahoSystemException (org.pentaho.platform.api.engine.PentahoSystemException)6 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)1 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)1