001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.sql;
031:
032: import com.caucho.config.ConfigException;
033: import com.caucho.util.L10N;
034:
035: import java.sql.Connection;
036:
037: /**
038: * Configures the connection
039: */
040: public class ConnectionConfig {
041: private static final L10N L = new L10N(ConnectionConfig.class);
042:
043: private int _isolation = -1;
044: private boolean _readOnly;
045: private String _catalog;
046:
047: /**
048: * Sets the isolation of the connection.
049: */
050: public void setTransactionIsolation(String name)
051: throws ConfigException {
052: if ("none".equals(name))
053: _isolation = Connection.TRANSACTION_NONE;
054: else if ("read-committed".equals(name))
055: _isolation = Connection.TRANSACTION_READ_COMMITTED;
056: else if ("read-uncommitted".equals(name))
057: _isolation = Connection.TRANSACTION_READ_UNCOMMITTED;
058: else if ("repeatable-read".equals(name))
059: _isolation = Connection.TRANSACTION_REPEATABLE_READ;
060: else if ("serializable".equals(name))
061: _isolation = Connection.TRANSACTION_SERIALIZABLE;
062: else
063: throw new ConfigException(L.l(
064: "'{0}' is an unknown transaction isolation.", name));
065: }
066:
067: /**
068: * Returns the isolation of the connection, with -1 for the default.
069: */
070: public int getTransactionIsolation() {
071: return _isolation;
072: }
073:
074: /**
075: * Sets the read-only status.
076: */
077: public void setReadOnly(boolean isReadOnly) {
078: _readOnly = isReadOnly;
079: }
080:
081: /**
082: * Gets the read-only status.
083: */
084: public boolean isReadOnly() {
085: return _readOnly;
086: }
087:
088: /**
089: * Sets the catalog
090: */
091: public void setCatalog(String catalog) {
092: if (!"".equals(catalog))
093: _catalog = catalog;
094: else
095: _catalog = null;
096: }
097:
098: /**
099: * Gets the catalog.
100: */
101: public String getCatalog() {
102: return _catalog;
103: }
104: }
|