Example usage for java.sql Connection TRANSACTION_REPEATABLE_READ

List of usage examples for java.sql Connection TRANSACTION_REPEATABLE_READ

Introduction

In this page you can find the example usage for java.sql Connection TRANSACTION_REPEATABLE_READ.

Prototype

int TRANSACTION_REPEATABLE_READ

To view the source code for java.sql Connection TRANSACTION_REPEATABLE_READ.

Click Source Link

Document

A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.

Usage

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java

public boolean connect(String username, String password) {
    final String S_ProcName = "connect-userpw";
    if (cnx != null) {
        return (false);
    }//from ww  w . j  a  v a 2  s .  c om
    if ((username == null) || (username.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "username");
    }
    if (password == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "password");
    }

    if (configuration != null) {
        try {
            Class.forName("com.sybase.jdbc4.jdbc.SybDriver");
        } catch (ClassNotFoundException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect",
                    "Could not load Sybase ASE 15.7 driver", e);
        }
        String dbServer = configuration.getDbServer();
        int dbPort = configuration.getDbPort();
        String dbDatabase = configuration.getDbDatabase();
        String dbUserName = username;
        String dbPassword = password;
        String url = "jdbc:sybase:Tds:" + dbServer + ":" + Integer.toString(dbPort);
        Properties props = new Properties();
        props.setProperty("user", dbUserName);
        props.setProperty("password", dbPassword);
        try {
            cnx = DriverManager.getConnection(url, props);
            cnx.setAutoCommit(false);
            cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            cnx.rollback();
            setDbSchemaName(dbDatabase);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<connect>>", e);
        }
        Statement stmtUseDatabase = null;
        try {
            stmtUseDatabase = cnx.createStatement();
            stmtUseDatabase.executeUpdate("use " + dbDatabase);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<useDatabase>>",
                    e);
        } finally {
            if (stmtUseDatabase != null) {
                try {
                    stmtUseDatabase.close();
                } catch (SQLException e) {
                }
                stmtUseDatabase = null;
            }
        }
        Statement stmtSetChainedOff = null;
        try {
            stmtSetChainedOff = cnx.createStatement();
            stmtSetChainedOff.executeUpdate("set chained off");
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(),
                    S_ProcName + "<<setChainedOff>>", e);
        } finally {
            if (stmtSetChainedOff != null) {
                try {
                    stmtSetChainedOff.close();
                } catch (SQLException e) {
                }
                stmtSetChainedOff = null;
            }
        }
        return (true);
    }
    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
            "configurationFile not found, do not know how to connect to database");
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlSchema.java

public boolean connect(String username, String password) {
    final String S_ProcName = "connect";
    if (cnx != null) {
        return (false);
    }/*  w ww. j  ava 2s.c om*/
    if ((username == null) || (username.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "username");
    }
    if (password == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "password");
    }

    if (configuration != null) {
        String dbServer = configuration.getDbServer();
        int dbPort = configuration.getDbPort();
        String dbDatabase = configuration.getDbDatabase();
        String dbUserName = username;
        String dbPassword = password;
        String url = "jdbc:postgresql://" + dbServer + ":" + Integer.toString(dbPort) + "/" + dbDatabase;
        Properties props = new Properties();
        props.setProperty("user", dbUserName);
        props.setProperty("password", dbPassword);
        try {
            cnx = DriverManager.getConnection(url, props);
            cnx.setAutoCommit(false);
            cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            cnx.rollback();
            setSchemaDbName(dbDatabase);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        return (true);
    }
    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
            "configurationFile not found, do not know how to connect to database");
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public boolean connect(String username, String password) {
    final String S_ProcName = "connect-userpw";
    if (cnx != null) {
        return (false);
    }//from w w  w .  j  a va  2 s  . c  o  m
    if ((username == null) || (username.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "username");
    }
    if (password == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "password");
    }

    if (configuration != null) {
        try {
            Class.forName("com.ibm.db2.jcc.DB2Driver");
        } catch (ClassNotFoundException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect",
                    "Could not load IBM DB/2 LUW 10.5 driver", e);
        }
        String dbServer = configuration.getDbServer();
        int dbPort = configuration.getDbPort();
        String dbDatabase = configuration.getDbDatabase();
        String dbUserName = username;
        String dbPassword = password;
        String url = "jdbc:db2://" + dbServer + ":" + Integer.toString(dbPort) + "/" + dbDatabase;
        Properties props = new Properties();
        props.setProperty("user", dbUserName);
        props.setProperty("password", dbPassword);
        try {
            cnx = DriverManager.getConnection(url, props);
            cnx.setAutoCommit(false);
            cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            cnx.rollback();
            setSchemaDbName(dbDatabase);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        return (true);
    }
    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
            "configurationFile not found, do not know how to connect to database");
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlSchema.java

public boolean connect(String username, String password) {
    final String S_ProcName = "connect-userpw";
    if (cnx != null) {
        return (false);
    }/*  w ww .  j av  a2  s.  co  m*/
    if ((username == null) || (username.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "username");
    }
    if (password == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "password");
    }

    if (configuration != null) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect",
                    "Could not load MySql 5.5 JDBC driver", e);
        }
        String dbServer = configuration.getDbServer();
        int dbPort = configuration.getDbPort();
        String dbDatabase = configuration.getDbDatabase();
        String dbUserName = username;
        String dbPassword = password;
        String url = "jdbc:mysql://" + dbServer + ":" + Integer.toString(dbPort) + "/" + dbDatabase;
        Properties props = new Properties();
        props.setProperty("user", dbUserName);
        props.setProperty("password", dbPassword);
        try {
            cnx = DriverManager.getConnection(url, props);
            cnx.setAutoCommit(false);
            cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            cnx.rollback();
            setSchemaDbName(dbDatabase);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        return (true);
    }
    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
            "configurationFile not found, do not know how to connect to database");
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java

public boolean connect(String username, String password) {
    final String S_ProcName = "connect";
    if (cnx != null) {
        return (false);
    }// www  .j  a v a 2s.  c  om
    if ((username == null) || (username.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "username");
    }
    if (password == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "password");
    }

    if (configuration != null) {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        } catch (ClassNotFoundException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect",
                    "Could not load MS SQL Server 2012 Express Advanced Edition driver", e);
        }
        String dbServer = configuration.getDbServer();
        int dbPort = configuration.getDbPort();
        String dbDatabase = configuration.getDbDatabase();
        String dbUserName = username;
        String dbPassword = password;
        String url = "jdbc:sqlserver://" + dbServer + ":" + Integer.toString(dbPort) + ";";
        Properties props = new Properties();
        props.setProperty("user", dbUserName);
        props.setProperty("password", dbPassword);
        try {
            cnx = DriverManager.getConnection(url, props);
            cnx.setAutoCommit(false);
            cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            cnx.rollback();
            setSchemaDbName(dbDatabase);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<connect>>", e);
        }
        Statement stmtUseDatabase = null;
        try {
            stmtUseDatabase = cnx.createStatement();
            stmtUseDatabase.executeUpdate("use " + dbDatabase);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<useDatabase>>",
                    e);
        } finally {
            if (stmtUseDatabase != null) {
                try {
                    stmtUseDatabase.close();
                } catch (SQLException e) {
                }
                stmtUseDatabase = null;
            }
        }
        return (true);
    }
    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
            "configurationFile not found, do not know how to connect to database");
}

From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java

private String getTransactionIsolation(Connection connection, SqlRepositoryConfiguration config) {
    String value = config.getTransactionIsolation() != null
            ? config.getTransactionIsolation().name() + "(read from repo configuration)"
            : null;/*from   w  ww. j a  v  a  2 s.c  o  m*/

    try {
        switch (connection.getTransactionIsolation()) {
        case Connection.TRANSACTION_NONE:
            value = "TRANSACTION_NONE (read from connection)";
            break;
        case Connection.TRANSACTION_READ_COMMITTED:
            value = "TRANSACTION_READ_COMMITTED (read from connection)";
            break;
        case Connection.TRANSACTION_READ_UNCOMMITTED:
            value = "TRANSACTION_READ_UNCOMMITTED (read from connection)";
            break;
        case Connection.TRANSACTION_REPEATABLE_READ:
            value = "TRANSACTION_REPEATABLE_READ (read from connection)";
            break;
        case Connection.TRANSACTION_SERIALIZABLE:
            value = "TRANSACTION_SERIALIZABLE (read from connection)";
            break;
        default:
            value = "Unknown value in connection.";
        }
    } catch (Exception ex) {
        //nowhere to report error (no operation result available)
    }

    return value;
}

From source file:ca.gnewton.lusql.core.LuSqlMain.java

static void setupOptions() {

    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Subquery in the form \"field|A:A:A|sql\" or \"field|A:A:A A:A:A...|sql\" or \"field|sql\"  (See -i for A:A:A values). Note that you can have multiple -Qs. Also note that putting a '*' before the field indicates you want the results cached (useful only if there is a possible for subsequent cache hits. Use only if you know what you are doing.")
            .create("Q"));

    options.addOption(OptionBuilder.hasArgs().withDescription(
            "For DocSinks (Indexes) that support multiple real indexes, either to eventual merging or as-is")
            .create("L"));

    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Set static Document field and value. This is a field that has the same value for all saved documents. Format: \"field=value\" or \"A:A:A:field=value\" (See -i for A:A:A values)")
            .create("g"));

    options.addOption(OptionBuilder.hasArg()
            .withDescription(//from  w  w  w  .  j a  va 2 s  .c om
                    "Full name class implementing Lucene Analyzer; Default: " + LuSql.DefaultAnalyzerClassName)
            .create("a"));

    options.addOption(OptionBuilder.hasArg()
            .withDescription(
                    "Offset # documents to ignore before indexing. Default:" + LuSqlFields.OffsetDefault)
            .create("O"));

    options.addOption(OptionBuilder.hasArg().withDescription(
            "Full name class implementing DocSink (the index class). Default: " + LuSql.DefaultDocSinkClassName)
            .create(CLIDocSinkClassName));

    options.addOption(OptionBuilder.hasArg()
            .withDescription("Full name class implementing DocSource (the index class). Default: "
                    + LuSql.DefaultDocSourceClassName)
            .create("so"));

    options.addOption(OptionBuilder.hasArg().withDescription(
            "Primary key field name fron DocSource to be used in DocSink. Only for DocSinks that need it. Lucene does not. BDB does. For JDBCDocSource, if not set, uses first field in SQL query.")
            .create("P"));

    options.addOption("A", false, "Append to existing Lucene index.");

    options.addOption(OptionBuilder.hasArg()
            .withDescription("Queue size for multithreading. Default: numThreads * 50").create("S"));

    options.addOption(OptionBuilder.hasArg().withDescription(
            "Tries to limit activity to keep load average below this (float) value. Can reduce performance. Default: "
                    + LuSql.loadAverageLimit)
            .create("V"));

    options.addOption("J", false, "For multiple indexes (see -L) do not merge. Default: false");

    options.addOption("X", false, "Print out command line arguments");

    options.addOption("Y", false, "Silent output");

    options.addOption("o", false, "If supported, have DocSink write to stdout");

    //////////////////////////
    options.addOption(OptionBuilder.hasArg()
            //.isRequired()
            .withDescription(
                    "JDBC connection URL: REQUIRED _OR_ Source location (Source dependent: file, url, etc)")
            .create("c"));

    //////////////////////////
    options.addOption(OptionBuilder.hasArg()
            .withDescription("Verbose output chunk size. Default:" + LuSqlFields.DefaultChunkSize).create("C"));

    //////////////////////////
    options.addOption(OptionBuilder.hasArg()
            .withDescription("Amount of documents to be processed per thread. Default:"
                    + LuSqlFields.DefaultWorkPerThread
                    + ". Increasing tends to improve throughput; Decreasing tends to reduce memory problems and can alleviate an \"Out of memory\" exception. Should be 5-100 for medium/small documents. Should be 1 for very large documents.")
            .create("w"));

    //////////////////////////
    options.addOption(OptionBuilder.hasArg()
            .withDescription("Full name of DB driver class (should be in CLASSPATH); Default: "
                    + LuSql.DefaultJDBCDriverClassName)
            .create("d"));

    //////////////////////////
    options.addOption(OptionBuilder.hasArgs()
            .withDescription("Full name class implementing DocumentFilter; Default: "
                    + LuSql.DefaultDocFilterClassName
                    + " (does nothing). This is applied before each Lucene Document is added to the Index. If it returns null, nothing is added. Note that multiple filters are allowed. They are applied in the same order as they appear in the command line.")
            .create(CLIDocFiltersClassName));

    //////////////////////////
    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Only include these fields from DocSource. Example: -F author -F id. Is absolute (i.e. even if you have additional fields - like in your SQL query - they will be filtered out.")
            .create("F"));

    //////////////////////////
    options.addOption("I", true,
            "Global field index parameters. This sets all the fields parameters to this one set. Format: A:A:A. See -i for A:A:A values. Note that -i has precedence over -I.");

    //////////////////////////
    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Size of internal arrays of documents. One of these arrays is put on the queue. So the number of objects waiting to be processed is K*S (array size * queue size). For small objects have more (k=100). For large objects have fewer (k=5). Default: "
                    + LuSqlFields.DefaultDocPacketSize)
            .create("K"));

    //////////////////////////
    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Full name plugin class; Get description and properties options needed by specific plugin (filter, source, or sink.")
            .create("e"));

    StringBuilder sb = new StringBuilder();
    sb.append("One set per field in SQL, and in same order as in SQL. ");
    sb.append("Used only if you want to overide the defaults (below). ");
    sb.append("See for more information Field.Index, Field.Store, Field.TermVector in");
    sb.append(
            "org.apache.lucene.document.Field http://lucene.apache.org/java/3_0_2/api/core/org/apache/lucene/document/Field.html");
    //http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/document/Field.html");
    sb.append("\nDefault: A:A:A= "
            //+ Util.getIndex(LuSql.IndexDefault, IndexParameterValues) 
            //+ Util.getIndex(LuSql.StoreDefault, StoreParameterValues) 
            //+ Util.getIndex(LuSql.TermVectorDefault, TermVectorParameterValues) 
            + LuceneFieldParameters.rindex.get(LuSql.defaultLuceneFieldParameters.getIndex()) + ":"
            + LuceneFieldParameters.rstorex.get(LuSql.defaultLuceneFieldParameters.getStore()) + ":"
            + LuceneFieldParameters.rtermx.get(LuSql.defaultLuceneFieldParameters.getTermVector()));

    sb.append("\nField Index Parameter values:");
    sb.append("\nIndex: Default: "
            + LuceneFieldParameters.rindex.get(LuSql.defaultLuceneFieldParameters.getIndex()));
    sb.append("\n");

    Set<String> names = LuceneFieldParameters.indexx.keySet();
    for (String name : names) {
        sb.append("\n-  " + name);
    }

    sb.append("\nStore: Default: "
            + LuceneFieldParameters.rstorex.get(LuSql.defaultLuceneFieldParameters.getStore()));

    sb.append("\n");
    names = LuceneFieldParameters.storex.keySet();
    for (String name : names) {
        sb.append("\n-  " + name);
    }
    sb.append("\n Term vector: Default: "
            + LuceneFieldParameters.rtermx.get(LuSql.defaultLuceneFieldParameters.getTermVector()));

    sb.append("\n");
    names = LuceneFieldParameters.termx.keySet();
    for (String name : names) {
        sb.append("\n-  " + name);
    }
    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Field index parameters. \nFormat: \"fieldName=A:A:A\". Note that -i can have a slightly different interpretation depending on the DocSource. For DocSource implementation where the syntax of the query allows for separate definition of the query and the fields of interest (like SQL), all of the fields defined in the query are stored/indexed. For other DocSource's where only the query can be defined and the fields of interest cannot (like the Lucene syntax of the LucenDocSource), the \"-i\" syntax is the only way to set the fields to be used. "
                    + sb)
            .create("i"));

    //////////////////////
    options.addOption(OptionBuilder.hasArg()
            //.isRequired()
            .withDescription("Sink destination (i.e. Lucene index to create/write to). Default: "
                    + LuSql.DefaultSinkLocationName)
            .create("l"));

    //////////////////////
    options.addOption("N", true,
            "Number of thread for multithreading. Defaults: Runtime.getRuntime().availableProcessors()) *"
                    + LuSql.ThreadFactor + ". For this machine this is: "
                    + (Runtime.getRuntime().availableProcessors() * LuSql.ThreadFactor));

    //////////////////////
    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Properties to be passed to the DocSource driver. Can be is multiple. Example: -pso foo=bar  -pso \"start=test 4\"")
            .create("pso"));

    //////////////////////
    options.addOption(OptionBuilder.hasArgs()
            .withDescription(
                    "Properties to be passed to the DocSink driver. Can be multiple. See 'pso' for examples")
            .create("psi"));

    //////////////////////
    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Properties to be passed to a filter. Can be multiple. Identify filter using integer (zero is the first filter). Example: -pf 0:size=10 -pf 0:name=fred -pf 1:reduce=true")
            .create("pf"));

    //////////////////////
    options.addOption(OptionBuilder
            .withDescription("Read from source using source driver's internal compression, if it supports it")
            .create("zso"));

    options.addOption(OptionBuilder
            .withDescription("Have sink driver use internal compression (opaque), if it supports it")
            .create("zsi"));

    //////////////////////
    options.addOption("n", true, "Number of documents to add. If unset all records from query are used.");

    //////////////////////
    options.addOption("M", true,
            "Changes the meta replacement string for the -Q command line parameters. Default: "
                    + SubQuery.getKeyMeta());

    //////////////////////
    options.addOption("m", false,
            "Turns off need get around MySql driver-caused OutOfMemory problem in large queries. Sets Statement.setFetchSize(Integer.MIN_VALUE)"
                    + "\n See http://benjchristensen.wordpress.com/2008/05/27/mysql-jdbc-memory-usage-on-large-resultset");

    //////////////////////
    options.addOption(OptionBuilder.hasArg().withDescription("Set JDBC Transaction level. Default: "
            + DefaultTransactionIsolation + ". Values:\n" + Connection.TRANSACTION_NONE + " TRANSACTION_NONE\n"
            + Connection.TRANSACTION_READ_UNCOMMITTED + " TRANSACTION_READ_UNCOMMITTED\n"
            + Connection.TRANSACTION_READ_COMMITTED + " TRANSACTION_READ_COMMITTED\n"
            + Connection.TRANSACTION_REPEATABLE_READ + " TRANSACTION_REPEATABLE_READ\n"
            + Connection.TRANSACTION_SERIALIZABLE + " TRANSACTION_SERIALIZABLE\n "
            + "(See http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.sql.Connection.TRANSACTION_NONE)")
            .create("E"));

    //////////////////////
    options.addOption("p", true, "Properties file");

    //////////////////////
    //////////////////////
    options.addOption(OptionBuilder.hasArg()
            //.isRequired()
            .withDescription("Primary SQL query (in double quotes). Only used by JDBC driver").create("q"));

    //////////////////////
    options.addOption("r", true,
            "LuceneRAMBufferSizeInMBs: IndexWriter.setRAMBufferSizeMB(). Only used by Lucene sinks. Default: "
                    + Double.toString(LuSql.DefaultRAMBufferSizeMB));

    //////////////////////
    options.addOption("s", true,
            "Name of stop word file to use (relative or full path). If supported by DocSource");

    //////////////////////
    options.addOption("T", false,
            "Turn off multithreading. Note that multithreading does not guarantee the ordering of documents. If you want the order of Lucene documents to match the ordering of DB records generated by the SQL query, turn-off multithreading");

    //////////////////////
    options.addOption("t", false,
            "Test mode. Does not open up Lucene index. Prints (-n) records from SQL query");

    //////////////////////
    options.addOption("v", false, "Verbose mode");

    //////////////////////
    options.addOption("onlyMap", false, "Only use the fields from the DocSource that are mapped using -map");

    options.addOption(OptionBuilder.hasArgs().withDescription(
            "Field map. Transforms field names in DocSource to new fieldnames: Example -map \"AU=author\", where \"AU\" is the original (source) field name and \"author\" is the new (sink) field")
            .create("map"));
}

From source file:com.cloud.utils.db.TransactionLegacy.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void initDataSource(Properties dbProps) {
    try {/*w  w w .ja va  2  s .  c o  m*/
        if (dbProps.size() == 0)
            return;

        s_dbHAEnabled = Boolean.valueOf(dbProps.getProperty("db.ha.enabled"));
        s_logger.info("Is Data Base High Availiability enabled? Ans : " + s_dbHAEnabled);
        String loadBalanceStrategy = dbProps.getProperty("db.ha.loadBalanceStrategy");
        // FIXME:  If params are missing...default them????
        final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive"));
        final int cloudMaxIdle = Integer.parseInt(dbProps.getProperty("db.cloud.maxIdle"));
        final long cloudMaxWait = Long.parseLong(dbProps.getProperty("db.cloud.maxWait"));
        final String cloudUsername = dbProps.getProperty("db.cloud.username");
        final String cloudPassword = dbProps.getProperty("db.cloud.password");
        final String cloudHost = dbProps.getProperty("db.cloud.host");
        final String cloudDriver = dbProps.getProperty("db.cloud.driver");
        final int cloudPort = Integer.parseInt(dbProps.getProperty("db.cloud.port"));
        final String cloudDbName = dbProps.getProperty("db.cloud.name");
        final boolean cloudAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.cloud.autoReconnect"));
        final String cloudValidationQuery = dbProps.getProperty("db.cloud.validationQuery");
        final String cloudIsolationLevel = dbProps.getProperty("db.cloud.isolation.level");

        int isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
        if (cloudIsolationLevel == null) {
            isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
        } else if (cloudIsolationLevel.equalsIgnoreCase("readcommitted")) {
            isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
        } else if (cloudIsolationLevel.equalsIgnoreCase("repeatableread")) {
            isolationLevel = Connection.TRANSACTION_REPEATABLE_READ;
        } else if (cloudIsolationLevel.equalsIgnoreCase("serializable")) {
            isolationLevel = Connection.TRANSACTION_SERIALIZABLE;
        } else if (cloudIsolationLevel.equalsIgnoreCase("readuncommitted")) {
            isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
        } else {
            s_logger.warn("Unknown isolation level " + cloudIsolationLevel + ".  Using read uncommitted");
        }

        final boolean cloudTestOnBorrow = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testOnBorrow"));
        final boolean cloudTestWhileIdle = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testWhileIdle"));
        final long cloudTimeBtwEvictionRunsMillis = Long
                .parseLong(dbProps.getProperty("db.cloud.timeBetweenEvictionRunsMillis"));
        final long cloudMinEvcitableIdleTimeMillis = Long
                .parseLong(dbProps.getProperty("db.cloud.minEvictableIdleTimeMillis"));
        final boolean cloudPoolPreparedStatements = Boolean
                .parseBoolean(dbProps.getProperty("db.cloud.poolPreparedStatements"));
        final String url = dbProps.getProperty("db.cloud.url.params");

        String cloudDbHAParams = null;
        String cloudSlaves = null;
        if (s_dbHAEnabled) {
            cloudDbHAParams = getDBHAParams("cloud", dbProps);
            cloudSlaves = dbProps.getProperty("db.cloud.slaves");
            s_logger.info("The slaves configured for Cloud Data base is/are : " + cloudSlaves);
        }

        final boolean useSSL = Boolean.parseBoolean(dbProps.getProperty("db.cloud.useSSL"));
        if (useSSL) {
            System.setProperty("javax.net.ssl.keyStore", dbProps.getProperty("db.cloud.keyStore"));
            System.setProperty("javax.net.ssl.keyStorePassword",
                    dbProps.getProperty("db.cloud.keyStorePassword"));
            System.setProperty("javax.net.ssl.trustStore", dbProps.getProperty("db.cloud.trustStore"));
            System.setProperty("javax.net.ssl.trustStorePassword",
                    dbProps.getProperty("db.cloud.trustStorePassword"));
        }

        final GenericObjectPool cloudConnectionPool = new GenericObjectPool(null, cloudMaxActive,
                GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, cloudMaxWait, cloudMaxIdle, cloudTestOnBorrow,
                false, cloudTimeBtwEvictionRunsMillis, 1, cloudMinEvcitableIdleTimeMillis, cloudTestWhileIdle);

        final String cloudConnectionUri = cloudDriver + "://" + cloudHost
                + (s_dbHAEnabled ? "," + cloudSlaves : "") + ":" + cloudPort + "/" + cloudDbName
                + "?autoReconnect=" + cloudAutoReconnect + (url != null ? "&" + url : "")
                + (useSSL ? "&useSSL=true" : "") + (s_dbHAEnabled ? "&" + cloudDbHAParams : "")
                + (s_dbHAEnabled ? "&loadBalanceStrategy=" + loadBalanceStrategy : "");
        DriverLoader.loadDriver(cloudDriver);

        final ConnectionFactory cloudConnectionFactory = new DriverManagerConnectionFactory(cloudConnectionUri,
                cloudUsername, cloudPassword);

        final KeyedObjectPoolFactory poolableObjFactory = (cloudPoolPreparedStatements
                ? new StackKeyedObjectPoolFactory()
                : null);

        final PoolableConnectionFactory cloudPoolableConnectionFactory = new PoolableConnectionFactory(
                cloudConnectionFactory, cloudConnectionPool, poolableObjFactory, cloudValidationQuery, false,
                false, isolationLevel);

        // Default Data Source for CloudStack
        s_ds = new PoolingDataSource(cloudPoolableConnectionFactory.getPool());

        // Configure the usage db
        final int usageMaxActive = Integer.parseInt(dbProps.getProperty("db.usage.maxActive"));
        final int usageMaxIdle = Integer.parseInt(dbProps.getProperty("db.usage.maxIdle"));
        final long usageMaxWait = Long.parseLong(dbProps.getProperty("db.usage.maxWait"));
        final String usageUsername = dbProps.getProperty("db.usage.username");
        final String usagePassword = dbProps.getProperty("db.usage.password");
        final String usageHost = dbProps.getProperty("db.usage.host");
        final String usageDriver = dbProps.getProperty("db.usage.driver");
        final int usagePort = Integer.parseInt(dbProps.getProperty("db.usage.port"));
        final String usageDbName = dbProps.getProperty("db.usage.name");
        final boolean usageAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.usage.autoReconnect"));
        final String usageUrl = dbProps.getProperty("db.usage.url.params");

        final GenericObjectPool usageConnectionPool = new GenericObjectPool(null, usageMaxActive,
                GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, usageMaxWait, usageMaxIdle);

        final String usageConnectionUri = usageDriver + "://" + usageHost
                + (s_dbHAEnabled ? "," + dbProps.getProperty("db.cloud.slaves") : "") + ":" + usagePort + "/"
                + usageDbName + "?autoReconnect=" + usageAutoReconnect
                + (usageUrl != null ? "&" + usageUrl : "")
                + (s_dbHAEnabled ? "&" + getDBHAParams("usage", dbProps) : "")
                + (s_dbHAEnabled ? "&loadBalanceStrategy=" + loadBalanceStrategy : "");
        DriverLoader.loadDriver(usageDriver);

        final ConnectionFactory usageConnectionFactory = new DriverManagerConnectionFactory(usageConnectionUri,
                usageUsername, usagePassword);

        final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory(
                usageConnectionFactory, usageConnectionPool, new StackKeyedObjectPoolFactory(), null, false,
                false);

        // Data Source for usage server
        s_usageDS = new PoolingDataSource(usagePoolableConnectionFactory.getPool());

        try {
            // Configure the simulator db
            final int simulatorMaxActive = Integer.parseInt(dbProps.getProperty("db.simulator.maxActive"));
            final int simulatorMaxIdle = Integer.parseInt(dbProps.getProperty("db.simulator.maxIdle"));
            final long simulatorMaxWait = Long.parseLong(dbProps.getProperty("db.simulator.maxWait"));
            final String simulatorUsername = dbProps.getProperty("db.simulator.username");
            final String simulatorPassword = dbProps.getProperty("db.simulator.password");
            final String simulatorHost = dbProps.getProperty("db.simulator.host");
            final String simulatorDriver = dbProps.getProperty("db.simulator.driver");
            final int simulatorPort = Integer.parseInt(dbProps.getProperty("db.simulator.port"));
            final String simulatorDbName = dbProps.getProperty("db.simulator.name");
            final boolean simulatorAutoReconnect = Boolean
                    .parseBoolean(dbProps.getProperty("db.simulator.autoReconnect"));

            final GenericObjectPool simulatorConnectionPool = new GenericObjectPool(null, simulatorMaxActive,
                    GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, simulatorMaxWait, simulatorMaxIdle);

            final String simulatorConnectionUri = simulatorDriver + "://" + simulatorHost + ":" + simulatorPort
                    + "/" + simulatorDbName + "?autoReconnect=" + simulatorAutoReconnect;
            DriverLoader.loadDriver(simulatorDriver);

            final ConnectionFactory simulatorConnectionFactory = new DriverManagerConnectionFactory(
                    simulatorConnectionUri, simulatorUsername, simulatorPassword);

            final PoolableConnectionFactory simulatorPoolableConnectionFactory = new PoolableConnectionFactory(
                    simulatorConnectionFactory, simulatorConnectionPool, new StackKeyedObjectPoolFactory(),
                    null, false, false);
            s_simulatorDS = new PoolingDataSource(simulatorPoolableConnectionFactory.getPool());
        } catch (Exception e) {
            s_logger.debug("Simulator DB properties are not available. Not initializing simulator DS");
        }
    } catch (final Exception e) {
        s_ds = getDefaultDataSource("cloud");
        s_usageDS = getDefaultDataSource("cloud_usage");
        s_simulatorDS = getDefaultDataSource("cloud_simulator");
        s_logger.warn(
                "Unable to load db configuration, using defaults with 5 connections. Falling back on assumed datasource on localhost:3306 using username:password=cloud:cloud. Please check your configuration",
                e);
    }
}

From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetDb2LUW.CFInternetDb2LUWSchema.java

public CFInternetDb2LUWSchema(Connection argCnx) {
    super();//from w  w  w . j  a v  a  2s . c  o m
    cnx = argCnx;
    inTransaction = false;
    tableAuditAction = new CFInternetDb2LUWAuditActionTable(this);
    tableCluster = new CFInternetDb2LUWClusterTable(this);
    tableDomain = new CFInternetDb2LUWDomainTable(this);
    tableDomainBase = new CFInternetDb2LUWDomainBaseTable(this);
    tableHostNode = new CFInternetDb2LUWHostNodeTable(this);
    tableISOCountry = new CFInternetDb2LUWISOCountryTable(this);
    tableISOCountryCurrency = new CFInternetDb2LUWISOCountryCurrencyTable(this);
    tableISOCountryLanguage = new CFInternetDb2LUWISOCountryLanguageTable(this);
    tableISOCurrency = new CFInternetDb2LUWISOCurrencyTable(this);
    tableISOLanguage = new CFInternetDb2LUWISOLanguageTable(this);
    tableISOTimezone = new CFInternetDb2LUWISOTimezoneTable(this);
    tableMajorVersion = new CFInternetDb2LUWMajorVersionTable(this);
    tableMimeType = new CFInternetDb2LUWMimeTypeTable(this);
    tableMinorVersion = new CFInternetDb2LUWMinorVersionTable(this);
    tableProjectBase = new CFInternetDb2LUWProjectBaseTable(this);
    tableRealProject = new CFInternetDb2LUWRealProjectTable(this);
    tableSecApp = new CFInternetDb2LUWSecAppTable(this);
    tableSecDevice = new CFInternetDb2LUWSecDeviceTable(this);
    tableSecForm = new CFInternetDb2LUWSecFormTable(this);
    tableSecGroup = new CFInternetDb2LUWSecGroupTable(this);
    tableSecGroupForm = new CFInternetDb2LUWSecGroupFormTable(this);
    tableSecGroupInclude = new CFInternetDb2LUWSecGroupIncludeTable(this);
    tableSecGroupMember = new CFInternetDb2LUWSecGroupMemberTable(this);
    tableSecSession = new CFInternetDb2LUWSecSessionTable(this);
    tableSecUser = new CFInternetDb2LUWSecUserTable(this);
    tableService = new CFInternetDb2LUWServiceTable(this);
    tableServiceType = new CFInternetDb2LUWServiceTypeTable(this);
    tableSubProject = new CFInternetDb2LUWSubProjectTable(this);
    tableTSecGroup = new CFInternetDb2LUWTSecGroupTable(this);
    tableTSecGroupInclude = new CFInternetDb2LUWTSecGroupIncludeTable(this);
    tableTSecGroupMember = new CFInternetDb2LUWTSecGroupMemberTable(this);
    tableTenant = new CFInternetDb2LUWTenantTable(this);
    tableTld = new CFInternetDb2LUWTldTable(this);
    tableTopDomain = new CFInternetDb2LUWTopDomainTable(this);
    tableTopProject = new CFInternetDb2LUWTopProjectTable(this);
    tableURLProtocol = new CFInternetDb2LUWURLProtocolTable(this);
    tableVersion = new CFInternetDb2LUWVersionTable(this);
    try {
        cnx.setAutoCommit(false);
        cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
        cnx.rollback();
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(),
                "CFInternetDb2LUWSchema-constructor", e);
    }
}

From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetMySql.CFInternetMySqlSchema.java

public CFInternetMySqlSchema(Connection argCnx) {
    super();// www .j  a  v  a  2  s  .  co  m
    cnx = argCnx;
    inTransaction = false;
    tableAuditAction = new CFInternetMySqlAuditActionTable(this);
    tableCluster = new CFInternetMySqlClusterTable(this);
    tableDomain = new CFInternetMySqlDomainTable(this);
    tableDomainBase = new CFInternetMySqlDomainBaseTable(this);
    tableHostNode = new CFInternetMySqlHostNodeTable(this);
    tableISOCountry = new CFInternetMySqlISOCountryTable(this);
    tableISOCountryCurrency = new CFInternetMySqlISOCountryCurrencyTable(this);
    tableISOCountryLanguage = new CFInternetMySqlISOCountryLanguageTable(this);
    tableISOCurrency = new CFInternetMySqlISOCurrencyTable(this);
    tableISOLanguage = new CFInternetMySqlISOLanguageTable(this);
    tableISOTimezone = new CFInternetMySqlISOTimezoneTable(this);
    tableMajorVersion = new CFInternetMySqlMajorVersionTable(this);
    tableMimeType = new CFInternetMySqlMimeTypeTable(this);
    tableMinorVersion = new CFInternetMySqlMinorVersionTable(this);
    tableProjectBase = new CFInternetMySqlProjectBaseTable(this);
    tableRealProject = new CFInternetMySqlRealProjectTable(this);
    tableSecApp = new CFInternetMySqlSecAppTable(this);
    tableSecDevice = new CFInternetMySqlSecDeviceTable(this);
    tableSecForm = new CFInternetMySqlSecFormTable(this);
    tableSecGroup = new CFInternetMySqlSecGroupTable(this);
    tableSecGroupForm = new CFInternetMySqlSecGroupFormTable(this);
    tableSecGroupInclude = new CFInternetMySqlSecGroupIncludeTable(this);
    tableSecGroupMember = new CFInternetMySqlSecGroupMemberTable(this);
    tableSecSession = new CFInternetMySqlSecSessionTable(this);
    tableSecUser = new CFInternetMySqlSecUserTable(this);
    tableService = new CFInternetMySqlServiceTable(this);
    tableServiceType = new CFInternetMySqlServiceTypeTable(this);
    tableSubProject = new CFInternetMySqlSubProjectTable(this);
    tableTSecGroup = new CFInternetMySqlTSecGroupTable(this);
    tableTSecGroupInclude = new CFInternetMySqlTSecGroupIncludeTable(this);
    tableTSecGroupMember = new CFInternetMySqlTSecGroupMemberTable(this);
    tableTenant = new CFInternetMySqlTenantTable(this);
    tableTld = new CFInternetMySqlTldTable(this);
    tableTopDomain = new CFInternetMySqlTopDomainTable(this);
    tableTopProject = new CFInternetMySqlTopProjectTable(this);
    tableURLProtocol = new CFInternetMySqlURLProtocolTable(this);
    tableVersion = new CFInternetMySqlVersionTable(this);
    try {
        cnx.setAutoCommit(false);
        cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
        cnx.rollback();
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "CFInternetMySqlSchema-constructor",
                e);
    }
}