Finish jooq & liquibase powered SQL ES POLYGENE-153
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/7a9789e6 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/7a9789e6 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/7a9789e6 Branch: refs/heads/serialization-3.0 Commit: 7a9789e61618b54d95e9aaa7a2049a9b588e9372 Parents: cc0210a Author: Paul Merlin <[email protected]> Authored: Mon Feb 27 14:03:36 2017 +0100 Committer: Paul Merlin <[email protected]> Committed: Sun Apr 2 19:16:23 2017 +0200 ---------------------------------------------------------------------- extensions/entitystore-sql/build.gradle | 9 +- extensions/entitystore-sql/src/docs/es-sql.txt | 14 +- .../sql/SQLMapEntityStoreConfiguration.java | 47 +++ .../sql/SQLMapEntityStoreMapping.java | 69 ---- .../entitystore/sql/SQLMapEntityStoreMixin.java | 124 +++---- .../sql/SQLMapEntityStoreService.java | 4 +- .../AbstractSQLMapEntityStoreAssembler.java | 42 ++- .../sql/internal/DatabaseSQLService.java | 96 ------ .../internal/DatabaseSQLServiceCoreMixin.java | 159 --------- .../sql/internal/DatabaseSQLServiceSpi.java | 81 ----- .../sql/internal/DatabaseSQLServiceState.java | 33 -- .../DatabaseSQLServiceStatementsMixin.java | 113 ------- .../sql/internal/DatabaseSQLStringsBuilder.java | 325 ------------------- .../DerbySQLDatabaseSQLServiceMixin.java | 67 ---- .../internal/H2SQLDatabaseSQLServiceMixin.java | 64 ---- .../internal/MySQLDatabaseSQLServiceMixin.java | 68 ---- .../PostgreSQLDatabaseSQLServiceMixin.java | 64 ---- .../internal/PostgreSQLStringBuilderMixin.java | 45 --- .../sql/internal/SQLEntityState.java | 189 ----------- .../internal/SQLiteDatabaseSQLServiceMixin.java | 66 ---- .../polygene/entitystore/sql/internal/SQLs.java | 29 -- .../entitystore/sql/internal/package.html | 24 -- .../polygene/entitystore/sql/changelog.xml | 37 +++ .../sql/DerbySQLEntityStoreTest.java | 17 +- .../entitystore/sql/MySQLEntityStoreTest.java | 14 +- .../sql/PostgreSQLEntityStoreTest.java | 12 +- .../entitystore/sql/SQLiteEntityStoreTest.java | 3 +- .../test/resources/mysql-datasource.properties | 2 +- .../sql/SQLIndexingEngineConfiguration.java | 31 ++ .../AbstractSQLIndexQueryAssembler.java | 4 +- .../support/skeletons/AbstractSQLStartup.java | 13 +- .../postgresql/PostgreSQLDBIntegrityTest.java | 6 +- libraries/sql-liquibase/build.gradle | 4 +- .../sql/liquibase/LiquibaseAssembler.java | 16 +- .../sql/liquibase/LiquibaseConfiguration.java | 12 +- .../library/sql/liquibase/LiquibaseService.java | 133 ++++---- .../sql/liquibase/LiquibaseServiceTest.java | 7 +- .../library/sql/common/SQLConfiguration.java | 4 - ...taSourceConfigurationManagerServiceTest.java | 18 +- .../apache/polygene/sample/sqlsupport/Main.java | 8 - .../sql/DerbySQLEntityStorePerformanceTest.java | 35 +- .../PostgreSQLEntityStorePerformanceTest.java | 34 +- 42 files changed, 373 insertions(+), 1769 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/build.gradle ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/build.gradle b/extensions/entitystore-sql/build.gradle index 7d2368a..223e85b 100644 --- a/extensions/entitystore-sql/build.gradle +++ b/extensions/entitystore-sql/build.gradle @@ -29,23 +29,16 @@ dependencies { api polygene.library( 'sql' ) api libraries.jooq - implementation libraries.slf4j_api implementation polygene.library( 'sql-liquibase' ) - // TODO Remove java SQL generator dependency - implementation libraries.javaSqlGenerator - implementation( libraries.javaSqlGeneratorImpl ) { - exclude group: 'junit' - } - runtimeOnly polygene.core.runtime testImplementation polygene.internals.testsupport testImplementation polygene.library( 'sql-dbcp' ) - testImplementation libraries.derby // Needed at compile time for polite test shutdown testImplementation libraries.docker_junit testRuntimeOnly libraries.logback + testRuntimeOnly libraries.derby testRuntimeOnly libraries.h2 testRuntimeOnly libraries.mysql_connector testRuntimeOnly libraries.postgres http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/docs/es-sql.txt ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/docs/es-sql.txt b/extensions/entitystore-sql/src/docs/es-sql.txt index 50e9f31..90a7175 100644 --- a/extensions/entitystore-sql/src/docs/es-sql.txt +++ b/extensions/entitystore-sql/src/docs/es-sql.txt @@ -30,6 +30,8 @@ EntityStore service backed by a SQL database. This extension fully leverage the <<library-sql>> meaning that you must use it to assemble your DataSource and that you get <<library-circuitbreaker,Circuit Breaker>> and <<library-jmx, JMX>> integration for free. +The database schema is managed using <<library-sql-liquibase>>. + TIP: See the <<sample-sql-support>> that demonstrate combined use of <<library-sql>>, <<extension-es-sql>> and <<extension-indexing-sql>>. @@ -44,15 +46,17 @@ The following SQL databases are supported: Each entity state is stored as a single row so maximum number of entities is the maximum number of rows per table supported by the underlying SQL database. -Implementations per database Vendor share a generic codebase but can override about everything SQL. As a consequence -they can have strong differences in terms of performance if they use vendor specific extensions. - include::../../build/docs/buildinfo/artifact.txt[] == Configuration == -SQL EntityStore Configuration is optional and provides only one configuration property: `schemaName` defaulted to -'polygene_es'. On SQL databases that don't support schemas this configuration property is simply ignored. +Here are the available configuration properties: + +[snippet,java] +---- +source=extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreConfiguration.java +tag=assembly +---- The assembly snippets below show the DataSource assembly alongside the SQL EntityStore assembly. Remember to configure the DataSource properly, see <<library-sql>> and <<howto-configure-service>>. http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreConfiguration.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreConfiguration.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreConfiguration.java new file mode 100644 index 0000000..cd832c0 --- /dev/null +++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreConfiguration.java @@ -0,0 +1,47 @@ +/* + * 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.entitystore.sql; + +import org.apache.polygene.api.common.UseDefaults; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.library.sql.common.SQLConfiguration; + +// START SNIPPET: config +public interface SQLMapEntityStoreConfiguration extends SQLConfiguration +{ + /** + * Name of the database schema to use. + * Ignored on SQL databases that don't support schemas. + */ + @UseDefaults( "POLYGENE_ES" ) + @Override + Property<String> schemaName(); + + /** + * Name of the entities table. + */ + @UseDefaults( "POLYGENE_ENTITIES" ) + Property<String> entityTableName(); + + /** + * Defines whether the database schema and table should be created if not already present. + */ + @UseDefaults( "true" ) + Property<Boolean> createIfMissing(); +} +// END SNIPPET: config http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMapping.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMapping.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMapping.java deleted file mode 100644 index 67f6066..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMapping.java +++ /dev/null @@ -1,69 +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.entitystore.sql; - -import org.jooq.DataType; -import org.jooq.impl.SQLDataType; - -/** - * Mapping for the entities table. - * - * If you change this once the table is created you'll have to ALTER it yourself. - */ -public interface SQLMapEntityStoreMapping -{ - default String defaultSchemaName() - { - return "POLYGENE_ES"; - } - - default String tableName() - { - return "POLYGENE_ENTITIES"; - } - - default String identityColumnName() - { - return "ENTITY_IDENTITY"; - } - - default String versionColumnName() - { - return "ENTITY_VERSION"; - } - - default String stateColumnName() - { - return "ENTITY_STATE"; - } - - default DataType<String> identityDataType() - { - return SQLDataType.VARCHAR( 64 ); - } - - default DataType<String> versionDataType() - { - return SQLDataType.VARCHAR( 64 ); - } - - default DataType<String> stateDataType() - { - return SQLDataType.VARCHAR( 10 * 1024 ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java index 7e08daf..77a7640 100644 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java +++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java @@ -22,13 +22,17 @@ import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.stream.Stream; import javax.json.Json; import javax.sql.DataSource; -import org.apache.polygene.api.common.Optional; +import liquibase.Contexts; +import liquibase.Liquibase; +import liquibase.database.Database; +import liquibase.database.ObjectQuotingStrategy; +import liquibase.exception.LiquibaseException; import org.apache.polygene.api.configuration.Configuration; import org.apache.polygene.api.entity.EntityDescriptor; import org.apache.polygene.api.entity.EntityReference; @@ -37,9 +41,8 @@ import org.apache.polygene.api.injection.scope.This; import org.apache.polygene.api.injection.scope.Uses; import org.apache.polygene.api.service.ServiceActivation; import org.apache.polygene.api.service.ServiceDescriptor; -import org.apache.polygene.library.sql.common.SQLConfiguration; +import org.apache.polygene.library.sql.liquibase.LiquibaseService; import org.apache.polygene.spi.entitystore.EntityNotFoundException; -import org.apache.polygene.spi.entitystore.EntityStoreException; import org.apache.polygene.spi.entitystore.helpers.JSONKeys; import org.apache.polygene.spi.entitystore.helpers.MapEntityStore; import org.jooq.DSLContext; @@ -51,26 +54,27 @@ import org.jooq.Schema; import org.jooq.Table; import org.jooq.conf.Settings; import org.jooq.impl.DSL; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -// TODO Implement optimistic locking! Maybe as a SPI helper (in-progress) -// TODO Add schema version data into the DB, check it -// TODO Remove old SQL ES Code +// TODO Remove old SQL ES Code and spurious dependencies public class SQLMapEntityStoreMixin implements ServiceActivation, MapEntityStore { - private static final Logger LOGGER = LoggerFactory.getLogger( SQLMapEntityStoreService.class ); + private static final String TABLE_NAME_LIQUIBASE_PARAMETER = "es-sql.table"; + private static final String IDENTITY_COLUMN_NAME = "ENTITY_IDENTITY"; + private static final String VERSION_COLUMN_NAME = "ENTITY_VERSION"; + private static final String STATE_COLUMN_NAME = "ENTITY_STATE"; @Service private DataSource dataSource; + @Service + private LiquibaseService liquibaseService; + @Uses private ServiceDescriptor descriptor; @This - @Optional - private Configuration<SQLConfiguration> configuration; + private Configuration<SQLMapEntityStoreConfiguration> configuration; private Schema schema; private Table<Record> table; @@ -82,40 +86,64 @@ public class SQLMapEntityStoreMixin @Override public void activateService() throws Exception { + configuration.refresh(); + SQLMapEntityStoreConfiguration config = configuration.get(); + + // Prepare jooq DSL SQLDialect dialect = descriptor.metaInfo( SQLDialect.class ); Settings settings = descriptor.metaInfo( Settings.class ); - SQLMapEntityStoreMapping mapping = descriptor.metaInfo( SQLMapEntityStoreMapping.class ); - String schemaName = getConfiguredSchemaName( mapping.defaultSchemaName() ); - if( schemaName == null ) - { - throw new EntityStoreException( "Schema name must not be null." ); - } - schema = DSL.schema( DSL.name( schemaName.toUpperCase() ) ); + String schemaName = config.schemaName().get(); + String tableName = config.entityTableName().get(); + schema = DSL.schema( DSL.name( schemaName ) ); table = DSL.table( dialect.equals( SQLDialect.SQLITE ) - ? DSL.name( mapping.tableName() ) - : DSL.name( schema.getName(), mapping.tableName() ) + ? DSL.name( tableName ) + : DSL.name( schema.getName(), tableName ) ); - identityColumn = DSL.field( mapping.identityColumnName(), String.class ); - versionColumn = DSL.field( mapping.versionColumnName(), String.class ); - stateColumn = DSL.field( mapping.stateColumnName(), String.class ); - + identityColumn = DSL.field( DSL.name( IDENTITY_COLUMN_NAME ), String.class ); + versionColumn = DSL.field( DSL.name( VERSION_COLUMN_NAME ), String.class ); + stateColumn = DSL.field( DSL.name( STATE_COLUMN_NAME ), String.class ); dsl = DSL.using( dataSource, dialect, settings ); - if( !dialect.equals( SQLDialect.SQLITE ) - && dsl.meta().getSchemas().stream().noneMatch( s -> schema.getName().equals( s.getName() ) ) ) + // Eventually create schema and apply Liquibase changelog + if( config.createIfMissing().get() ) { - dsl.createSchema( schema ).execute(); + if( !dialect.equals( SQLDialect.SQLITE ) + && dsl.meta().getSchemas().stream().noneMatch( s -> schema.getName().equalsIgnoreCase( s.getName() ) ) ) + { + dsl.createSchema( schema ).execute(); + } + + applyLiquibaseChangelog( dialect ); } + } - if( dsl.meta().getTables().stream().noneMatch( t -> table.getName().equals( t.getName() ) ) ) + private void applyLiquibaseChangelog( SQLDialect dialect ) throws SQLException, LiquibaseException + { + Liquibase liquibase = liquibaseService.newConnectedLiquibase(); + Database db = liquibase.getDatabase(); + db.setObjectQuotingStrategy( ObjectQuotingStrategy.QUOTE_ALL_OBJECTS ); + try { - dsl.createTable( table ) - .column( identityColumn, mapping.identityDataType().nullable( false ) ) - .column( versionColumn, mapping.versionDataType().nullable( false ) ) - .column( stateColumn, mapping.stateDataType().nullable( false ) ) - .constraint( DSL.constraint( "ENTITY_IDENTITY_CONSTRAINT" ).primaryKey( identityColumn ) ) - .execute(); + if( !dialect.equals( SQLDialect.SQLITE ) ) + { + if( db.supportsSchemas() ) + { + db.setDefaultSchemaName( schema.getName() ); + db.setLiquibaseSchemaName( schema.getName() ); + } + if( db.supportsCatalogs() ) + { + db.setDefaultCatalogName( schema.getName() ); + db.setLiquibaseCatalogName( schema.getName() ); + } + } + liquibase.getChangeLogParameters().set( TABLE_NAME_LIQUIBASE_PARAMETER, table.getName() ); + liquibase.update( new Contexts() ); + } + finally + { + db.close(); } } @@ -210,30 +238,4 @@ public class SQLMapEntityStoreMixin } ); dsl.batch( operations ).execute(); } - - - /** - * Configuration is optional at both assembly and runtime. - */ - protected String getConfiguredSchemaName( String defaultSchemaName ) - { - if( configuration == null ) - { - Objects.requireNonNull( defaultSchemaName, "default schema name" ); - LOGGER.debug( "No configuration, will use default schema name: '{}'", defaultSchemaName ); - return defaultSchemaName; - } - String result = configuration.get().schemaName().get(); - if( result == null ) - { - Objects.requireNonNull( defaultSchemaName, "default schema name" ); - result = defaultSchemaName; - LOGGER.debug( "No database schema name in configuration, will use default: '{}'", defaultSchemaName ); - } - else - { - LOGGER.debug( "Will use configured database schema name: '{}'", result ); - } - return result; - } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreService.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreService.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreService.java index 0ff1e59..7c770df 100644 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreService.java +++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreService.java @@ -19,9 +19,10 @@ package org.apache.polygene.entitystore.sql; import org.apache.polygene.api.concern.Concerns; import org.apache.polygene.api.configuration.Configuration; +import org.apache.polygene.api.injection.scope.Uses; import org.apache.polygene.api.mixin.Mixins; import org.apache.polygene.api.service.ServiceActivation; -import org.apache.polygene.api.service.ServiceComposite; +import org.apache.polygene.api.service.ServiceDescriptor; import org.apache.polygene.spi.entitystore.ConcurrentModificationCheckConcern; import org.apache.polygene.spi.entitystore.EntityStateVersions; import org.apache.polygene.spi.entitystore.EntityStore; @@ -39,7 +40,6 @@ public interface SQLMapEntityStoreService JSONMapEntityStoreActivation, EntityStore, EntityStateVersions, - ServiceComposite, Configuration { } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/assembly/AbstractSQLMapEntityStoreAssembler.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/assembly/AbstractSQLMapEntityStoreAssembler.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/assembly/AbstractSQLMapEntityStoreAssembler.java index 4e205d1..aac6dfc 100644 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/assembly/AbstractSQLMapEntityStoreAssembler.java +++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/assembly/AbstractSQLMapEntityStoreAssembler.java @@ -22,10 +22,12 @@ import org.apache.polygene.api.identity.StringIdentity; import org.apache.polygene.bootstrap.Assemblers; import org.apache.polygene.bootstrap.AssemblyException; import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.entitystore.sql.SQLMapEntityStoreMapping; +import org.apache.polygene.entitystore.sql.SQLMapEntityStoreConfiguration; import org.apache.polygene.entitystore.sql.SQLMapEntityStoreService; -import org.apache.polygene.library.sql.common.SQLConfiguration; +import org.apache.polygene.library.sql.liquibase.LiquibaseAssembler; +import org.apache.polygene.library.sql.liquibase.LiquibaseConfiguration; import org.jooq.SQLDialect; +import org.jooq.conf.RenderNameStyle; import org.jooq.conf.Settings; /** @@ -35,6 +37,9 @@ public abstract class AbstractSQLMapEntityStoreAssembler<AssemblerType> extends Assemblers.VisibilityIdentityConfig<AssemblerType> { public static final Identity DEFAULT_ENTITYSTORE_IDENTITY = new StringIdentity( "entitystore-sql" ); + private static final String DEFAULT_CHANGELOG_PATH = "org/apache/polygene/entitystore/sql/changelog.xml"; + + private String changelogPath = DEFAULT_CHANGELOG_PATH; @Override public void assemble( ModuleAssembly module ) @@ -49,37 +54,44 @@ public abstract class AbstractSQLMapEntityStoreAssembler<AssemblerType> { throw new AssemblyException( "Settings must not be null" ); } - SQLMapEntityStoreMapping mapping = getMapping(); - if( settings == null ) + + String identity = ( hasIdentity() ? identity() : DEFAULT_ENTITYSTORE_IDENTITY ).toString(); + + LiquibaseAssembler liquibase = new LiquibaseAssembler().identifiedBy( identity + "-liquibase" ); + if( hasConfig() ) { - throw new AssemblyException( "SQLMapEntityStoreSchema must not be null" ); + liquibase.withConfig( configModule(), configVisibility() ); + LiquibaseConfiguration liquibaseconfig = configModule().forMixin( LiquibaseConfiguration.class ) + .declareDefaults(); + liquibaseconfig.changeLog().set( changelogPath ); } + liquibase.assemble( module ); module.services( SQLMapEntityStoreService.class ) - .identifiedBy( ( hasIdentity() ? identity() : DEFAULT_ENTITYSTORE_IDENTITY ).toString() ) + .identifiedBy( identity ) .visibleIn( visibility() ) .setMetaInfo( dialect ) - .setMetaInfo( settings ) - .setMetaInfo( mapping ); + .setMetaInfo( settings ); if( hasConfig() ) { - configModule().entities( SQLConfiguration.class ).visibleIn( configVisibility() ); + configModule().entities( SQLMapEntityStoreConfiguration.class ).visibleIn( configVisibility() ); } } - protected Settings getSettings() + public AssemblerType withLiquibaseChangelog( String changelogPath ) { - return new Settings(); + this.changelogPath = changelogPath; + return (AssemblerType) this; } - protected SQLDialect getSQLDialect() + protected Settings getSettings() { - return SQLDialect.DEFAULT; + return new Settings().withRenderNameStyle( RenderNameStyle.QUOTED ); } - protected SQLMapEntityStoreMapping getMapping() + protected SQLDialect getSQLDialect() { - return new SQLMapEntityStoreMapping() {}; + return SQLDialect.DEFAULT; } } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLService.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLService.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLService.java deleted file mode 100644 index fddb19f..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLService.java +++ /dev/null @@ -1,96 +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.entitystore.sql.internal; - -import java.io.Reader; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.polygene.api.entity.EntityReference; -import org.apache.polygene.api.service.ServiceComposite; - -@SuppressWarnings( "PublicInnerClass" ) -public interface DatabaseSQLService -{ - interface DatabaseSQLServiceComposite extends DatabaseSQLService, ServiceComposite - { - } - - final class EntityValueResult - { - private final Reader reader; - - EntityValueResult( Reader reader ) - { - this.reader = reader; - } - - /** - * @return the reader - */ - public Reader getReader() - { - return reader; - } - } - - void startDatabase() - throws Exception; - - void stopDatabase() - throws Exception; - - Connection getConnection() - throws SQLException; - - PreparedStatement prepareGetEntityStatement( Connection connection ) - throws SQLException; - - PreparedStatement prepareGetAllEntitiesStatement( Connection connection ) - throws SQLException; - - PreparedStatement prepareInsertEntityStatement( Connection connection ) - throws SQLException; - - PreparedStatement prepareUpdateEntityStatement( Connection connection ) - throws SQLException; - - PreparedStatement prepareRemoveEntityStatement( Connection connection ) - throws SQLException; - - void populateGetEntityStatement( PreparedStatement ps, EntityReference ref ) - throws SQLException; - - void populateGetAllEntitiesStatement( PreparedStatement ps ) - throws SQLException; - - void populateInsertEntityStatement( PreparedStatement ps, EntityReference ref, String entity ) - throws SQLException; - - void populateUpdateEntityStatement( PreparedStatement ps, EntityReference ref, String entity ) - throws SQLException; - - void populateRemoveEntityStatement( PreparedStatement ps, EntityReference ref ) - throws SQLException; - - Reader getEntityStateReader( ResultSet rs ) - throws SQLException; -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceCoreMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceCoreMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceCoreMixin.java deleted file mode 100644 index 3c37457..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceCoreMixin.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.entitystore.sql.internal; - -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Objects; -import javax.sql.DataSource; -import org.apache.polygene.api.configuration.Configuration; -import org.apache.polygene.api.injection.scope.Service; -import org.apache.polygene.api.injection.scope.Structure; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.api.injection.scope.Uses; -import org.apache.polygene.api.service.ServiceDescriptor; -import org.apache.polygene.api.structure.Application; -import org.apache.polygene.api.structure.Application.Mode; -import org.apache.polygene.library.sql.common.SQLConfiguration; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.apache.polygene.spi.entitystore.EntityStoreException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sql.generation.api.vendor.SQLVendor; - -@SuppressWarnings( "ProtectedField" ) -public abstract class DatabaseSQLServiceCoreMixin - implements DatabaseSQLService -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( DatabaseSQLServiceCoreMixin.class ); - - @Structure - private Application application; - - @Service - private DataSource dataSource; - - @This - private DatabaseSQLServiceState state; - - @This - protected DatabaseSQLServiceSpi spi; - - @This - private DatabaseSQLStringsBuilder sqlStrings; - - @Uses - private ServiceDescriptor descriptor; - - @This - private Configuration<SQLConfiguration> configuration; - - @Override - public Connection getConnection() - throws SQLException - { - return dataSource.getConnection(); - } - - @Override - public void startDatabase() - throws Exception - { - Connection connection = getConnection(); - String schema = this.getConfiguredSchemaName( SQLs.DEFAULT_SCHEMA_NAME ); - if ( schema == null ) { - throw new EntityStoreException( "Schema name must not be null." ); - } else { - state.schemaName().set( schema ); - state.vendor().set( this.descriptor.metaInfo( SQLVendor.class ) ); - - sqlStrings.init(); - - if ( !spi.schemaExists( connection ) ) { - LOGGER.debug( "Database Schema '{}' NOT found!", schema ); - Statement stmt = null; - try { - stmt = connection.createStatement(); - for ( String sql : sqlStrings.buildSQLForSchemaCreation() ) { - stmt.execute( sql ); - } - } finally { - SQLUtil.closeQuietly( stmt ); - } - LOGGER.debug( "Database Schema '{}' created", schema ); - } - - if ( !spi.tableExists( connection ) ) { - Statement stmt = null; - try { - stmt = connection.createStatement(); - for ( String sql : sqlStrings.buildSQLForTableCreation() ) { - stmt.execute( sql ); - } - for ( String sql : sqlStrings.buildSQLForIndexCreation() ) { - stmt.execute( sql ); - } - } finally { - SQLUtil.closeQuietly( stmt ); - } - LOGGER.trace( "Table {} created", SQLs.TABLE_NAME ); - } - - connection.setAutoCommit( false ); - - } - - SQLUtil.closeQuietly( connection ); - - } - - @Override - public void stopDatabase() - throws Exception - { - if ( Mode.production == application.mode() ) { - // NOOP - } - } - - /** - * Configuration is optional at both assembly and runtime. - */ - protected String getConfiguredSchemaName( String defaultSchemaName ) - { - if ( configuration == null ) { - Objects.requireNonNull( defaultSchemaName, "default schema name" ); - LOGGER.debug( "No configuration, will use default schema name: '{}'", defaultSchemaName ); - return defaultSchemaName; - } - String result = configuration.get().schemaName().get(); - if ( result == null ) { - Objects.requireNonNull( defaultSchemaName, "default schema name" ); - result = defaultSchemaName; - LOGGER.debug( "No database schema name in configuration, will use default: '{}'", defaultSchemaName ); - } else { - LOGGER.debug( "Will use configured database schema name: '{}'", result ); - } - return result; - } - -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceSpi.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceSpi.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceSpi.java deleted file mode 100644 index 9042182..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceSpi.java +++ /dev/null @@ -1,81 +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.entitystore.sql.internal; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public interface DatabaseSQLServiceSpi -{ - - boolean schemaExists( Connection connection ) - throws SQLException; - - String getCurrentSchemaName(); - - boolean tableExists( Connection connection ) - throws SQLException; - - @SuppressWarnings( "PublicInnerClass" ) - public abstract class CommonMixin - implements DatabaseSQLServiceSpi - { - - private static final Logger LOGGER = LoggerFactory.getLogger( DatabaseSQLServiceSpi.class ); - - @This - private DatabaseSQLServiceState state; - - @Override - public boolean schemaExists( Connection connection ) - throws SQLException - { - ResultSet rs = null; - try { - Boolean schemaFound = false; - rs = connection.getMetaData().getSchemas(); - String schemaName = this.getCurrentSchemaName(); - - while ( rs.next() && !schemaFound ) { - String eachResult = rs.getString( 1 ); - LOGGER.trace( "Schema candidate: {}", eachResult ); - schemaFound = eachResult.equalsIgnoreCase( schemaName ); - } - LOGGER.trace( "Schema {} found? {}", schemaName, schemaFound ); - return schemaFound; - } finally { - SQLUtil.closeQuietly( rs ); - } - } - - @Override - public String getCurrentSchemaName() - { - return this.state.schemaName().get(); - } - - } - -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceState.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceState.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceState.java deleted file mode 100644 index 3e3926d..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceState.java +++ /dev/null @@ -1,33 +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.entitystore.sql.internal; - -import org.apache.polygene.api.common.Optional; -import org.apache.polygene.api.property.Property; -import org.sql.generation.api.vendor.SQLVendor; - -public interface DatabaseSQLServiceState -{ - @Optional - Property<String> schemaName(); - - @Optional - Property<SQLVendor> vendor(); -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceStatementsMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceStatementsMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceStatementsMixin.java deleted file mode 100644 index cce4568..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLServiceStatementsMixin.java +++ /dev/null @@ -1,113 +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.entitystore.sql.internal; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import org.apache.polygene.api.entity.EntityReference; -import org.apache.polygene.api.injection.scope.This; - -public abstract class DatabaseSQLServiceStatementsMixin - implements DatabaseSQLService -{ - - @This - private DatabaseSQLStringsBuilder sqlStrings; - - // - // Used by the EntityStore, will probably remain the same even if we support several sql servers - // - @Override - public PreparedStatement prepareGetAllEntitiesStatement( Connection connection ) - throws SQLException - { - return connection.prepareStatement( sqlStrings.buildSQLForSelectAllEntitiesStatement() ); - } - - @Override - public PreparedStatement prepareGetEntityStatement( Connection connection ) - throws SQLException - { - return connection.prepareStatement( sqlStrings.buildSQLForSelectEntityStatement() ); - } - - @Override - public PreparedStatement prepareInsertEntityStatement( Connection connection ) - throws SQLException - { - return connection.prepareStatement( sqlStrings.buildSQLForInsertEntityStatement() ); - } - - @Override - public PreparedStatement prepareRemoveEntityStatement( Connection connection ) - throws SQLException - { - return connection.prepareStatement( sqlStrings.buildSQLForRemoveEntityStatement() ); - } - - @Override - public PreparedStatement prepareUpdateEntityStatement( Connection connection ) - throws SQLException - { - return connection.prepareStatement( sqlStrings.buildSQLForUpdateEntityStatement() ); - } - - // - // Populate statement methods, to move in a separated fragment if needed for multi sql server support - // - @Override - public void populateGetAllEntitiesStatement( PreparedStatement ps ) - throws SQLException - { - // Nothing to do. - } - - @Override - public void populateGetEntityStatement( PreparedStatement ps, EntityReference ref ) - throws SQLException - { - ps.setString( 1, ref.identity().toString() ); - } - - @Override - public void populateInsertEntityStatement( PreparedStatement ps, EntityReference ref, String entity ) - throws SQLException - { - ps.setString( 1, ref.identity().toString() ); - ps.setString( 2, entity ); - } - - @Override - public void populateRemoveEntityStatement( PreparedStatement ps, EntityReference ref ) - throws SQLException - { - ps.setString( 1, ref.identity().toString() ); - } - - @Override - public void populateUpdateEntityStatement( PreparedStatement ps, EntityReference ref, String entity ) - throws SQLException - { - ps.setString( 1, ref.identity().toString() ); - ps.setString( 2, entity ); - } - -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLStringsBuilder.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLStringsBuilder.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLStringsBuilder.java deleted file mode 100644 index 6fb04cb..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DatabaseSQLStringsBuilder.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with work for additional information - * regarding copyright ownership. The ASF licenses file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use 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.entitystore.sql.internal; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.apache.polygene.api.injection.scope.This; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sql.generation.api.grammar.builders.modification.DeleteBySearchBuilder; -import org.sql.generation.api.grammar.builders.modification.UpdateBySearchBuilder; -import org.sql.generation.api.grammar.common.SQLStatement; -import org.sql.generation.api.grammar.common.datatypes.SQLDataType; -import org.sql.generation.api.grammar.definition.table.UniqueSpecification; -import org.sql.generation.api.grammar.factories.BooleanFactory; -import org.sql.generation.api.grammar.factories.ColumnsFactory; -import org.sql.generation.api.grammar.factories.DefinitionFactory; -import org.sql.generation.api.grammar.factories.LiteralFactory; -import org.sql.generation.api.grammar.factories.ModificationFactory; -import org.sql.generation.api.grammar.factories.QueryFactory; -import org.sql.generation.api.grammar.factories.TableReferenceFactory; -import org.sql.generation.api.vendor.SQLVendor; - -public interface DatabaseSQLStringsBuilder -{ - void init(); - - String[] buildSQLForSchemaCreation(); - - String[] buildSQLForIndexCreation(); - - String[] buildSQLForTableCreation(); - - String buildSQLForSelectAllEntitiesStatement(); - - String buildSQLForSelectEntityStatement(); - - String buildSQLForInsertEntityStatement(); - - String buildSQLForUpdateEntityStatement(); - - String buildSQLForRemoveEntityStatement(); - - abstract class CommonMixin - implements DatabaseSQLStringsBuilder - { - private static final Logger LOGGER = LoggerFactory.getLogger( DatabaseSQLStringsBuilder.class ); - - @This - private DatabaseSQLServiceState dbState; - - private SQLVendor vendor; - private String schemaName; - - private String[] schemaCreationSQLs; - private String[] indexCreationSQLs; - private String[] tableCreationSQLs; - - private String selectAllEntitiesSQL; - private String selectEntitySQL; - private String insertEntitySQL; - private String updateEntitySQL; - private String removeEntitySQL; - - @Override - public void init() - { - vendor = dbState.vendor().get(); - schemaName = dbState.schemaName().get(); - schemaCreationSQLs = toString( createSchemaStatements( vendor ) ); - indexCreationSQLs = toString( createIndicesStatements( vendor ) ); - tableCreationSQLs = toString( createTableStatements( vendor ) ); - selectAllEntitiesSQL = vendor.toString( createSelectAllEntitiesStatement( vendor ) ); - selectEntitySQL = vendor.toString( createSelectEntityStatement( vendor ) ); - insertEntitySQL = vendor.toString( createInsertEntityStatement( vendor ) ); - updateEntitySQL = vendor.toString( createUpdateEntityStatement( vendor ) ); - removeEntitySQL = vendor.toString( createRemoveEntityStatement( vendor ) ); - - if( LOGGER.isTraceEnabled() ) - { - LOGGER.trace( "SQL for schema creation: {}", Arrays.asList( schemaCreationSQLs ) ); - LOGGER.trace( "SQL for index creation: {}", Arrays.asList( indexCreationSQLs ) ); - LOGGER.trace( "SQL for table creation: {}", Arrays.asList( tableCreationSQLs ) ); - LOGGER.trace( "SQL for select all entities: {}", selectAllEntitiesSQL ); - LOGGER.trace( "SQL for select entity: {}", selectEntitySQL ); - LOGGER.trace( "SQL for insert entity: {}", insertEntitySQL ); - LOGGER.trace( "SQL for update entity: {}", updateEntitySQL ); - LOGGER.trace( "SQL for remove entity: {}", removeEntitySQL ); - } - } - - protected String[] toString( SQLStatement[] stmts ) - { - List<String> result = new ArrayList<>(); - if( stmts != null ) - { - for( Integer idx = 0; idx < stmts.length; ++idx ) - { - SQLStatement statement = stmts[ idx ]; - if( statement != null ) - { - String stringStatement = vendor.toString( statement ); - if( stringStatement != null && stringStatement.length() > 0 ) - { - result.add( vendor.toString( statement ) ); - } - } - } - } - return result.toArray( new String[ result.size() ] ); - } - - protected SQLVendor getVendor() - { - return vendor; - } - - protected String getSchemaName() - { - return schemaName; - } - - protected SQLStatement[] createSchemaStatements( SQLVendor vendor ) - { - return new SQLStatement[] { - vendor.getDefinitionFactory().createSchemaDefinitionBuilder() - .setSchemaName( schemaName ).createExpression() - }; - } - - protected SQLStatement[] createIndicesStatements( SQLVendor vendor ) - { - return new SQLStatement[] {}; - } - - protected SQLStatement[] createTableStatements( SQLVendor vendor ) - { - DefinitionFactory d = vendor.getDefinitionFactory(); - TableReferenceFactory t = vendor.getTableReferenceFactory(); - - return new SQLStatement[] { - d.createTableDefinitionBuilder() - .setTableName( t.tableName( getSchemaName(), SQLs.TABLE_NAME ) ) - .setTableContentsSource( - d.createTableElementListBuilder() - .addTableElement( d.createColumnDefinition( SQLs.ENTITY_IDENTITY_COLUMN_NAME, - getIDType(), false ) ) - .addTableElement( d.createColumnDefinition( SQLs.ENTITY_VERSION_COLUMN_NAME, - getVersionType(), false ) ) - .addTableElement( d.createColumnDefinition( SQLs.ENTITY_STATE_COLUMN_NAME, - getStateType(), false ) ) - .addTableElement( d.createTableConstraintDefinition( - d.createUniqueConstraintBuilder() - .setUniqueness( UniqueSpecification.PRIMARY_KEY ) - .addColumns( SQLs.ENTITY_IDENTITY_COLUMN_NAME ) - .createExpression() ) - ).createExpression() - ).createExpression() - }; - } - - protected SQLStatement createSelectAllEntitiesStatement( SQLVendor vendor ) - { - QueryFactory q = vendor.getQueryFactory(); - TableReferenceFactory t = vendor.getTableReferenceFactory(); - - return q.simpleQueryBuilder() - .select( SQLs.ENTITY_STATE_COLUMN_NAME ) - .from( t.tableName( schemaName, SQLs.TABLE_NAME ) ) - .createExpression(); - } - - protected SQLStatement createSelectEntityStatement( SQLVendor vendor ) - { - QueryFactory q = vendor.getQueryFactory(); - TableReferenceFactory t = vendor.getTableReferenceFactory(); - BooleanFactory b = vendor.getBooleanFactory(); - ColumnsFactory c = vendor.getColumnsFactory(); - LiteralFactory l = vendor.getLiteralFactory(); - - return q.simpleQueryBuilder() - .select( SQLs.ENTITY_STATE_COLUMN_NAME ) - .from( t.tableName( schemaName, SQLs.TABLE_NAME ) ) - .where( b.eq( c.colName( SQLs.ENTITY_IDENTITY_COLUMN_NAME ), l.param() ) ) - .createExpression(); - } - - protected SQLStatement createInsertEntityStatement( SQLVendor vendor ) - { - ModificationFactory m = vendor.getModificationFactory(); - TableReferenceFactory t = vendor.getTableReferenceFactory(); - LiteralFactory l = vendor.getLiteralFactory(); - - return m.insert() - .setTableName( t.tableName( schemaName, SQLs.TABLE_NAME ) ) - .setColumnSource( m.columnSourceByValues() - .addColumnNames( SQLs.ENTITY_IDENTITY_COLUMN_NAME, - SQLs.ENTITY_STATE_COLUMN_NAME ) - .addValues( l.param(), - l.param() ) - .createExpression() - ).createExpression(); - } - - protected SQLStatement createUpdateEntityStatement( SQLVendor vendor ) - { - ModificationFactory m = vendor.getModificationFactory(); - TableReferenceFactory t = vendor.getTableReferenceFactory(); - LiteralFactory l = vendor.getLiteralFactory(); - BooleanFactory b = vendor.getBooleanFactory(); - ColumnsFactory c = vendor.getColumnsFactory(); - - UpdateBySearchBuilder builder = m.updateBySearch().setTargetTable( - m.createTargetTable( t.tableName( schemaName, SQLs.TABLE_NAME ) ) - ).addSetClauses( - m.setClause( SQLs.ENTITY_VERSION_COLUMN_NAME, m.updateSourceByExp( l.param() ) ), - m.setClause( SQLs.ENTITY_STATE_COLUMN_NAME, m.updateSourceByExp( l.param() ) ) - ); - builder.getWhereBuilder().reset( - b.eq( c.colName( SQLs.ENTITY_IDENTITY_COLUMN_NAME ), l.param() ) - ).and( - b.eq( c.colName( SQLs.ENTITY_VERSION_COLUMN_NAME ), l.param() ) - ); - return builder.createExpression(); - } - - protected SQLStatement createRemoveEntityStatement( SQLVendor vendor ) - { - ModificationFactory m = vendor.getModificationFactory(); - TableReferenceFactory t = vendor.getTableReferenceFactory(); - LiteralFactory l = vendor.getLiteralFactory(); - BooleanFactory b = vendor.getBooleanFactory(); - ColumnsFactory c = vendor.getColumnsFactory(); - - DeleteBySearchBuilder builder = m.deleteBySearch().setTargetTable( - m.createTargetTable( t.tableName( schemaName, SQLs.TABLE_NAME ) ) - ); - builder.getWhere().reset( - b.eq( c.colName( SQLs.ENTITY_IDENTITY_COLUMN_NAME ), l.param() ) - ); - return builder.createExpression(); - } - - protected SQLDataType getIDType() - { - return vendor.getDataTypeFactory().sqlVarChar( 64 ); - } - - protected SQLDataType getVersionType() - { - return vendor.getDataTypeFactory().sqlVarChar( 64 ); - } - - protected SQLDataType getStateType() - { - return vendor.getDataTypeFactory().sqlVarChar( 10000 ); - } - - @Override - public String[] buildSQLForSchemaCreation() - { - return schemaCreationSQLs; - } - - @Override - public String[] buildSQLForIndexCreation() - { - return indexCreationSQLs; - } - - @Override - public String buildSQLForSelectAllEntitiesStatement() - { - return selectAllEntitiesSQL; - } - - @Override - public String buildSQLForSelectEntityStatement() - { - return selectEntitySQL; - } - - @Override - public String buildSQLForInsertEntityStatement() - { - return insertEntitySQL; - } - - @Override - public String buildSQLForUpdateEntityStatement() - { - return updateEntitySQL; - } - - @Override - public String buildSQLForRemoveEntityStatement() - { - return removeEntitySQL; - } - - @Override - public String[] buildSQLForTableCreation() - { - return tableCreationSQLs; - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DerbySQLDatabaseSQLServiceMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DerbySQLDatabaseSQLServiceMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DerbySQLDatabaseSQLServiceMixin.java deleted file mode 100644 index 083d79e..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/DerbySQLDatabaseSQLServiceMixin.java +++ /dev/null @@ -1,67 +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.entitystore.sql.internal; - -import java.io.Reader; -import java.io.StringReader; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings( "ProtectedField" ) -public abstract class DerbySQLDatabaseSQLServiceMixin - implements DatabaseSQLService, DatabaseSQLStringsBuilder, DatabaseSQLServiceSpi -{ - private static final Logger LOGGER = LoggerFactory.getLogger( DerbySQLDatabaseSQLServiceMixin.class ); - - @This - protected DatabaseSQLServiceSpi spi; - - @Override - public boolean tableExists( Connection connection ) - throws SQLException - { - ResultSet rs = null; - try - { - String tableNameForQuery = SQLs.TABLE_NAME.toUpperCase(); - rs = connection.getMetaData().getTables( null, null, tableNameForQuery, - new String[] { "TABLE" } ); - boolean tableExists = rs.next(); - LOGGER.trace( "Found table {}? {}", tableNameForQuery, tableExists ); - return tableExists; - } - finally - { - SQLUtil.closeQuietly( rs ); - } - } - - @Override - public Reader getEntityStateReader( ResultSet rs ) - throws SQLException - { - return new StringReader( rs.getString( SQLs.ENTITY_STATE_COLUMN_NAME ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/H2SQLDatabaseSQLServiceMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/H2SQLDatabaseSQLServiceMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/H2SQLDatabaseSQLServiceMixin.java deleted file mode 100644 index 3b870c6..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/H2SQLDatabaseSQLServiceMixin.java +++ /dev/null @@ -1,64 +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.entitystore.sql.internal; - -import java.io.Reader; -import java.io.StringReader; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class H2SQLDatabaseSQLServiceMixin - implements DatabaseSQLService, DatabaseSQLStringsBuilder, DatabaseSQLServiceSpi -{ - private static final Logger LOGGER = LoggerFactory.getLogger( H2SQLDatabaseSQLServiceMixin.class ); - - @This - protected DatabaseSQLServiceSpi spi; - - public boolean tableExists( Connection connection ) - throws SQLException - { - ResultSet rs = null; - try - { - String tableNameForQuery = SQLs.TABLE_NAME.toUpperCase(); - rs = connection.getMetaData().getTables( null, null, tableNameForQuery, - new String[] { "TABLE" } ); - boolean tableExists = rs.next(); - LOGGER.trace( "Found table {}? {}", tableNameForQuery, tableExists ); - return tableExists; - } - finally - { - SQLUtil.closeQuietly( rs ); - } - } - - public Reader getEntityStateReader( ResultSet rs ) - throws SQLException - { - return new StringReader( rs.getString( SQLs.ENTITY_STATE_COLUMN_NAME ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java deleted file mode 100644 index 1c6c534..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/MySQLDatabaseSQLServiceMixin.java +++ /dev/null @@ -1,68 +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.entitystore.sql.internal; - -import java.io.Reader; -import java.io.StringReader; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings( "ProtectedField" ) -public abstract class MySQLDatabaseSQLServiceMixin - implements DatabaseSQLService, DatabaseSQLStringsBuilder, DatabaseSQLServiceSpi -{ - - private static final Logger LOGGER = LoggerFactory.getLogger( MySQLDatabaseSQLServiceMixin.class ); - - @This - protected DatabaseSQLServiceSpi spi; - - @Override - public boolean tableExists( Connection connection ) - throws SQLException - { - ResultSet rs = null; - try - { - String tableNameForQuery = SQLs.TABLE_NAME.toUpperCase(); - rs = connection.getMetaData().getTables( null, null, tableNameForQuery, - new String[] { "TABLE" } ); - boolean tableExists = rs.next(); - LOGGER.trace( "Found table {}? {}", tableNameForQuery, tableExists ); - return tableExists; - } - finally - { - SQLUtil.closeQuietly( rs ); - } - } - - @Override - public Reader getEntityStateReader( ResultSet rs ) - throws SQLException - { - return new StringReader( rs.getString( SQLs.ENTITY_STATE_COLUMN_NAME ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLDatabaseSQLServiceMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLDatabaseSQLServiceMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLDatabaseSQLServiceMixin.java deleted file mode 100644 index a4cf014..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLDatabaseSQLServiceMixin.java +++ /dev/null @@ -1,64 +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.entitystore.sql.internal; - -import java.io.Reader; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class PostgreSQLDatabaseSQLServiceMixin - implements DatabaseSQLServiceSpi, DatabaseSQLStringsBuilder, DatabaseSQLService -{ - private static final Logger LOGGER = LoggerFactory.getLogger( PostgreSQLDatabaseSQLServiceMixin.class ); - - @This - protected DatabaseSQLServiceSpi spi; - - @Override - public boolean tableExists( Connection connection ) - throws SQLException - { - ResultSet rs = null; - try - { - rs = connection.getMetaData().getTables( null, spi.getCurrentSchemaName(), SQLs.TABLE_NAME, - new String[] { "TABLE" } ); - boolean tableExists = rs.next(); - LOGGER.trace( "Found table {}? {}", SQLs.TABLE_NAME, tableExists ); - return tableExists; - } - finally - { - SQLUtil.closeQuietly( rs ); - } - } - - @Override - public Reader getEntityStateReader( ResultSet rs ) - throws SQLException - { - return rs.getCharacterStream( SQLs.ENTITY_STATE_COLUMN_NAME ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLStringBuilderMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLStringBuilderMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLStringBuilderMixin.java deleted file mode 100644 index b43d1c7..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/PostgreSQLStringBuilderMixin.java +++ /dev/null @@ -1,45 +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.entitystore.sql.internal; - -import org.apache.polygene.entitystore.sql.internal.DatabaseSQLStringsBuilder.CommonMixin; -import org.sql.generation.api.grammar.common.datatypes.SQLDataType; -import org.sql.generation.api.vendor.PostgreSQLVendor; - -/** - * - * @author Stanislav Muhametsin - */ -public class PostgreSQLStringBuilderMixin extends CommonMixin -{ - - @Override - protected SQLDataType getIDType() - { - return ((PostgreSQLVendor) this.getVendor()).getDataTypeFactory().text(); - } - - @Override - protected SQLDataType getStateType() - { - return ((PostgreSQLVendor) this.getVendor()).getDataTypeFactory().text(); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLEntityState.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLEntityState.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLEntityState.java deleted file mode 100644 index 2db6f7c..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLEntityState.java +++ /dev/null @@ -1,189 +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.entitystore.sql.internal; - -import java.time.Instant; -import java.util.Objects; -import org.apache.polygene.api.common.QualifiedName; -import org.apache.polygene.api.entity.EntityDescriptor; -import org.apache.polygene.api.entity.EntityReference; -import org.apache.polygene.spi.entity.EntityState; -import org.apache.polygene.spi.entity.EntityStatus; -import org.apache.polygene.spi.entity.ManyAssociationState; -import org.apache.polygene.spi.entity.NamedAssociationState; -import org.apache.polygene.spi.entitystore.helpers.DefaultEntityState; - -public interface SQLEntityState - extends EntityState -{ - - Long getEntityPK(); - - Long getEntityOptimisticLock(); - - DefaultEntityState getDefaultEntityState(); - - @SuppressWarnings( "PublicInnerClass" ) - public final class DefaultSQLEntityState - implements SQLEntityState - { - - private final DefaultEntityState state; - - private final Long entityPK; - - private final Long entityOptimisticLock; - - public DefaultSQLEntityState( DefaultEntityState state ) - { - Objects.requireNonNull( state, "Entity state" ); - this.state = state; - this.entityPK = null; - this.entityOptimisticLock = null; - } - - public DefaultSQLEntityState( DefaultEntityState state, Long entityPK, Long entityOptimisticLock ) - { - Objects.requireNonNull( state, "Entity state" ); - Objects.requireNonNull( entityPK, "Entity PK" ); - Objects.requireNonNull( entityOptimisticLock, "Entity OptimisticLock" ); - this.state = state; - this.entityPK = entityPK; - this.entityOptimisticLock = entityOptimisticLock; - } - - @Override - public Long getEntityPK() - { - return entityPK; - } - - @Override - public Long getEntityOptimisticLock() - { - return entityOptimisticLock; - } - - @Override - public DefaultEntityState getDefaultEntityState() - { - return state; - } - - @Override - public EntityDescriptor entityDescriptor() - { - return state.entityDescriptor(); - } - - @Override - public EntityReference associationValueOf( QualifiedName stateName ) - { - return state.associationValueOf( stateName ); - } - - @Override - public ManyAssociationState manyAssociationValueOf( QualifiedName stateName ) - { - return state.manyAssociationValueOf( stateName ); - } - - @Override - public NamedAssociationState namedAssociationValueOf( QualifiedName stateName ) - { - return state.namedAssociationValueOf( stateName ); - } - - @Override - public Object propertyValueOf( QualifiedName stateName ) - { - return state.propertyValueOf( stateName ); - } - - @Override - public EntityReference entityReference() - { - return state.entityReference(); - } - - @Override - public boolean isAssignableTo( Class<?> type ) - { - return state.isAssignableTo( type ); - } - - @Override - public Instant lastModified() - { - return state.lastModified(); - } - - @Override - public void remove() - { - state.remove(); - } - - @Override - public void setAssociationValue( QualifiedName stateName, EntityReference newEntity ) - { - state.setAssociationValue( stateName, newEntity ); - } - - @Override - public void setPropertyValue( QualifiedName stateName, Object json ) - { - state.setPropertyValue( stateName, json ); - } - - @Override - public EntityStatus status() - { - return state.status(); - } - - @Override - public String version() - { - return state.version(); - } - - @Override - @SuppressWarnings( "EqualsWhichDoesntCheckParameterClass" ) - public boolean equals( Object obj ) - { - return state.equals( obj ); - } - - @Override - public int hashCode() - { - return state.hashCode(); - } - - @Override - public String toString() - { - return state.toString(); - } - - } - -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLiteDatabaseSQLServiceMixin.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLiteDatabaseSQLServiceMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLiteDatabaseSQLServiceMixin.java deleted file mode 100644 index d762f8b..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLiteDatabaseSQLServiceMixin.java +++ /dev/null @@ -1,66 +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.entitystore.sql.internal; - -import java.io.Reader; -import java.io.StringReader; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.apache.polygene.api.injection.scope.This; -import org.apache.polygene.library.sql.common.SQLUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class SQLiteDatabaseSQLServiceMixin - implements DatabaseSQLService, DatabaseSQLStringsBuilder, DatabaseSQLServiceSpi -{ - private static final Logger LOGGER = LoggerFactory.getLogger( SQLiteDatabaseSQLServiceMixin.class ); - - @This - protected DatabaseSQLServiceSpi spi; - - @Override - public boolean tableExists( Connection connection ) - throws SQLException - { - ResultSet rs = null; - try - { - String tableNameForQuery = SQLs.TABLE_NAME.toUpperCase(); - rs = connection.getMetaData().getTables( null, null, tableNameForQuery, - new String[] { "TABLE" } ); - boolean tableExists = rs.next(); - LOGGER.trace( "Found table {}? {}", tableNameForQuery, tableExists ); - return tableExists; - } - finally - { - SQLUtil.closeQuietly( rs ); - } - } - - @Override - public Reader getEntityStateReader( ResultSet rs ) - throws SQLException - { - return new StringReader( rs.getString( SQLs.ENTITY_STATE_COLUMN_NAME ) ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLs.java ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLs.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLs.java deleted file mode 100644 index 8555a5d..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/SQLs.java +++ /dev/null @@ -1,29 +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.entitystore.sql.internal; - -public interface SQLs -{ - String DEFAULT_SCHEMA_NAME = "POLYGENE_ES"; - String TABLE_NAME = "POLYGENE_ENTITIES"; - String ENTITY_IDENTITY_COLUMN_NAME = "ENTITY_IDENTITY"; - String ENTITY_VERSION_COLUMN_NAME = "ENTITY_VERSION"; - String ENTITY_STATE_COLUMN_NAME = "ENTITY_STATE"; -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/package.html ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/package.html b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/package.html deleted file mode 100644 index 508f1fc..0000000 --- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/internal/package.html +++ /dev/null @@ -1,24 +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. - ~ - ~ - --> -<html> - <body> - <h2>SQL EntityStore Internal Package.</h2> - </body> -</html> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7a9789e6/extensions/entitystore-sql/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml ---------------------------------------------------------------------- diff --git a/extensions/entitystore-sql/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml b/extensions/entitystore-sql/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml new file mode 100644 index 0000000..47ef554 --- /dev/null +++ b/extensions/entitystore-sql/src/main/resources/org/apache/polygene/entitystore/sql/changelog.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<databaseChangeLog + xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd" + objectQuotingStrategy="QUOTE_ALL_OBJECTS"> + <changeSet id="0" author="paul"> + <createTable tableName="${es-sql.table}"> + <column name="ENTITY_IDENTITY" type="varchar(64)"> + <constraints primaryKey="true" nullable="false"/> + </column> + <column name="ENTITY_VERSION" type="varchar(64)"> + <constraints nullable="false"/> + </column> + <column name="ENTITY_STATE" type="varchar(10240)"> + <constraints nullable="false"/> + </column> + </createTable> + </changeSet> +</databaseChangeLog>
