<commit_before>/**
 *  Copyright (C) 2004 Orbeon, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU Lesser General Public License as published by the Free Software Foundation; either version
 *  2.1 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Lesser General Public License for more details.
 *
 *  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */
package org.orbeon.oxf.processor.tamino;

import com.softwareag.tamino.db.api.accessor.TAccessLocation;
import com.softwareag.tamino.db.api.connection.*;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.orbeon.oxf.common.OXFException;
import org.orbeon.oxf.pipeline.api.PipelineContext;
import org.orbeon.oxf.processor.ProcessorImpl;
import org.orbeon.oxf.util.LoggerFactory;
import org.orbeon.oxf.xml.XPathUtils;
import org.orbeon.oxf.resources.OXFProperties;

import java.util.Map;
import java.util.HashMap;

public abstract class TaminoProcessor extends ProcessorImpl {

    private static final Logger logger = LoggerFactory.createLogger(TaminoProcessor.class);
    private static final Map ISOLATION_DEGREE_VALUES = new HashMap();
    private static final Map LOCK_MODE_VALUES = new HashMap();
	private static final Map LOCK_WAIT_VALUES = new HashMap();
    private static final String ISOLATION_DEGREE_PROPERTY = "oxf.tamino.isolation-degree";
    private static final String LOCK_MODE_PROPERTY = "oxf.tamino.lock-mode";
	private static final String LOCK_WAIT_PROPERTY = "oxf.tamino.lock-wait";

    public static final String TAMINO_CONFIG_URI = "http://www.orbeon.org/oxf/tamino-config";
    public static final String TAMINO_QUERY_URI = "http://www.orbeon.org/oxf/tamino-query";

    public static final String URL_PROPERTY = "url";
    public static final String USERNAME_PROPERTY = "username";
    public static final String PASSWORD_PROPERTY = "password";

    protected static final String TAMINO_CONNECTION = TaminoProcessor.class.getName() + "_connection_";

    static {
        ISOLATION_DEGREE_VALUES.put("committedCommand", TIsolationDegree.COMMITTED_COMMAND);
        ISOLATION_DEGREE_VALUES.put("serializable", TIsolationDegree.SERIALIZABLE);
        ISOLATION_DEGREE_VALUES.put("stableCursor", TIsolationDegree.STABLE_CURSOR);
        ISOLATION_DEGREE_VALUES.put("stableDocument", TIsolationDegree.STABLE_DOCUMENT);
        ISOLATION_DEGREE_VALUES.put("uncommittedDocument", TIsolationDegree.UNCOMMITTED_DOCUMENT);
        LOCK_MODE_VALUES.put("protected", TLockMode.PROTECTED);
        LOCK_MODE_VALUES.put("shared", TLockMode.SHARED);
        LOCK_MODE_VALUES.put("unprotected", TLockMode.UNPROTECTED);
		LOCK_WAIT_VALUES.put("yes", TLockwaitMode.YES);
		LOCK_WAIT_VALUES.put("no", TLockwaitMode.NO);
    }

    protected Config readConfig(Document doc) {
        Config config = new Config();

        // Try local configuration first
        String url = XPathUtils.selectStringValueNormalize(doc, "/config/url");
        String username = XPathUtils.selectStringValueNormalize(doc, "/config/username");
        String password = XPathUtils.selectStringValueNormalize(doc, "/config/password");
		String isolationDegree = XPathUtils.selectStringValueNormalize(doc, "/config/isolation-degree");
		String lockMode = XPathUtils.selectStringValueNormalize(doc, "/config/lock-mode");
		String lockWait = XPathUtils.selectStringValueNormalize(doc, "/config/lock-wait");

        // Override with properties if needed
        config.setUrl(url != null ? url : getPropertySet().getString(URL_PROPERTY));
        config.setUsername(username != null ? username : getPropertySet().getString(USERNAME_PROPERTY));
        config.setPassword(password != null ? password : getPropertySet().getString(PASSWORD_PROPERTY));
		// Set isolation and locking properties, override from global if set
		OXFProperties.PropertySet propertySet = getPropertySet();
        config.setIsolationDegree(isolationDegree != null ? isolationDegree : propertySet.getString(ISOLATION_DEGREE_PROPERTY));
		config.setLockMode(lockMode != null ? lockMode : propertySet.getString(LOCK_MODE_PROPERTY));
		config.setLockWait(lockWait != null ? lockWait : propertySet.getString(LOCK_WAIT_PROPERTY));

        config.setCollection(TAccessLocation.newInstance(XPathUtils.selectStringValueNormalize(doc, "/config/collection")));

        return config;
    }

    protected TConnection getConnection(PipelineContext context, Config config) {
        String attributeName = TAMINO_CONNECTION + config.getUrl() + config.getUsername();<commit_msg>Fix: get properties for isolation level etc from right place<commit_after>/**
 *  Copyright (C) 2004 Orbeon, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU Lesser General Public License as published by the Free Software Foundation; either version
 *  2.1 of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Lesser General Public License for more details.
 *
 *  The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */
package org.orbeon.oxf.processor.tamino;

import com.softwareag.tamino.db.api.accessor.TAccessLocation;
import com.softwareag.tamino.db.api.connection.*;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.orbeon.oxf.common.OXFException;
import org.orbeon.oxf.pipeline.api.PipelineContext;
import org.orbeon.oxf.processor.ProcessorImpl;
import org.orbeon.oxf.util.LoggerFactory;
import org.orbeon.oxf.xml.XPathUtils;

import java.util.HashMap;
import java.util.Map;

public abstract class TaminoProcessor extends ProcessorImpl {

    private static final Logger logger = LoggerFactory.createLogger(TaminoProcessor.class);
    private static final Map ISOLATION_DEGREE_VALUES = new HashMap();
    private static final Map LOCK_MODE_VALUES = new HashMap();
	private static final Map LOCK_WAIT_VALUES = new HashMap();
    private static final String ISOLATION_DEGREE_PROPERTY = "oxf.tamino.isolation-degree";
    private static final String LOCK_MODE_PROPERTY = "oxf.tamino.lock-mode";
	private static final String LOCK_WAIT_PROPERTY = "oxf.tamino.lock-wait";

    public static final String TAMINO_CONFIG_URI = "http://www.orbeon.org/oxf/tamino-config";
    public static final String TAMINO_QUERY_URI = "http://www.orbeon.org/oxf/tamino-query";

    public static final String URL_PROPERTY = "url";
    public static final String USERNAME_PROPERTY = "username";
    public static final String PASSWORD_PROPERTY = "password";

    protected static final String TAMINO_CONNECTION = TaminoProcessor.class.getName() + "_connection_";

    static {
        ISOLATION_DEGREE_VALUES.put("committedCommand", TIsolationDegree.COMMITTED_COMMAND);
        ISOLATION_DEGREE_VALUES.put("serializable", TIsolationDegree.SERIALIZABLE);
        ISOLATION_DEGREE_VALUES.put("stableCursor", TIsolationDegree.STABLE_CURSOR);
        ISOLATION_DEGREE_VALUES.put("stableDocument", TIsolationDegree.STABLE_DOCUMENT);
        ISOLATION_DEGREE_VALUES.put("uncommittedDocument", TIsolationDegree.UNCOMMITTED_DOCUMENT);
        LOCK_MODE_VALUES.put("protected", TLockMode.PROTECTED);
        LOCK_MODE_VALUES.put("shared", TLockMode.SHARED);
        LOCK_MODE_VALUES.put("unprotected", TLockMode.UNPROTECTED);
		LOCK_WAIT_VALUES.put("yes", TLockwaitMode.YES);
		LOCK_WAIT_VALUES.put("no", TLockwaitMode.NO);
    }

    protected Config readConfig(Document doc) {
        Config config = new Config();

        // Try local configuration first
        String url = XPathUtils.selectStringValueNormalize(doc, "/config/url");
        String username = XPathUtils.selectStringValueNormalize(doc, "/config/username");
        String password = XPathUtils.selectStringValueNormalize(doc, "/config/password");
		String isolationDegree = XPathUtils.selectStringValueNormalize(doc, "/config/isolation-degree");
		String lockMode = XPathUtils.selectStringValueNormalize(doc, "/config/lock-mode");
		String lockWait = XPathUtils.selectStringValueNormalize(doc, "/config/lock-wait");

        // Override with properties if needed
        config.setUrl(url != null ? url : getPropertySet().getString(URL_PROPERTY));
        config.setUsername(username != null ? username : getPropertySet().getString(USERNAME_PROPERTY));
        config.setPassword(password != null ? password : getPropertySet().getString(PASSWORD_PROPERTY));
		// Set isolation and locking properties, override from global if set
        config.setIsolationDegree(isolationDegree != null ? isolationDegree : getPropertySet().getString(ISOLATION_DEGREE_PROPERTY));
		config.setLockMode(lockMode != null ? lockMode : getPropertySet().getString(LOCK_MODE_PROPERTY));
		config.setLockWait(lockWait != null ? lockWait : getPropertySet().getString(LOCK_WAIT_PROPERTY));

        config.setCollection(TAccessLocation.newInstance(XPathUtils.selectStringValueNormalize(doc, "/config/collection")));

        return config;
    }

    protected TConnection getConnection(PipelineContext context, Config config) {
        String attributeName = TAMINO_CONNECTION + config.getUrl() + config.getUsername();
{'fraction_non_alphanumeric': 0.09550151341196117, 'fraction_numerical': 0.0016699718192255506, 'mean_word_length': 4.761876127480457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 2}, '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': '4262890', 'n_tokens_mistral': 2861, 'n_tokens_neox': 2769, 'n_words': 653}