<commit_before>/*
 * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * 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.wso2.ei.businessprocess.utils.processcleanup;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

/**
 * Class used to trigger the relevant SQL query according to the DB type
 */
public class DBQuery {
	private static final Log log = LogFactory.getLog(DBQuery.class);

	private String ODE_PARTNER_LINK;
	private String ODE_SCOPE;
	private String ODE_EVENT;
	private String ODE_CORSET_PROP;
	private String ODE_CORRELATION_SET;
	private String ODE_XML_DATA_PROP;
	private String ODE_XML_DATA;
	private String ODE_MEX_PROP;
	private String ODE_MESSAGE;
	private String ODE_MESSAGE_EXCHANGE;
	private String ODE_MESSAGE_ROUTE;
	private String GET_INSTANCES_IDS;
	private String SEARCH;
	private String ODE_PROCESS;
	private String ODE_PROCESS_INSTANCE;
	private String STORE_DU;
	private String STORE_PROCESS;

	DBQuery(String databaseURL, String bpsHome) {
		Properties prop = new Properties();

		try {
			String configPath = bpsHome + File.separator + CleanupConstants.CONF +
								File.separator + CleanupConstants.CLEANUP_PROPERTIES;
			prop.load(new FileInputStream(configPath));
		} catch (IOException e) {
			log.error("Configuration path error.", e);
			System.exit(1);
		}

		//for mysql, oracle and sqlserver the query is same
		if (databaseURL.contains(CleanupConstants.MY_SQL) ||
		    databaseURL.contains(CleanupConstants.ORACLE) ||
		    databaseURL.contains(CleanupConstants.SQL_SERVER) ||
		    databaseURL.contains(CleanupConstants.POSTGRE_SQL)) {

			SEARCH = "select distinct(s.PID) as PROCESS_ID, " +
			         "case when o.ID is null then \"-1\" else o.ID end as ID" +
			         ", s.VERSION, s.DU\n" +
			         "from STORE_PROCESS s left join ODE_PROCESS o\n" +
			         "on s.PID = o.PROCESS_ID\n" +
			         "where s.STATE != \"ACTIVE\" {0}\n" +
			         "and s.DU not in \n" +<commit_msg>Fix oracle issue of running cleanup db script<commit_after>/*
 * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * 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.wso2.ei.businessprocess.utils.processcleanup;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

/**
 * Class used to trigger the relevant SQL query according to the DB type
 */
public class DBQuery {
	private static final Log log = LogFactory.getLog(DBQuery.class);

	private String ODE_PARTNER_LINK;
	private String ODE_SCOPE;
	private String ODE_EVENT;
	private String ODE_CORSET_PROP;
	private String ODE_CORRELATION_SET;
	private String ODE_XML_DATA_PROP;
	private String ODE_XML_DATA;
	private String ODE_MEX_PROP;
	private String ODE_MESSAGE;
	private String ODE_MESSAGE_EXCHANGE;
	private String ODE_MESSAGE_ROUTE;
	private String GET_INSTANCES_IDS;
	private String SEARCH;
	private String ODE_PROCESS;
	private String ODE_PROCESS_INSTANCE;
	private String STORE_DU;
	private String STORE_PROCESS;

	DBQuery(String databaseURL, String bpsHome) {
		Properties prop = new Properties();

		try {
			String configPath = bpsHome + File.separator + CleanupConstants.CONF +
								File.separator + CleanupConstants.CLEANUP_PROPERTIES;
			prop.load(new FileInputStream(configPath));
		} catch (IOException e) {
			log.error("Configuration path error.", e);
			System.exit(1);
		}

		//for mysql, oracle and sqlserver the query is same
		if (databaseURL.contains(CleanupConstants.MY_SQL) ||
		    databaseURL.contains(CleanupConstants.ORACLE) ||
		    databaseURL.contains(CleanupConstants.SQL_SERVER) ||
		    databaseURL.contains(CleanupConstants.POSTGRE_SQL)) {

			SEARCH = "select distinct(s.PID) as PROCESS_ID, " +
			         "case when o.ID is null then -1 else o.ID end as ID" +
			         ", s.VERSION, s.DU\n" +
			         "from STORE_PROCESS s left join ODE_PROCESS o\n" +
			         "on s.PID = o.PROCESS_ID\n" +
			         "where s.STATE != \"ACTIVE\" {0}\n" +
			         "and s.DU not in \n" +
{'fraction_non_alphanumeric': 0.08918617614269789, 'fraction_numerical': 0.005202526941657376, 'mean_word_length': 3.80625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6208938', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1627, 'n_words': 517}