Author: sergiykarpenko
Date: 2009-12-28 11:12:42 -0500 (Mon, 28 Dec 2009)
New Revision: 1220
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OracleConnectionFactory.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OraclePoolConnectionFactory.java
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBConnectionFactory.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java
Log:
EXOJCR-302: oracle factory added
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java 2009-12-28
15:44:24 UTC (rev 1219)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java 2009-12-28
16:12:42 UTC (rev 1220)
@@ -23,7 +23,6 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
-import org.exoplatform.services.jcr.impl.storage.jdbc.db.OracleConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializerException;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.IngresSQLDBInitializer;
@@ -31,6 +30,7 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.init.PgSQLDBInitializer;
import
org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.HSQLDBConnectionFactory;
import
org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.MySQLConnectionFactory;
+import
org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.OracleConnectionFactory;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
import org.exoplatform.services.naming.InitialContextInitializer;
import org.picocontainer.Startable;
@@ -103,9 +103,11 @@
}
else if (dbDialect == DBConstants.DB_DIALECT_ORACLE)
{
+
this.connFactory = defaultConnectionFactory();
sqlPath = "/conf/storage/jcr-" + (multiDb ? "m" :
"s") + "jdbc.ora.sql";
dbInitilizer = new OracleDBInitializer(containerName,
this.connFactory.getJdbcConnection(), sqlPath, multiDb);
+
}
else if (dbDialect == DBConstants.DB_DIALECT_PGSQL)
{
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java
(rev 0)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/GenericCQConnectionFactory.java 2009-12-28
16:12:42 UTC (rev 1220)
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This 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 software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
+import org.exoplatform.services.jcr.impl.storage.jdbc.monitor.ManagedConnection;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import javax.jcr.RepositoryException;
+import javax.sql.DataSource;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 15.03.2007
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
+ * @version $Id: GenericConnectionFactory.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class GenericCQConnectionFactory extends GenericConnectionFactory
+{
+
+ /**
+ * GenericConnectionFactory constructor.
+ *
+ * @param dataSource
+ * - DataSource
+ * @param dbDriver
+ * - JDBC Driver
+ * @param dbUrl
+ * - JDBC URL
+ * @param dbUserName
+ * - database username
+ * @param dbPassword
+ * - database user password
+ * @param containerName
+ * - Container name (see configuration)
+ * @param multiDb
+ * - multidatabase state flag
+ * @param valueStorageProvider
+ * - external Value Storages provider
+ * @param maxBufferSize
+ * - Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * - Swap directory (see configuration)
+ * @param swapCleaner
+ * - Swap cleaner (internal FileCleaner).
+ */
+ protected GenericCQConnectionFactory(DataSource dataSource, String dbDriver, String
dbUrl, String dbUserName,
+ String dbPassword, String containerName, boolean multiDb,
ValueStoragePluginProvider valueStorageProvider,
+ int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
+ {
+ super(dataSource, dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider,
+ maxBufferSize, swapDirectory, swapCleaner);
+ }
+
+ /**
+ * GenericConnectionFactory constructor.
+ *
+ * @param dataSource
+ * - DataSource
+ * @param containerName
+ * - Container name (see configuration)
+ * @param multiDb
+ * - multidatabase state flag
+ * @param valueStorageProvider
+ * - external Value Storages provider
+ * @param maxBufferSize
+ * - Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * - Swap directory (see configuration)
+ * @param swapCleaner
+ * - Swap cleaner (internal FileCleaner).
+ */
+ public GenericCQConnectionFactory(DataSource dataSource, String containerName, boolean
multiDb,
+ ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File
swapDirectory, FileCleaner swapCleaner)
+ {
+
+ this(dataSource, null, null, null, null, containerName, multiDb,
valueStorageProvider, maxBufferSize,
+ swapDirectory, swapCleaner);
+ }
+
+ /**
+ * GenericConnectionFactory constructor.
+ *
+ * @param dbDriver
+ * - JDBC Driver
+ * @param dbUrl
+ * - JDBC URL
+ * @param dbUserName
+ * - database username
+ * @param dbPassword
+ * - database user password
+ * @param containerName
+ * - Container name (see configuration)
+ * @param multiDb
+ * - multidatabase state flag
+ * @param valueStorageProvider
+ * - external Value Storages provider
+ * @param maxBufferSize
+ * - Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * - Swap directory (see configuration)
+ * @param swapCleaner
+ * - Swap cleaner (internal FileCleaner).
+ */
+ public GenericCQConnectionFactory(String dbDriver, String dbUrl, String dbUserName,
String dbPassword,
+ String containerName, boolean multiDb, ValueStoragePluginProvider
valueStorageProvider, int maxBufferSize,
+ File swapDirectory, FileCleaner swapCleaner) throws RepositoryException
+ {
+
+ this(null, dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize,
+ swapDirectory, swapCleaner);
+
+ try
+ {
+ Class.forName(dbDriver).newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public WorkspaceStorageConnection openConnection() throws RepositoryException
+ {
+ return openConnection(false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public WorkspaceStorageConnection openConnection(boolean readOnly) throws
RepositoryException
+ {
+ try
+ {
+
+ if (multiDb)
+ {
+ return new MultiDbJDBCConnection(getJdbcConnection(readOnly), readOnly,
containerName,
+ valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+ }
+
+ return new SingleDbJDBCConnection(getJdbcConnection(readOnly), readOnly,
containerName, valueStorageProvider,
+ maxBufferSize, swapDirectory, swapCleaner);
+
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Connection getJdbcConnection(boolean readOnly) throws RepositoryException
+ {
+ try
+ {
+ final Connection conn =
+ dbDataSource != null ? dbDataSource.getConnection() : (dbUserName != null ?
DriverManager.getConnection(
+ dbUrl, dbUserName, dbPassword) : DriverManager.getConnection(dbUrl));
+
+ if (readOnly) // set this feature only if it asked
+ conn.setReadOnly(readOnly);
+
+ return monitorInterest == 0 ? conn : new ManagedConnection(conn,
monitorInterest);
+ }
+ catch (SQLException e)
+ {
+ String err =
+ "Error of JDBC connection open. SQLException: " + e.getMessage() +
", SQLState: " + e.getSQLState()
+ + ", VendorError: " + e.getErrorCode();
+ throw new RepositoryException(err, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Connection getJdbcConnection() throws RepositoryException
+ {
+ return getJdbcConnection(false);
+ }
+
+}
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBConnectionFactory.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBConnectionFactory.java 2009-12-28
15:44:24 UTC (rev 1219)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBConnectionFactory.java 2009-12-28
16:12:42 UTC (rev 1220)
@@ -16,7 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
-import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
@@ -35,7 +34,7 @@
* @author <a href="mailto:dezder@bk.ru">Denis Grebenyuk</a>
* @version $Id:$
*/
-public class HSQLDBConnectionFactory extends GenericConnectionFactory
+public class HSQLDBConnectionFactory extends GenericCQConnectionFactory
{
/**
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java 2009-12-28
15:44:24 UTC (rev 1219)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java 2009-12-28
16:12:42 UTC (rev 1220)
@@ -18,7 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
-import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
@@ -37,7 +36,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
* @version $Id: MySQLConnectionFactory.java 34801 2009-07-31 15:44:50Z dkatayev $
*/
-public class MySQLConnectionFactory extends GenericConnectionFactory
+public class MySQLConnectionFactory extends GenericCQConnectionFactory
{
/**
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OracleConnectionFactory.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OracleConnectionFactory.java
(rev 0)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OracleConnectionFactory.java 2009-12-28
16:12:42 UTC (rev 1220)
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This 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 software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.util.Properties;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 23.03.2007
+ *
+ * Access Oracle implicit connection caching and pooling stuff using reflection to
prevent Maven
+ * dependecies on ora drivers from POM.
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
+ * @version $Id: OracleConnectionFactory.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class OracleConnectionFactory extends GenericCQConnectionFactory
+{
+
+ public static int CONNCACHE_MAX_LIMIT = 25;
+
+ public static int CONNCACHE_MIN_LIMIT = 2;
+
+ public static int CONNCACHE_INACTIVITY_TIMEOUT = 3600;
+
+ public static int CONNCACHE_ABADONDED_TIMEOUT = 1800;
+
+ protected final Object ociDataSource;
+
+ /**
+ * OracleConnectionFactory constructor. For CLI interface ONLY!
+ *
+ * @param dbDriver
+ * - JDBC Driver
+ * @param dbUrl
+ * - JDBC URL
+ * @param dbUserName
+ * - database username
+ * @param dbPassword
+ * - database user password
+ * @param containerName
+ * - Container name (see configuration)
+ * @param multiDb
+ * - multidatabase state flag
+ * @param valueStorageProvider
+ * - external Value Storages provider
+ * @param maxBufferSize
+ * - Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * - Swap directory (see configuration)
+ * @param swapCleaner
+ * - Swap cleaner (internal FileCleaner).
+ * @throws RepositoryException
+ * if error occurs
+ */
+ public OracleConnectionFactory(String dbDriver, String dbUrl, String dbUserName,
String dbPassword,
+ String containerName, boolean multiDb, ValueStoragePluginProvider
valueStorageProvider, int maxBufferSize,
+ File swapDirectory, FileCleaner swapCleaner) throws RepositoryException
+ {
+
+ // ;D:\Devel\oracle_instantclient_10_2\;C:\oracle\ora92\bin;
+
+ /*
+ * ERROR: if no oci in path and oci url requested Error:
+ * java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException at
+ * sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
+ *
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
+ * at
+ *
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl
+ * .java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at
+ * ocipool.ConnPoolAppl.main(ConnPoolAppl.java:58) Caused by:
java.lang.UnsatisfiedLinkError: no
+ * ocijdbc10 in java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
+ * ---------------------------------------------------------------------------
ERROR: if thin
+ * url used and trying obtain oci data source
java.lang.reflect.InvocationTargetException at
+ * sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
+ *
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
+ * at
+ *
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl
+ * .java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at
+ * ocipool.ConnPoolAppl.main(ConnPoolAppl.java:58) Caused by:
java.lang.ClassCastException:
+ * oracle.jdbc.driver.T4CConnection at
+ * oracle.jdbc.pool.OracleOCIConnectionPool.createConnectionPool
+ * (OracleOCIConnectionPool.java:893)
+ */
+
+ super(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize,
+ swapDirectory, swapCleaner);
+
+ Object cds = null;
+ try
+ {
+ Class cdsClass =
OracleConnectionFactory.class.getClassLoader().loadClass("oracle.jdbc.pool.OracleDataSource");
+ Constructor cdsConstructor = cdsClass.getConstructor(new Class[]{});
+ cds = cdsConstructor.newInstance(new Object[]{});
+
+ // set cache properties
+ Properties prop = new java.util.Properties();
+ prop.setProperty("InitialLimit",
String.valueOf(CONNCACHE_MIN_LIMIT));
+ prop.setProperty("MinLimit", String.valueOf(CONNCACHE_MIN_LIMIT));
+ prop.setProperty("MaxLimit", String.valueOf(CONNCACHE_MAX_LIMIT));
+ prop.setProperty("InactivityTimeout",
String.valueOf(CONNCACHE_INACTIVITY_TIMEOUT));
+ prop.setProperty("AbandonedConnectionTimeout",
String.valueOf(CONNCACHE_ABADONDED_TIMEOUT));
+
+ Method setURL = cds.getClass().getMethod("setURL", new
Class[]{String.class});
+ setURL.invoke(cds, new Object[]{this.dbUrl});
+
+ Method setUser = cds.getClass().getMethod("setUser", new
Class[]{String.class});
+ setUser.invoke(cds, new Object[]{this.dbUserName});
+
+ Method setPassword = cds.getClass().getMethod("setPassword", new
Class[]{String.class});
+ setPassword.invoke(cds, new Object[]{this.dbPassword});
+
+ Method setConnectionCachingEnabled =
+ cds.getClass().getMethod("setConnectionCachingEnabled", new
Class[]{boolean.class});
+ setConnectionCachingEnabled.invoke(cds, new Object[]{true});
+
+ Method setConnectionCacheProperties =
+ cds.getClass().getMethod("setConnectionCacheProperties", new
Class[]{Properties.class});
+ setConnectionCacheProperties.invoke(cds, new Object[]{prop});
+
+ Method setConnectionCacheName =
cds.getClass().getMethod("setConnectionCacheName", new Class[]{String.class});
+ setConnectionCacheName.invoke(cds, new Object[]{"EXOJCR_OCI__" +
containerName});
+
+ }
+ catch (Throwable e)
+ {
+ cds = null;
+ String err = "Oracle OCI connection cache is unavailable due to error
" + e;
+ if (e.getCause() != null)
+ {
+ err += " (" + e.getCause() + ")";
+ }
+ err += ". Standard JDBC DriverManager will be used for connections
opening.";
+ if (log.isDebugEnabled())
+ log.warn(err, e);
+ else
+ log.warn(err);
+ }
+ this.ociDataSource = cds; // actually instance of javax.sql.DataSource
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Connection getJdbcConnection(boolean readOnly) throws RepositoryException
+ {
+ if (ociDataSource != null)
+ try
+ {
+ Connection conn = getCachedConnection();
+
+ if (readOnly) // set this feature only if it asked
+ conn.setReadOnly(true);
+
+ return conn;
+ }
+ catch (Throwable e)
+ {
+ throw new RepositoryException("Oracle OCI cached connection open error
" + e, e);
+ }
+
+ return super.getJdbcConnection(readOnly);
+ }
+
+ /**
+ * Get CachedConnection.
+ *
+ * @return
+ * @throws NoSuchMethodException
+ * @throws IllegalArgumentException
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ protected Connection getCachedConnection() throws NoSuchMethodException,
IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException
+ {
+
+ // NOTE: ociDataSource - actually instance of javax.sql.DataSource
+ Method getConnection =
ociDataSource.getClass().getMethod("getConnection", new Class[]{});
+ Connection conn = (Connection)getConnection.invoke(ociDataSource, new Object[]{});
+
+ return conn;
+ }
+
+}
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OraclePoolConnectionFactory.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OraclePoolConnectionFactory.java
(rev 0)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/OraclePoolConnectionFactory.java 2009-12-28
16:12:42 UTC (rev 1220)
@@ -0,0 +1,240 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This 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 software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.util.Properties;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 16.03.2007
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
+ * @version $Id: OraclePoolConnectionFactory.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class OraclePoolConnectionFactory extends GenericCQConnectionFactory
+{
+
+ public static int CONNPOOL_MAX_LIMIT = 20;
+
+ public static int CONNPOOL_MIN_LIMIT = 2;
+
+ public static int CONNPOOL_INCREMENT = 1;
+
+ protected final Object ociPool;
+
+ /**
+ * OraclePoolConnectionFactory constructor. For CLI interface ONLY!
+ *
+ * @param dbDriver
+ * - JDBC Driver
+ * @param dbUrl
+ * - JDBC URL
+ * @param dbUserName
+ * - database username
+ * @param dbPassword
+ * - database user password
+ * @param containerName
+ * - Container name (see configuration)
+ * @param multiDb
+ * - multidatabase state flag
+ * @param valueStorageProvider
+ * - external Value Storages provider
+ * @param maxBufferSize
+ * - Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * - Swap directory (see configuration)
+ * @param swapCleaner
+ * - Swap cleaner (internal FileCleaner).
+ * @throws RepositoryException
+ * if error occurs
+ */
+ public OraclePoolConnectionFactory(String dbDriver, String dbUrl, String dbUserName,
String dbPassword,
+ String containerName, boolean multiDb, ValueStoragePluginProvider
valueStorageProvider, int maxBufferSize,
+ File swapDirectory, FileCleaner swapCleaner) throws RepositoryException
+ {
+
+ // ;D:\Devel\oracle_instantclient_10_2\;C:\oracle\ora92\bin;
+
+ /*
+ * ERROR: if no oci in path and oci url requested Error:
+ * java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException at
+ * sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
+ *
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
+ * at
+ *
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl
+ * .java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at
+ * ocipool.ConnPoolAppl.main(ConnPoolAppl.java:58) Caused by:
java.lang.UnsatisfiedLinkError: no
+ * ocijdbc10 in java.library.path at
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
+ * ---------------------------------------------------------------------------
ERROR: if thin
+ * url used and trying obtain oci data source
java.lang.reflect.InvocationTargetException at
+ * sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
+ *
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
+ * at
+ *
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl
+ * .java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at
+ * ocipool.ConnPoolAppl.main(ConnPoolAppl.java:58) Caused by:
java.lang.ClassCastException:
+ * oracle.jdbc.driver.T4CConnection at
+ * oracle.jdbc.pool.OracleOCIConnectionPool.createConnectionPool
+ * (OracleOCIConnectionPool.java:893)
+ */
+
+ super(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
valueStorageProvider, maxBufferSize,
+ swapDirectory, swapCleaner);
+
+ Object cpool = null;
+ try
+ {
+ Class cpoolClass =
+
OraclePoolConnectionFactory.class.getClassLoader().loadClass("oracle.jdbc.pool.OracleOCIConnectionPool");
+ Constructor cpoolConstructor =
+ cpoolClass.getConstructor(new Class[]{String.class, String.class,
String.class, Properties.class});
+
+ cpool = cpoolConstructor.newInstance(new Object[]{this.dbUserName,
this.dbPassword, this.dbUrl, null});
+ Method setConnectionCachingEnabled =
+ cpool.getClass().getMethod("setConnectionCachingEnabled", new
Class[]{boolean.class});
+ setConnectionCachingEnabled.invoke(cpool, new Object[]{true});
+ }
+ catch (Throwable e)
+ {
+ cpool = null;
+ String err = "Oracle OCI connection pool is unavailable due to error "
+ e;
+ if (e.getCause() != null)
+ {
+ err += " (" + e.getCause() + ")";
+ }
+ err += ". Standard JDBC DriverManager will be used for connections
opening.";
+ if (log.isDebugEnabled())
+ log.warn(err, e);
+ else
+ log.warn(err);
+ }
+ this.ociPool = cpool;
+
+ // configure using CONNPOOL_MAX_LIMIT, CONNPOOL_MIN_LIMIT, CONNPOOL_INCREMENT
+ try
+ {
+ reconfigure();
+ displayPoolConfig();
+ }
+ catch (Throwable e)
+ {
+ if (log.isDebugEnabled())
+ log.warn("Oracle OCI connection pool configuration error " + e,
e);
+ else
+ log.warn("Oracle OCI connection pool configuration error " + e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Connection getJdbcConnection(boolean readOnly) throws RepositoryException
+ {
+ if (ociPool != null)
+ try
+ {
+ Connection conn = getPoolConnection();
+
+ if (readOnly) // set this feature only if it asked
+ conn.setReadOnly(true);
+
+ return conn;
+ }
+ catch (Throwable e)
+ {
+ throw new RepositoryException("Oracle OCI pool connection open error
" + e, e);
+ }
+
+ return super.getJdbcConnection(readOnly);
+ }
+
+ /**
+ * getPoolConnection.
+ *
+ * @return
+ * @throws NoSuchMethodException
+ * @throws IllegalArgumentException
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ protected Connection getPoolConnection() throws NoSuchMethodException,
IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException
+ {
+ Method getConnection = ociPool.getClass().getMethod("getConnection", new
Class[]{});
+ return (Connection)getConnection.invoke(ociPool, new Object[]{});
+ }
+
+ protected void reconfigure() throws NoSuchMethodException, IllegalArgumentException,
IllegalAccessException,
+ InvocationTargetException, NoSuchFieldException
+ {
+ if (ociPool != null)
+ {
+ // Set up the initial pool configuration
+ Properties p1 = new Properties();
+ String minLimitName =
(String)ociPool.getClass().getField("CONNPOOL_MIN_LIMIT").get(null);
+ String maxLimitName =
(String)ociPool.getClass().getField("CONNPOOL_MAX_LIMIT").get(null);
+ String incrName =
(String)ociPool.getClass().getField("CONNPOOL_INCREMENT").get(null);
+
+ p1.put(minLimitName, Integer.toString(CONNPOOL_MIN_LIMIT));
+ p1.put(maxLimitName, Integer.toString(CONNPOOL_MAX_LIMIT));
+ p1.put(incrName, Integer.toString(CONNPOOL_INCREMENT));
+
+ // Enable the initial configuration
+ ociPool.getClass().getMethod("setPoolConfig", new
Class[]{Properties.class}).invoke(ociPool, new Object[]{p1});
+ }
+ }
+
+ /**
+ * Display the current status of the OracleOCIConnectionPool.
+ */
+ protected void displayPoolConfig() throws NoSuchMethodException,
IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException
+ {
+ if (ociPool != null)
+ {
+
+ log.info(" =========== Oracle OCI connection pool config ===========
");
+
+ log.info(" Min poolsize Limit:\t"
+ + ociPool.getClass().getMethod("getMinLimit", new
Class[]{}).invoke(ociPool, new Object[]{}));
+
+ log.info(" Max poolsize Limit:\t"
+ + ociPool.getClass().getMethod("getMaxLimit", new
Class[]{}).invoke(ociPool, new Object[]{}));
+
+ log.info(" PoolSize:\t\t\t"
+ + ociPool.getClass().getMethod("getPoolSize", new
Class[]{}).invoke(ociPool, new Object[]{}));
+
+ log.info(" ActiveSize:\t\t"
+ + ociPool.getClass().getMethod("getActiveSize", new
Class[]{}).invoke(ociPool, new Object[]{}));
+ }
+ }
+
+}