Author: rmannibucau Date: Wed Apr 16 18:11:32 2014 New Revision: 1588008 URL: http://svn.apache.org/r1588008 Log: TOMEE-1179 support custom datasource with properties without setters + skipping wrapping when not needed - no pooling
Added: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/SimpleDataSourceCreator.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java?rev=1588008&r1=1588007&r2=1588008&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/DataSourceFactory.java Wed Apr 16 18:11:32 2014 @@ -59,6 +59,7 @@ public class DataSourceFactory { private static final Map<CommonDataSource, DataSourceCreator> creatorByDataSource = new HashMap<CommonDataSource, DataSourceCreator>(); private static final Map<String, String> KNOWN_CREATORS = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) {{ + put("simple", "org.apache.openejb.resource.jdbc.SimpleDataSourceCreator"); // use user provided DS, pooling not supported put("dbcp", "org.apache.openejb.resource.jdbc.pool.DefaultDataSourceCreator"); // the original one put("dbcp-alternative", "org.apache.openejb.resource.jdbc.dbcp.DbcpDataSourceCreator"); // dbcp for the ds pool only put("tomcat", "org.apache.tomee.jdbc.TomEEDataSourceCreator"); // tomee @@ -120,6 +121,7 @@ public class DataSourceFactory { recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES); recipe.allow(Option.IGNORE_MISSING_PROPERTIES); recipe.allow(Option.NAMED_PARAMETERS); + recipe.allow(Option.PRIVATE_PROPERTIES); recipe.setAllProperties(properties); if (!properties.containsKey("url") && properties.containsKey("JdbcUrl")) { // depend on the datasource class so add all well known keys recipe.setProperty("url", properties.getProperty("JdbcUrl")); @@ -252,7 +254,18 @@ public class DataSourceFactory { } private static boolean usePool(final Properties properties) { - return "true".equalsIgnoreCase(properties.getProperty(POOL_PROPERTY, "true")); + String property = properties.getProperty(POOL_PROPERTY); + if (property != null) { + properties.remove(POOL_PROPERTY); + } else { // defined from @DataSourceDefinition and doesn't need pooling + final String initialPoolSize = properties.getProperty("initialPoolSize"); + final String maxPoolSize = properties.getProperty("maxPoolSize"); + if ((null == initialPoolSize || "-1".equals(initialPoolSize)) + && ("-1".equals(maxPoolSize) || maxPoolSize == null)) { + property = "false"; + } + } + return "true".equalsIgnoreCase(property) || null == property; } private static Properties asProperties(final String definition) throws IOException { Added: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/SimpleDataSourceCreator.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/SimpleDataSourceCreator.java?rev=1588008&view=auto ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/SimpleDataSourceCreator.java (added) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/resource/jdbc/SimpleDataSourceCreator.java Wed Apr 16 18:11:32 2014 @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.openejb.resource.jdbc; + +import org.apache.openejb.OpenEJB; +import org.apache.openejb.resource.XAResourceWrapper; +import org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource; +import org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource; +import org.apache.openejb.resource.jdbc.pool.DataSourceCreator; +import org.apache.xbean.recipe.ObjectRecipe; + +import javax.sql.CommonDataSource; +import javax.sql.DataSource; +import javax.sql.XADataSource; +import javax.transaction.TransactionManager; +import java.util.Properties; + +public class SimpleDataSourceCreator implements DataSourceCreator { + @Override + public DataSource managed(final String name, final CommonDataSource ds) { + final TransactionManager transactionManager = OpenEJB.getTransactionManager(); + if (XADataSource.class.isInstance(ds)) { + return new ManagedXADataSource(XADataSource.class.cast(ds), transactionManager); + } + return new ManagedDataSource(DataSource.class.cast(ds), transactionManager); + } + + @Override + public DataSource poolManaged(final String name, final DataSource ds, final Properties properties) { + throw new UnsupportedOperationException("pooling not supported"); + } + + @Override + public DataSource pool(final String name, final DataSource ds, final Properties properties) { + throw new UnsupportedOperationException("pooling not supported"); + } + + @Override + public DataSource poolManagedWithRecovery(final String name, final XAResourceWrapper xaResourceWrapper, + final String driver, final Properties properties) { + throw new UnsupportedOperationException("pooling not supported"); + } + + @Override + public DataSource poolManaged(final String name, final String driver, final Properties properties) { + throw new UnsupportedOperationException("pooling not supported"); + } + + @Override + public CommonDataSource pool(final String name, final String driver, final Properties properties) { + throw new UnsupportedOperationException("pooling not supported"); + } + + @Override + public void destroy(final Object object) throws Throwable { + // no-op + } + + @Override + public ObjectRecipe clearRecipe(final Object object) { + return null; + } +}