:libraries:sql refine
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/0e984740 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/0e984740 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/0e984740 Branch: refs/heads/develop Commit: 0e984740dffff1e984182adf96988d5c88caba1c Parents: 89439fe Author: Paul Merlin <[email protected]> Authored: Mon May 15 10:08:28 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Mon May 15 10:08:28 2017 +0200 ---------------------------------------------------------------------- .../polygene/library/sql/common/Databases.java | 159 ------------------- .../AbstractDataSourceServiceImporterMixin.java | 3 +- .../sql/datasource/DataSourceConfiguration.java | 3 +- .../DataSourceConfigurationManagerService.java | 2 - 4 files changed, 3 insertions(+), 164 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0e984740/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/Databases.java ---------------------------------------------------------------------- diff --git a/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/Databases.java b/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/Databases.java deleted file mode 100644 index 7710444..0000000 --- a/libraries/sql/src/main/java/org/apache/polygene/library/sql/common/Databases.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.polygene.library.sql.common; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import javax.sql.DataSource; -import org.apache.polygene.api.util.Visitor; - -/** - * Utility methods for performing SQL calls wrapping a given DataSource. - */ -// TODO Remove me! -public class Databases -{ - DataSource source; - - /** - * Create a new Databases wrapper for a given DataSource. - */ - public Databases( DataSource source ) - { - this.source = source; - } - - /** - * Perform SQL update statement. - */ - public int update( String sql ) - throws SQLException - { - Connection connection = null; - PreparedStatement stmt = null; - try - { - connection = source.getConnection(); - stmt = connection.prepareStatement( sql ); - return stmt.executeUpdate(); - } - finally - { - SQLUtil.closeQuietly( stmt ); - SQLUtil.closeQuietly( connection ); - } - } - - /** - * Perform SQL update statement. - * - * If the SQL string contains ? placeholders, use the StatementVisitor to - * update the PreparedStatement with actual values. - */ - public int update( String sql, StatementVisitor visitor ) - throws SQLException - { - Connection connection = null; - PreparedStatement stmt = null; - try - { - connection = source.getConnection(); - stmt = connection.prepareStatement( sql ); - visitor.visit( stmt ); - return stmt.executeUpdate(); - } - finally - { - SQLUtil.closeQuietly( stmt ); - SQLUtil.closeQuietly( connection ); - } - } - - /** - * Perform SQL query and let visitor handle results. - */ - public void query( String sql, ResultSetVisitor visitor ) - throws SQLException - { - query( sql, null, visitor ); - } - - /** - * Perform SQL query and let visitor handle results. - * - * If the SQL string contains ? placeholders, use the StatementVisitor to - * update the PreparedStatement with actual values. - */ - public void query( String sql, StatementVisitor statementVisitor, ResultSetVisitor resultSetVisitor ) - throws SQLException - { - Connection connection = null; - PreparedStatement statement = null; - ResultSet resultSet = null; - try - { - connection = source.getConnection(); - statement = connection.prepareStatement( sql ); - if( statementVisitor != null ) - { - statementVisitor.visit( statement ); - } - resultSet = statement.executeQuery(); - while( resultSet.next() ) - { - if( !resultSetVisitor.visit( resultSet ) ) - { - return; - } - } - resultSet.close(); - } - finally - { - SQLUtil.closeQuietly( resultSet ); - SQLUtil.closeQuietly( statement ); - SQLUtil.closeQuietly( connection ); - } - } - - /** - * Visitor for PreparedStatements. - * - * These are created when the SQL statements contain ? placeholders. - */ - public interface StatementVisitor - { - void visit( PreparedStatement preparedStatement ) - throws SQLException; - } - - /** - * Visitor for the ResultSet. - * - * Only access data from the given ResultSet, as the iteration will be done - * by this API. - */ - public interface ResultSetVisitor - extends Visitor<ResultSet, SQLException> - { - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0e984740/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/AbstractDataSourceServiceImporterMixin.java ---------------------------------------------------------------------- diff --git a/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/AbstractDataSourceServiceImporterMixin.java b/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/AbstractDataSourceServiceImporterMixin.java index 054f068..37e740e 100644 --- a/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/AbstractDataSourceServiceImporterMixin.java +++ b/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/AbstractDataSourceServiceImporterMixin.java @@ -25,6 +25,7 @@ import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.sql.DataSource; +import org.apache.polygene.api.composite.Composite; import org.apache.polygene.api.composite.PropertyMapper; import org.apache.polygene.api.entity.EntityBuilder; import org.apache.polygene.api.identity.Identity; @@ -142,7 +143,7 @@ public abstract class AbstractDataSourceServiceImporterMixin<PooledDataSourceTyp InputStream asStream = DataSourceConfiguration.class.getClassLoader().getResourceAsStream( s ); if ( asStream != null ) { try { - PropertyMapper.map( asStream, configBuilder.instance() ); + PropertyMapper.map( asStream, (Composite) configBuilder.instance() ); } catch ( IOException e1 ) { uow.discard(); InstantiationException exception = new InstantiationException( "Could not read underlying Properties file." ); http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0e984740/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/DataSourceConfiguration.java ---------------------------------------------------------------------- diff --git a/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/DataSourceConfiguration.java b/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/DataSourceConfiguration.java index 1a44a35..93a27df 100644 --- a/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/DataSourceConfiguration.java +++ b/libraries/sql/src/main/java/org/apache/polygene/library/sql/datasource/DataSourceConfiguration.java @@ -19,13 +19,12 @@ */ package org.apache.polygene.library.sql.datasource; -import org.apache.polygene.api.composite.Composite; import org.apache.polygene.api.identity.HasIdentity; /** * Configuration Entity for a DataSource. */ public interface DataSourceConfiguration - extends HasIdentity, Composite, DataSourceConfigurationState + extends HasIdentity, DataSourceConfigurationState { } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0e984740/libraries/sql/src/main/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerService.java ---------------------------------------------------------------------- diff --git a/libraries/sql/src/main/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerService.java b/libraries/sql/src/main/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerService.java index 0b56f0f..777d419 100644 --- a/libraries/sql/src/main/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerService.java +++ b/libraries/sql/src/main/java/org/apache/polygene/library/sql/jmx/DataSourceConfigurationManagerService.java @@ -54,7 +54,6 @@ import org.apache.polygene.api.injection.scope.Service; import org.apache.polygene.api.injection.scope.Structure; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.property.Property; -import org.apache.polygene.api.service.ServiceComposite; import org.apache.polygene.api.service.ServiceImporter; import org.apache.polygene.api.service.ServiceReference; import org.apache.polygene.api.structure.Application; @@ -72,7 +71,6 @@ import org.apache.polygene.spi.PolygeneSPI; @Mixins( DataSourceConfigurationManagerService.Mixin.class ) @Activators( DataSourceConfigurationManagerService.Activator.class ) public interface DataSourceConfigurationManagerService - extends ServiceComposite { void exportDataSources()
