You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2017/06/11 03:43:37 UTC
[01/11] polygene-java git commit: Introducing the beginning of an SQL
entity store that is "enterprisey", laid out in a table per type,
with manyassociations in mapping tables and so on.
Repository: polygene-java
Updated Branches:
refs/heads/es-jooq [created] 59a086292
Introducing the beginning of an SQL entity store that is "enterprisey", laid out in a table per type, with manyassociations in mapping tables and so on.
Signed-off-by: niclas <ni...@hedhman.org>
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/c3d8e013
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/c3d8e013
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/c3d8e013
Branch: refs/heads/es-jooq
Commit: c3d8e013009eafd7f74344d4f08f66f0636e0a4c
Parents: 718fa57
Author: niclas <ni...@hedhman.org>
Authored: Fri May 12 14:18:16 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Fri May 12 14:18:16 2017 +0800
----------------------------------------------------------------------
extensions/entitystore-jooq/build.gradle | 44 +++
extensions/entitystore-jooq/dev-status.xml | 38 ++
extensions/entitystore-jooq/src/docs/es-orm.txt | 58 +++
.../entitystore/jooq/AssociationValue.java | 25 ++
.../polygene/entitystore/jooq/BaseEntity.java | 16 +
.../entitystore/jooq/JooqDslContext.java | 44 +++
.../jooq/JooqEntityStoreConfiguration.java | 62 ++++
.../entitystore/jooq/JooqEntityStoreMixin.java | 198 +++++++++++
.../jooq/JooqEntityStoreService.java | 36 ++
.../polygene/entitystore/jooq/SqlTable.java | 356 +++++++++++++++++++
.../polygene/entitystore/jooq/SqlType.java | 148 ++++++++
.../jooq/assembly/JooqEntityStoreAssembler.java | 74 ++++
.../entitystore/jooq/JooqEntityStoreTest.java | 71 ++++
settings.gradle | 1 +
14 files changed, 1171 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/build.gradle
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/build.gradle b/extensions/entitystore-jooq/build.gradle
new file mode 100644
index 0000000..32ceb70
--- /dev/null
+++ b/extensions/entitystore-jooq/build.gradle
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ *
+ *
+ */
+
+apply plugin: 'polygene-extension'
+
+description = "Apache Polygene™ ORM EntityStore Extension"
+
+jar { manifest { name = "Apache Polygene™ Extension - EntityStore - ORM" } }
+
+dependencies {
+ api polygene.core.bootstrap
+ api polygene.library( 'sql' )
+ api libraries.jooq
+
+ runtimeOnly polygene.core.runtime
+
+ testImplementation polygene.internals.testsupport
+ testImplementation polygene.library( 'sql-dbcp' )
+ testImplementation libraries.docker_junit
+
+ testRuntimeOnly libraries.logback
+ testRuntimeOnly libraries.derby
+ testRuntimeOnly libraries.h2
+ testRuntimeOnly libraries.mysql_connector
+ testRuntimeOnly libraries.postgres
+ testRuntimeOnly libraries.sqlite
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/dev-status.xml
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/dev-status.xml b/extensions/entitystore-jooq/dev-status.xml
new file mode 100644
index 0000000..0914c52
--- /dev/null
+++ b/extensions/entitystore-jooq/dev-status.xml
@@ -0,0 +1,38 @@
+<?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.
+ ~
+ ~
+ -->
+<module xmlns="http://polygene.apache.org/schemas/2008/dev-status/1"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://polygene.apache.org/schemas/2008/dev-status/1
+ http://polygene.apache.org/schemas/2008/dev-status/1/dev-status.xsd">
+ <status>
+ <!--none,early,beta,stable,mature-->
+ <codebase>stable</codebase>
+
+ <!-- none, brief, good, complete -->
+ <documentation>good</documentation>
+
+ <!-- none, some, good, complete -->
+ <unittests>good</unittests>
+ </status>
+ <licenses>
+ <license>ALv2</license>
+ </licenses>
+</module>
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/docs/es-orm.txt
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/docs/es-orm.txt b/extensions/entitystore-jooq/src/docs/es-orm.txt
new file mode 100644
index 0000000..413eb7b
--- /dev/null
+++ b/extensions/entitystore-jooq/src/docs/es-orm.txt
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////
+ * 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.
+///////////////////////////////////////////////////////////////
+
+[[extension-es-orm,ORM EntityStore]]
+= ORM EntityStore =
+
+[devstatus]
+--------------
+source=extensions/entitystore-orm/dev-status.xml
+--------------
+
+This entitystore is backed by a SQL server, and maps each type of the Composite into separate tables. This is more
+enterprise-friendly, but comes at the cost of less performance compared to the <<extension-es-sql>>.
+
+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.
+
+include::../../build/docs/buildinfo/artifact.txt[]
+
+== Assembly ==
+
+Assembly is done using the provided Assembler:
+
+[snippet,java]
+----
+source=extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/orm/OrmEntityStoreTest.java
+tag=assembly
+----
+
+== Configuration ==
+
+Here are the available configuration properties:
+
+[snippet,java]
+----
+source=extensions/entitystore-riak/src/main/java/org/apache/polygene/entitystore/orm/OrmEntityStoreConfiguration.java
+tag=config
+----
+
+All authentication related properties are optional.
+By default no authentication is used.
+As soon as you provide a `username`, authentication is set up.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java
new file mode 100644
index 0000000..81331cf
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java
@@ -0,0 +1,25 @@
+/*
+ * 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.jooq;
+
+class AssociationValue
+{
+ String name;
+ String position;
+ String reference;
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
new file mode 100644
index 0000000..07fb05c
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
@@ -0,0 +1,16 @@
+package org.apache.polygene.entitystore.jooq;
+
+import java.time.Instant;
+import org.apache.polygene.api.entity.EntityDescriptor;
+import org.apache.polygene.api.identity.Identity;
+
+class BaseEntity
+{
+ EntityDescriptor type;
+ Identity identity;
+ String version;
+ String applicationVersion;
+ Instant modifedAt;
+ Instant createdAt;
+ Identity currentValueIdentity;
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java
new file mode 100644
index 0000000..8737936
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java
@@ -0,0 +1,44 @@
+package org.apache.polygene.entitystore.jooq;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import javax.sql.DataSource;
+import org.apache.polygene.api.injection.scope.Service;
+import org.apache.polygene.api.injection.scope.Uses;
+import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.service.ServiceDescriptor;
+import org.jooq.Configuration;
+import org.jooq.DSLContext;
+import org.jooq.SQLDialect;
+import org.jooq.conf.Settings;
+import org.jooq.impl.DSL;
+import org.jooq.impl.DefaultConfiguration;
+
+@Mixins( JooqDslContext.Mixin.class )
+public interface JooqDslContext extends DSLContext
+{
+
+ class Mixin
+ implements InvocationHandler
+ {
+ private DSLContext dsl;
+
+ public Mixin( @Service DataSource dataSource, @Uses ServiceDescriptor serviceDescriptor )
+ {
+ Settings settings = serviceDescriptor.metaInfo( Settings.class );
+ SQLDialect sqlDialect = serviceDescriptor.metaInfo( SQLDialect.class );
+ Configuration configuration = new DefaultConfiguration()
+ .set( dataSource )
+ .set( sqlDialect )
+ .set( settings );
+ dsl = DSL.using( configuration );
+ }
+
+ @Override
+ public Object invoke( Object o, Method method, Object[] objects )
+ throws Throwable
+ {
+ return method.invoke( dsl, objects ); // delegate all
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
new file mode 100644
index 0000000..e3a79f6
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
@@ -0,0 +1,62 @@
+/*
+ * 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.jooq;
+
+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 JooqEntityStoreConfiguration extends SQLConfiguration
+{
+ /**
+ * Name of the database schema to use.
+ * Ignored on SQL databases that don't support schemas.
+ */
+ @UseDefaults( "POLYGENE" )
+ @Override
+ Property<String> schemaName();
+
+ /**
+ * Name of the entities table.
+ * <p>
+ * This table contains the Identity and other metadata about each entity instance
+ * </p>
+ */
+ @UseDefaults( "ENTITIES" )
+ Property<String> entitiesTableName();
+
+ /**
+ * Name of the entity types table.
+ * <p>
+ * This table contains the metainfo about each type. Types are versioned according to
+ * application version, to support entity migration over time, and therefor there might
+ * be (but not necessarily) multiple tables for entity types that has evolved beyond
+ * what can be managed within a single table.
+ * </p>
+ */
+ @UseDefaults( "TYPES" )
+ Property<String> typesTableName();
+
+ /**
+ * 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/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
new file mode 100644
index 0000000..8974181
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
@@ -0,0 +1,198 @@
+/*
+ * 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.jooq;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+import org.apache.polygene.api.association.AssociationDescriptor;
+import org.apache.polygene.api.association.AssociationStateDescriptor;
+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.api.identity.IdentityGenerator;
+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.structure.ModuleDescriptor;
+import org.apache.polygene.api.usecase.Usecase;
+import org.apache.polygene.spi.PolygeneSPI;
+import org.apache.polygene.spi.entity.EntityState;
+import org.apache.polygene.spi.entity.EntityStatus;
+import org.apache.polygene.spi.entitystore.DefaultEntityStoreUnitOfWork;
+import org.apache.polygene.spi.entitystore.EntityNotFoundException;
+import org.apache.polygene.spi.entitystore.EntityStore;
+import org.apache.polygene.spi.entitystore.EntityStoreSPI;
+import org.apache.polygene.spi.entitystore.EntityStoreUnitOfWork;
+import org.apache.polygene.spi.entitystore.StateCommitter;
+import org.apache.polygene.spi.entitystore.helpers.DefaultEntityState;
+import org.jooq.Record;
+import org.jooq.Result;
+import org.jooq.SelectQuery;
+
+import static org.apache.polygene.api.entity.EntityReference.parseEntityReference;
+
+public class JooqEntityStoreMixin
+ implements EntityStore, EntityStoreSPI
+{
+
+ @Structure
+ private PolygeneSPI spi;
+
+ @This
+ private SqlType sqlType;
+
+ @This
+ private SqlTable sqlTable;
+
+ @This
+ private JooqDslContext jooqDslContext;
+
+ @Service
+ private IdentityGenerator identityGenerator;
+
+ @Override
+ public EntityState newEntityState( EntityStoreUnitOfWork unitOfWork, EntityReference reference, EntityDescriptor entityDescriptor )
+ {
+ return new DefaultEntityState( unitOfWork.currentTime(), reference, entityDescriptor );
+ }
+
+ @Override
+ public EntityState entityStateOf( EntityStoreUnitOfWork unitOfWork, ModuleDescriptor module, EntityReference reference )
+ {
+ BaseEntity baseEntity = sqlTable.fetchBaseEntity( reference, module );
+ SelectQuery<Record> selectQuery = sqlTable.createGetEntityQuery( baseEntity.type, reference );
+ Result<Record> result = selectQuery.fetch();
+ if( result.isEmpty() )
+ {
+ throw new EntityNotFoundException( reference );
+ }
+ AssociationStateDescriptor stateDescriptor = baseEntity.type.state();
+ Map<QualifiedName, Object> properties = new HashMap<>();
+ stateDescriptor.properties().forEach( prop ->
+ {
+ QualifiedName qualifiedName = prop.qualifiedName();
+ Object value = result.getValue( 0, qualifiedName.name() );
+ properties.put( qualifiedName, value );
+ } );
+ Map<QualifiedName, EntityReference> assocations = new HashMap<>();
+ stateDescriptor.associations().forEach( assoc ->
+ {
+ QualifiedName qualifiedName = assoc.qualifiedName();
+ String value = (String) result.getValue( 0, qualifiedName.name() );
+ assocations.put( qualifiedName, parseEntityReference( value ) );
+ } );
+ Map<QualifiedName, List<EntityReference>> manyAssocs = new HashMap<>();
+ Map<QualifiedName, Map<String, EntityReference>> namedAssocs = new HashMap<>();
+ result.forEach( record ->
+ {
+ sqlTable.fetchAssociations( record, associationValue ->
+ {
+ // TODO: Perhaps introduce "preserveManyAssociationOrder" option which would have an additional column, separating 'ordinal position' and 'name position'
+ if( associationValue.position == null )
+ {
+ addManyAssociation( stateDescriptor, manyAssocs, associationValue );
+ }
+ else
+ {
+ addNamedAssociation( stateDescriptor, namedAssocs, associationValue );
+ }
+ } );
+ } );
+
+ return new DefaultEntityState( baseEntity.version,
+ baseEntity.modifedAt,
+ reference,
+ EntityStatus.LOADED,
+ baseEntity.type,
+ properties,
+ assocations,
+ manyAssocs,
+ namedAssocs );
+ }
+
+ private void addNamedAssociation( AssociationStateDescriptor stateDescriptor, Map<QualifiedName, Map<String, EntityReference>> namedAssocs, AssociationValue associationValue )
+ {
+ AssociationDescriptor descriptor = stateDescriptor.getNamedAssociationByName( associationValue.name );
+ QualifiedName qualifiedName = descriptor.qualifiedName();
+ Map<String, EntityReference> map = namedAssocs.computeIfAbsent( qualifiedName, k -> new HashMap<>() );
+ map.put( associationValue.position, parseEntityReference( associationValue.reference ) );
+ }
+
+ private void addManyAssociation( AssociationStateDescriptor stateDescriptor, Map<QualifiedName, List<EntityReference>> manyAssocs, AssociationValue associationValue )
+ {
+ AssociationDescriptor descriptor = stateDescriptor.getManyAssociationByName( associationValue.name );
+ QualifiedName qualifiedName = descriptor.qualifiedName();
+ List<EntityReference> list = manyAssocs.computeIfAbsent( qualifiedName, k -> new ArrayList<>() );
+ list.add( parseEntityReference( associationValue.reference ) );
+ }
+
+ @Override
+ public String versionOf( EntityStoreUnitOfWork unitOfWork, EntityReference reference )
+ {
+ BaseEntity baseEntity = sqlTable.fetchBaseEntity( reference, unitOfWork.module() );
+ return baseEntity.version;
+ }
+
+ @Override
+ public StateCommitter applyChanges( EntityStoreUnitOfWork unitOfWork, Iterable<EntityState> state )
+ {
+ return new JooqStateCommitter( unitOfWork, state );
+ }
+
+ @Override
+ public EntityStoreUnitOfWork newUnitOfWork( ModuleDescriptor module, Usecase usecase, Instant currentTime )
+ {
+ return new DefaultEntityStoreUnitOfWork( module,
+ this,
+ identityGenerator.generate( JooqEntityStoreService.class ),
+ usecase,
+ currentTime
+ );
+ }
+
+ @Override
+ public Stream<EntityState> entityStates( ModuleDescriptor module )
+ {
+ return null;
+ }
+
+ private static class JooqStateCommitter
+ implements StateCommitter
+ {
+ public JooqStateCommitter( EntityStoreUnitOfWork unitOfWork, Iterable<EntityState> state )
+ {
+
+ }
+
+ @Override
+ public void commit()
+ {
+
+ }
+
+ @Override
+ public void cancel()
+ {
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java
new file mode 100644
index 0000000..0259151
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java
@@ -0,0 +1,36 @@
+/*
+ * 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.jooq;
+
+import org.apache.polygene.api.concern.Concerns;
+import org.apache.polygene.api.configuration.Configuration;
+import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.spi.entitystore.ConcurrentModificationCheckConcern;
+import org.apache.polygene.spi.entitystore.EntityStateVersions;
+import org.apache.polygene.spi.entitystore.EntityStore;
+import org.apache.polygene.spi.entitystore.StateChangeNotificationConcern;
+
+/**
+ * SQL EntityStore service.
+ */
+@Concerns( { StateChangeNotificationConcern.class, ConcurrentModificationCheckConcern.class } )
+@Mixins( { JooqEntityStoreMixin.class } )
+public interface JooqEntityStoreService
+ extends EntityStore, EntityStateVersions, Configuration
+{
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
new file mode 100644
index 0000000..1cf0c1c
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
@@ -0,0 +1,356 @@
+/*
+ * 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.jooq;
+
+import java.lang.reflect.Method;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import org.apache.polygene.api.configuration.Configuration;
+import org.apache.polygene.api.entity.EntityDescriptor;
+import org.apache.polygene.api.entity.EntityReference;
+import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.injection.scope.Uses;
+import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.property.Property;
+import org.apache.polygene.api.property.PropertyDescriptor;
+import org.apache.polygene.api.service.ServiceActivation;
+import org.apache.polygene.api.service.ServiceDescriptor;
+import org.apache.polygene.api.structure.ModuleDescriptor;
+import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.api.unitofwork.NoSuchEntityTypeException;
+import org.apache.polygene.spi.entitystore.EntityNotFoundException;
+import org.jooq.Condition;
+import org.jooq.CreateTableAsStep;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Result;
+import org.jooq.SQLDialect;
+import org.jooq.Schema;
+import org.jooq.SelectJoinStep;
+import org.jooq.SelectQuery;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+
+@Mixins( SqlTable.Mixin.class )
+public interface SqlTable
+{
+ String IDENTITY_COLUMN_NAME = "identity";
+ String VALUEID_COLUMN_NAME = "value_id";
+ String VERSION_COLUMN_NAME = "version";
+ String APPLICATIONVERSION_COLUMN_NAME = "app_version";
+ String TYPE_COLUMN_NAME = "type";
+ String LASTMODIFIED_COLUMN_NAME = "modified_at";
+ String CREATED_COLUMN_NAME = "created_at";
+ String TABLENAME_COLUMN_NAME = "table_name";
+ String ASSOCIATIONS_COLUMN_NAME = "assocations";
+ String POSITION_COLUMN_NAME = "position";
+
+ String createNewTableName( Class<?> type );
+
+ Result<Record> createNewTable( Class<?> mixinType, EntityDescriptor descriptor );
+
+ boolean isProperty( Method method );
+
+ Table<Record> findTable( Class<?> type, EntityDescriptor descriptor );
+
+ Table<Record> createTable( Class<?> type, EntityDescriptor descriptor );
+
+ String findTableName( Class<?> type, EntityDescriptor descriptor );
+
+ List<Table<Record>> getTableJoins( EntityDescriptor entityDescriptor );
+
+ Result<Record> fetchTypeInfoFromTable( Class<?> entityType );
+
+ BaseEntity fetchBaseEntity( EntityReference reference, ModuleDescriptor module );
+
+ EntityDescriptor findEntityDescriptor( String typeName, ModuleDescriptor module );
+
+ Record createNewBaseEntity( EntityReference reference, EntityDescriptor descriptor );
+
+ SelectQuery<Record> createGetEntityQuery( EntityDescriptor entityDescriptor, EntityReference reference );
+
+ void fetchAssociations( Record record, Consumer<AssociationValue> consume );
+
+ class Mixin
+ implements SqlTable, ServiceActivation
+ {
+
+ @This
+ JooqDslContext dsl;
+
+ @This
+ private Configuration<JooqEntityStoreConfiguration> configuration;
+
+ @This
+ private SqlType sqlType;
+
+ @Uses
+ private ServiceDescriptor serviceDescriptor;
+
+ private Table<Record> typesTable;
+ private Table<Record> entitiesTable;
+ private Map<Class, Table<Record>> entityTables;
+ private Field<String> identityColumn;
+ private Field<String> valueIdentityColumn;
+ private Field<String> typeColumn;
+ private Field<String> versionColumn;
+ private Field<String> applicationVersionColumn;
+ private Field<Instant> modifiedColumn;
+ private Field<Instant> createdColumn;
+ private Field<String> tableNameColumn;
+ private Field<String> assocationsColumn;
+ private Field<String> positionColumn;
+
+ private Schema schema;
+
+ private SQLDialect dialect;
+
+ @Override
+ public void activateService()
+ throws Exception
+ {
+ configuration.refresh();
+ JooqEntityStoreConfiguration config = configuration.get();
+
+ // Prepare jooq DSL
+ dialect = serviceDescriptor.metaInfo( SQLDialect.class );
+
+ String schemaName = config.schemaName().get();
+ String typesTableName = config.typesTableName().get();
+ String entitiesTableName = config.entitiesTableName().get();
+ schema = DSL.schema( DSL.name( schemaName ) );
+ typesTable = DSL.table(
+ dialect.equals( SQLDialect.SQLITE )
+ ? DSL.name( typesTableName )
+ : DSL.name( schema.getName(), typesTableName )
+ );
+ entitiesTable = DSL.table(
+ dialect.equals( SQLDialect.SQLITE )
+ ? DSL.name( entitiesTableName )
+ : DSL.name( schema.getName(), entitiesTableName ) );
+
+ identityColumn = DSL.field( DSL.name( IDENTITY_COLUMN_NAME ), String.class );
+ valueIdentityColumn = DSL.field( DSL.name( VALUEID_COLUMN_NAME ), String.class );
+ versionColumn = DSL.field( DSL.name( VERSION_COLUMN_NAME ), String.class );
+ applicationVersionColumn = DSL.field( DSL.name( APPLICATIONVERSION_COLUMN_NAME ), String.class );
+ typeColumn = DSL.field( DSL.name( TYPE_COLUMN_NAME ), String.class );
+ modifiedColumn = DSL.field( DSL.name( LASTMODIFIED_COLUMN_NAME ), Instant.class );
+ createdColumn = DSL.field( DSL.name( CREATED_COLUMN_NAME ), Instant.class );
+ tableNameColumn = DSL.field( DSL.name( TABLENAME_COLUMN_NAME ), String.class );
+ assocationsColumn = DSL.field( DSL.name( ASSOCIATIONS_COLUMN_NAME ), String.class );
+ positionColumn = DSL.field( DSL.name( POSITION_COLUMN_NAME ), String.class );
+
+ // Eventually create schema
+ if( config.createIfMissing().get() )
+ {
+ if( !dialect.equals( SQLDialect.SQLITE )
+ && dsl.meta().getSchemas().stream().noneMatch( s -> schema.getName().equalsIgnoreCase( s.getName() ) ) )
+ {
+ dsl.createSchema( schema ).execute();
+ }
+ }
+ }
+
+ @Override
+ public BaseEntity fetchBaseEntity( EntityReference reference, ModuleDescriptor module )
+ {
+ BaseEntity result = new BaseEntity();
+
+ Result<Record> baseEntityResult = dsl
+ .select()
+ .from( entitiesTable )
+ .where( identityColumn.eq( reference.toURI() ) )
+ .fetch();
+
+ if( baseEntityResult.isEmpty() )
+ {
+ throw new EntityNotFoundException( reference );
+ }
+ Record baseEntity = baseEntityResult.get( 0 );
+ String typeName = baseEntity.field( typeColumn ).get( baseEntity );
+ result.type = findEntityDescriptor( typeName, module );
+ result.version = baseEntity.field( versionColumn ).get( baseEntity );
+ result.applicationVersion = baseEntity.field( applicationVersionColumn ).get( baseEntity );
+ result.identity = EntityReference.parseEntityReference( baseEntity.field( identityColumn ).get( baseEntity ) ).identity();
+ result.currentValueIdentity = EntityReference.parseEntityReference( baseEntity.field( valueIdentityColumn ).get( baseEntity ) ).identity();
+ result.modifedAt = baseEntity.field( modifiedColumn ).get( baseEntity );
+ result.createdAt = baseEntity.field( createdColumn ).get( baseEntity );
+ return result;
+ }
+
+ @Override
+ public void passivateService()
+ throws Exception
+ {
+ schema = null;
+ }
+
+ public Result<Record> fetchTypeInfoFromTable( Class<?> entityType )
+ {
+ return dsl
+ .select()
+ .from( typesTable )
+ .where( identityColumn.eq( entityType.getName() ) )
+ .fetch();
+ }
+
+ public List<Table<Record>> getTableJoins( EntityDescriptor entityDescriptor )
+ {
+ return entityDescriptor
+ .mixinTypes()
+ .map( ( Class<?> type ) -> findTable( type, entityDescriptor ) )
+ .collect( Collectors.toList() );
+ }
+
+ public Table<Record> findTable( Class<?> type, EntityDescriptor descriptor )
+ {
+ return entityTables.computeIfAbsent( type, t -> createTable( t, descriptor ) );
+ }
+
+ public Table<Record> createTable( Class<?> type, EntityDescriptor descriptor )
+ {
+ String tableName = findTableName( type, descriptor );
+ return null;
+ }
+
+ public String findTableName( Class<?> type, EntityDescriptor descriptor )
+ {
+ Result<Record> typeInfo = fetchTypeInfoFromTable( type );
+ if( typeInfo.isEmpty() )
+ {
+ typeInfo = createNewTable( type, descriptor );
+ }
+ return typeInfo.getValue( 0, tableNameColumn );
+ }
+
+ @Override
+ public String createNewTableName( Class<?> type )
+ {
+ return null;
+ }
+
+ public Result<Record> createNewTable( Class<?> mixinType, EntityDescriptor descriptor )
+ {
+ String tableName = createNewTableName( mixinType );
+ CreateTableAsStep<Record> table = dsl.createTable( tableName );
+ Arrays.stream( mixinType.getDeclaredMethods() )
+ .filter( this::isProperty )
+ .forEach( method ->
+ {
+ PropertyDescriptor propertyDescriptor = descriptor.state().findPropertyModelByName( method.getName() );
+ ValueType valueType = propertyDescriptor.valueType();
+ Class<?> propertyType = valueType.primaryType();
+ String propertyName = method.getName();
+ table.column( propertyName, sqlType.getSqlDataTypeFor( propertyType ) );
+ } );
+
+ return fetchTypeInfoFromTable( mixinType );
+ }
+
+ public boolean isProperty( Method method )
+ {
+ return Property.class.isAssignableFrom( method.getReturnType() ) && method.getParameterCount() == 0;
+ }
+
+ public EntityDescriptor findEntityDescriptor( String typeName, ModuleDescriptor module )
+ {
+ try
+ {
+ Class<?> type = getClass().getClassLoader().loadClass( typeName );
+ return module.typeLookup().lookupEntityModel( type );
+ }
+ catch( ClassNotFoundException e )
+ {
+ throw new NoSuchEntityTypeException( typeName, module.name(), module.typeLookup() );
+ }
+ }
+
+ @Override
+ public Record createNewBaseEntity( EntityReference reference, EntityDescriptor descriptor )
+ {
+ return null;
+ }
+
+ /**
+ * Builds the SELECT statement for a given entity.
+ * <p>
+ * Example; If we have the following entity
+ * </p>
+ * <code><pre>
+ * public interface LegalEntity
+ * {
+ * Property<String> registration();
+ * }
+ * <p>
+ * public interface Person extends LegalEntity
+ * {
+ * Property<String> name();
+ * <p>
+ * @Optional
+ * Association<Person> spouse();
+ * <p>
+ * ManyAssocation<Person> children();
+ * }
+ * </pre></code>
+ * <p>
+ * and we do a simple;
+ * <code><pre>
+ * Person p = uow.get( Person.class, "niclas" );
+ * </pre></code>
+ * <p>
+ * then the generated query will be
+ * </p>
+ * <code><pre>
+ * SELECT * FROM ENTITIES
+ * JOIN Person ON identity = ENTITIES.value_id
+ * JOIN LegalEntity ON identity = ENTITIES.value_id
+ * JOIN Person_Assoc ON identity = ENTITIES.value_id
+ * WHERE ENTITIES.identity = '123'
+ * </pre></code>
+ *
+ * @param entityDescriptor The descriptor of the entity type to be built.
+ * @return The SELECT query that can be executed to retrieve the entity.
+ */
+ public SelectQuery<Record> createGetEntityQuery( EntityDescriptor entityDescriptor, EntityReference reference )
+ {
+ SelectJoinStep<Record> from = dsl.select().from( entitiesTable );
+ List<Table<Record>> joins = getTableJoins( entityDescriptor );
+ for( Table<Record> joinedTable : joins )
+ {
+ Field<String> joinedField = joinedTable.field( identityColumn );
+ Condition joinCondition = joinedField.eq( entitiesTable.field( valueIdentityColumn ) );
+ from = from.join( joinedTable ).on( joinCondition );
+ }
+ return from.where( identityColumn.eq( reference.identity().toString() ) ).getQuery();
+ }
+
+ @Override
+ public void fetchAssociations( Record record, Consumer<AssociationValue> consume )
+ {
+ AssociationValue value = new AssociationValue();
+ value.name = record.getValue( assocationsColumn );
+ value.position = record.getValue( positionColumn );
+ value.reference = record.getValue( this.assocationsColumn );
+ consume.accept( value );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java
new file mode 100644
index 0000000..c872d62
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java
@@ -0,0 +1,148 @@
+/*
+ * 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.jooq;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.time.Period;
+import java.time.ZonedDateTime;
+import org.apache.polygene.api.mixin.Mixins;
+import org.jooq.DataType;
+import org.jooq.impl.SQLDataType;
+import org.jooq.types.Interval;
+
+@Mixins( SqlType.Mixin.class )
+public interface SqlType
+{
+ DataType<?> getSqlDataTypeFor( Class<?> propertyType );
+
+ class Mixin
+ implements SqlType
+ {
+ public DataType<?> getSqlDataTypeFor( Class<?> propertyType )
+ {
+ if( String.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.VARCHAR;
+ }
+ if( Integer.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.INTEGER;
+ }
+ if( Long.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.BIGINT;
+ }
+ if( Boolean.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.BOOLEAN;
+ }
+ if( Float.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.FLOAT;
+ }
+ if( Double.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.DOUBLE;
+ }
+ if( Instant.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.TIMESTAMPWITHTIMEZONE;
+ }
+ if( Interval.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.VARCHAR;
+ }
+ if( Period.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.VARCHAR;
+ }
+ if( LocalDate.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.LOCALDATE;
+ }
+ if( LocalTime.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.LOCALTIME;
+ }
+ if( LocalDateTime.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.LOCALDATETIME;
+ }
+ if( ZonedDateTime.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.OFFSETDATETIME;
+ }
+ if( OffsetDateTime.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.OFFSETDATETIME;
+ }
+ if( Character.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.CHAR( 1 );
+ }
+ if( Short.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.INTEGER;
+ }
+ if( Byte.class.isAssignableFrom( propertyType ) )
+ {
+ return SQLDataType.INTEGER;
+ }
+ if( propertyType.isPrimitive() )
+ {
+ if( propertyType.equals( Integer.TYPE ) )
+ {
+ return SQLDataType.INTEGER;
+ }
+ if( propertyType.equals( Long.TYPE ) )
+ {
+ return SQLDataType.BIGINT;
+ }
+ if( propertyType.equals( Boolean.TYPE ) )
+ {
+ return SQLDataType.BOOLEAN;
+ }
+ if( propertyType.equals( Float.TYPE ) )
+ {
+ return SQLDataType.FLOAT;
+ }
+ if( propertyType.equals( Double.TYPE ) )
+ {
+ return SQLDataType.DOUBLE;
+ }
+ if( propertyType.equals( Character.TYPE ) )
+ {
+ return SQLDataType.CHAR( 1 );
+ }
+ if( propertyType.equals( Short.TYPE ) )
+ {
+ return SQLDataType.INTEGER;
+ }
+ if( propertyType.equals( Byte.TYPE ) )
+ {
+ return SQLDataType.INTEGER;
+ }
+ }
+ return SQLDataType.VARCHAR;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java
new file mode 100644
index 0000000..8a986a9
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java
@@ -0,0 +1,74 @@
+/*
+ * 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.jooq.assembly;
+
+import org.apache.polygene.api.identity.Identity;
+import org.apache.polygene.api.identity.StringIdentity;
+import org.apache.polygene.bootstrap.Assembler;
+import org.apache.polygene.bootstrap.Assemblers;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.jooq.JooqEntityStoreConfiguration;
+import org.apache.polygene.entitystore.jooq.JooqEntityStoreService;
+import org.jooq.SQLDialect;
+import org.jooq.conf.RenderNameStyle;
+import org.jooq.conf.Settings;
+
+/**
+ * MySQL EntityStore assembly.
+ */
+public class JooqEntityStoreAssembler extends Assemblers.VisibilityIdentityConfig<JooqEntityStoreAssembler>
+ implements Assembler
+{
+ public static final Identity DEFAULT_ENTITYSTORE_IDENTITY = new StringIdentity( "entitystore-jooq" );
+
+ @Override
+ public void assemble( ModuleAssembly module )
+ {
+ Settings settings = getSettings();
+ if( settings == null )
+ {
+ throw new AssemblyException( "Settings must not be null" );
+ }
+
+ String identity = ( hasIdentity() ? identity() : DEFAULT_ENTITYSTORE_IDENTITY ).toString();
+
+ module.services( JooqEntityStoreService.class )
+ .identifiedBy( identity )
+ .visibleIn( visibility() )
+ .setMetaInfo( getSQLDialect() )
+ .setMetaInfo( settings );
+
+ if( hasConfig() )
+ {
+ configModule().entities( JooqEntityStoreConfiguration.class ).visibleIn( configVisibility() );
+ }
+ }
+
+ protected Settings getSettings()
+ {
+ return new Settings().withRenderNameStyle( RenderNameStyle.QUOTED );
+ }
+
+ protected SQLDialect getSQLDialect()
+ {
+ return SQLDialect.DEFAULT;
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java b/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
new file mode 100644
index 0000000..8db2784
--- /dev/null
+++ b/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.jooq;
+
+import java.util.HashMap;
+import org.apache.polygene.api.common.Visibility;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.jooq.assembly.JooqEntityStoreAssembler;
+import org.apache.polygene.test.EntityTestAssembler;
+import org.apache.polygene.test.entity.AbstractEntityStoreTest;
+import org.apache.polygene.test.internal.DockerRule;
+import org.jooq.SQLDialect;
+import org.junit.ClassRule;
+
+public class JooqEntityStoreTest
+ extends AbstractEntityStoreTest
+{
+ @ClassRule
+ public static final DockerRule DOCKER = new DockerRule(
+ "mysql",
+ new HashMap<String, String>()
+ {{
+ put( "MYSQL_ROOT_PASSWORD", "" );
+ put( "MYSQL_ALLOW_EMPTY_PASSWORD", "yes" );
+ put( "MYSQL_DATABASE", "jdbc_test_db" );
+ put( "MYSQL_ROOT_HOST", "172.17.0.1" );
+ }},
+ 30000L
+// , "mysqld: ready for connections" TODO: add this after next release of tdomzal/junit-docker-rule
+ );
+
+ @Override
+ // START SNIPPET: assembly
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ // END SNIPPET: assembly
+ super.assemble( module );
+ ModuleAssembly config = module.layer().module( "config" );
+ new EntityTestAssembler().visibleIn( Visibility.module ).assemble( config );
+
+ // START SNIPPET: assembly
+ new JooqEntityStoreAssembler()
+ .withConfig( config, Visibility.layer )
+ .identifiedBy( "jooq-entitystore" )
+ .assemble( module );
+ // END SNIPPET: assembly
+
+ config.forMixin( JooqEntityStoreConfiguration.class ).setMetaInfo( SQLDialect.MARIADB );
+ // START SNIPPET: assembly
+ }
+ // END SNIPPET: assembly
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c3d8e013/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index 0cee4a7..13b502c 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -61,6 +61,7 @@ include 'core:api',
'extensions:entitystore-hazelcast',
'extensions:entitystore-jclouds',
'extensions:entitystore-jdbm',
+ 'extensions:entitystore-jooq',
'extensions:entitystore-leveldb',
'extensions:entitystore-memory',
'extensions:entitystore-mongodb',
[11/11] polygene-java git commit: A lot of things fixed to get closer
to a working implementation.
Posted by ni...@apache.org.
A lot of things fixed to get closer to a working implementation.
Signed-off-by: niclas <ni...@hedhman.org>
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/59a08629
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/59a08629
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/59a08629
Branch: refs/heads/es-jooq
Commit: 59a08629239a38bdf93cf02fb1a3722e36abbdd8
Parents: ffd7207
Author: niclas <ni...@hedhman.org>
Authored: Sun Jun 11 11:43:12 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Sun Jun 11 11:43:12 2017 +0800
----------------------------------------------------------------------
.../test/entity/AbstractEntityStoreTest.java | 3 -
extensions/entitystore-jooq/dev-status.xml | 20 +-
.../entitystore-jooq/src/docs/es-jooq.txt | 58 +++++
extensions/entitystore-jooq/src/docs/es-orm.txt | 58 -----
.../entitystore/jooq/AssociationValue.java | 7 +-
.../polygene/entitystore/jooq/BaseEntity.java | 3 +-
.../entitystore/jooq/EntitiesTable.java | 210 ++++++++++++++-----
.../entitystore/jooq/JooqEntityStoreMixin.java | 128 ++++++-----
.../polygene/entitystore/jooq/MixinTable.java | 197 +++++++++++------
.../polygene/entitystore/jooq/SqlTable.java | 37 +++-
.../polygene/entitystore/jooq/TableFields.java | 22 +-
.../polygene/entitystore/jooq/TypesTable.java | 10 +-
.../entitystore/jooq/JooqEntityStoreTest.java | 21 +-
manual/src/docs/userguide/extensions.txt | 4 +
14 files changed, 506 insertions(+), 272 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java b/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
index 2bb6abb..0eee83a 100644
--- a/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
+++ b/core/testsupport/src/main/java/org/apache/polygene/test/entity/AbstractEntityStoreTest.java
@@ -359,7 +359,6 @@ public abstract class AbstractEntityStoreTest
try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() )
{
EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class );
-
testEntity = builder.newInstance();
unitOfWork.complete();
}
@@ -368,7 +367,6 @@ public abstract class AbstractEntityStoreTest
testEntity = unitOfWork.get( testEntity );
testEntity.name().set( "Rickard" );
version = spi.entityStateOf( testEntity ).version();
-
unitOfWork.complete();
}
try( UnitOfWork unitOfWork = unitOfWorkFactory.newUnitOfWork() )
@@ -376,7 +374,6 @@ public abstract class AbstractEntityStoreTest
testEntity = unitOfWork.get( testEntity );
String newVersion = spi.entityStateOf( testEntity ).version();
assertThat( "version has not changed", newVersion, not( equalTo( version ) ) );
-
unitOfWork.complete();
}
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/dev-status.xml
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/dev-status.xml b/extensions/entitystore-jooq/dev-status.xml
index 0914c52..6710bdd 100644
--- a/extensions/entitystore-jooq/dev-status.xml
+++ b/extensions/entitystore-jooq/dev-status.xml
@@ -23,16 +23,16 @@
xsi:schemaLocation="http://polygene.apache.org/schemas/2008/dev-status/1
http://polygene.apache.org/schemas/2008/dev-status/1/dev-status.xsd">
<status>
- <!--none,early,beta,stable,mature-->
- <codebase>stable</codebase>
+ <!--none,early,beta,stable,mature-->
+ <codebase>early</codebase>
- <!-- none, brief, good, complete -->
- <documentation>good</documentation>
+ <!-- none, brief, good, complete -->
+ <documentation>none</documentation>
- <!-- none, some, good, complete -->
- <unittests>good</unittests>
- </status>
- <licenses>
- <license>ALv2</license>
- </licenses>
+ <!-- none, some, good, complete -->
+ <unittests>good</unittests>
+ </status>
+ <licenses>
+ <license>ALv2</license>
+ </licenses>
</module>
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/docs/es-jooq.txt
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/docs/es-jooq.txt b/extensions/entitystore-jooq/src/docs/es-jooq.txt
new file mode 100644
index 0000000..a36d463
--- /dev/null
+++ b/extensions/entitystore-jooq/src/docs/es-jooq.txt
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////
+ * 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.
+///////////////////////////////////////////////////////////////
+
+[[extension-es-jooq,SQL EntityStore]]
+= ORM EntityStore =
+
+[devstatus]
+--------------
+source=extensions/entitystore-jooq/dev-status.xml
+--------------
+
+This entitystore is backed by a SQL server, and maps each mixin type of the Composite into separate tables. This is more
+enterprise-friendly, but comes at the cost of less performance compared to the <<extension-es-sql>>.
+
+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.
+
+include::../../build/docs/buildinfo/artifact.txt[]
+
+== Assembly ==
+
+Assembly is done using the provided Assembler:
+
+[snippet,java]
+----
+source=extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
+tag=assembly
+----
+
+== Configuration ==
+
+Here are the available configuration properties:
+
+[snippet,java]
+----
+source=extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
+tag=config
+----
+
+All authentication related properties are optional.
+By default no authentication is used.
+As soon as you provide a `username`, authentication is set up.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/docs/es-orm.txt
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/docs/es-orm.txt b/extensions/entitystore-jooq/src/docs/es-orm.txt
deleted file mode 100644
index 413eb7b..0000000
--- a/extensions/entitystore-jooq/src/docs/es-orm.txt
+++ /dev/null
@@ -1,58 +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.
-///////////////////////////////////////////////////////////////
-
-[[extension-es-orm,ORM EntityStore]]
-= ORM EntityStore =
-
-[devstatus]
---------------
-source=extensions/entitystore-orm/dev-status.xml
---------------
-
-This entitystore is backed by a SQL server, and maps each type of the Composite into separate tables. This is more
-enterprise-friendly, but comes at the cost of less performance compared to the <<extension-es-sql>>.
-
-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.
-
-include::../../build/docs/buildinfo/artifact.txt[]
-
-== Assembly ==
-
-Assembly is done using the provided Assembler:
-
-[snippet,java]
-----
-source=extensions/entitystore-riak/src/test/java/org/apache/polygene/entitystore/orm/OrmEntityStoreTest.java
-tag=assembly
-----
-
-== Configuration ==
-
-Here are the available configuration properties:
-
-[snippet,java]
-----
-source=extensions/entitystore-riak/src/main/java/org/apache/polygene/entitystore/orm/OrmEntityStoreConfiguration.java
-tag=config
-----
-
-All authentication related properties are optional.
-By default no authentication is used.
-As soon as you provide a `username`, authentication is set up.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java
index 81331cf..528ab8b 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/AssociationValue.java
@@ -17,9 +17,12 @@
*/
package org.apache.polygene.entitystore.jooq;
-class AssociationValue
+import org.apache.polygene.api.common.QualifiedName;
+
+@SuppressWarnings( "WeakerAccess" )
+public class AssociationValue
{
- String name;
+ QualifiedName name;
String position;
String reference;
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
index e4eaa40..3c16f16 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
@@ -21,7 +21,8 @@ import java.time.Instant;
import org.apache.polygene.api.entity.EntityDescriptor;
import org.apache.polygene.api.identity.Identity;
-class BaseEntity
+@SuppressWarnings( "WeakerAccess" )
+public class BaseEntity
{
EntityDescriptor type;
Identity identity;
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java
index dc765a9..001b590 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java
@@ -26,12 +26,18 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.polygene.api.association.AssociationDescriptor;
import org.apache.polygene.api.common.QualifiedName;
+import org.apache.polygene.api.composite.Composite;
+import org.apache.polygene.api.entity.EntityComposite;
import org.apache.polygene.api.entity.EntityDescriptor;
import org.apache.polygene.api.entity.EntityReference;
+import org.apache.polygene.api.identity.HasIdentity;
+import org.apache.polygene.api.identity.StringIdentity;
import org.apache.polygene.api.property.PropertyDescriptor;
import org.apache.polygene.api.structure.ModuleDescriptor;
import org.apache.polygene.api.type.EntityCompositeType;
@@ -48,10 +54,14 @@ import org.jooq.Schema;
import org.jooq.SelectJoinStep;
import org.jooq.SelectQuery;
import org.jooq.Table;
+import org.jooq.impl.DSL;
+@SuppressWarnings( "WeakerAccess" )
public class EntitiesTable
implements TableFields
{
+ private static final Predicate<? super Class<?>> NOT_COMPOSITE = type -> !( type.equals( Composite.class ) || type.equals( EntityComposite.class ) );
+ private static final Predicate<? super Class<?>> NOT_HASIDENTITY = type -> !( type.equals( HasIdentity.class ) );
private Map<EntityCompositeType, Set<Class<?>>> mixinTypeCache = new ConcurrentHashMap<>();
private Map<Class<?>, MixinTable> mixinTablesCache = new ConcurrentHashMap<>();
@@ -60,6 +70,7 @@ public class EntitiesTable
private final TypesTable types;
private final Schema schema;
private String applicationVersion;
+ private boolean replacementStrategy = false; // Figure out later if we should support both and if so, how.
EntitiesTable( JooqDslContext dsl, Schema schema, TypesTable types, String applicationVersion, String entitiesTableName )
{
@@ -72,7 +83,6 @@ public class EntitiesTable
public BaseEntity fetchEntity( EntityReference reference, ModuleDescriptor module )
{
- BaseEntity result = new BaseEntity();
Result<Record> baseEntityResult = dsl
.selectFrom( entitiesTable )
@@ -83,18 +93,32 @@ public class EntitiesTable
{
throw new EntityNotFoundException( reference );
}
- Record baseEntity = baseEntityResult.get( 0 );
- String typeName = baseEntity.field( typeNameColumn ).get( baseEntity );
+ Record row = baseEntityResult.get( 0 );
+ return toBaseEntity( row, module );
+ }
+
+ protected BaseEntity toBaseEntity( Record row, ModuleDescriptor module )
+ {
+ BaseEntity result = new BaseEntity();
+ String typeName = row.field( typeNameColumn ).get( row );
result.type = findEntityDescriptor( typeName, module );
- result.version = baseEntity.field( versionColumn ).get( baseEntity );
- result.applicationVersion = baseEntity.field( applicationVersionColumn ).get( baseEntity );
- result.identity = EntityReference.parseEntityReference( baseEntity.field( identityColumn ).get( baseEntity ) ).identity();
- result.currentValueIdentity = EntityReference.parseEntityReference( baseEntity.field( valueIdentityColumn ).get( baseEntity ) ).identity();
- result.modifedAt = Instant.ofEpochMilli( baseEntity.field( modifiedColumn ).get( baseEntity ).getTime() );
- result.createdAt = Instant.ofEpochMilli( baseEntity.field( createdColumn ).get( baseEntity ).getTime() );
+ result.version = row.field( versionColumn ).get( row );
+ result.applicationVersion = row.field( applicationVersionColumn ).get( row );
+ result.identity = new StringIdentity( row.field( identityColumn ).get( row ) );
+ result.currentValueIdentity = EntityReference.parseEntityReference( row.field( valueIdentityColumn ).get( row ) ).identity();
+ result.modifedAt = Instant.ofEpochMilli( row.field( modifiedColumn ).get( row ).getTime() );
+ result.createdAt = Instant.ofEpochMilli( row.field( createdColumn ).get( row ).getTime() );
return result;
}
+ public Stream<BaseEntity> fetchAll( EntityDescriptor type, ModuleDescriptor module )
+ {
+ Result<Record> baseEntityResult = dsl
+ .selectFrom( entitiesTable )
+ .fetch();
+ return baseEntityResult.stream().map( record -> toBaseEntity( record, module ) );
+ }
+
private EntityDescriptor findEntityDescriptor( String typeName, ModuleDescriptor module )
{
try
@@ -108,34 +132,36 @@ public class EntitiesTable
}
}
- void insertEntity( DefaultEntityState state )
+ void insertEntity( DefaultEntityState state, BaseEntity baseEntity )
{
EntityCompositeType compositeType = state.entityDescriptor().valueType();
- Set<Class<?>> mixinTypes = mixinTypeCache.computeIfAbsent( compositeType, type ->
- {
- Set<Class<?>> mixins = compositeType
- .properties()
- .map( PropertyDescriptor::accessor )
- .filter( Classes.instanceOf( Method.class ) )
- .map( accessor -> (Method) accessor )
- .map( Method::getDeclaringClass )
- .collect( Collectors.toSet() );
- Set<Class<?>> mixinsWithAssociations = mixinsOf( compositeType.associations() );
- Set<Class<?>> mixinsWithManyAssociations = mixinsOf( compositeType.manyAssociations() );
- Set<Class<?>> mixinsWithNamedAssociations = mixinsOf( compositeType.namedAssociations() );
- mixins.addAll( mixinsWithAssociations );
- mixins.addAll( mixinsWithManyAssociations );
- mixins.addAll( mixinsWithNamedAssociations );
- return mixins;
- } );
- String valueIdentity = UUID.randomUUID().toString();
+ Set<Class<?>> mixinTypes = mixinTypeCache.computeIfAbsent( compositeType, createMixinTypesSet( compositeType ) );
mixinTypes.forEach( type ->
{
MixinTable table = findMixinTable( type, state.entityDescriptor() );
- table.insertMixinState( state, valueIdentity );
+ table.insertMixinState( state, baseEntity.currentValueIdentity.toString() );
} );
}
+ void modifyEntity( DefaultEntityState state, BaseEntity baseEntity, EntityStoreUnitOfWork uow )
+ {
+ updateBaseEntity( baseEntity, uow );
+ if( replacementStrategy )
+ {
+ insertEntity( state, baseEntity ); // replacement strategy (more safe)
+ }
+ else
+ {
+ EntityCompositeType compositeType = state.entityDescriptor().valueType();
+ Set<Class<?>> mixinTypes = mixinTypeCache.computeIfAbsent( compositeType, createMixinTypesSet( compositeType ) );
+ mixinTypes.forEach( type ->
+ {
+ MixinTable table = findMixinTable( type, state.entityDescriptor() );
+ table.modifyMixinState( state, baseEntity.currentValueIdentity.toString() );
+ } );
+ }
+ }
+
private MixinTable findMixinTable( Class<?> type, EntityDescriptor entityDescriptor )
{
return mixinTablesCache.computeIfAbsent( type, t -> new MixinTable( dsl, schema, types, type, entityDescriptor ) );
@@ -148,17 +174,32 @@ public class EntitiesTable
.filter( Classes.instanceOf( Method.class ) )
.map( accessor -> (Method) accessor )
.map( Method::getDeclaringClass )
+ .filter( NOT_HASIDENTITY )
+ .filter( NOT_COMPOSITE )
.collect( Collectors.toSet() );
}
- private String columnNameOf( QualifiedName propertyName )
- {
- return null;
- }
-
- void modifyEntity( Class<?> mixinType, DefaultEntityState state )
+ private Function<EntityCompositeType, Set<Class<?>>> createMixinTypesSet( EntityCompositeType compositeType )
{
-
+ return type ->
+ {
+ Set<Class<?>> mixins = compositeType
+ .properties()
+ .map( PropertyDescriptor::accessor )
+ .filter( Classes.instanceOf( Method.class ) )
+ .map( accessor -> (Method) accessor )
+ .map( Method::getDeclaringClass )
+ .filter( NOT_HASIDENTITY )
+ .filter( NOT_COMPOSITE )
+ .collect( Collectors.toSet() );
+ Set<Class<?>> mixinsWithAssociations = mixinsOf( compositeType.associations() );
+ Set<Class<?>> mixinsWithManyAssociations = mixinsOf( compositeType.manyAssociations() );
+ Set<Class<?>> mixinsWithNamedAssociations = mixinsOf( compositeType.namedAssociations() );
+ mixins.addAll( mixinsWithAssociations );
+ mixins.addAll( mixinsWithManyAssociations );
+ mixins.addAll( mixinsWithNamedAssociations );
+ return mixins;
+ };
}
void createNewBaseEntity( EntityReference reference, EntityDescriptor descriptor, EntityStoreUnitOfWork uow )
@@ -175,6 +216,27 @@ public class EntitiesTable
.execute();
}
+ private void updateBaseEntity( BaseEntity entity, EntityStoreUnitOfWork uow )
+ {
+ entity.version = increment( entity.version );
+ if( replacementStrategy )
+ {
+ entity.currentValueIdentity = new StringIdentity( UUID.randomUUID().toString() );
+ }
+ dsl.update( entitiesTable )
+ .set( modifiedColumn, new Timestamp( uow.currentTime().toEpochMilli() ) )
+ .set( valueIdentityColumn, entity.currentValueIdentity.toString() )
+ .set( versionColumn, entity.version )
+ .set( applicationVersionColumn, applicationVersion )
+ .execute();
+ }
+
+ private String increment( String version )
+ {
+ long ver = Long.parseLong( version );
+ return Long.toString( ver + 1 );
+ }
+
/**
* Builds the SELECT statement for a given entity.
* <p>
@@ -217,31 +279,85 @@ public class EntitiesTable
*/
public SelectQuery<Record> createGetEntityQuery( EntityDescriptor entityDescriptor, EntityReference reference )
{
+ List<Table<Record>> joins = getMixinTables( entityDescriptor );
SelectJoinStep<Record> from = dsl.select().from( entitiesTable );
- List<Table<Record>> joins = getTableJoins( entityDescriptor );
for( Table<Record> joinedTable : joins )
{
- Field<String> joinedField = joinedTable.field( identityColumn );
- Condition joinCondition = joinedField.eq( entitiesTable.field( valueIdentityColumn ) );
+ Condition joinCondition = valueIdentityColumn.eq( identityColumnOf( joinedTable ) );
+ from = from.leftJoin( joinedTable ).on( joinCondition );
+ }
+ return from.where( identityColumnOf( entitiesTable ).eq( reference.identity().toString() ) ).getQuery();
+ }
+
+ public void fetchAssociations( BaseEntity entity, EntityDescriptor entityDescriptor, Consumer<AssociationValue> consume )
+ {
+ List<Table<Record>> joins = getAssocationsTables( entityDescriptor );
+ SelectJoinStep<Record> from = dsl.select().from( entitiesTable );
+ for( Table<Record> joinedTable : joins )
+ {
+ Condition joinCondition = valueIdentityColumn.eq( identityColumnOf( joinedTable ) );
from = from.join( joinedTable ).on( joinCondition );
}
- return from.where( identityColumn.eq( reference.identity().toString() ) ).getQuery();
+ String reference = entity.identity.toString();
+ SelectQuery<Record> query = from.where( identityColumnOf( entitiesTable ).eq( reference ) ).getQuery();
+ Result<Record> result = query.fetch();
+ result.forEach( record ->
+ {
+ AssociationValue value = new AssociationValue();
+ value.name = QualifiedName.fromClass( entityDescriptor.primaryType(), record.getValue( nameColumn ) );
+ value.position = record.getValue( indexColumn );
+ value.reference = record.getValue( referenceColumn );
+ consume.accept( value );
+ } );
}
- public void fetchAssociations( Record record, Consumer<AssociationValue> consume )
+ private Field<String> identityColumnOf( Table<Record> joinedTable )
{
- AssociationValue value = new AssociationValue();
- value.name = record.getValue( nameColumn );
- value.position = record.getValue( indexColumn );
- value.reference = record.getValue( referenceColumn );
- consume.accept( value );
+ return DSL.field( DSL.name( joinedTable.getName(), identityColumn.getName() ), String.class );
}
- public List<Table<Record>> getTableJoins( EntityDescriptor entityDescriptor )
+ public List<Table<Record>> getMixinTables( EntityDescriptor entityDescriptor )
{
return entityDescriptor
.mixinTypes()
+ .filter( NOT_COMPOSITE )
+ .filter( NOT_HASIDENTITY )
.map( ( Class<?> type ) -> types.tableFor( type, entityDescriptor ) )
.collect( Collectors.toList() );
}
+
+ public List<Table<Record>> getAssocationsTables( EntityDescriptor entityDescriptor )
+ {
+ return entityDescriptor
+ .mixinTypes()
+ .filter( NOT_COMPOSITE )
+ .filter( NOT_HASIDENTITY )
+ .map( type -> findMixinTable( type, entityDescriptor ) )
+ .map( MixinTable::associationsTable )
+ .collect( Collectors.toList() );
+ }
+
+ public void removeEntity( EntityReference entityReference, EntityDescriptor descriptor )
+ {
+ ModuleDescriptor module = descriptor.module();
+ BaseEntity baseEntity = fetchEntity( entityReference, module );
+ if( replacementStrategy )
+ {
+ // TODO; Mark deleted, I guess... not implemented
+ }
+ else
+ {
+ dsl.delete( entitiesTable )
+ .where(
+ identityColumnOf( entitiesTable ).eq( entityReference.identity().toString() )
+ )
+ .execute()
+ ;
+ String valueId = baseEntity.currentValueIdentity.toString();
+ List<Table<Record>> mixinTables = getMixinTables( descriptor );
+ List<Table<Record>> assocTables = getAssocationsTables( descriptor );
+ mixinTables.forEach( table -> dsl.delete( table ).where( identityColumnOf( table ).eq( valueId ) ).execute() );
+ assocTables.forEach( table -> dsl.delete( table ).where( identityColumnOf( table ).eq( valueId ) ).execute() );
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
index a22354b..5a062d8 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
@@ -28,9 +28,11 @@ import org.apache.polygene.api.association.AssociationStateDescriptor;
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.api.identity.HasIdentity;
import org.apache.polygene.api.identity.IdentityGenerator;
import org.apache.polygene.api.injection.scope.Service;
import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.serialization.Serialization;
import org.apache.polygene.api.structure.ModuleDescriptor;
import org.apache.polygene.api.usecase.Usecase;
import org.apache.polygene.spi.entity.EntityState;
@@ -57,6 +59,9 @@ public class JooqEntityStoreMixin
@Service
private IdentityGenerator identityGenerator;
+ @Service
+ private Serialization serialization;
+
@Override
public EntityState newEntityState( EntityStoreUnitOfWork unitOfWork, EntityReference reference, EntityDescriptor entityDescriptor )
{
@@ -73,36 +78,45 @@ public class JooqEntityStoreMixin
{
throw new EntityNotFoundException( reference );
}
+ return toEntityState( result, baseEntity, reference );
+ }
+
+ protected EntityState toEntityState( Result<Record> result, BaseEntity baseEntity, EntityReference reference )
+ {
AssociationStateDescriptor stateDescriptor = baseEntity.type.state();
Map<QualifiedName, Object> properties = new HashMap<>();
- stateDescriptor.properties().forEach( prop ->
- {
- QualifiedName qualifiedName = prop.qualifiedName();
- Object value = result.getValue( 0, qualifiedName.name() );
- properties.put( qualifiedName, value );
- } );
+ stateDescriptor.properties()
+ .filter( prop -> !HasIdentity.IDENTITY_STATE_NAME.equals( prop.qualifiedName() ) )
+ .forEach( prop ->
+ {
+ QualifiedName qualifiedName = prop.qualifiedName();
+ Object value = result.getValue( 0, qualifiedName.name() );
+ properties.put( qualifiedName, value );
+ } );
Map<QualifiedName, EntityReference> assocations = new HashMap<>();
- stateDescriptor.associations().forEach( assoc ->
- {
- QualifiedName qualifiedName = assoc.qualifiedName();
- String value = (String) result.getValue( 0, qualifiedName.name() );
- assocations.put( qualifiedName, parseEntityReference( value ) );
- } );
+ stateDescriptor.associations()
+ .forEach( assoc ->
+ {
+ QualifiedName qualifiedName = assoc.qualifiedName();
+ String value = (String) result.getValue( 0, qualifiedName.name() );
+ if( value != null )
+ {
+ assocations.put( qualifiedName, parseEntityReference( value ) );
+ }
+ } );
Map<QualifiedName, List<EntityReference>> manyAssocs = new HashMap<>();
Map<QualifiedName, Map<String, EntityReference>> namedAssocs = new HashMap<>();
- result.forEach( record ->
- sqlTable.fetchAssociations( record, associationValue ->
- {
- // TODO: Perhaps introduce "preserveManyAssociationOrder" option which would have an additional column, separating 'ordinal position' and 'name position'
- if( associationValue.position == null )
- {
- addManyAssociation( stateDescriptor, manyAssocs, associationValue );
- }
- else
- {
- addNamedAssociation( stateDescriptor, namedAssocs, associationValue );
- }
- } ) );
+ sqlTable.fetchAssociations( baseEntity, baseEntity.type, associationValue ->
+ {
+ if( stateDescriptor.hasManyAssociation( associationValue.name ) )
+ {
+ addManyAssociation( stateDescriptor, manyAssocs, associationValue );
+ }
+ else if( stateDescriptor.hasNamedAssociation( associationValue.name ) )
+ {
+ addNamedAssociation( stateDescriptor, namedAssocs, associationValue );
+ }
+ } );
return new DefaultEntityState( baseEntity.version,
baseEntity.modifedAt,
@@ -117,7 +131,7 @@ public class JooqEntityStoreMixin
private void addNamedAssociation( AssociationStateDescriptor stateDescriptor, Map<QualifiedName, Map<String, EntityReference>> namedAssocs, AssociationValue associationValue )
{
- AssociationDescriptor descriptor = stateDescriptor.getNamedAssociationByName( associationValue.name );
+ AssociationDescriptor descriptor = stateDescriptor.getNamedAssociationByName( associationValue.name.name() );
QualifiedName qualifiedName = descriptor.qualifiedName();
Map<String, EntityReference> map = namedAssocs.computeIfAbsent( qualifiedName, k -> new HashMap<>() );
map.put( associationValue.position, parseEntityReference( associationValue.reference ) );
@@ -125,10 +139,11 @@ public class JooqEntityStoreMixin
private void addManyAssociation( AssociationStateDescriptor stateDescriptor, Map<QualifiedName, List<EntityReference>> manyAssocs, AssociationValue associationValue )
{
- AssociationDescriptor descriptor = stateDescriptor.getManyAssociationByName( associationValue.name );
+ AssociationDescriptor descriptor = stateDescriptor.getManyAssociationByName( associationValue.name.name() );
QualifiedName qualifiedName = descriptor.qualifiedName();
List<EntityReference> list = manyAssocs.computeIfAbsent( qualifiedName, k -> new ArrayList<>() );
- list.add( parseEntityReference( associationValue.reference ) );
+ String reference = associationValue.reference;
+ list.add( reference == null ? null : parseEntityReference( reference ) );
}
@Override
@@ -158,7 +173,16 @@ public class JooqEntityStoreMixin
@Override
public Stream<EntityState> entityStates( ModuleDescriptor module )
{
- return null;
+ Stream<? extends EntityDescriptor> entityTypes = module.entityComposites();
+ return entityTypes
+ .flatMap( type -> sqlTable.fetchAll( type, module ) )
+ .map( baseEntity ->
+ {
+ EntityReference reference = EntityReference.entityReferenceFor( baseEntity.identity );
+ SelectQuery<Record> selectQuery = sqlTable.createGetEntityQuery( baseEntity.type, reference );
+ Result<Record> result = selectQuery.fetch();
+ return toEntityState( result, baseEntity, reference );
+ } );
}
private class JooqStateCommitter
@@ -167,12 +191,36 @@ public class JooqEntityStoreMixin
private final EntityStoreUnitOfWork unitOfWork;
private final Iterable<EntityState> states;
private final JooqDslContext dslContext;
+ private final ModuleDescriptor module;
JooqStateCommitter( EntityStoreUnitOfWork unitOfWork, Iterable<EntityState> states, JooqDslContext dslContext )
{
this.unitOfWork = unitOfWork;
this.states = states;
this.dslContext = dslContext;
+ this.module = unitOfWork.module();
+ }
+
+ private void newState( DefaultEntityState state, EntityStoreUnitOfWork unitOfWork )
+ {
+ EntityReference ref = state.entityReference();
+ EntityDescriptor descriptor = state.entityDescriptor();
+ sqlTable.createNewBaseEntity( ref, descriptor, this.unitOfWork );
+ sqlTable.insertEntity( state, sqlTable.fetchBaseEntity( ref, module ), unitOfWork );
+ }
+
+ private void updateState( DefaultEntityState state, EntityStoreUnitOfWork unitOfWork )
+ {
+ EntityDescriptor descriptor = state.entityDescriptor();
+ BaseEntity baseEntity = sqlTable.fetchBaseEntity( state.entityReference(), descriptor.module() );
+ sqlTable.updateEntity( state, baseEntity, unitOfWork );
+ }
+
+ private void removeState( DefaultEntityState state )
+ {
+ EntityReference reference = state.entityReference();
+ EntityDescriptor descriptor = state.entityDescriptor();
+ sqlTable.removeEntity( reference, descriptor );
}
@Override
@@ -185,11 +233,11 @@ public class JooqEntityStoreMixin
DefaultEntityState state = (DefaultEntityState) es;
if( state.status() == EntityStatus.NEW )
{
- newState( state );
+ newState( state, unitOfWork );
}
if( state.status() == EntityStatus.UPDATED )
{
- updateState( state );
+ updateState( state, unitOfWork );
}
if( state.status() == EntityStatus.REMOVED )
{
@@ -199,24 +247,6 @@ public class JooqEntityStoreMixin
} );
}
- private void newState( DefaultEntityState state )
- {
- EntityReference ref = state.entityReference();
- EntityDescriptor descriptor = state.entityDescriptor();
- sqlTable.createNewBaseEntity( ref, descriptor, unitOfWork );
- sqlTable.insertEntity( state );
- }
-
- private void updateState( DefaultEntityState state )
- {
-
- }
-
- private void removeState( DefaultEntityState state )
- {
- EntityReference reference = state.entityReference();
- }
-
@Override
public void cancel()
{
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
index fee95ef..257134e 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
@@ -20,7 +20,11 @@ package org.apache.polygene.entitystore.jooq;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import org.apache.polygene.api.association.AssociationDescriptor;
import org.apache.polygene.api.common.QualifiedName;
@@ -32,10 +36,12 @@ import org.apache.polygene.spi.entity.NamedAssociationState;
import org.apache.polygene.spi.entitystore.helpers.DefaultEntityState;
import org.jooq.Field;
import org.jooq.InsertSetMoreStep;
+import org.jooq.InsertSetStep;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
import org.jooq.Table;
+import org.jooq.UpdateSetMoreStep;
import org.jooq.impl.DSL;
class MixinTable
@@ -46,6 +52,11 @@ class MixinTable
private final Table<Record> mixinAssocsTable;
private final JooqDslContext dsl;
+ private final Map<QualifiedName, Field<Object>> properties = new ConcurrentHashMap<>();
+ private final Map<QualifiedName, Field<String>> associations = new ConcurrentHashMap<>();
+ private final List<QualifiedName> manyAssociations = new CopyOnWriteArrayList<>();
+ private final List<QualifiedName> namedAssociations = new CopyOnWriteArrayList<>();
+
private TypesTable types;
private final Class<?> mixinType;
@@ -57,6 +68,34 @@ class MixinTable
this.mixinType = mixinType;
mixinTable = types.tableFor( mixinType, descriptor );
mixinAssocsTable = getAssocsTable( descriptor, schema );
+
+ descriptor.valueType().properties()
+ .filter( this::isThisMixin )
+ .forEach( propDescriptor ->
+ {
+ QualifiedName propertyName = propDescriptor.qualifiedName();
+ Field<Object> propertyField = types.fieldOf( propDescriptor );
+ properties.put( propertyName, propertyField );
+ }
+ );
+
+ descriptor.valueType().associations()
+ .filter( this::isThisMixin )
+ .forEach( assocDescriptor ->
+ {
+ QualifiedName assocName = assocDescriptor.qualifiedName();
+ Field<String> assocField = types.fieldOf( assocDescriptor );
+ associations.put( assocName, assocField );
+ }
+ );
+
+ descriptor.valueType().manyAssociations()
+ .filter( this::isThisMixin )
+ .forEach( assocDescriptor -> manyAssociations.add( assocDescriptor.qualifiedName() ) );
+
+ descriptor.valueType().namedAssociations()
+ .filter( this::isThisMixin )
+ .forEach( assocDescriptor -> manyAssociations.add( assocDescriptor.qualifiedName() ) );
}
void insertMixinState( DefaultEntityState state, String valueIdentity )
@@ -64,93 +103,99 @@ class MixinTable
InsertSetMoreStep<Record> primaryTable =
dsl.insertInto( mixinTable )
.set( identityColumn, valueIdentity )
- .set( createdColumn, new Timestamp( System.currentTimeMillis() ) )
- .set( modifiedColumn, new Timestamp( System.currentTimeMillis() ) );
+ .set( createdColumn, new Timestamp( System.currentTimeMillis() ) );
- EntityDescriptor entityDescriptor = state.entityDescriptor();
- entityDescriptor.valueType().properties()
- .filter( this::isThisMixin )
- .forEach( propDescriptor ->
+ properties.forEach( ( propertyName, propertyField ) -> primaryTable.set( propertyField, state.propertyValueOf( propertyName ) ) );
+ associations.forEach( ( assocName, assocField ) ->
+ {
+ EntityReference reference = state.associationValueOf( assocName );
+ String identity = null;
+ if( reference != null )
{
- QualifiedName propertyName = propDescriptor.qualifiedName();
- Field<Object> propertyField = types.fieldOf( propDescriptor );
- primaryTable.set( propertyField, state.propertyValueOf( propertyName ) );
+ identity = reference.identity().toString();
}
- );
- entityDescriptor.valueType().associations()
- .filter( this::isThisMixin )
- .forEach( assocDescriptor ->
- {
- QualifiedName assocName = assocDescriptor.qualifiedName();
- Field<String> assocField = types.fieldOf( assocDescriptor );
- EntityReference reference = state.associationValueOf( assocName );
- String identity = null;
- if( reference != null )
- {
- identity = reference.identity().toString();
- }
- primaryTable.set( assocField, identity );
- }
- );
+ primaryTable.set( assocField, identity );
+ }
+ );
+ int result = primaryTable.execute();
if( mixinAssocsTable != null )
{
- entityDescriptor.valueType().manyAssociations()
- .filter( this::isThisMixin )
- .forEach( setManyAssociations( state, valueIdentity ) );
-
- entityDescriptor.valueType().namedAssociations()
- .filter( this::isThisMixin )
- .forEach( setNamedAssociations( state, valueIdentity ) );
+ insertManyAndNamedAssociations( state, valueIdentity );
}
}
- private Consumer<? super AssociationDescriptor> setManyAssociations( DefaultEntityState state, String valueIdentity )
+ private void insertManyAndNamedAssociations( DefaultEntityState state, String valueIdentity )
{
- return assocDescriptor ->
- {
- QualifiedName assocName = assocDescriptor.qualifiedName();
- ManyAssociationState entityReferences = state.manyAssociationValueOf( assocName );
- entityReferences.stream().forEach( setManyAssociation( state, assocDescriptor, valueIdentity ) );
- };
+ InsertSetStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable );
+ manyAssociations.forEach( assocName ->
+ {
+ ManyAssociationState entityReferences = state.manyAssociationValueOf( assocName );
+ entityReferences.stream().forEach( setManyAssociation( assocName, valueIdentity, assocsTable ) );
+ } );
+
+ namedAssociations.forEach( assocName ->
+ {
+ NamedAssociationState entityReferences = state.namedAssociationValueOf( assocName );
+ entityReferences.stream().forEach( setNamedAssociation( assocName, valueIdentity, assocsTable ) );
+ } );
+
+ InsertSetMoreStep<Record> assocs = assocsTable.set( Collections.emptyMap() );
+ assocs.execute();
}
- private Consumer<? super EntityReference> setManyAssociation( DefaultEntityState state,
- AssociationDescriptor assocDescriptor,
- String valueIdentity )
+ Table<Record> associationsTable()
{
- QualifiedName assocName = assocDescriptor.qualifiedName();
- Field<String> assocField = types.fieldOf( assocDescriptor );
- InsertSetMoreStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable ).set( identityColumn, valueIdentity );
- return ref ->
- {
- assocsTable.newRecord();
- assocsTable.set( assocField, state.associationValueOf( assocName ).identity().toString() );
- };
+ return mixinAssocsTable;
}
- private Consumer<? super AssociationDescriptor> setNamedAssociations( DefaultEntityState state,
- String valueIdentity )
+ /**
+ * Writes one ManyAssoc Reference to the _ASSOCS table.
+ * <ul>
+ * <li>identityColumn - valueIdentity of primaryTable row</li>
+ * <li>nameColumn - index in the of association in state holder</li>
+ * <li>indexColumn - the position within the many association, starting at 0</li>
+ * <li>referenceColumn - referenced entity's identity</li>
+ * </ul>
+ */
+ private Consumer<? super EntityReference> setManyAssociation( QualifiedName assocName,
+ String valueIdentity,
+ InsertSetStep<Record> assocsTable )
{
- return assocDescriptor ->
+ return new Consumer<EntityReference>()
{
- QualifiedName assocName = assocDescriptor.qualifiedName();
- NamedAssociationState entityReferences = state.namedAssociationValueOf( assocName );
- entityReferences.stream().forEach( setNamedAssociation( state, assocDescriptor, valueIdentity ) );
+ private int counter = 0;
+
+ @Override
+ public void accept( EntityReference ref )
+ {
+ InsertSetMoreStep<Record> set = assocsTable.set( identityColumn, valueIdentity )
+ .set( nameColumn, assocName.name() )
+ .set( indexColumn, "" + counter++ )
+ .set( referenceColumn, ref == null ? null : ref.identity().toString() );
+ }
};
}
- private Consumer<? super Map.Entry<String, EntityReference>> setNamedAssociation( DefaultEntityState state,
- AssociationDescriptor assocDescriptor,
- String valueIdentity )
+ /**
+ * Writes one Named Reference to the _ASSOCS table.
+ * <ul>
+ * <li>identityColumn - valueIdentity of primaryTable row</li>
+ * <li>nameColumn - name of association in state holder</li>
+ * <li>indexColumn - the key/lookup name of the reference</li>
+ * <li>referenceColumn - referenced entity's identity</li>
+ * </ul>
+ */
+ private Consumer<? super Map.Entry<String, EntityReference>> setNamedAssociation( QualifiedName assocName,
+ String valueIdentity,
+ InsertSetStep<Record> assocsTable )
{
- QualifiedName assocName = assocDescriptor.qualifiedName();
- Field<String> assocField = types.fieldOf( assocDescriptor );
- InsertSetMoreStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable ).set( identityColumn, valueIdentity );
return ref ->
{
- assocsTable.newRecord();
- assocsTable.set( assocField, state.associationValueOf( assocName ).identity().toString() );
+ InsertSetMoreStep<Record> set = assocsTable.set( identityColumn, valueIdentity )
+ .set( nameColumn, assocName.name() )
+ .set( indexColumn, ref.getKey() )
+ .set( referenceColumn, ref.getValue().identity().toString() );
};
}
@@ -186,9 +231,31 @@ class MixinTable
throw new UnsupportedOperationException( "Property declared as " + accessor.getClass() + " is not supported in this Entity Store yet." );
}
- void modifyMixinState( Class<?> mixinType, DefaultEntityState state )
+ void modifyMixinState( DefaultEntityState state, String valueId )
{
+ UpdateSetMoreStep<Record> primaryTable =
+ dsl.update( mixinTable )
+ .set( Collections.emptyMap() ); // empty map is a hack to get the right type returned from JOOQ.
+
+ properties.forEach( ( propertyName, propertyField ) -> primaryTable.set( propertyField, state.propertyValueOf( propertyName ) ) );
+ associations.forEach( ( assocName, assocField ) ->
+ {
+ EntityReference reference = state.associationValueOf( assocName );
+ primaryTable.set( assocField,
+ reference == null ? null : reference.identity().toString()
+ );
+ }
+ );
+ int result = primaryTable.execute();
+ if( mixinAssocsTable != null )
+ {
+ // Need to remove existing records.
+ dsl.delete( mixinAssocsTable )
+ .where( identityColumn.eq( valueId ) )
+ .execute();
+ insertManyAndNamedAssociations( state, valueId );
+ }
}
private Table<Record> getAssocsTable( EntityDescriptor descriptor, Schema schema )
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
index 2801f57..13b6c37 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
@@ -18,6 +18,7 @@
package org.apache.polygene.entitystore.jooq;
import java.util.function.Consumer;
+import java.util.stream.Stream;
import javax.sql.DataSource;
import org.apache.polygene.api.PolygeneAPI;
import org.apache.polygene.api.composite.TransientBuilderFactory;
@@ -99,14 +100,20 @@ public interface SqlTable extends ServiceActivation
SelectQuery<Record> createGetEntityQuery( EntityDescriptor descriptor, EntityReference reference );
- void fetchAssociations( Record record, Consumer<AssociationValue> consume );
+ void fetchAssociations( BaseEntity entity, EntityDescriptor descriptor, Consumer<AssociationValue> consume );
void createNewBaseEntity( EntityReference ref, EntityDescriptor descriptor, EntityStoreUnitOfWork unitOfWork );
- void insertEntity( DefaultEntityState state );
+ void insertEntity( DefaultEntityState state, BaseEntity baseEntity, EntityStoreUnitOfWork unitOfWork );
+
+ void updateEntity( DefaultEntityState state, BaseEntity baseEntity, EntityStoreUnitOfWork unitOfWork );
JooqDslContext jooqDslContext();
+ void removeEntity( EntityReference entityReference, EntityDescriptor descriptor );
+
+ Stream<BaseEntity> fetchAll( EntityDescriptor type, ModuleDescriptor module );
+
class Mixin
implements SqlTable, TableFields, ServiceActivation
{
@@ -143,15 +150,21 @@ public interface SqlTable extends ServiceActivation
}
@Override
+ public Stream<BaseEntity> fetchAll( EntityDescriptor type, ModuleDescriptor module )
+ {
+ return entitiesTable.fetchAll( type, module );
+ }
+
+ @Override
public SelectQuery<Record> createGetEntityQuery( EntityDescriptor descriptor, EntityReference reference )
{
return entitiesTable.createGetEntityQuery( descriptor, reference );
}
@Override
- public void fetchAssociations( Record record, Consumer<AssociationValue> consume )
+ public void fetchAssociations( BaseEntity entity, EntityDescriptor descriptor, Consumer<AssociationValue> consume )
{
- entitiesTable.fetchAssociations( record, consume );
+ entitiesTable.fetchAssociations( entity, descriptor, consume );
}
@Override
@@ -161,9 +174,15 @@ public interface SqlTable extends ServiceActivation
}
@Override
- public void insertEntity( DefaultEntityState state )
+ public void insertEntity( DefaultEntityState state, BaseEntity baseEntity, EntityStoreUnitOfWork unitOfWork )
{
- entitiesTable.insertEntity( state );
+ entitiesTable.insertEntity( state, baseEntity );
+ }
+
+ @Override
+ public void updateEntity( DefaultEntityState state, BaseEntity baseEntity, EntityStoreUnitOfWork unitOfWork )
+ {
+ entitiesTable.modifyEntity( state, baseEntity, unitOfWork );
}
@Override
@@ -173,6 +192,12 @@ public interface SqlTable extends ServiceActivation
}
@Override
+ public void removeEntity( EntityReference reference, EntityDescriptor descriptor )
+ {
+ entitiesTable.removeEntity( reference, descriptor );
+ }
+
+ @Override
public void activateService()
throws Exception
{
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java
index 2454ae4..db42413 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java
@@ -25,23 +25,23 @@ import static org.apache.polygene.entitystore.jooq.TypesTable.makeField;
public interface TableFields
{
// Common in all tables
- String IDENTITY_COLUMN_NAME = "identity";
- String CREATED_COLUMN_NAME = "created_at";
- String LASTMODIFIED_COLUMN_NAME = "modified_at";
+ String IDENTITY_COLUMN_NAME = "_identity";
+ String CREATED_COLUMN_NAME = "_created_at";
+ String LASTMODIFIED_COLUMN_NAME = "_modified_at";
// Types Table
- String TABLENAME_COLUMN_NAME = "table_name";
+ String TABLENAME_COLUMN_NAME = "_table_name";
// Entities Table
- String VALUEID_COLUMN_NAME = "value_id";
- String TYPE_COLUMN_NAME = "type";
- String VERSION_COLUMN_NAME = "version";
- String APPLICATIONVERSION_COLUMN_NAME = "app_version";
+ String VALUEID_COLUMN_NAME = "_value_id";
+ String TYPE_COLUMN_NAME = "_type";
+ String VERSION_COLUMN_NAME = "_version";
+ String APPLICATIONVERSION_COLUMN_NAME = "_app_version";
// Mixin Tables
- String NAME_COLUMN_NAME = "name";
- String INDEX_COLUMN_NAME = "index"; // either index in ManyAssociation or name in NamedAssociation
- String REFERENCE_COLUMN_NAME = "reference";
+ String NAME_COLUMN_NAME = "_name";
+ String INDEX_COLUMN_NAME = "_index"; // either index in ManyAssociation or name in NamedAssociation
+ String REFERENCE_COLUMN_NAME = "_reference";
String ASSOCS_TABLE_POSTFIX = "_ASSOCS";
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java
index 4672d4f..c816c95 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java
@@ -110,12 +110,14 @@ public class TypesTable
{
String mixinTypeName = mixinType.getName();
String tableName = createNewTableName( mixinType );
- CreateTableColumnStep primaryTable = dsl.createTable( tableName ).column( identityColumn );
+ CreateTableColumnStep primaryTable = dsl.createTable( DSL.name( schema.getName(), tableName ) )
+ .column( identityColumn )
+ .column( createdColumn );
descriptor.state().properties().forEach(
property ->
{
QualifiedName qualifiedName = property.qualifiedName();
- if( qualifiedName.toNamespace().equals( mixinTypeName ) )
+ if( qualifiedName.type().replace( '-', '$' ).equals( mixinTypeName ) )
{
primaryTable.column( fieldOf( property ) );
}
@@ -124,12 +126,12 @@ public class TypesTable
assoc ->
{
QualifiedName qualifiedName = assoc.qualifiedName();
- if( qualifiedName.toNamespace().equals( mixinTypeName ) )
+ if( qualifiedName.type().replace( '-', '$' ).equals( mixinTypeName ) )
{
primaryTable.column( fieldOf( assoc ) );
}
} );
-
+ int result1 = primaryTable.execute();
int result3 = dsl.insertInto( typesTable )
.set( identityColumn, mixinTypeName )
.set( tableNameColumn, tableName )
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java b/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
index e097662..f36db0e 100644
--- a/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
+++ b/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
@@ -29,22 +29,13 @@ import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
import org.apache.polygene.test.EntityTestAssembler;
import org.apache.polygene.test.entity.AbstractEntityStoreTest;
import org.jooq.SQLDialect;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
public class JooqEntityStoreTest extends AbstractEntityStoreTest
{
-// @ClassRule
-// public static final DockerRule DOCKER = new DockerRule(
-// "mysql",
-// new HashMap<String, String>()
-// {{
-// put( "MYSQL_ROOT_PASSWORD", "" );
-// put( "MYSQL_ALLOW_EMPTY_PASSWORD", "yes" );
-// put( "MYSQL_DATABASE", "jdbc_test_db" );
-// put( "MYSQL_ROOT_HOST", "127.0.0.1" );
-// }},
-// 30000L
-//// , "mysqld: ready for connections" TODO: add this after next release of tdomzal/junit-docker-rule
-// );
+ @Rule
+ public final TemporaryFolder tmpDir = new TemporaryFolder();
@Override
// START SNIPPET: assembly
@@ -83,8 +74,6 @@ public class JooqEntityStoreTest extends AbstractEntityStoreTest
.declareDefaults();
jooqDefaults.entitiesTableName().set( "ENTITIES" );
- String path = System.getProperty( "user.dir" ) + "/testdb";
- System.out.println("Niclas: " + path);
DataSourceConfiguration dsDefaults = config.forMixin( DataSourceConfiguration.class ).declareDefaults();
dsDefaults.driver().set( org.h2.Driver.class.getName() );
dsDefaults.enabled().set( true );
@@ -92,7 +81,7 @@ public class JooqEntityStoreTest extends AbstractEntityStoreTest
dsDefaults.minPoolSize().set( 1 );
dsDefaults.username().set( "" );
dsDefaults.password().set( "" );
- dsDefaults.url().set( "jdbc:h2:"+path+";create=true" );
+ dsDefaults.url().set( "jdbc:h2:" + tmpDir.getRoot().getAbsolutePath() + "/testdb;create=true" );
// START SNIPPET: assembly
}
// END SNIPPET: assembly
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/59a08629/manual/src/docs/userguide/extensions.txt
----------------------------------------------------------------------
diff --git a/manual/src/docs/userguide/extensions.txt b/manual/src/docs/userguide/extensions.txt
index 44bfd3f..5026259 100644
--- a/manual/src/docs/userguide/extensions.txt
+++ b/manual/src/docs/userguide/extensions.txt
@@ -105,6 +105,10 @@ include::../../../../extensions/entitystore-riak/src/docs/es-riak.txt[]
:leveloffset: 2
+include::../../../../extensions/entitystore-jooq/src/docs/es-jooq.txt[]
+
+:leveloffset: 2
+
include::../../../../extensions/entitystore-sql/src/docs/es-sql.txt[]
:leveloffset: 2
[06/11] polygene-java git commit: Committing an intermediate state of
the JOOQ ES, to dig into the classloading issue in the Service composition.
Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java b/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
index 8db2784..e097662 100644
--- a/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
+++ b/extensions/entitystore-jooq/src/test/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreTest.java
@@ -19,33 +19,32 @@
*/
package org.apache.polygene.entitystore.jooq;
-import java.util.HashMap;
import org.apache.polygene.api.common.Visibility;
import org.apache.polygene.bootstrap.AssemblyException;
import org.apache.polygene.bootstrap.ModuleAssembly;
import org.apache.polygene.entitystore.jooq.assembly.JooqEntityStoreAssembler;
+import org.apache.polygene.library.sql.assembly.DataSourceAssembler;
+import org.apache.polygene.library.sql.datasource.DataSourceConfiguration;
+import org.apache.polygene.library.sql.dbcp.DBCPDataSourceServiceAssembler;
import org.apache.polygene.test.EntityTestAssembler;
import org.apache.polygene.test.entity.AbstractEntityStoreTest;
-import org.apache.polygene.test.internal.DockerRule;
import org.jooq.SQLDialect;
-import org.junit.ClassRule;
-public class JooqEntityStoreTest
- extends AbstractEntityStoreTest
+public class JooqEntityStoreTest extends AbstractEntityStoreTest
{
- @ClassRule
- public static final DockerRule DOCKER = new DockerRule(
- "mysql",
- new HashMap<String, String>()
- {{
- put( "MYSQL_ROOT_PASSWORD", "" );
- put( "MYSQL_ALLOW_EMPTY_PASSWORD", "yes" );
- put( "MYSQL_DATABASE", "jdbc_test_db" );
- put( "MYSQL_ROOT_HOST", "172.17.0.1" );
- }},
- 30000L
-// , "mysqld: ready for connections" TODO: add this after next release of tdomzal/junit-docker-rule
- );
+// @ClassRule
+// public static final DockerRule DOCKER = new DockerRule(
+// "mysql",
+// new HashMap<String, String>()
+// {{
+// put( "MYSQL_ROOT_PASSWORD", "" );
+// put( "MYSQL_ALLOW_EMPTY_PASSWORD", "yes" );
+// put( "MYSQL_DATABASE", "jdbc_test_db" );
+// put( "MYSQL_ROOT_HOST", "127.0.0.1" );
+// }},
+// 30000L
+//// , "mysqld: ready for connections" TODO: add this after next release of tdomzal/junit-docker-rule
+// );
@Override
// START SNIPPET: assembly
@@ -54,17 +53,46 @@ public class JooqEntityStoreTest
{
// END SNIPPET: assembly
super.assemble( module );
+ module.defaultServices();
ModuleAssembly config = module.layer().module( "config" );
new EntityTestAssembler().visibleIn( Visibility.module ).assemble( config );
// START SNIPPET: assembly
+ // Assemble a DataSource
+ new DataSourceAssembler()
+ .withDataSourceServiceIdentity( "datasource" )
+ .identifiedBy( "ds-mysql" )
+ .visibleIn( Visibility.module )
+ .assemble( module );
+
+ // Assemble the Apache DBCP based Service Importer
+ new DBCPDataSourceServiceAssembler()
+ .identifiedBy( "datasource" )
+ .visibleIn( Visibility.module )
+ .withConfig( config, Visibility.layer )
+ .assemble( module );
+
new JooqEntityStoreAssembler()
.withConfig( config, Visibility.layer )
.identifiedBy( "jooq-entitystore" )
.assemble( module );
// END SNIPPET: assembly
- config.forMixin( JooqEntityStoreConfiguration.class ).setMetaInfo( SQLDialect.MARIADB );
+ JooqEntityStoreConfiguration jooqDefaults = config.forMixin( JooqEntityStoreConfiguration.class )
+ .setMetaInfo( SQLDialect.H2 )
+ .declareDefaults();
+ jooqDefaults.entitiesTableName().set( "ENTITIES" );
+
+ String path = System.getProperty( "user.dir" ) + "/testdb";
+ System.out.println("Niclas: " + path);
+ DataSourceConfiguration dsDefaults = config.forMixin( DataSourceConfiguration.class ).declareDefaults();
+ dsDefaults.driver().set( org.h2.Driver.class.getName() );
+ dsDefaults.enabled().set( true );
+ dsDefaults.maxPoolSize().set( 3 );
+ dsDefaults.minPoolSize().set( 1 );
+ dsDefaults.username().set( "" );
+ dsDefaults.password().set( "" );
+ dsDefaults.url().set( "jdbc:h2:"+path+";create=true" );
// START SNIPPET: assembly
}
// END SNIPPET: assembly
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/libraries/sql-dbcp/src/main/java/org/apache/polygene/library/sql/dbcp/DBCPDataSourceServiceImporter.java
----------------------------------------------------------------------
diff --git a/libraries/sql-dbcp/src/main/java/org/apache/polygene/library/sql/dbcp/DBCPDataSourceServiceImporter.java b/libraries/sql-dbcp/src/main/java/org/apache/polygene/library/sql/dbcp/DBCPDataSourceServiceImporter.java
index 38b6c5a..6e89f1f 100644
--- a/libraries/sql-dbcp/src/main/java/org/apache/polygene/library/sql/dbcp/DBCPDataSourceServiceImporter.java
+++ b/libraries/sql-dbcp/src/main/java/org/apache/polygene/library/sql/dbcp/DBCPDataSourceServiceImporter.java
@@ -35,8 +35,7 @@ public interface DBCPDataSourceServiceImporter
extends ServiceImporter<DataSource>, DataSourceServiceImporterActivation, ServiceComposite
{
- class Mixin
- extends AbstractDataSourceServiceImporterMixin<BasicDataSource>
+ class Mixin extends AbstractDataSourceServiceImporterMixin<BasicDataSource>
{
@Override
[04/11] polygene-java git commit: Merge remote-tracking branch
'origin/develop' into entitystore_sqlng
Posted by ni...@apache.org.
Merge remote-tracking branch 'origin/develop' into entitystore_sqlng
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/437d04ce
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/437d04ce
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/437d04ce
Branch: refs/heads/es-jooq
Commit: 437d04ce696b9ca01ad4992b5286b79b51d07347
Parents: 1f7357c c201ff5
Author: niclas <ni...@hedhman.org>
Authored: Tue Jun 6 08:11:41 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Tue Jun 6 08:11:41 2017 +0800
----------------------------------------------------------------------
.../manual/AsciidocBuildInfoPlugin.groovy | 10 +-
.../api/property/InitialValueProvider.java | 27 ---
.../api/property/PropertyDescriptor.java | 2 -
.../api/composite/PropertyMapperTest.java | 4 +-
.../polygene/bootstrap/MetaInfoDeclaration.java | 8 -
.../polygene/bootstrap/MixinDeclaration.java | 4 -
.../layered/LayeredApplicationAssembler.java | 17 +-
.../layered/LayeredLayerAssembler.java | 8 +-
.../runtime/bootstrap/AssemblyHelper.java | 5 +-
.../bootstrap/CompositeAssemblyImpl.java | 5 +-
.../composite/InterfaceDefaultMethodsMixin.java | 5 +-
.../runtime/property/PropertyModel.java | 24 +-
.../polygene/test/util/FreePortFinder.java | 2 +-
dependencies.gradle | 1 +
.../memcache/assembly/MemcacheAssembler.java | 2 +-
extensions/entitystore-mongodb/build.gradle | 2 +-
.../mongodb/MongoDBEntityStoreTest.java | 15 +-
.../MongoDBEntityStoreWithCacheTest.java | 15 +-
.../index/solr/EmbeddedSolrService.java | 5 +-
.../src/main/docker/mongo/Dockerfile | 16 ++
manual/src/docs/userguide/tools.txt | 12 +-
.../apache/polygene/sample/rental/web/Page.java | 6 +-
tools/envisage/src/docs/envisage.txt | 10 +-
tools/generator-polygene/app/index.js | 13 -
.../SerializationModule/bootstrap.tmpl | 10 +-
.../SerializationModule/module.js | 2 +-
.../StorageModule/bootstrap.tmpl | 11 +
.../InfrastructureLayer/StorageModule/module.js | 6 +-
.../storage/ds-es-h2sql.properties | 2 +-
.../InfrastructureLayer/bootstrap.tmpl | 2 +-
.../RestAPIApplication/bootstrap-test.tmpl | 235 ++++++++++++-------
.../app/templates/buildtool/gradle-app.tmpl | 2 +-
.../templates/buildtool/gradle-bootstrap.tmpl | 2 +-
.../src/docs/yeoman_polygene.txt | 25 +-
tools/generator-polygene/test/generator_test.js | 102 ++++----
tools/model-detail/src/docs/model-detail.txt | 52 ++++
.../tools/model/DocumentationSupport.java | 118 ++++++++++
.../src/test/resources/doc-support-report.json | 129 ++++++++++
38 files changed, 622 insertions(+), 294 deletions(-)
----------------------------------------------------------------------
[05/11] polygene-java git commit: Merge branch 'develop' into
entitystore_sqlng
Posted by ni...@apache.org.
Merge branch 'develop' into entitystore_sqlng
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/c2a30f73
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/c2a30f73
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/c2a30f73
Branch: refs/heads/es-jooq
Commit: c2a30f73a0fd2f128b37b988ff188b72ff9beb5e
Parents: 437d04c 4f15279
Author: niclas <ni...@hedhman.org>
Authored: Wed Jun 7 12:40:49 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Wed Jun 7 12:40:49 2017 +0800
----------------------------------------------------------------------
.../org/apache/polygene/api/PolygeneAPI.java | 8 ++-
.../polygene/runtime/PolygeneRuntimeImpl.java | 13 +++++
.../composite/AbstractModifierModel.java | 1 -
.../runtime/composite/UsesInstance.java | 11 ++++
.../runtime/composite/IsCompositeTest.java | 55 ++++++++++++++++++++
tools/generator-polygene/test/generator_test.js | 3 +-
6 files changed, 87 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
[08/11] polygene-java git commit: Better error message for missing
return types need to be public classes or interfaces
Posted by ni...@apache.org.
Better error message for missing return types need to be public classes or interfaces
Signed-off-by: niclas <ni...@hedhman.org>
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/0f58a7d5
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/0f58a7d5
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/0f58a7d5
Branch: refs/heads/es-jooq
Commit: 0f58a7d570d25ad8caa448e3f1fb2a2a06e14057
Parents: 60d2eeb
Author: niclas <ni...@hedhman.org>
Authored: Fri Jun 9 12:37:41 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Fri Jun 9 12:37:41 2017 +0800
----------------------------------------------------------------------
.../runtime/composite/ConstructorModel.java | 5 ++-
.../TypedModifierInvocationHandler.java | 17 +++++++-
.../runtime/methods/AccessibleTest.java | 41 +++++++++++++++-----
3 files changed, 50 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0f58a7d5/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java
index 427cff0..026a4e1 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/ConstructorModel.java
@@ -27,13 +27,14 @@ import java.util.stream.Stream;
import org.apache.polygene.api.common.ConstructionException;
import org.apache.polygene.api.composite.ConstructorDescriptor;
import org.apache.polygene.api.composite.InvalidCompositeException;
-import org.apache.polygene.api.util.AccessibleObjects;
import org.apache.polygene.api.util.HierarchicalVisitor;
import org.apache.polygene.api.util.VisitableHierarchy;
import org.apache.polygene.runtime.injection.DependencyModel;
import org.apache.polygene.runtime.injection.InjectedParametersModel;
import org.apache.polygene.runtime.injection.InjectionContext;
+import static org.apache.polygene.api.util.AccessibleObjects.accessible;
+
/**
* JAVADOC
*/
@@ -46,7 +47,7 @@ public final class ConstructorModel
public ConstructorModel( Constructor<?> constructor, InjectedParametersModel parameters )
{
- this.constructor = AccessibleObjects.accessible( constructor );
+ this.constructor = accessible( constructor );
this.parameters = parameters;
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0f58a7d5/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java
index 7d96abf..bf750e9 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/TypedModifierInvocationHandler.java
@@ -21,6 +21,7 @@ package org.apache.polygene.runtime.composite;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
/**
* JAVADOC
@@ -38,7 +39,21 @@ public final class TypedModifierInvocationHandler
}
catch( InvocationTargetException e )
{
- throw cleanStackTrace( e.getTargetException(), proxy, method );
+ Throwable targetException = e.getTargetException();
+ if( targetException instanceof IllegalAccessError )
+ {
+ // We get here if any of the return types or parameters are not public. This is probably due to
+ // the _Stub class ends up in a different classpace than the original mixin. We intend to fix this in
+ // 3.1 or 3.2
+ if( !Modifier.isPublic( method.getReturnType().getModifiers() ) )
+ {
+ String message = "Return types must be public: " + method.getReturnType().getName();
+ IllegalAccessException illegalAccessException = new IllegalAccessException( message );
+ illegalAccessException.initCause( e.getTargetException() );
+ throw cleanStackTrace( illegalAccessException, proxy, method );
+ }
+ }
+ throw cleanStackTrace( targetException, proxy, method );
}
catch( Throwable e )
{
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/0f58a7d5/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java
index 0d3ccb4..f420ef7 100644
--- a/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java
@@ -19,6 +19,7 @@
*/
package org.apache.polygene.runtime.methods;
+import java.lang.reflect.UndeclaredThrowableException;
import org.apache.polygene.api.injection.scope.This;
import org.apache.polygene.api.mixin.Mixins;
import org.apache.polygene.bootstrap.AssemblyException;
@@ -26,8 +27,9 @@ import org.apache.polygene.bootstrap.ModuleAssembly;
import org.apache.polygene.test.AbstractPolygeneTest;
import org.junit.Test;
-import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
public class AccessibleTest extends AbstractPolygeneTest
{
@@ -40,10 +42,18 @@ public class AccessibleTest extends AbstractPolygeneTest
}
@Test
- public void givenPrivateMixinWhenCallingFromWithinExpectSuccess()
+ public void givenPackageReturnTypeWhenCallingFromWithinExpectSuccess()
{
MyComposite myComposite = transientBuilderFactory.newTransient( MyComposite.class );
- assertThat(myComposite.doSomething(), equalTo("Hello"));
+ try
+ {
+ myComposite.doSomething();
+ fail("Should have gotten an IllegalAccessException");
+ } catch( UndeclaredThrowableException e )
+ {
+ Throwable thrown = e.getUndeclaredThrowable();
+ assertThat( thrown, instanceOf(IllegalAccessException.class));
+ }
}
@Mixins( MyCompositeMixin.class)
@@ -55,10 +65,9 @@ public class AccessibleTest extends AbstractPolygeneTest
@Mixins( MyFunctionMixin.class )
public interface MyFunction
{
- String doSomething();
+ MyString doSomething();
}
-
public class MyCompositeMixin
implements MyComposite
{
@@ -70,19 +79,20 @@ public class AccessibleTest extends AbstractPolygeneTest
{
return new MyObject( function ).doSomething() + " ---- " + getClass().getClassLoader();
}
+
}
- public class MyFunctionMixin
+ public static class MyFunctionMixin
implements MyFunction
{
@Override
- public String doSomething()
+ public MyString doSomething()
{
- return "Hello " + getClass().getClassLoader();
+ return new MyString( "Hello " );
}
}
- public class MyObject
+ public static class MyObject
{
private MyFunction fn;
@@ -93,7 +103,18 @@ public class AccessibleTest extends AbstractPolygeneTest
String doSomething()
{
- return fn.doSomething();
+ return fn.doSomething().mine;
}
}
+
+ static class MyString
+ {
+ String mine;
+
+ public MyString( String mine )
+ {
+ this.mine = mine;
+ }
+ }
+
}
[02/11] polygene-java git commit: Merge branch 'develop' into
entitystore_sqlng
Posted by ni...@apache.org.
Merge branch 'develop' into entitystore_sqlng
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/57438d0e
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/57438d0e
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/57438d0e
Branch: refs/heads/es-jooq
Commit: 57438d0e94bc0f44b16187506390f20bd6121449
Parents: c3d8e01 955eaa9
Author: niclas <ni...@hedhman.org>
Authored: Tue May 16 11:15:25 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Tue May 16 11:15:25 2017 +0800
----------------------------------------------------------------------
.gitignore | 1 +
NOTICE.txt | 2 -
buildSrc/build.gradle | 1 +
.../DependenciesDeclarationExtension.groovy | 1 +
.../distributions/DistributionsPlugin.groovy | 63 +-
.../structure/manual/DocumentationTask.groovy | 21 +-
.../reports/AggregatedJacocoReportTask.groovy | 68 ++-
.../structure/reports/ReportsPlugin.groovy | 10 +-
.../gradle/structure/tools/NpmToolPlugin.groovy | 47 ++
.../gradle-plugins/polygene-tool-npm.properties | 18 +
.../org/apache/polygene/api/PolygeneAPI.java | 26 +-
.../api/activation/ActivationException.java | 1 -
.../ApplicationPassivationThread.java | 1 -
.../api/activation/PassivationException.java | 2 -
.../api/association/AssociationStateHolder.java | 3 +-
.../api/association/ManyAssociation.java | 9 +
.../api/association/ManyAssociationWrapper.java | 6 +
.../api/association/NamedAssociation.java | 8 +-
.../association/NamedAssociationWrapper.java | 6 +
.../apache/polygene/api/cache/CacheOptions.java | 5 +
.../polygene/api/common/AppliesToFilter.java | 9 +-
.../api/common/ConstructionException.java | 2 -
.../api/common/InvalidApplicationException.java | 5 +-
.../polygene/api/common/QualifiedName.java | 3 +-
.../apache/polygene/api/common/TypeName.java | 3 +-
.../api/composite/AmbiguousTypeException.java | 5 +-
.../api/composite/CompositeInstance.java | 8 +
.../api/composite/DefaultMethodsFilter.java | 36 ++
.../InvalidValueCompositeException.java | 3 +-
.../api/composite/NoSuchCompositeException.java | 5 +-
.../polygene/api/composite/PropertyMapper.java | 27 +-
.../StatefulAssociationCompositeDescriptor.java | 3 +
.../polygene/api/constraint/Constraint.java | 2 -
...nstraintImplementationNotFoundException.java | 34 --
.../api/constraint/ConstraintViolation.java | 2 -
.../ConstraintViolationException.java | 5 +-
.../polygene/api/entity/EntityDescriptor.java | 4 +
.../polygene/api/entity/EntityReference.java | 6 +-
.../polygene/api/entity/LifecycleException.java | 5 +-
.../polygene/api/identity/HasIdentity.java | 1 -
.../api/mixin/InitializationException.java | 5 +-
.../api/mixin/InvalidMixinException.java | 35 --
.../api/mixin/MixinMappingException.java | 35 --
.../apache/polygene/api/mixin/NoopMixin.java | 5 +
.../polygene/api/property/DefaultValues.java | 2 +-
.../api/query/NotQueryableException.java | 5 +-
.../org/apache/polygene/api/query/Query.java | 4 +-
.../polygene/api/query/QueryException.java | 5 +-
.../api/query/QueryExpressionException.java | 3 -
.../polygene/api/serialization/ConvertedBy.java | 7 +-
.../polygene/api/serialization/Converters.java | 97 ++-
.../JavaSerializationConverter.java | 88 +++
.../polygene/api/serialization/Serializer.java | 61 +-
.../polygene/api/service/qualifier/Active.java | 2 +-
.../service/qualifier/AnnotationQualifier.java | 2 +-
.../api/service/qualifier/Available.java | 2 +-
.../api/service/qualifier/HasMetaInfo.java | 34 +-
.../api/service/qualifier/IdentifiedBy.java | 4 +-
.../api/service/qualifier/Qualifier.java | 2 +-
.../api/service/qualifier/ServiceQualifier.java | 48 +-
.../api/service/qualifier/ServiceTags.java | 3 -
.../polygene/api/structure/Application.java | 2 +-
.../polygene/api/type/EntityCompositeType.java | 63 ++
.../api/type/StatefulAssociationValueType.java | 75 +++
.../polygene/api/type/ValueCompositeType.java | 40 +-
.../polygene/api/unitofwork/UnitOfWork.java | 2 +-
.../apache/polygene/api/usecase/Usecase.java | 4 +-
.../org/apache/polygene/api/util/Classes.java | 2 +-
.../polygene/api/value/ValueDescriptor.java | 1 +
.../polygene/api/type/ValueTypeFactoryTest.java | 28 +-
.../polygene/api/value/ValueCompositeTest.java | 27 +-
.../polygene/bootstrap/ApplicationAssembly.java | 7 +
.../polygene/bootstrap/AssemblyVisitor.java | 18 +-
.../bootstrap/ImportedServiceDeclaration.java | 8 +-
.../polygene/bootstrap/ModuleAssembly.java | 2 +-
.../polygene/bootstrap/RuntimeFactory.java | 2 +-
.../polygene/bootstrap/SingletonAssembler.java | 68 ++-
.../bootstrap/layered/LayerAssembler.java | 1 +
.../bootstrap/layered/ModuleAssembler.java | 1 +
.../DefaultSerializationAssembler.java | 12 +-
core/runtime/src/docs/runtime.txt | 2 +-
.../polygene/runtime/PolygeneRuntimeImpl.java | 93 ++-
.../runtime/activation/ActivationDelegate.java | 43 +-
.../association/AbstractAssociationModel.java | 226 +++++++
.../runtime/association/AssociationModel.java | 190 +-----
.../association/ManyAssociationInstance.java | 12 +-
.../association/ManyAssociationModel.java | 226 +------
.../association/ManyAssociationsModel.java | 4 +-
.../association/NamedAssociationInstance.java | 19 +-
.../association/NamedAssociationModel.java | 229 +------
.../association/NamedAssociationsModel.java | 4 -
.../bootstrap/ApplicationAssemblyImpl.java | 1 +
.../bootstrap/CompositeAssemblyImpl.java | 296 ++++-----
.../ImplementsMethodAppliesToFilter.java | 4 +-
.../runtime/composite/AtomicInstancePool.java | 2 +-
.../runtime/composite/CompositeMethodModel.java | 10 +-
.../composite/CompositeMethodsModel.java | 57 +-
.../runtime/composite/ConcernsModel.java | 6 +-
.../runtime/composite/ConstraintsCheck.java | 2 +-
.../runtime/composite/ConstraintsModel.java | 4 +-
.../runtime/composite/ConstructorModel.java | 17 +-
.../runtime/composite/ConstructorsModel.java | 11 +-
.../runtime/composite/FragmentClassLoader.java | 1 -
.../composite/FunctionStateResolver.java | 32 +-
.../runtime/composite/GenericPredicate.java | 38 ++
.../runtime/composite/Genericpredicate.java | 38 --
.../runtime/composite/InstancePool.java | 4 +-
.../composite/InterfaceDefaultMethodsMixin.java | 85 +++
.../polygene/runtime/composite/MixinsModel.java | 21 +-
.../runtime/composite/SideEffectsModel.java | 6 +-
.../runtime/composite/TransientInstance.java | 7 -
.../polygene/runtime/composite/UsageGraph.java | 4 +-
.../composite/ValueConstraintsInstance.java | 2 -
.../polygene/runtime/entity/EntityInstance.java | 12 +-
.../polygene/runtime/entity/EntityModel.java | 32 +-
.../runtime/entity/EntityStateInstance.java | 49 +-
.../InvocationInjectionProviderFactory.java | 3 +-
.../polygene/runtime/internal/Activator.java | 14 +-
.../runtime/property/PropertyInstance.java | 55 +-
.../runtime/property/PropertyModel.java | 10 -
.../runtime/query/QueryBuilderFactoryImpl.java | 4 +-
.../polygene/runtime/query/QueryImpl.java | 10 +-
.../ImportedServiceReferenceInstance.java | 4 +-
.../runtime/service/ServiceInstance.java | 7 -
.../runtime/structure/ModuleClassLoader.java | 6 +-
.../runtime/structure/ModuleInstance.java | 4 +-
.../runtime/type/ValueTypeFactoryInstance.java | 18 +-
.../runtime/unitofwork/BuilderEntityState.java | 18 +-
.../unitofwork/BuilderManyAssociationState.java | 18 +-
.../BuilderNamedAssociationState.java | 11 +
.../runtime/unitofwork/EntityStateStore.java | 39 --
.../runtime/unitofwork/ModuleUnitOfWork.java | 45 +-
.../unitofwork/UnitOfWorkFactoryMixin.java | 3 +-
.../runtime/unitofwork/UnitOfWorkInstance.java | 18 +-
.../value/ManyAssociationValueState.java | 14 +-
.../value/NamedAssociationValueState.java | 11 +
.../value/ValueBuilderWithPrototype.java | 16 +-
.../polygene/runtime/value/ValueInstance.java | 78 +--
.../polygene/runtime/value/ValueModel.java | 16 +-
.../runtime/value/ValueStateInstance.java | 18 +-
.../polygene/bootstrap/RuntimeMixinsTest.java | 187 ++++++
.../composite/InterfaceDefaultMethodsTest.java | 164 ++++-
.../entity/EntityCompositeToStringTest.java | 90 +++
.../runtime/injection/ServiceInjectionTest.java | 24 +-
.../runtime/mixin/DefaultMethodsTest.java | 97 +++
.../memory/MemoryMapEntityStoreMixin.java | 11 +-
.../serialization/javaxjson/JavaxJson.java | 49 --
.../javaxjson/JavaxJsonAdapter.java | 5 +-
.../javaxjson/JavaxJsonAdapters.java | 72 ++-
.../javaxjson/JavaxJsonDeserializer.java | 58 +-
.../javaxjson/JavaxJsonFactories.java | 133 ++++
.../javaxjson/JavaxJsonSerializer.java | 68 +--
.../spi/entity/ManyAssociationState.java | 2 +
.../spi/entity/NamedAssociationState.java | 2 +
.../ReadOnlyEntityStoreException.java | 32 -
.../entitystore/helpers/DefaultEntityState.java | 18 +-
.../helpers/DefaultManyAssociationState.java | 17 +-
.../helpers/DefaultNamedAssociationState.java | 12 +
.../entitystore/helpers/JSONEntityState.java | 360 ++++-------
.../spi/entitystore/helpers/JSONKeys.java | 16 +-
.../helpers/JSONManyAssociationState.java | 25 +-
.../helpers/JSONMapEntityStoreMixin.java | 95 +--
.../helpers/JSONNamedAssociationState.java | 25 +-
.../helpers/MapEntityStoreMixin.java | 74 +--
.../spi/serialization/AbstractDeserializer.java | 23 +-
.../spi/serialization/AbstractSerializer.java | 18 -
.../spi/serialization/JsonDeserializer.java | 5 +-
.../spi/serialization/XmlDeserializer.java | 5 +-
.../helpers/JSONManyAssociationStateTest.java | 47 +-
.../helpers/JsonNamedAssociationStateTest.java | 30 +-
core/testsupport/NOTICE | 256 --------
.../org/apache/polygene/test/model/Domain.java | 1 -
.../AbstractConvertersSerializationTest.java | 16 +-
.../AbstractPlainValueSerializationTest.java | 17 +
...AbstractValueCompositeSerializationTest.java | 56 +-
.../org/apache/polygene/test/util/Assume.java | 12 +-
dependencies.gradle | 18 +-
distributions/build.gradle | 17 +
distributions/src/src-dist/README.txt | 16 +-
extensions/cache-ehcache/NOTICE | 10 -
.../cache/ehcache/EhCacheConfiguration.java | 3 +-
.../cache/ehcache/EhCachePoolMixin.java | 1 -
extensions/cache-memcache/NOTICE | 103 ----
.../cache/memcache/MemcacheConfiguration.java | 2 -
.../CassandraEntityStoreConfiguration.java | 2 -
.../cassandra/CassandraEntityStoreService.java | 2 -
.../entitystore/cassandra/ClusterBuilder.java | 2 +-
.../file/FileEntityStoreConfiguration.java | 2 -
.../entitystore/file/FileEntityStoreMixin.java | 6 +-
.../file/FileEntityStoreService.java | 2 -
extensions/entitystore-geode/NOTICE | 3 -
.../entitystore/geode/GeodeConfiguration.java | 2 -
.../geode/GeodeEntityStoreService.java | 2 -
extensions/entitystore-hazelcast/NOTICE | 23 -
.../hazelcast/HazelcastConfiguration.java | 2 -
.../hazelcast/HazelcastEntityStoreService.java | 2 -
extensions/entitystore-jclouds/NOTICE | 3 -
.../JCloudsMapEntityStoreConfiguration.java | 2 -
.../jclouds/JCloudsMapEntityStoreService.java | 2 -
extensions/entitystore-jdbm/NOTICE | 50 --
.../entitystore/jdbm/JdbmConfiguration.java | 2 -
.../jdbm/JdbmEntityStoreActivation.java | 2 +-
.../jdbm/JdbmEntityStoreService.java | 2 -
extensions/entitystore-leveldb/NOTICE | 30 -
.../LevelDBEntityStoreConfiguration.java | 4 -
.../leveldb/LevelDBEntityStoreService.java | 2 -
extensions/entitystore-mongodb/NOTICE | 92 ---
.../mongodb/MongoEntityStoreConfiguration.java | 7 +-
.../mongodb/MongoMapEntityStoreMixin.java | 63 +-
.../mongodb/MongoMapEntityStoreService.java | 2 -
.../mongodb/EmbedMongoMapEntityStoreTest.java | 11 +-
.../mongodb/MongoMapEntityStoreTest.java | 5 +-
.../preferences/PreferencesEntityStoreInfo.java | 2 -
.../PreferencesEntityStoreService.java | 3 +-
extensions/entitystore-redis/NOTICE | 26 -
.../redis/RedisEntityStoreConfiguration.java | 2 -
.../redis/RedisMapEntityStoreService.java | 2 -
extensions/entitystore-riak/NOTICE | 6 -
.../riak/RiakEntityStoreConfiguration.java | 3 +-
.../riak/RiakMapEntityStoreService.java | 2 -
extensions/entitystore-sql/NOTICE | 4 -
.../entitystore/sql/SQLMapEntityStoreMixin.java | 10 +-
.../sql/SQLMapEntityStoreService.java | 2 -
extensions/indexing-elasticsearch/NOTICE | 10 -
.../ElasticSearchConfiguration.java | 2 -
.../elasticsearch/ElasticSearchFinder.java | 2 +-
.../ElasticSearchFinderSupport.java | 2 +-
.../elasticsearch/ElasticSearchIndexer.java | 80 ++-
.../client/ESClientIndexQueryService.java | 3 +-
.../cluster/ESClusterIndexQueryService.java | 3 +-
.../ESFilesystemIndexQueryService.java | 3 +-
.../index/elasticsearch/ImmenseTermTest.java | 15 +-
extensions/indexing-rdf/NOTICE | 3 -
.../index/rdf/RdfIndexingEngineService.java | 3 +-
...llectingQualifiedIdentityResultCallback.java | 2 +-
.../index/rdf/query/RdfQueryParserFactory.java | 2 -
.../index/rdf/query/RdfQueryService.java | 5 +-
.../index/rdf/query/internal/Namespaces.java | 2 +-
extensions/indexing-solr/NOTICE | 3 -
.../index/solr/EmbeddedSolrService.java | 5 +-
.../polygene/index/solr/SolrQueryService.java | 3 +-
.../apache/polygene/index/solr/SolrSearch.java | 2 +-
.../solr/internal/SolrEntityIndexerMixin.java | 14 +-
.../solr/internal/SolrEntityQueryMixin.java | 6 +-
extensions/indexing-sql/build.gradle | 2 +-
.../index/sql/SQLIndexingEngineService.java | 3 +-
.../index/sql/support/api/SQLQuerying.java | 6 +-
.../sql/support/common/RebuildingStrategy.java | 6 +-
.../sql/support/common/ReindexingStrategy.java | 6 +-
.../postgresql/PostgreSQLTypeHelper.java | 2 +-
.../skeletons/SQLCompatEntityStateWrapper.java | 13 +
extensions/metrics-codahale/NOTICE | 16 -
extensions/migration/NOTICE | 25 -
.../migration/MigrationConfiguration.java | 2 -
.../polygene/migration/MigrationService.java | 609 +++++++------------
.../polygene/migration/MigrationTest.java | 4 +-
extensions/reindexer/NOTICE | 25 -
.../index/reindexer/ReindexAllService.java | 3 +-
.../index/reindexer/ReindexerConfiguration.java | 2 -
.../index/reindexer/ReindexerService.java | 3 +-
extensions/serialization-javaxjson/NOTICE | 3 -
.../JavaxJsonSerializationAssembler.java | 5 +-
.../javaxjson/CustomJsonAdapterTest.java | 16 +-
...avaxJsonValueCompositeSerializationTest.java | 28 +-
.../javaxxml/JavaxXmlDeserializer.java | 59 +-
.../javaxxml/JavaxXmlSerializer.java | 43 +-
.../JavaxXmlSerializationAssembler.java | 5 +-
...JavaxXmlValueCompositeSerializationTest.java | 20 +-
extensions/serialization-messagepack/NOTICE | 40 --
.../messagepack/MessagePackDeserializer.java | 72 +--
.../messagepack/MessagePackSerializer.java | 47 +-
.../MessagePackSerializationAssembler.java | 7 +-
internals/testsupport-internal/NOTICE | 3 -
.../polygene/test/internal/DockerRule.java | 2 +-
.../polygene/library/alarm/AlarmEvent.java | 3 +-
.../polygene/library/alarm/AlarmPoint.java | 7 +-
.../library/alarm/AlarmPointEntity.java | 3 +-
.../library/alarm/AlarmPointFactory.java | 3 +-
.../polygene/library/alarm/AlarmProxy.java | 3 +-
.../polygene/library/alarm/AlarmStatus.java | 3 +-
.../polygene/library/alarm/AlarmSystem.java | 4 +-
.../library/alarm/AlarmSystemService.java | 4 +-
.../alarm/ExtendedAlarmModelService.java | 7 +-
.../library/alarm/SimpleAlarmModelService.java | 7 +-
.../alarm/StandardAlarmModelService.java | 7 +-
libraries/circuitbreaker/NOTICE | 25 -
.../jmx/CircuitBreakerJMXMBean.java | 16 +-
.../jmx/CircuitBreakerManagement.java | 2 -
.../library/constraints/ContainsConstraint.java | 3 -
.../constraints/GreaterThanConstraint.java | 3 -
.../constraints/InstanceOfConstraint.java | 3 -
.../library/constraints/LessThanConstraint.java | 3 -
.../library/constraints/MatchesConstraint.java | 3 -
.../constraints/MaxLengthConstraint.java | 5 -
.../constraints/MinLengthConstraint.java | 5 -
.../NotEmptyCollectionConstraint.java | 3 -
.../library/constraints/OneOfConstraint.java | 3 -
.../library/constraints/RangeConstraint.java | 3 -
.../library/constraints/URIConstraint.java | 4 -
.../library/constraints/URLConstraint.java | 4 -
.../library/constraints/annotation/OneOf.java | 2 +-
libraries/fileconfig/NOTICE | 25 -
.../fileconfig/FileConfigurationDataWiper.java | 27 +-
.../fileconfig/FileConfigurationService.java | 11 +-
libraries/http/NOTICE | 353 -----------
.../polygene/library/http/ConstraintInfo.java | 5 +-
.../library/http/ConstraintService.java | 6 +-
.../library/http/ContextListenerInfo.java | 2 -
.../apache/polygene/library/http/Interface.java | 2 +-
.../polygene/library/http/JettyActivation.java | 2 +-
.../library/http/JettyConfiguration.java | 2 -
.../polygene/library/http/JettyService.java | 3 +-
.../library/http/UnitOfWorkFilterService.java | 3 +-
.../library/http/WelcomeServletService.java | 3 +-
.../library/http/HelloWorldServlet.java | 2 -
libraries/jmx/NOTICE | 25 -
.../library/jmx/ApplicationManagerService.java | 2 -
.../jmx/ConfigurationManagerService.java | 2 -
.../library/jmx/JMXConnectorConfiguration.java | 3 +-
.../library/jmx/JMXConnectorService.java | 3 +-
.../polygene/library/jmx/MBeanTracker.java | 6 +-
.../polygene/library/jmx/ModelMBeanBuilder.java | 8 +-
.../polygene/library/logging/debug/Debug.java | 7 +-
.../library/logging/debug/DebugConcern.java | 7 +-
.../records/CompositeDebugRecordEntity.java | 3 +-
.../logging/debug/records/DebugRecord.java | 3 +-
.../debug/records/EntityDebugRecordEntity.java | 2 +-
.../debug/records/ServiceDebugRecordEntity.java | 3 +-
.../debug/service/DebugOnConsoleSideEffect.java | 9 +-
.../service/DebugServiceConfiguration.java | 2 -
.../logging/debug/service/DebuggingService.java | 7 +-
.../service/DebuggingServiceComposite.java | 3 +-
.../debug/service/DebuggingServiceMixin.java | 19 +-
.../library/logging/log/CategoryLog.java | 19 +-
.../library/logging/log/CategoryLogConcern.java | 19 +-
.../library/logging/log/CategoryLogMixin.java | 20 +-
.../polygene/library/logging/log/SimpleLog.java | 19 +-
.../library/logging/log/SimpleLogConcern.java | 19 +-
.../library/logging/log/StandardLog.java | 7 +-
.../library/logging/log/StandardLogConcern.java | 7 +-
.../logging/log/records/CompositeLogRecord.java | 3 +-
.../library/logging/log/records/LogRecord.java | 3 +-
.../logging/log/service/LoggingService.java | 3 +-
.../log/service/LoggingServiceComposite.java | 3 +-
.../log/service/LoggingServiceMixin.java | 19 +-
.../records/CompositeTraceRecordEntity.java | 3 +-
.../trace/records/EntityTraceRecordEntity.java | 2 +-
.../trace/records/ServiceTraceRecordEntity.java | 3 +-
.../service/StandardTraceServiceComposite.java | 3 +-
.../service/TraceServiceConfiguration.java | 3 +-
.../library/osgi/OSGiEnabledService.java | 7 +-
.../library/osgi/OSGiServiceExporter.java | 6 +-
.../polygene/library/osgi/OSGiServiceTest.java | 1 +
libraries/rdf/NOTICE | 103 ----
.../polygene/library/rdf/model/Model2XML.java | 4 +-
.../repository/HttpRepositoryConfiguration.java | 2 -
.../rdf/repository/HttpRepositoryService.java | 7 +-
.../rdf/repository/MemoryRepositoryService.java | 7 +-
.../rdf/repository/NativeRepositoryService.java | 3 +-
.../rdf/repository/RdbmsRepositoryService.java | 11 +-
libraries/rest-client/NOTICE | 4 -
.../rest/client/RequestWriterDelegator.java | 2 +-
.../rest/client/ResponseReaderDelegator.java | 2 +-
.../rest/client/api/ContextResourceClient.java | 6 +-
.../api/ContextResourceClientFactory.java | 8 +-
.../library/rest/client/api/ErrorHandler.java | 21 +-
.../library/rest/client/api/HandlerCommand.java | 10 +-
.../responsereader/JSONResponseReader.java | 18 +-
.../responsereader/TableResponseReader.java | 11 +-
.../library/rest/client/spi/RequestWriter.java | 2 +-
libraries/rest-common/NOTICE | 7 -
.../library/rest/common/table/Table.java | 12 +-
.../library/rest/common/table/TableBuilder.java | 3 +-
.../library/rest/common/table/TableQuery.java | 24 +-
libraries/rest-server/NOTICE | 34 --
.../rest/server/api/ContextResource.java | 6 +-
.../library/rest/server/api/ResourceIndex.java | 2 +-
.../server/api/constraint/ServiceAvailable.java | 2 +-
.../server/restlet/InteractionConstraints.java | 4 +-
.../restlet/InteractionConstraintsService.java | 4 +-
.../server/restlet/RequestReaderDelegator.java | 2 +-
.../server/restlet/ResponseWriterDelegator.java | 2 +-
.../requestreader/DefaultRequestReader.java | 7 +-
.../responsewriter/FormResponseWriter.java | 9 +-
.../responsewriter/LinksResponseWriter.java | 14 +-
.../responsewriter/ResourceResponseWriter.java | 9 +-
.../ResourceTemplateResponseWriter.java | 4 +-
.../responsewriter/TableResponseWriter.java | 41 +-
.../ValueCompositeResponseWriter.java | 8 +-
.../ValueDescriptorResponseWriter.java | 13 +-
.../library/rest/server/spi/CommandResult.java | 2 +-
libraries/rest/NOTICE | 6 -
.../library/rest/admin/EntityResource.java | 10 +-
.../rest/admin/ExtensionMediaTypeFilter.java | 2 +-
.../admin/PolygeneServerServletService.java | 3 +-
.../library/rest/admin/RestServerComposite.java | 5 +-
libraries/restlet/NOTICE | 4 -
.../library/restlet/PolygeneServerServlet.java | 3 -
.../serialization/FormRepresentation.java | 9 +-
.../library/scripting/ScriptRedirect.java | 1 -
libraries/servlet/NOTICE | 25 -
libraries/shiro-core/NOTICE | 47 --
.../domain/common/IdentifiableSubject.java | 2 -
.../passwords/PasswordRealmConfiguration.java | 4 -
.../domain/passwords/PasswordRealmService.java | 4 +-
.../domain/passwords/PasswordSecurable.java | 5 +-
.../library/shiro/domain/permissions/Role.java | 8 +-
.../shiro/domain/permissions/RoleAssignee.java | 14 +-
.../domain/permissions/RoleAssignment.java | 4 -
.../shiro/domain/permissions/RoleFactory.java | 2 -
.../shiro/ini/IniSecurityManagerService.java | 4 +-
.../shiro/ini/ShiroIniConfiguration.java | 4 -
libraries/shiro-web/NOTICE | 28 -
.../library/shiro/web/ShiroFilterService.java | 3 +-
libraries/spring/NOTICE | 4 -
.../PolygeneApplicationFactoryBean.java | 15 +-
.../PolygeneBootstrapBeanDefinitionParser.java | 2 +-
libraries/sql-bonecp/NOTICE | 3 -
libraries/sql-dbcp/NOTICE | 3 -
libraries/sql-generator/NOTICE | 25 -
...ene.library.sql.generator.vendor.DerbyVendor | 16 +
...lygene.library.sql.generator.vendor.H2Vendor | 16 +
...ene.library.sql.generator.vendor.MySQLVendor | 16 +
...ibrary.sql.generator.vendor.PostgreSQLVendor | 16 +
...ygene.library.sql.generator.vendor.SQLVendor | 16 +
...ne.library.sql.generator.vendor.SQLiteVendor | 16 +
libraries/sql-liquibase/NOTICE | 3 -
libraries/sql/NOTICE | 25 -
.../polygene/library/sql/common/Databases.java | 159 -----
.../AbstractDataSourceServiceImporterMixin.java | 3 +-
.../sql/datasource/DataSourceConfiguration.java | 3 +-
.../DataSourceConfigurationManagerService.java | 2 -
libraries/uowfile/NOTICE | 25 -
.../ConcurrentUoWFileModificationException.java | 2 -
.../library/uowfile/internal/UoWFile.java | 2 +-
.../uowfile/plural/HasUoWFilesLifecycle.java | 2 +-
.../src/docs/tutorials/howto-build-system.txt | 7 +
.../docs/tutorials/howto-releasing-apache.txt | 43 ++
manual/src/docs/website/resources/css/style.css | 1 -
.../polygene/manual/recipes/assemble/Docs.java | 3 +-
.../polygene/manual/recipes/assemble/Main.java | 41 +-
.../recipes/contextualFragments/TraceAll.java | 2 -
.../createConstraint/DialerComposite.java | 3 +-
.../recipes/createEntity/AccidentValue.java | 2 +-
.../manual/recipes/createEntity/CarEntity.java | 4 +-
.../createEntity/CarEntityFactoryService.java | 3 +-
.../manual/recipes/createEntity/Main.java | 10 +-
.../createEntity/ManufacturerEntity.java | 4 +-
.../ManufacturerRepositoryMixin.java | 2 +-
.../ManufacturerRepositoryService.java | 3 +-
.../recipes/createEntity/MyAssembler.java | 2 +-
.../manual/recipes/sideeffects/OrderEntity.java | 4 +-
.../org/apache/polygene/manual/travel/Main.java | 13 +-
.../manual/travel/TravelPlanService.java | 3 +-
release/build.gradle | 17 +
reports/build.gradle | 17 +
samples/rental/build.gradle | 11 +-
.../binding/internal/BoundManyAssociation.java | 6 +
.../binding/internal/BoundNamedAssociation.java | 6 +
settings.gradle | 2 +-
.../jdbm/JdbmEntityStorePerformanceTest.java | 20 +-
.../org/apache/polygene/envisage/Envisage.java | 18 +-
.../envisage/detail/DependencyPane.java | 9 +-
.../envisage/detail/DetailModelPane.java | 9 +-
.../polygene/envisage/detail/MethodPane.java | 9 +-
.../polygene/envisage/detail/StatePane.java | 9 +-
.../polygene/envisage/graph/GraphBuilder.java | 3 +-
.../polygene/envisage/graph/GraphPane.java | 18 +-
.../envisage/graph/StackedGraphDisplay.java | 9 +-
.../envisage/tree/StructureModelBuilder.java | 8 +-
.../polygene/envisage/tree/TreeModelPane.java | 27 +-
.../envisage/tree/TypeModelBuilder.java | 17 +-
.../envisage/sample/EnvisageSample.java | 6 +-
.../school/config/mail/MailConfiguration.java | 2 -
.../domain/person/assembly/PersonEntity.java | 4 +-
.../initialdata/SamplePersonInitialData.java | 4 +-
.../domain/school/assembly/SchoolEntity.java | 5 +-
.../assembly/SchoolRepositoryService.java | 3 +-
.../domain/school/assembly/StudentEntity.java | 6 +-
.../domain/school/assembly/SubjectEntity.java | 8 +-
.../mail/assembly/MailServiceComposite.java | 5 +-
.../infrastructure/mail/assembly/MailValue.java | 3 +-
tools/generator-polygene/README.md | 47 ++
tools/generator-polygene/app/index.js | 3 +-
.../app/templates/CommandLineApplication/app.js | 17 +
.../ConfigurationLayer/ConfigModule/module.js | 17 +
.../app/templates/ConfigurationLayer/layer.js | 17 +
.../ConnectivityLayer/RestApiModule/module.js | 17 +
.../app/templates/ConnectivityLayer/layer.js | 17 +
.../templates/DomainLayer/CrudModule/module.js | 17 +
.../DomainLayer/DomainModule/module.js | 18 +
.../templates/DomainLayer/JmxModule/module.js | 18 +
.../DomainLayer/SecurityModule/module.js | 18 +
.../app/templates/DomainLayer/layer.js | 17 +
.../InfrastructureLayer/CachingModule/module.js | 17 +
.../FileConfigurationModule/module.js | 18 +
.../IndexingModule/module.js | 18 +
.../InfrastructureLayer/MetricsModule/module.js | 18 +
.../SerializationModule/module.js | 18 +
.../InfrastructureLayer/StorageModule/module.js | 18 +
.../app/templates/InfrastructureLayer/layer.js | 17 +
.../app/templates/RestAPIApplication/app.js | 18 +
.../CommandLineModule/module.js | 17 +
.../app/templates/UserInterfaceLayer/layer.js | 17 +
.../app/templates/buildtool/build.js | 18 +
.../app/templates/buildtool/gradle-root.tmpl | 1 -
.../buildtool/gradle-wrapper.properties_ | 2 +-
.../app/templates/buildtool/settings.tmpl | 16 -
tools/generator-polygene/build.gradle | 100 +++
tools/generator-polygene/package.json | 28 +-
tools/generator-polygene/test/generator_test.js | 57 +-
.../ApplicationDetailDescriptorBuilder.java | 9 +-
.../MethodConcernsDetailDescriptor.java | 2 +-
.../MethodConstraintsDetailDescriptor.java | 2 +-
.../MethodSideEffectDetailDescriptor.java | 6 +-
.../MethodSideEffectsDetailDescriptor.java | 2 +-
.../model/descriptor/MixinDetailDescriptor.java | 6 +-
tutorials/composites/src/docs/step2.txt | 2 +-
tutorials/composites/src/docs/step3.txt | 2 +-
.../tutorial10/HelloWorldComposite.java | 2 -
.../tutorial3/HelloWorldComposite.java | 3 +-
.../tutorial4/HelloWorldComposite.java | 4 +-
.../tutorial5/HelloWorldComposite.java | 4 +-
.../tutorial6/HelloWorldComposite.java | 4 +-
.../tutorial7/HelloWorldComposite.java | 3 +-
.../tutorial8/HelloWorldComposite.java | 3 +-
.../tutorial9/HelloWorldComposite.java | 3 +-
.../apache/polygene/tutorials/hello/Hello.java | 16 +-
.../polygene/tutorials/hello/HelloTest.java | 2 -
.../introduction/src/docs/state-modeling.txt | 6 +-
.../polygene/demo/intro/StateModelingDocs.java | 53 +-
.../polygene/demo/intro/WhatsAnObjectDocs.java | 24 +-
.../tenminutes/src/docs/ten-minutes.txt | 5 +-
.../polygene/demo/tenminute/OrderEntity.java | 6 +-
.../demo/thirtyminutes/ThirtyMinutesDocs.java | 8 +-
.../apache/polygene/demo/twominute/Main.java | 13 +-
.../polygene/tutorials/services/step2/Book.java | 2 -
.../services/step2/LibraryService.java | 3 +-
.../polygene/tutorials/services/step3/Book.java | 2 -
.../tutorials/services/step3/LibraryMixin.java | 4 +-
.../services/step3/LibraryService.java | 3 +-
.../polygene/tutorials/services/step4/Book.java | 2 -
.../services/step4/LibraryConfiguration.java | 2 -
.../tutorials/services/step4/LibraryMixin.java | 4 +-
.../services/step4/LibraryService.java | 3 +-
.../polygene/tutorials/services/step5/Book.java | 2 -
.../services/step5/LibraryService.java | 13 +-
.../polygene/tutorials/services/step6/Book.java | 2 -
.../services/step6/LibraryService.java | 8 +-
549 files changed, 4819 insertions(+), 5759 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/57438d0e/settings.gradle
----------------------------------------------------------------------
[03/11] polygene-java git commit: Merge branch 'develop' into
entitystore_sqlng
Posted by ni...@apache.org.
Merge branch 'develop' into entitystore_sqlng
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/1f7357c3
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/1f7357c3
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/1f7357c3
Branch: refs/heads/es-jooq
Commit: 1f7357c320a60c42a2020dce924c99c37d0a533f
Parents: 57438d0 6e5d911
Author: niclas <ni...@hedhman.org>
Authored: Mon Jun 5 14:12:34 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Mon Jun 5 14:12:34 2017 +0800
----------------------------------------------------------------------
buildSrc/build.gradle | 2 +-
.../polygene/gradle/code/CodePlugin.groovy | 16 +-
.../gradle/code/PublishingPlugin.groovy | 23 +-
.../DependenciesDeclarationExtension.groovy | 1 +
.../gradle/structure/ProjectGroupTasks.groovy | 36 +
.../polygene/gradle/structure/RootPlugin.groovy | 23 +
.../gradle/structure/core/CorePlugin.groovy | 3 +
.../distributions/DistributionsPlugin.groovy | 48 +-
.../structure/extensions/ExtensionPlugin.groovy | 3 +
.../internals/InternalDockerPlugin.groovy | 2 +-
.../structure/internals/InternalPlugin.groovy | 10 +-
.../structure/libraries/LibraryPlugin.groovy | 5 +
.../structure/release/ReleasePlugin.groovy | 1 +
.../structure/samples/SamplePlugin.groovy | 3 +
.../gradle/structure/tools/ToolPlugin.groovy | 3 +
.../structure/tutorials/TutorialPlugin.groovy | 3 +
.../gradle-plugins/polygene-internal.properties | 2 +-
core/api/build.gradle | 1 +
core/api/src/docs/api.txt | 2 +-
core/api/src/docs/composition.txt | 10 +-
core/api/src/docs/dependency-injection.txt | 136 +++
core/api/src/docs/fragment.txt | 10 +-
core/api/src/docs/layer.txt | 24 +
core/api/src/docs/module.txt | 12 +
core/api/src/docs/serialization.txt | 1 +
core/api/src/docs/structure.txt | 35 +-
core/api/src/docs/visibility.txt | 16 +
.../api/composite/NoSuchTransientException.java | 9 +-
.../polygene/api/composite/PropertyMapper.java | 2 +-
.../api/configuration/Configuration.java | 222 ++--
.../configuration/ConfigurationComposite.java | 2 +-
.../NoSuchConfigurationTypeException.java | 36 +
.../api/service/NoSuchServiceException.java | 6 +-
.../importer/ServiceInstanceImporter.java | 7 +-
.../api/structure/ApplicationDescriptor.java | 10 +
.../unitofwork/NoSuchEntityTypeException.java | 13 +-
.../api/value/NoSuchValueException.java | 11 +-
.../org/apache/polygene/api/OperatorsTest.java | 16 +-
.../activation/PassivationExceptionTest.java | 61 +-
.../api/docsupport/ApplicationDocs.java | 33 +-
.../api/value/DocumentationSupport.java | 19 +-
core/bootstrap/src/docs/bootstrap.txt | 2 +-
.../bootstrap/ApplicationAssembler.java | 1 +
.../bootstrap/ApplicationAssemblerAdapter.java | 1 -
.../polygene/bootstrap/ApplicationName.java | 1 -
.../apache/polygene/bootstrap/Assembler.java | 1 +
.../apache/polygene/bootstrap/LayerName.java | 1 -
.../polygene/bootstrap/ModuleAssembly.java | 30 +-
.../apache/polygene/bootstrap/ModuleName.java | 1 -
.../polygene/bootstrap/SingletonAssembler.java | 8 +-
.../bootstrap/builder/ApplicationBuilder.java | 56 +-
.../bootstrap/builder/LayerDeclaration.java | 2 -
.../bootstrap/builder/ModuleDeclaration.java | 3 -
.../DefaultIdentityGeneratorAssembler.java | 39 +
.../DefaultMetricsProviderAssembler.java | 37 +
.../defaults/DefaultSerializationAssembler.java | 52 +
.../defaults/DefaultUnitOfWorkAssembler.java | 58 +
.../polygene/bootstrap/defaults/package.html | 24 +
.../DefaultIdentityGeneratorAssembler.java | 38 -
.../layered/LayeredApplicationAssembler.java | 9 +-
.../layered/LayeredLayerAssembler.java | 16 +-
.../DefaultSerializationAssembler.java | 50 -
.../unitofwork/DefaultUnitOfWorkAssembler.java | 55 -
.../polygene/bootstrap/ClassScannerTest.java | 13 +-
.../bootstrap/DocumentationSupport.java | 419 ++++---
core/runtime/src/docs/runtime.txt | 2 +-
.../association/AssociationInstance.java | 6 +-
.../ApplicationAssemblyFactoryImpl.java | 3 -
.../bootstrap/ApplicationModelFactoryImpl.java | 125 ++-
.../runtime/bootstrap/ModuleAssemblyImpl.java | 86 +-
.../runtime/composite/CompositeMethodModel.java | 2 +-
.../runtime/composite/CompositeModel.java | 38 +-
.../GenericFragmentInvocationHandler.java | 2 -
.../polygene/runtime/service/ServiceModel.java | 29 +-
.../polygene/runtime/structure/LayerModel.java | 2 -
.../runtime/structure/ModuleInstance.java | 23 +-
.../polygene/runtime/structure/ModuleModel.java | 4 +
.../runtime/structure/UsedLayersModel.java | 6 +
.../runtime/unitofwork/ModuleUnitOfWork.java | 11 -
.../bootstrap/ApplicationAssemblerTest.java | 40 +-
.../polygene/bootstrap/ErrorReportingTest.java | 2 -
.../polygene/bootstrap/RuntimeMixinsTest.java | 69 +-
...ceCollisionWithUnrelatedReturnTypesTest.java | 1 +
.../polygene/regression/qi382/Qi382Test.java | 7 +-
.../polygene/regression/qi383/Qi383Test.java | 5 +-
.../polygene/regression/qi78/IssueTest.java | 23 +-
.../activation/ApplicationActivationTest.java | 19 +-
.../ImportedServiceActivationTest.java | 70 +-
.../runtime/activation/LayerActivationTest.java | 19 +-
.../activation/ModuleActivationTest.java | 19 +-
.../activation/ServiceActivationTest.java | 32 +-
.../AppliesToOrConditionQI241Test.java | 6 +-
.../association/AssociationAssignmentTest.java | 5 +-
.../bootstrap/docs/DocumentationSupport.java | 25 +-
.../runtime/concerns/GenericConcernTest.java | 8 +-
.../runtime/defaults/UseDefaultsTest.java | 2 +
.../entity/EntityBuilderWithStateTest.java | 2 -
.../runtime/entity/EntityVisibilityTest.java | 17 +-
.../entity/associations/AssociationTest.java | 10 +
.../ConstructorInjectionOfThisTest.java | 51 +-
.../injection/InvocationInjectionTest.java | 17 +-
.../runtime/injection/ServiceInjectionTest.java | 60 +-
.../ConfigurationInstantiationTest.java | 119 ++
.../objects/ObjectBuilderFactoryTest.java | 64 +-
.../runtime/objects/ObjectConcernTest.java | 14 +-
.../runtime/objects/ObjectVisibilityTest.java | 20 +-
.../property/ValueNestedBuilderTest.java | 2 +
.../runtime/query/IterableQuerySourceTest.java | 14 +-
.../runtime/query/NonQueryableTest.java | 7 +-
.../runtime/service/AvailableServiceTest.java | 10 +-
.../service/ConfigurationConstraintTest.java | 124 +++
.../runtime/service/ServiceVisibilityTest.java | 18 +-
.../runtime/structure/MixinVisibilityTest.java | 213 ++--
.../polygene/runtime/structure/ModuleTest.java | 54 +-
.../PrivateCompositeVisibilityTest.java | 6 +-
.../runtime/structure/StructureTest.java | 39 +-
.../structure/TypeToCompositeLookupTest.java | 9 -
.../transients/TransientVisibilityTest.java | 9 -
.../unitofwork/PrivateEntityUnitOfWorkTest.java | 13 +-
.../runtime/value/AssociationToValueTest.java | 5 +-
.../runtime/value/NestedValueBuilderTest.java | 10 +-
.../runtime/value/ValueComposite2Test.java | 8 +-
.../runtime/value/ValueCompositeBasicsTest.java | 2 +
.../runtime/value/ValueVisibilityTest.java | 8 -
.../runtime/value/ValueWithAssociationTest.java | 5 +-
.../visibility/VisibilityInUnitOfWorkTest.java | 8 +-
.../test/composite/CleanStackTraceTest.java | 15 +-
.../memory/MemoryEntityStoreTest.java | 2 +
.../service/HelloWorldService.properties | 2 +-
.../runtime/service/TestService1.properties | 20 +
.../runtime/service/TestService2.properties | 20 +
.../helpers/JSONManyAssociationStateTest.java | 1 +
.../helpers/JsonNamedAssociationStateTest.java | 1 +
.../polygene/test/AbstractPolygeneTest.java | 4 -
.../polygene/test/EntityTestAssembler.java | 21 +-
.../cache/AbstractEntityStoreWithCacheTest.java | 9 +-
...bstractConfigurationDeserializationTest.java | 6 +-
.../test/entity/AbstractEntityStoreTest.java | 92 +-
.../test/indexing/AbstractAnyQueryTest.java | 2 -
.../AbstractMultiLayeredIndexingTest.java | 3 +-
.../metrics/AbstractPolygeneMetricsTest.java | 6 +-
.../test/metrics/AbstractTimingCaptureTest.java | 2 -
.../test/model/assembly/AccessLayer.java | 10 +-
.../test/model/assembly/AccountModule.java | 2 -
.../model/assembly/ApplicationAssembler.java | 1 -
.../test/model/assembly/ConfigLayer.java | 3 -
.../test/model/assembly/ConfigModule.java | 3 -
.../test/model/assembly/DomainLayer.java | 3 -
.../test/model/assembly/FamilyModule.java | 3 -
.../test/model/assembly/IndexingLayer.java | 3 -
.../test/model/assembly/PersistenceLayer.java | 3 -
.../test/model/assembly/PersistenceModule.java | 3 -
.../test/model/assembly/PetShopModule.java | 3 -
.../model/assembly/TestExecutionModule.java | 2 -
.../test/model/assembly/TestSuite1Module.java | 2 -
.../test/model/assembly/TestSuite2Module.java | 2 -
.../test/model/assembly/TestSuite3Module.java | 2 -
.../AbstractCollectionSerializationTest.java | 2 -
dependencies.gradle | 13 +-
distributions/src/src-dist/README.txt | 16 +-
.../gradle/wrapper-install/build.gradle | 25 +
.../gradle/wrapper-install/settings.gradle | 19 +
.../ehcache/assembly/EhCacheAssembler.java | 2 -
.../cache/memcache/MemcachePoolMixin.java | 69 +-
.../memcache/assembly/MemcacheAssembler.java | 2 -
.../cache/memcache/MemcacheCachePoolTest.java | 2 +-
extensions/entitystore-cassandra/build.gradle | 1 +
.../CassandraEntityStoreConfiguration.java | 2 +
.../cassandra/CassandraEntityStoreMixin.java | 7 +-
.../entitystore/cassandra/ClusterBuilder.java | 18 +-
.../assembly/CassandraEntityStoreAssembler.java | 2 -
.../cassandra/CassandraEntityStoreTest.java | 85 ++
.../cassandra/CassandraMapEntityStoreTest.java | 83 --
.../cassandra/EmptyCassandraTableMixin.java | 2 -
.../file/assembly/FileEntityStoreAssembler.java | 2 -
.../entitystore/file/FileEntityStoreTest.java | 2 +-
.../file/FileEntityStoreWithCacheTest.java | 2 +-
.../entitystore/geode/GeodeConfiguration.java | 81 --
.../geode/GeodeEntityStoreConfiguration.java | 81 ++
.../geode/GeodeEntityStoreMixin.java | 10 +-
.../assembly/GeodeEntityStoreAssembler.java | 6 +-
.../entitystore/geode/GeodeEntityStoreTest.java | 2 +-
.../geode/GeodeEntityStoreWithCacheTest.java | 2 +-
.../hazelcast/HazelcastConfiguration.java | 39 -
.../HazelcastEntityStoreConfiguration.java | 50 +
.../hazelcast/HazelcastEntityStoreMixin.java | 8 +-
.../assembly/HazelcastEntityStoreAssembler.java | 6 +-
.../hazelcast/HazelcastEntityStoreTest.java | 2 +-
.../HazelcastEntityStoreWithCacheTest.java | 2 +-
.../JCloudsEntityStoreConfiguration.java | 54 +
.../jclouds/JCloudsEntityStoreMixin.java | 284 +++++
.../jclouds/JCloudsEntityStoreService.java | 48 +
.../JCloudsMapEntityStoreConfiguration.java | 54 -
.../jclouds/JCloudsMapEntityStoreMixin.java | 284 -----
.../jclouds/JCloudsMapEntityStoreService.java | 48 -
.../assembly/JCloudsEntityStoreAssembler.java | 10 +-
.../jclouds/JCloudsFilesystemTest.java | 6 +-
.../entitystore/jclouds/JCloudsS3Test.java | 9 +-
.../jclouds/JCloudsTransientTest.java | 2 +-
.../jclouds/JCloudsWithCacheTest.java | 2 +-
.../entitystore/jdbm/JdbmConfiguration.java | 52 -
.../jdbm/JdbmEntityStoreConfiguration.java | 52 +
.../entitystore/jdbm/JdbmEntityStoreMixin.java | 4 +-
.../jdbm/JdbmEntityStoreService.java | 8 +-
.../jdbm/assembly/JdbmEntityStoreAssembler.java | 6 +-
.../entitystore/jdbm/JdbmEntityStoreTest.java | 2 +-
.../jdbm/JdbmEntityStoreWithCacheTest.java | 2 +-
.../LevelDBEntityStoreConfiguration.java | 3 +
.../leveldb/LevelDBEntityStoreMixin.java | 15 +-
.../assembly/LevelDBEntityStoreAssembler.java | 2 -
.../leveldb/JavaLevelDBEntityStoreTest.java | 2 +-
.../leveldb/JniLevelDBEntityStoreTest.java | 2 +-
.../LevelDBEntityStoreWithCacheTest.java | 2 +-
.../assembly/MemoryEntityStoreAssembler.java | 2 -
.../memory/MemoryEntityStoreTest.java | 1 +
.../memory/MemoryEntityStoreWithCacheTest.java | 1 +
.../entitystore/mongodb/MongoAccessors.java | 32 -
.../entitystore/mongodb/MongoDBAccessors.java | 32 +
.../MongoDBEntityStoreConfiguration.java | 92 ++
.../mongodb/MongoDBEntityStoreMixin.java | 322 ++++++
.../mongodb/MongoDBEntityStoreService.java | 49 +
.../mongodb/MongoEntityStoreConfiguration.java | 92 --
.../mongodb/MongoMapEntityStoreMixin.java | 322 ------
.../mongodb/MongoMapEntityStoreService.java | 49 -
.../assembly/MongoDBEntityStoreAssembler.java | 10 +-
.../mongodb/EmbedMongoDBMapEntityStoreTest.java | 88 ++
.../mongodb/EmbedMongoMapEntityStoreTest.java | 88 --
.../mongodb/MongoDBEntityStoreTest.java | 88 ++
.../MongoDBEntityStoreWithCacheTest.java | 84 ++
.../mongodb/MongoMapEntityStoreTest.java | 88 --
.../MongoMapEntityStoreWithCacheTest.java | 84 --
.../PreferencesEntityStoreMixin.java | 44 +-
.../PreferencesEntityStoreAssembler.java | 2 -
.../preferences/PreferencesEntityStoreTest.java | 4 +-
.../redis/RedisEntityStoreConfiguration.java | 2 +-
.../redis/RedisEntityStoreMixin.java | 177 +++
.../redis/RedisEntityStoreService.java | 49 +
.../redis/RedisMapEntityStoreMixin.java | 177 ---
.../redis/RedisMapEntityStoreService.java | 49 -
.../assembly/RedisEntityStoreAssembler.java | 6 +-
.../entitystore/redis/RedisEntityStoreTest.java | 80 ++
.../redis/RedisEntityStoreWithCacheTest.java | 74 ++
.../redis/RedisMapEntityStoreTest.java | 80 --
.../redis/RedisMapEntityStoreWithCacheTest.java | 74 --
.../entitystore/riak/RiakEntityStoreMixin.java | 384 +++++++
.../riak/RiakEntityStoreService.java | 53 +
.../riak/RiakMapEntityStoreMixin.java | 384 -------
.../riak/RiakMapEntityStoreService.java | 53 -
.../riak/assembly/RiakEntityStoreAssembler.java | 11 +-
.../entitystore/riak/RiakEntityStoreTest.java | 71 ++
.../riak/RiakEntityStoreWithCacheTest.java | 69 ++
.../riak/RiakMapEntityStoreTest.java | 71 --
.../riak/RiakMapEntityStoreWithCacheTest.java | 69 --
.../sql/SQLEntityStoreConfiguration.java | 47 +
.../entitystore/sql/SQLEntityStoreMixin.java | 244 +++++
.../entitystore/sql/SQLEntityStoreService.java | 43 +
.../sql/SQLMapEntityStoreConfiguration.java | 47 -
.../entitystore/sql/SQLMapEntityStoreMixin.java | 244 -----
.../sql/SQLMapEntityStoreService.java | 43 -
.../AbstractSQLEntityStoreAssembler.java | 97 ++
.../AbstractSQLMapEntityStoreAssembler.java | 97 --
.../assembly/DerbySQLEntityStoreAssembler.java | 2 +-
.../sql/assembly/H2SQLEntityStoreAssembler.java | 2 +-
.../sql/assembly/MySQLEntityStoreAssembler.java | 2 +-
.../PostgreSQLEntityStoreAssembler.java | 2 +-
.../assembly/SQLiteEntityStoreAssembler.java | 2 +-
.../sql/DerbySQLEntityStoreTest.java | 6 +-
.../entitystore/sql/H2SQLEntityStoreTest.java | 2 +-
.../entitystore/sql/MySQLEntityStoreTest.java | 8 +-
.../sql/PostgreSQLEntityStoreTest.java | 4 +-
.../entitystore/sql/SQLiteEntityStoreTest.java | 2 +-
.../ElasticSearchClusterConfiguration.java | 2 +-
.../ElasticSearchConfiguration.java | 50 -
.../ElasticSearchIndexException.java | 36 -
.../ElasticSearchIndexExporter.java | 5 +-
.../elasticsearch/ElasticSearchIndexer.java | 2 +-
.../ElasticSearchIndexingConfiguration.java | 49 +
.../ElasticSearchIndexingException.java | 35 +
.../elasticsearch/ElasticSearchSupport.java | 5 +-
.../assembly/ESClientIndexQueryAssembler.java | 7 +-
.../assembly/ESClusterIndexQueryAssembler.java | 2 -
.../ESFilesystemIndexQueryAssembler.java | 6 +-
.../elasticsearch/client/ESClientSupport.java | 6 +-
.../filesystem/ESFilesystemSupport.java | 6 +-
.../index/elasticsearch/ESEmbeddedRule.java | 9 +-
.../ElasticSearchComplexQueryTest.java | 2 +-
.../elasticsearch/ElasticSearchFinderTest.java | 2 +-
.../ElasticSearchQueryMultimoduleTest.java | 4 +-
.../elasticsearch/ElasticSearchQueryTest.java | 2 +-
.../index/elasticsearch/ElasticSearchTest.java | 2 +-
.../index/elasticsearch/ImmenseTermTest.java | 2 +-
.../index/rdf/RdfIndexingEngineService.java | 30 -
.../polygene/index/rdf/RdfIndexingService.java | 30 +
.../rdf/assembly/RdfMemoryStoreAssembler.java | 6 +-
.../assembly/RdfNativeSesameStoreAssembler.java | 6 +-
.../assembly/RdfRdbmsSesameStoreAssembler.java | 6 +-
.../index/rdf/indexing/RdfExporter.java | 106 --
.../index/rdf/indexing/RdfIndexExporter.java | 92 ++
.../index/rdf/indexing/RdfIndexerService.java | 239 ++++
.../index/rdf/indexing/RdfIndexingService.java | 240 ----
.../polygene/index/rdf/RdfComplexQueryTest.java | 2 +-
.../polygene/index/rdf/RdfEntityFinderTest.java | 2 +-
.../index/rdf/RdfNamedQueryMultimoduleTest.java | 3 -
.../index/rdf/RdfQueryMultimoduleTest.java | 4 -
.../apache/polygene/index/rdf/RdfQueryTest.java | 2 -
.../polygene/index/rdf/qi95/Qi95IssueTest.java | 187 +---
.../polygene/index/solr/SolrQueryService.java | 3 +-
.../index/sql/SQLIndexingConfiguration.java | 31 +
.../sql/SQLIndexingEngineConfiguration.java | 31 -
.../index/sql/SQLIndexingEngineService.java | 44 -
.../polygene/index/sql/SQLIndexingService.java | 44 +
.../AbstractSQLIndexQueryAssembler.java | 8 +-
.../assembly/PostgreSQLIndexQueryAssembler.java | 4 +-
.../support/postgresql/PostgreSQLService.java | 4 +-
.../postgresql/PostgreSQLComplexQueryTest.java | 2 +-
.../postgresql/PostgreSQLDBIntegrityTest.java | 2 +-
.../postgresql/PostgreSQLEntityFinderTest.java | 2 +-
.../sql/postgresql/PostgreSQLQueryTest.java | 2 +-
.../codahale/CodahaleMetricsProvider.java | 3 +-
.../assembly/CodahaleMetricsAssembler.java | 2 -
.../polygene/migration/MigrationTest.java | 58 +-
.../polygene/index/reindexer/ReindexerTest.java | 8 +-
...vaxJsonConfigurationDeserializationTest.java | 8 +
gradle/wrapper/gradle-wrapper.jar | Bin 54227 -> 54416 bytes
gradlew | 6 +-
internals/testsupport-internal/build.gradle | 7 +-
.../polygene/test/docker/DelayChecker.java | 60 +
.../apache/polygene/test/docker/DockerRule.java | 156 +++
.../apache/polygene/test/docker/package.html | 25 +
.../polygene/test/internal/DelayChecker.java | 60 -
.../polygene/test/internal/DockerRule.java | 156 ---
.../apache/polygene/test/internal/package.html | 25 -
.../library/alarm/AlarmSystemAssembler.java | 2 -
libraries/constraints/build.gradle | 2 +
.../library/constraints/HostPortConstraint.java | 43 +
.../constraints/HostPortListConstraint.java | 58 +
.../constraints/annotation/HostPort.java | 37 +
.../constraints/annotation/HostPortList.java | 37 +
.../constraints/HostPortConstraintTest.java | 119 ++
.../constraints/HostPortListConstraintTest.java | 159 +++
.../fileconfig/FileConfigurationAssembler.java | 2 -
.../fileconfig/FileConfigurationTest.java | 42 +-
.../library/http/JettyServiceAssembler.java | 4 +-
.../library/http/SecureJettyConfiguration.java | 2 +-
.../http/VirtualHostJettyServiceTest.java | 2 -
libraries/jmx/src/docs/jmx.txt | 2 +-
.../polygene/library/jmx/JMXAssembler.java | 2 -
.../apache/polygene/library/jmx/JMXTest.java | 15 +-
.../log/assemblies/LoggingAssembler.java | 2 -
.../trace/assemblies/TracingAssembler.java | 2 -
.../polygene/library/rdf/Model2XMLTest.java | 54 +-
.../library/rest/client/ClientAssembler.java | 3 +-
.../ContextResourceClientFactoryTest.java | 2 +
.../rest/client/ContinuousIntegrationTest.java | 2 +
.../library/rest/client/RssReaderTest.java | 2 +
.../library/rest/common/ValueAssembler.java | 2 -
.../server/assembler/RestServerAssembler.java | 3 +-
.../library/rest/admin/EntitiesResource.java | 1 -
.../library/rest/admin/IndexResource.java | 10 +-
.../library/rest/admin/RestAssembler.java | 2 -
.../library/rest/admin/DomainAssembler.java | 4 +-
.../polygene/library/rest/admin/RestTest.java | 4 +-
.../restlet/PolygeneRestApplication.java | 84 +-
.../PolygeneRestApplicationLauncher.java | 104 ++
.../restlet/assembly/CrudServiceAssembler.java | 2 -
.../restlet/assembly/GenericRestLayer.java | 2 -
.../assembly/RestApplicationAssembler.java | 1 -
.../RestletCrudConnectivityAssembler.java | 2 -
.../assembly/RestletCrudModuleAssembler.java | 2 -
.../configuration/ConfigurationLayer.java | 2 -
.../configuration/ConfigurationModule.java | 2 -
.../connectivity/ConnectivityLayer.java | 2 -
.../assembly/connectivity/RestModule.java | 2 -
.../assembly/connectivity/SecurityModule.java | 2 -
.../restlet/assembly/domain/CrudModule.java | 2 -
.../restlet/assembly/domain/DomainLayer.java | 2 -
.../infrastructue/FileStorageModule.java | 4 +-
.../assembly/infrastructue/IndexingModule.java | 2 -
.../infrastructue/InfrastructureLayer.java | 2 -
.../infrastructue/SerializationModule.java | 2 -
.../assembly/resource/ResourceLayer.java | 2 -
.../polygene/library/scripting/Scripting.java | 2 +-
.../library/scripting/HelloSpeakerTest.java | 31 +-
.../shiro/assembly/PasswordDomainAssembler.java | 2 -
.../assembly/PermissionsDomainAssembler.java | 2 -
.../assembly/StandaloneShiroAssembler.java | 2 -
.../library/shiro/web/ShiroFilterService.java | 5 +-
.../shiro/web/assembly/HttpShiroAssembler.java | 25 +-
.../PolygeneApplicationFactoryBean.java | 8 +-
.../importer/SpringImporterAssembler.java | 3 +-
.../sql/liquibase/LiquibaseAssembler.java | 2 -
...bstractPooledDataSourceServiceAssembler.java | 2 -
.../sql/assembly/DataSourceAssembler.java | 2 -
.../sql/assembly/DataSourceJMXAssembler.java | 2 -
.../assembly/ExternalDataSourceAssembler.java | 2 -
.../DataSourceConfigurationState.java | 3 +-
...taSourceConfigurationManagerServiceTest.java | 3 -
.../assembly/PersistingSequencingAssembler.java | 2 -
.../assembly/TransientSequencingAssembler.java | 2 -
.../uid/uuid/assembly/UuidServiceAssembler.java | 2 -
.../uowfile/bootstrap/UoWFileAssembler.java | 2 -
.../docs/tutorials/howto-releasing-apache.txt | 11 +-
manual/src/docs/userguide/extensions.txt | 4 +
manual/src/docs/userguide/glossary.txt | 8 +
manual/src/docs/userguide/tools.txt | 9 +-
.../src/docs/website/resources/css/polygene.css | 4 +
.../docs/website/resources/images/cloudbees.png | Bin 7493 -> 0 bytes
.../website/resources/images/library-jmx.png | Bin 36579 -> 244987 bytes
.../resources/images/tools-entity-viewer.png | Bin 52322 -> 0 bytes
.../images/tools-envisage-stacked-collapsed.png | Bin 30355 -> 211242 bytes
.../resources/images/tools-envisage-stacked.png | Bin 36070 -> 225560 bytes
.../images/tools-envisage-structure.png | Bin 90145 -> 277222 bytes
.../resources/images/tools-envisage-type.png | Bin 88278 -> 279752 bytes
.../moneytransfer/test/TransferMoneyTest.java | 21 +-
.../moneytransfer/test/TransferMoneyTest2.java | 29 +-
.../sample/forum/assembler/ForumAssembler.java | 2 -
.../apache/polygene/sample/forum/web/Main.java | 4 +-
.../sample/rental/web/assembly/PagesModule.java | 2 -
.../assembly/RentalApplicationAssembler.java | 2 -
.../rental/web/assembly/RentalModule.java | 2 -
.../rental/web/assembly/StorageModule.java | 2 -
.../sample/sqlsupport/AppAssembler.java | 2 -
.../swing/binding/SwingBindingAssembler.java | 2 +-
.../sample/swing/binding/example/Main.java | 20 +-
.../jdbm/JdbmEntityStorePerformanceTest.java | 6 +-
.../MemoryEntityStorePerformanceTest.java | 13 +-
.../sql/DerbySQLEntityStorePerformanceTest.java | 51 +-
.../PostgreSQLEntityStorePerformanceTest.java | 57 +-
.../indexing/rdf/QueryPerformanceTest.java | 9 +-
.../CompositeCreationPerformanceTest.java | 14 +-
.../composite/InvocationPerformanceTest.java | 6 +-
.../PropertyMixinInvocationPerformanceTest.java | 4 +-
.../object/ObjectCreationPerformanceTest.java | 16 +-
.../ServiceInvocationPerformanceTest.java | 16 +-
.../test/regression/ConcernsOnPropertyTest.java | 6 +-
tools/envisage/src/docs/envisage.txt | 56 +
.../java/org/apache/polygene/envisage/Main.java | 7 +-
.../envisage/school/EnvisageSchoolSample.java | 12 +-
.../envisage/school/SchoolAssembler.java | 8 +-
.../persistence/PersistenceAssembler.java | 4 +-
tools/generator-polygene/.gitignore | 1 +
tools/generator-polygene/app/index.js | 238 ++--
.../application.java.tmpl | 83 ++
.../CommandLineApplication/bootstrap.tmpl | 49 +
.../ConfigModule/bootstrap.tmpl | 3 +
.../templates/ConfigurationLayer/bootstrap.tmpl | 2 +-
.../HttpServerModule/bootstrap.tmpl | 95 ++
.../HttpServerModule/module.js | 29 +
.../RestApiModule/DefaultEnroler.tmpl | 7 +-
.../templates/ConnectivityLayer/bootstrap.tmpl | 3 +-
.../DomainLayer/DomainModule/Configuration.tmpl | 10 +-
.../DomainLayer/DomainModule/Crud.tmpl | 5 +-
.../DomainLayer/DomainModule/Entity.tmpl | 5 +-
.../DomainLayer/DomainModule/bootstrap.tmpl | 19 +-
.../DomainModule/config.properties.tmpl | 22 +
.../DomainLayer/DomainModule/config.yaml.tmpl | 23 -
.../DomainLayer/DomainModule/module.js | 12 +-
.../DomainLayer/JmxModule/bootstrap.tmpl | 6 +-
.../DomainLayer/SecurityModule/bootstrap.tmpl | 20 -
.../IndexingModule/bootstrap.tmpl | 29 +-
.../indexing/ds-index-postgresql.properties | 23 +
.../indexing/index-rdf.properties | 57 +
.../IndexingModule/indexing/solr-schema.xml | 606 ++++++++++
.../IndexingModule/indexing/solrconfig.xml | 1036 ++++++++++++++++++
.../IndexingModule/module.js | 13 +
.../MetricsModule/bootstrap.tmpl | 31 +-
.../InfrastructureLayer/MetricsModule/module.js | 8 +-
.../StorageModule/bootstrap.tmpl | 45 +-
.../InfrastructureLayer/StorageModule/module.js | 18 +
.../storage/ds-es-derbysql.properties | 24 +
.../storage/ds-es-h2sql.properties | 24 +
.../storage/ds-es-mysql.properties | 24 +
.../storage/ds-es-postgresql.properties | 24 +
.../storage/ds-es-sqlite.properties | 24 +
.../storage/es-cassandra.properties | 50 +
.../StorageModule/storage/es-file.properties | 49 +
.../StorageModule/storage/es-geode.properties | 53 +
.../storage/es-hazelcast.properties | 29 +
.../StorageModule/storage/es-jclouds.properties | 48 +
.../StorageModule/storage/es-jdbm.properties | 31 +
.../StorageModule/storage/es-leveldb.properties | 52 +
.../StorageModule/storage/es-mongodb.properties | 71 ++
.../StorageModule/storage/es-redis.properties | 44 +
.../StorageModule/storage/es-riak.properties | 107 ++
.../StorageModule/storage/es-sql.properties | 36 +
.../InfrastructureLayer/bootstrap.tmpl | 12 +-
.../DevelopmentKeyManagement.java.tmpl | 259 +++++
.../RestAPIApplication/Launcher.java.tmpl | 72 ++
.../app/templates/RestAPIApplication/app.js | 23 +-
.../RestAPIApplication/application.java.tmpl | 89 ++
.../RestAPIApplication/bootstrap-test.tmpl | 336 ++++++
.../templates/RestAPIApplication/bootstrap.tmpl | 71 ++
.../RestAPIApplication/web-shiro.ini.tmpl | 44 +
.../templates/RestAPIApplication/web.xml.tmpl | 46 -
.../CommandLineModule/bootstrap.tmpl | 2 +-
.../app/templates/buildtool/build.js | 8 +-
.../app/templates/buildtool/gradle-app.tmpl | 118 +-
.../templates/buildtool/gradle-bootstrap.tmpl | 60 +-
.../app/templates/buildtool/gradle-model.tmpl | 8 +-
.../app/templates/buildtool/gradle-rest.tmpl | 6 +-
.../app/templates/buildtool/gradle-root.tmpl | 18 +-
.../app/templates/buildtool/gradle-wrapper.jar_ | Bin 51348 -> 0 bytes
.../buildtool/gradle-wrapper.properties_ | 24 -
.../app/templates/buildtool/gradlew-bat.tmpl | 109 --
.../app/templates/buildtool/gradlew.tmpl | 183 ----
tools/generator-polygene/build.gradle | 24 +-
tools/generator-polygene/package.json | 2 +-
.../src/docs/yeoman_polygene.txt | 438 ++++++++
tools/generator-polygene/test/generator_test.js | 6 +-
tools/model-detail/dev-status.xml | 2 +-
.../descriptor/ActivatorDetailDescriptor.java | 29 +
.../descriptor/ApplicationDetailDescriptor.java | 26 +
.../descriptor/CompositeDetailDescriptor.java | 27 +-
.../CompositeMethodDetailDescriptor.java | 36 +-
.../descriptor/ConstructorDetailDescriptor.java | 8 +
.../descriptor/EntityDetailDescriptor.java | 10 +-
.../ImportedServiceCompositeDescriptor.java | 17 +
.../ImportedServiceDetailDescriptor.java | 14 +
.../InjectedFieldDetailDescriptor.java | 9 +
.../InjectedMethodDetailDescriptor.java | 8 +
.../InjectedParametersDetailDescriptor.java | 29 +-
.../model/descriptor/LayerDetailDescriptor.java | 29 +
.../MethodConcernDetailDescriptor.java | 28 +
.../MethodConcernsDetailDescriptor.java | 14 +
.../MethodConstraintDetailDescriptor.java | 9 +
.../MethodConstraintsDetailDescriptor.java | 6 +
.../MethodSideEffectDetailDescriptor.java | 27 +
.../MethodSideEffectsDetailDescriptor.java | 9 +
.../model/descriptor/MixinDetailDescriptor.java | 28 +
.../descriptor/ModuleDetailDescriptor.java | 21 +
.../descriptor/ObjectDetailDescriptor.java | 28 +
.../descriptor/ServiceDetailDescriptor.java | 7 +
.../tools/model/descriptor/ServiceUsage.java | 17 +
.../descriptor/TransientDetailDescriptor.java | 7 +
.../model/descriptor/ValueDetailDescriptor.java | 10 +-
.../tools/model/descriptor/package.html | 2 +-
.../polygene/tools/model/util/APIFinder.java | 4 +-
.../polygene/tools/model/util/package.html | 2 +-
tools/src/docs/envisage.txt | 55 -
tools/src/docs/yeoman_polygene.txt | 388 -------
.../cargo/step2/SequencingConcernTest.java | 36 +-
.../composites/tutorial10/HelloWorldTest.java | 16 +-
.../composites/tutorial3/HelloWorldTest.java | 16 +-
.../composites/tutorial4/HelloWorldTest.java | 16 +-
.../composites/tutorial5/HelloWorldTest.java | 16 +-
.../composites/tutorial6/HelloWorldTest.java | 16 +-
.../composites/tutorial7/HelloWorldTest.java | 16 +-
.../composites/tutorial8/HelloWorldTest.java | 18 +-
.../composites/tutorial9/HelloWorldTest.java | 18 +-
.../polygene/tutorials/hello/HelloTest4.java | 7 +-
550 files changed, 11843 insertions(+), 7355 deletions(-)
----------------------------------------------------------------------
[10/11] polygene-java git commit: Added hasProperty, hasAssociation,
hasManyAssociation, hasNamedAssociation query methods in StateDescriptor & co.
Posted by ni...@apache.org.
Added hasProperty, hasAssociation, hasManyAssociation, hasNamedAssociation query methods in StateDescriptor & co.
Signed-off-by: niclas <ni...@hedhman.org>
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/ffd72078
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/ffd72078
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/ffd72078
Branch: refs/heads/es-jooq
Commit: ffd7207876386e30854ecd8afcf8ded742db3ead
Parents: 914ed58
Author: niclas <ni...@hedhman.org>
Authored: Sun Jun 11 11:30:21 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Sun Jun 11 11:30:21 2017 +0800
----------------------------------------------------------------------
.../association/AssociationStateDescriptor.java | 6 +++++
.../polygene/api/common/QualifiedName.java | 2 --
.../polygene/api/composite/PropertyMapper.java | 2 +-
.../polygene/api/composite/StateDescriptor.java | 2 ++
.../polygene/api/entity/EntityReference.java | 13 +++++++++-
.../runtime/association/AssociationsModel.java | 16 ++++++++-----
.../association/ManyAssociationsModel.java | 16 +++++++++----
.../association/NamedAssociationsModel.java | 21 +++++++++-------
.../polygene/runtime/composite/StateModel.java | 6 +++++
.../runtime/entity/EntityStateModel.java | 21 ++++++++++++++--
.../runtime/property/PropertiesModel.java | 18 ++++++++------
.../polygene/runtime/value/ValueStateModel.java | 18 ++++++++++++++
.../skeletons/SQLCompatEntityStateWrapper.java | 25 +++++++++++++++++++-
13 files changed, 133 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/api/src/main/java/org/apache/polygene/api/association/AssociationStateDescriptor.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/association/AssociationStateDescriptor.java b/core/api/src/main/java/org/apache/polygene/api/association/AssociationStateDescriptor.java
index dbee470..2c11b63 100644
--- a/core/api/src/main/java/org/apache/polygene/api/association/AssociationStateDescriptor.java
+++ b/core/api/src/main/java/org/apache/polygene/api/association/AssociationStateDescriptor.java
@@ -34,18 +34,24 @@ public interface AssociationStateDescriptor extends StateDescriptor
AssociationDescriptor getAssociationByQualifiedName( QualifiedName name )
throws IllegalArgumentException;
+ boolean hasAssociation( QualifiedName name );
+
AssociationDescriptor getManyAssociationByName( String name )
throws IllegalArgumentException;
AssociationDescriptor getManyAssociationByQualifiedName( QualifiedName name )
throws IllegalArgumentException;
+ boolean hasManyAssociation( QualifiedName name );
+
AssociationDescriptor getNamedAssociationByName( String name )
throws IllegalArgumentException;
AssociationDescriptor getNamedAssociationByQualifiedName( QualifiedName name )
throws IllegalArgumentException;
+ boolean hasNamedAssociation( QualifiedName name );
+
Stream<? extends AssociationDescriptor> associations();
Stream<? extends AssociationDescriptor> manyAssociations();
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/api/src/main/java/org/apache/polygene/api/common/QualifiedName.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/common/QualifiedName.java b/core/api/src/main/java/org/apache/polygene/api/common/QualifiedName.java
index 36bf86a..657b6de 100644
--- a/core/api/src/main/java/org/apache/polygene/api/common/QualifiedName.java
+++ b/core/api/src/main/java/org/apache/polygene/api/common/QualifiedName.java
@@ -238,9 +238,7 @@ public final class QualifiedName
{
return false;
}
-
QualifiedName that = (QualifiedName) o;
-
return name.equals( that.name ) && typeName.equals( that.typeName );
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java b/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
index 59e1f67..c4e13f3 100644
--- a/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
+++ b/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
@@ -236,7 +236,7 @@ public final class PropertyMapper
{
return new Properties()
{
- private static final long serialVersionUID = 3550125427530538865L;
+ private static final long serialVersionUID = 1L;
@Override
public Object get( Object o )
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/api/src/main/java/org/apache/polygene/api/composite/StateDescriptor.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/composite/StateDescriptor.java b/core/api/src/main/java/org/apache/polygene/api/composite/StateDescriptor.java
index 20c07c2..8bf4738 100644
--- a/core/api/src/main/java/org/apache/polygene/api/composite/StateDescriptor.java
+++ b/core/api/src/main/java/org/apache/polygene/api/composite/StateDescriptor.java
@@ -35,5 +35,7 @@ public interface StateDescriptor
PropertyDescriptor findPropertyModelByQualifiedName( QualifiedName name )
throws IllegalArgumentException;
+ boolean hasProperty( QualifiedName name );
+
Stream<? extends PropertyDescriptor> properties();
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/api/src/main/java/org/apache/polygene/api/entity/EntityReference.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/entity/EntityReference.java b/core/api/src/main/java/org/apache/polygene/api/entity/EntityReference.java
index 98d1003..3bc557e 100644
--- a/core/api/src/main/java/org/apache/polygene/api/entity/EntityReference.java
+++ b/core/api/src/main/java/org/apache/polygene/api/entity/EntityReference.java
@@ -21,6 +21,7 @@
package org.apache.polygene.api.entity;
import java.util.Objects;
+import org.apache.polygene.api.identity.HasIdentity;
import org.apache.polygene.api.identity.Identity;
import org.apache.polygene.api.identity.StringIdentity;
@@ -39,6 +40,7 @@ public final class EntityReference
*/
public static EntityReference parseEntityReference(String identityString)
{
+ Objects.requireNonNull( identityString, "identityString must not be null" );
return new EntityReference( new StringIdentity( identityString ) );
}
@@ -48,7 +50,16 @@ public final class EntityReference
*/
public static EntityReference entityReferenceFor(Object object)
{
- return new EntityReference(((EntityComposite) object).identity().get());
+ Objects.requireNonNull( object );
+ if( object instanceof Identity )
+ {
+ return new EntityReference( ((Identity) object) );
+ }
+ if( object instanceof HasIdentity )
+ {
+ return new EntityReference( ((HasIdentity) object).identity().get() );
+ }
+ throw new IllegalArgumentException( "Can not get an entity reference for " + object.getClass() );
}
public static EntityReference create(Identity identity)
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationsModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationsModel.java
index a9a53a0..e47adcc 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationsModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationsModel.java
@@ -38,6 +38,7 @@ public final class AssociationsModel
implements VisitableHierarchy<AssociationsModel, AssociationModel>
{
private final Map<AccessibleObject, AssociationModel> mapAccessorAssociationModel = new LinkedHashMap<>();
+ private final Map<QualifiedName, AssociationModel> mapNameAssociationModel = new LinkedHashMap<>();
public AssociationsModel()
{
@@ -51,6 +52,7 @@ public final class AssociationsModel
public void addAssociation( AssociationModel associationModel )
{
mapAccessorAssociationModel.put( associationModel.accessor(), associationModel );
+ mapNameAssociationModel.put( associationModel.qualifiedName(), associationModel );
}
@Override
@@ -97,16 +99,19 @@ public final class AssociationsModel
public AssociationDescriptor getAssociationByQualifiedName( QualifiedName name )
throws IllegalArgumentException
{
- for( AssociationModel associationModel : mapAccessorAssociationModel.values() )
+ AssociationModel associationModel = mapNameAssociationModel.get( name );
+ if( associationModel != null )
{
- if( associationModel.qualifiedName().equals( name ) )
- {
- return associationModel;
- }
+ return associationModel;
}
throw new IllegalArgumentException( "No association found with qualified name:" + name );
}
+ public boolean hasAssociation( QualifiedName name )
+ {
+ return mapNameAssociationModel.containsKey( name );
+ }
+
public void checkConstraints( AssociationStateHolder state )
{
for( AssociationModel associationModel : mapAccessorAssociationModel.values() )
@@ -116,5 +121,4 @@ public final class AssociationsModel
associationModel.checkConstraints( association.get() );
}
}
-
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/runtime/src/main/java/org/apache/polygene/runtime/association/ManyAssociationsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/association/ManyAssociationsModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/association/ManyAssociationsModel.java
index 8765f42..96c51b2 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/association/ManyAssociationsModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/association/ManyAssociationsModel.java
@@ -40,6 +40,7 @@ public final class ManyAssociationsModel
implements VisitableHierarchy<ManyAssociationsModel, ManyAssociationModel>
{
private final Map<AccessibleObject, ManyAssociationModel> mapAccessorAssociationModel = new LinkedHashMap<>();
+ private final Map<QualifiedName, ManyAssociationModel> mapNameAssociationModel = new LinkedHashMap<>();
public ManyAssociationsModel()
{
@@ -53,6 +54,7 @@ public final class ManyAssociationsModel
public void addManyAssociation( ManyAssociationModel model )
{
mapAccessorAssociationModel.put( model.accessor(), model );
+ mapNameAssociationModel.put( model.qualifiedName(), model );
}
@Override
@@ -106,16 +108,20 @@ public final class ManyAssociationsModel
public AssociationDescriptor getManyAssociationByQualifiedName( QualifiedName name )
throws IllegalArgumentException
{
- for( ManyAssociationModel associationModel : mapAccessorAssociationModel.values() )
+
+ ManyAssociationModel associationModel = mapNameAssociationModel.get( name );
+ if( associationModel != null )
{
- if( associationModel.qualifiedName().equals( name ) )
- {
- return associationModel;
- }
+ return associationModel;
}
throw new IllegalArgumentException( "No many-association found with qualified name:" + name );
}
+ public boolean hasAssociation( QualifiedName name )
+ {
+ return mapNameAssociationModel.containsKey( name );
+ }
+
public void checkConstraints( ValueStateInstance state )
{
for( ManyAssociationModel manyAssociationModel : mapAccessorAssociationModel.values() )
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/runtime/src/main/java/org/apache/polygene/runtime/association/NamedAssociationsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/association/NamedAssociationsModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/association/NamedAssociationsModel.java
index 9007abf..c21b3d6 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/association/NamedAssociationsModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/association/NamedAssociationsModel.java
@@ -40,6 +40,7 @@ public final class NamedAssociationsModel
implements VisitableHierarchy<NamedAssociationsModel, NamedAssociationModel>
{
private final Map<AccessibleObject, NamedAssociationModel> mapAccessorAssociationModel = new LinkedHashMap<>();
+ private final Map<QualifiedName, NamedAssociationModel> mapNameAssociationModel = new LinkedHashMap<>();
public NamedAssociationsModel()
{
@@ -53,6 +54,7 @@ public final class NamedAssociationsModel
public void addNamedAssociation( NamedAssociationModel model )
{
mapAccessorAssociationModel.put( model.accessor(), model );
+ mapNameAssociationModel.put( model.qualifiedName(), model );
}
@Override
@@ -83,11 +85,11 @@ public final class NamedAssociationsModel
throws IllegalArgumentException
{
NamedAssociationModel namedAssociationModel = mapAccessorAssociationModel.get( accessor );
- if( namedAssociationModel == null )
+ if( namedAssociationModel != null )
{
- throw new IllegalArgumentException( "No named-association found with name:" + ( (Member) accessor ).getName() );
+ return namedAssociationModel;
}
- return namedAssociationModel;
+ throw new IllegalArgumentException( "No named-association found with name:" + ( (Member) accessor ).getName() );
}
public AssociationDescriptor getNamedAssociationByName( String name )
@@ -106,16 +108,19 @@ public final class NamedAssociationsModel
public AssociationDescriptor getNamedAssociationByQualifiedName( QualifiedName name )
throws IllegalArgumentException
{
- for( NamedAssociationModel associationModel : mapAccessorAssociationModel.values() )
+ NamedAssociationModel associationModel = mapNameAssociationModel.get( name );
+ if( associationModel != null )
{
- if( associationModel.qualifiedName().equals( name ) )
- {
- return associationModel;
- }
+ return associationModel;
}
throw new IllegalArgumentException( "No named-association found with qualified name:" + name );
}
+ public boolean hasAssociation( QualifiedName name )
+ {
+ return mapNameAssociationModel.containsKey( name );
+ }
+
public void checkConstraints( ValueStateInstance state )
{
for( NamedAssociationModel associationModel : mapAccessorAssociationModel.values() )
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/runtime/src/main/java/org/apache/polygene/runtime/composite/StateModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/StateModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/StateModel.java
index 9995d1b..e330d6b 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/StateModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/StateModel.java
@@ -67,6 +67,12 @@ public class StateModel
}
@Override
+ public boolean hasProperty( QualifiedName name )
+ {
+ return propertiesModel.hasProperty( name );
+ }
+
+ @Override
public <ThrowableType extends Throwable> boolean accept( HierarchicalVisitor<? super Object, ? super Object, ThrowableType> visitor )
throws ThrowableType
{
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/runtime/src/main/java/org/apache/polygene/runtime/entity/EntityStateModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/entity/EntityStateModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/entity/EntityStateModel.java
index 7601b4e..7ed42e4 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/entity/EntityStateModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/entity/EntityStateModel.java
@@ -38,8 +38,7 @@ import org.apache.polygene.runtime.property.PropertiesModel;
/**
* Model for EntityComposite state.
*/
-public final class EntityStateModel
- extends StateModel
+public final class EntityStateModel extends StateModel
implements AssociationStateDescriptor
{
private final AssociationsModel associationsModel;
@@ -77,6 +76,12 @@ public final class EntityStateModel
return associationsModel.getAssociationByQualifiedName( name );
}
+ @Override
+ public boolean hasAssociation( QualifiedName name )
+ {
+ return associationsModel.hasAssociation( name );
+ }
+
public ManyAssociationModel getManyAssociation( AccessibleObject accessor )
throws IllegalArgumentException
{
@@ -97,6 +102,12 @@ public final class EntityStateModel
return manyAssociationsModel.getManyAssociationByQualifiedName( name );
}
+ @Override
+ public boolean hasManyAssociation( QualifiedName name )
+ {
+ return manyAssociationsModel.hasAssociation( name );
+ }
+
public NamedAssociationModel getNamedAssociation( AccessibleObject accessor )
throws IllegalArgumentException
{
@@ -118,6 +129,12 @@ public final class EntityStateModel
}
@Override
+ public boolean hasNamedAssociation( QualifiedName name )
+ {
+ return namedAssociationsModel.hasAssociation( name );
+ }
+
+ @Override
public Stream<AssociationModel> associations()
{
return associationsModel.associations();
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertiesModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertiesModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertiesModel.java
index cfcfcb5..ef1f831 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertiesModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/property/PropertiesModel.java
@@ -34,7 +34,8 @@ import org.apache.polygene.api.util.VisitableHierarchy;
public class PropertiesModel
implements VisitableHierarchy<Object, Object>
{
- protected final Map<AccessibleObject, PropertyModel> mapAccessiblePropertyModel = new LinkedHashMap<>();
+ private final Map<AccessibleObject, PropertyModel> mapAccessiblePropertyModel = new LinkedHashMap<>();
+ private final Map<QualifiedName, PropertyModel> mapNamePropertyModel = new LinkedHashMap<>();
public PropertiesModel()
{
@@ -43,6 +44,7 @@ public class PropertiesModel
public void addProperty( PropertyModel property )
{
mapAccessiblePropertyModel.put( property.accessor(), property );
+ mapNamePropertyModel.put( property.qualifiedName(), property );
}
@Override
@@ -75,7 +77,6 @@ public class PropertiesModel
{
throw new IllegalArgumentException( "No property found with name: " + ( (Member) accessor ).getName() );
}
-
return propertyModel;
}
@@ -95,13 +96,16 @@ public class PropertiesModel
public PropertyModel getPropertyByQualifiedName( QualifiedName name )
throws IllegalArgumentException
{
- for( PropertyModel propertyModel : mapAccessiblePropertyModel.values() )
+ PropertyModel propertyModel = mapNamePropertyModel.get( name );
+ if( propertyModel != null )
{
- if( propertyModel.qualifiedName().equals( name ) )
- {
- return propertyModel;
- }
+ return propertyModel;
}
throw new IllegalArgumentException( "No property found with qualified name: " + name );
}
+
+ public boolean hasProperty( QualifiedName name )
+ {
+ return mapNamePropertyModel.containsKey( name );
+ }
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueStateModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueStateModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueStateModel.java
index 73c6a17..f8ef350 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueStateModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/value/ValueStateModel.java
@@ -70,6 +70,12 @@ public final class ValueStateModel
}
@Override
+ public boolean hasAssociation( QualifiedName name )
+ {
+ return associationsModel.hasAssociation( name );
+ }
+
+ @Override
public AssociationDescriptor getManyAssociationByName( String name )
{
return manyAssociationsModel.getManyAssociationByName( name );
@@ -82,6 +88,12 @@ public final class ValueStateModel
}
@Override
+ public boolean hasManyAssociation( QualifiedName name )
+ {
+ return manyAssociationsModel.hasAssociation( name );
+ }
+
+ @Override
public AssociationDescriptor getNamedAssociationByName( String name )
{
return namedAssociationsModel.getNamedAssociationByName( name );
@@ -94,6 +106,12 @@ public final class ValueStateModel
}
@Override
+ public boolean hasNamedAssociation( QualifiedName name )
+ {
+ return namedAssociationsModel.hasAssociation( name );
+ }
+
+ @Override
public Stream<AssociationModel> associations()
{
return associationsModel.associations();
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ffd72078/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/SQLCompatEntityStateWrapper.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/SQLCompatEntityStateWrapper.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/SQLCompatEntityStateWrapper.java
index bf665c6..4b1d9a2 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/SQLCompatEntityStateWrapper.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/SQLCompatEntityStateWrapper.java
@@ -34,7 +34,6 @@ import org.apache.polygene.api.property.PropertyDescriptor;
import org.apache.polygene.api.structure.ModuleDescriptor;
import org.apache.polygene.api.type.CollectionType;
import org.apache.polygene.api.type.EntityCompositeType;
-import org.apache.polygene.api.type.ValueCompositeType;
import org.apache.polygene.api.type.ValueType;
import org.apache.polygene.api.value.ValueComposite;
import org.apache.polygene.spi.entity.EntityState;
@@ -307,6 +306,12 @@ class SQLCompatEntityStateWrapper
}
@Override
+ public boolean hasAssociation( QualifiedName name )
+ {
+ return wrappedAssociationStateDescriptor.hasAssociation( name );
+ }
+
+ @Override
public AssociationDescriptor getManyAssociationByName( String name )
throws IllegalArgumentException
{
@@ -321,6 +326,12 @@ class SQLCompatEntityStateWrapper
}
@Override
+ public boolean hasManyAssociation( QualifiedName name )
+ {
+ return false;
+ }
+
+ @Override
public AssociationDescriptor getNamedAssociationByName( String name )
throws IllegalArgumentException
{
@@ -335,6 +346,12 @@ class SQLCompatEntityStateWrapper
}
@Override
+ public boolean hasNamedAssociation( QualifiedName name )
+ {
+ return false;
+ }
+
+ @Override
public Stream<? extends AssociationDescriptor> associations()
{
return wrappedAssociationStateDescriptor.associations();
@@ -367,6 +384,12 @@ class SQLCompatEntityStateWrapper
}
@Override
+ public boolean hasProperty( QualifiedName name )
+ {
+ return wrappedAssociationStateDescriptor.hasProperty( name );
+ }
+
+ @Override
public Stream<? extends PropertyDescriptor> properties()
{
return wrappedAssociationStateDescriptor.properties().filter( PROPERTY_SPEC );
[07/11] polygene-java git commit: Committing an intermediate state of
the JOOQ ES, to dig into the classloading issue in the Service composition.
Posted by ni...@apache.org.
Committing an intermediate state of the JOOQ ES, to dig into the classloading issue in the Service composition.
Signed-off-by: niclas <ni...@hedhman.org>
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/60d2eebd
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/60d2eebd
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/60d2eebd
Branch: refs/heads/es-jooq
Commit: 60d2eebd709dc2eb7078b04a305aaba2e4485299
Parents: c2a30f7
Author: niclas <ni...@hedhman.org>
Authored: Fri Jun 9 11:40:09 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Fri Jun 9 11:40:09 2017 +0800
----------------------------------------------------------------------
.../org/apache/polygene/api/PolygeneAPI.java | 1 +
.../api/association/AssociationDescriptor.java | 8 +-
.../api/property/PropertyDescriptor.java | 8 +-
.../runtime/methods/AccessibleTest.java | 99 +++++
.../polygene/entitystore/jooq/BaseEntity.java | 17 +
.../entitystore/jooq/EntitiesTable.java | 247 +++++++++++
.../entitystore/jooq/JooqDslContext.java | 24 +-
.../jooq/JooqEntityStoreConfiguration.java | 11 +
.../entitystore/jooq/JooqEntityStoreMixin.java | 67 ++-
.../jooq/JooqEntityStoreService.java | 2 +-
.../polygene/entitystore/jooq/MixinTable.java | 214 ++++++++++
.../polygene/entitystore/jooq/SqlTable.java | 416 +++++++------------
.../polygene/entitystore/jooq/SqlType.java | 185 ++++-----
.../polygene/entitystore/jooq/TableFields.java | 69 +++
.../polygene/entitystore/jooq/TypesTable.java | 187 +++++++++
.../jooq/assembly/JooqEntityStoreAssembler.java | 7 +-
.../entitystore/jooq/JooqEntityStoreTest.java | 66 ++-
.../sql/dbcp/DBCPDataSourceServiceImporter.java | 3 +-
18 files changed, 1218 insertions(+), 413 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java b/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
index 2823cb6..15d104e 100644
--- a/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
+++ b/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
@@ -143,6 +143,7 @@ public interface PolygeneAPI
* @return true if the given object is a Composite type.
*/
boolean isComposite( Object object );
+
/**
* Function that returns the CompositeInstance of a Composite.
*/
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/core/api/src/main/java/org/apache/polygene/api/association/AssociationDescriptor.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/association/AssociationDescriptor.java b/core/api/src/main/java/org/apache/polygene/api/association/AssociationDescriptor.java
index e7a1c01..09cd2c4 100644
--- a/core/api/src/main/java/org/apache/polygene/api/association/AssociationDescriptor.java
+++ b/core/api/src/main/java/org/apache/polygene/api/association/AssociationDescriptor.java
@@ -59,11 +59,11 @@ public interface AssociationDescriptor extends MetaInfoHolder
*/
Type type();
- boolean isImmutable();
-
- boolean isAggregated();
-
AccessibleObject accessor();
boolean queryable();
+
+ boolean isImmutable();
+
+ boolean isAggregated();
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java b/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java
index 6c7df05..4a21920 100644
--- a/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java
+++ b/core/api/src/main/java/org/apache/polygene/api/property/PropertyDescriptor.java
@@ -32,8 +32,6 @@ import org.apache.polygene.api.type.ValueType;
*/
public interface PropertyDescriptor extends MetaInfoHolder
{
- boolean isImmutable();
-
/**
* Get the qualified name of the property which is equal to:
* <pre><code>
@@ -54,9 +52,11 @@ public interface PropertyDescriptor extends MetaInfoHolder
AccessibleObject accessor();
- Object resolveInitialValue(ModuleDescriptor moduleDescriptor);
+ boolean isImmutable();
+
+ boolean queryable();
ValueType valueType();
- boolean queryable();
+ Object resolveInitialValue(ModuleDescriptor moduleDescriptor);
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java
new file mode 100644
index 0000000..0d3ccb4
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/methods/AccessibleTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.runtime.methods;
+
+import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.test.AbstractPolygeneTest;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class AccessibleTest extends AbstractPolygeneTest
+{
+
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.transients( MyComposite.class );
+ }
+
+ @Test
+ public void givenPrivateMixinWhenCallingFromWithinExpectSuccess()
+ {
+ MyComposite myComposite = transientBuilderFactory.newTransient( MyComposite.class );
+ assertThat(myComposite.doSomething(), equalTo("Hello"));
+ }
+
+ @Mixins( MyCompositeMixin.class)
+ public interface MyComposite
+ {
+ String doSomething();
+ }
+
+ @Mixins( MyFunctionMixin.class )
+ public interface MyFunction
+ {
+ String doSomething();
+ }
+
+
+ public class MyCompositeMixin
+ implements MyComposite
+ {
+ @This
+ private MyFunction function;
+
+ @Override
+ public String doSomething()
+ {
+ return new MyObject( function ).doSomething() + " ---- " + getClass().getClassLoader();
+ }
+ }
+
+ public class MyFunctionMixin
+ implements MyFunction
+ {
+ @Override
+ public String doSomething()
+ {
+ return "Hello " + getClass().getClassLoader();
+ }
+ }
+
+ public class MyObject
+ {
+ private MyFunction fn;
+
+ public MyObject( MyFunction fn )
+ {
+ this.fn = fn;
+ }
+
+ String doSomething()
+ {
+ return fn.doSomething();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
index 07fb05c..e4eaa40 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/BaseEntity.java
@@ -1,3 +1,20 @@
+/*
+ * 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.jooq;
import java.time.Instant;
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java
new file mode 100644
index 0000000..dc765a9
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/EntitiesTable.java
@@ -0,0 +1,247 @@
+/*
+ * 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.jooq;
+
+import java.lang.reflect.Method;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.polygene.api.association.AssociationDescriptor;
+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.api.property.PropertyDescriptor;
+import org.apache.polygene.api.structure.ModuleDescriptor;
+import org.apache.polygene.api.type.EntityCompositeType;
+import org.apache.polygene.api.unitofwork.NoSuchEntityTypeException;
+import org.apache.polygene.api.util.Classes;
+import org.apache.polygene.spi.entitystore.EntityNotFoundException;
+import org.apache.polygene.spi.entitystore.EntityStoreUnitOfWork;
+import org.apache.polygene.spi.entitystore.helpers.DefaultEntityState;
+import org.jooq.Condition;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Result;
+import org.jooq.Schema;
+import org.jooq.SelectJoinStep;
+import org.jooq.SelectQuery;
+import org.jooq.Table;
+
+public class EntitiesTable
+ implements TableFields
+{
+ private Map<EntityCompositeType, Set<Class<?>>> mixinTypeCache = new ConcurrentHashMap<>();
+ private Map<Class<?>, MixinTable> mixinTablesCache = new ConcurrentHashMap<>();
+
+ private final Table<Record> entitiesTable;
+ private JooqDslContext dsl;
+ private final TypesTable types;
+ private final Schema schema;
+ private String applicationVersion;
+
+ EntitiesTable( JooqDslContext dsl, Schema schema, TypesTable types, String applicationVersion, String entitiesTableName )
+ {
+ this.dsl = dsl;
+ this.types = types;
+ this.schema = schema;
+ this.applicationVersion = applicationVersion;
+ entitiesTable = types.tableOf( entitiesTableName );
+ }
+
+ public BaseEntity fetchEntity( EntityReference reference, ModuleDescriptor module )
+ {
+ BaseEntity result = new BaseEntity();
+
+ Result<Record> baseEntityResult = dsl
+ .selectFrom( entitiesTable )
+ .where( identityColumn.eq( reference.identity().toString() ) )
+ .fetch();
+
+ if( baseEntityResult.isEmpty() )
+ {
+ throw new EntityNotFoundException( reference );
+ }
+ Record baseEntity = baseEntityResult.get( 0 );
+ String typeName = baseEntity.field( typeNameColumn ).get( baseEntity );
+ result.type = findEntityDescriptor( typeName, module );
+ result.version = baseEntity.field( versionColumn ).get( baseEntity );
+ result.applicationVersion = baseEntity.field( applicationVersionColumn ).get( baseEntity );
+ result.identity = EntityReference.parseEntityReference( baseEntity.field( identityColumn ).get( baseEntity ) ).identity();
+ result.currentValueIdentity = EntityReference.parseEntityReference( baseEntity.field( valueIdentityColumn ).get( baseEntity ) ).identity();
+ result.modifedAt = Instant.ofEpochMilli( baseEntity.field( modifiedColumn ).get( baseEntity ).getTime() );
+ result.createdAt = Instant.ofEpochMilli( baseEntity.field( createdColumn ).get( baseEntity ).getTime() );
+ return result;
+ }
+
+ private EntityDescriptor findEntityDescriptor( String typeName, ModuleDescriptor module )
+ {
+ try
+ {
+ Class<?> type = getClass().getClassLoader().loadClass( typeName );
+ return module.typeLookup().lookupEntityModel( type );
+ }
+ catch( ClassNotFoundException e )
+ {
+ throw new NoSuchEntityTypeException( typeName, module.name(), module.typeLookup() );
+ }
+ }
+
+ void insertEntity( DefaultEntityState state )
+ {
+ EntityCompositeType compositeType = state.entityDescriptor().valueType();
+ Set<Class<?>> mixinTypes = mixinTypeCache.computeIfAbsent( compositeType, type ->
+ {
+ Set<Class<?>> mixins = compositeType
+ .properties()
+ .map( PropertyDescriptor::accessor )
+ .filter( Classes.instanceOf( Method.class ) )
+ .map( accessor -> (Method) accessor )
+ .map( Method::getDeclaringClass )
+ .collect( Collectors.toSet() );
+ Set<Class<?>> mixinsWithAssociations = mixinsOf( compositeType.associations() );
+ Set<Class<?>> mixinsWithManyAssociations = mixinsOf( compositeType.manyAssociations() );
+ Set<Class<?>> mixinsWithNamedAssociations = mixinsOf( compositeType.namedAssociations() );
+ mixins.addAll( mixinsWithAssociations );
+ mixins.addAll( mixinsWithManyAssociations );
+ mixins.addAll( mixinsWithNamedAssociations );
+ return mixins;
+ } );
+ String valueIdentity = UUID.randomUUID().toString();
+ mixinTypes.forEach( type ->
+ {
+ MixinTable table = findMixinTable( type, state.entityDescriptor() );
+ table.insertMixinState( state, valueIdentity );
+ } );
+ }
+
+ private MixinTable findMixinTable( Class<?> type, EntityDescriptor entityDescriptor )
+ {
+ return mixinTablesCache.computeIfAbsent( type, t -> new MixinTable( dsl, schema, types, type, entityDescriptor ) );
+ }
+
+ private Set<Class<?>> mixinsOf( Stream<? extends AssociationDescriptor> stream )
+ {
+ return stream
+ .map( AssociationDescriptor::accessor )
+ .filter( Classes.instanceOf( Method.class ) )
+ .map( accessor -> (Method) accessor )
+ .map( Method::getDeclaringClass )
+ .collect( Collectors.toSet() );
+ }
+
+ private String columnNameOf( QualifiedName propertyName )
+ {
+ return null;
+ }
+
+ void modifyEntity( Class<?> mixinType, DefaultEntityState state )
+ {
+
+ }
+
+ void createNewBaseEntity( EntityReference reference, EntityDescriptor descriptor, EntityStoreUnitOfWork uow )
+ {
+ String valueIdentity = UUID.randomUUID().toString();
+ dsl.insertInto( entitiesTable )
+ .set( identityColumn, reference.identity().toString() )
+ .set( createdColumn, new Timestamp( uow.currentTime().toEpochMilli() ) )
+ .set( modifiedColumn, new Timestamp( uow.currentTime().toEpochMilli() ) )
+ .set( valueIdentityColumn, valueIdentity )
+ .set( typeNameColumn, descriptor.primaryType().getName() )
+ .set( versionColumn, "1" )
+ .set( applicationVersionColumn, applicationVersion )
+ .execute();
+ }
+
+ /**
+ * Builds the SELECT statement for a given entity.
+ * <p>
+ * Example; If we have the following entity
+ * </p>
+ * <code><pre>
+ * public interface LegalEntity
+ * {
+ * Property<String> registration();
+ * }
+ * <p>
+ * public interface Person extends LegalEntity
+ * {
+ * Property<String> name();
+ * <p>
+ * @Optional
+ * Association<Person> spouse();
+ * <p>
+ * ManyAssocation<Person> children();
+ * }
+ * </pre></code>
+ * <p>
+ * and we do a simple;
+ * <code><pre>
+ * Person p = uow.get( Person.class, "niclas" );
+ * </pre></code>
+ * <p>
+ * then the generated query will be
+ * </p>
+ * <code><pre>
+ * SELECT * FROM ENTITIES
+ * JOIN Person ON identity = ENTITIES.value_id
+ * JOIN LegalEntity ON identity = ENTITIES.value_id
+ * JOIN Person_Assoc ON identity = ENTITIES.value_id
+ * WHERE ENTITIES.identity = '123'
+ * </pre></code>
+ *
+ * @param entityDescriptor The descriptor of the entity type to be built.
+ * @return The SELECT query that can be executed to retrieve the entity.
+ */
+ public SelectQuery<Record> createGetEntityQuery( EntityDescriptor entityDescriptor, EntityReference reference )
+ {
+ SelectJoinStep<Record> from = dsl.select().from( entitiesTable );
+ List<Table<Record>> joins = getTableJoins( entityDescriptor );
+ for( Table<Record> joinedTable : joins )
+ {
+ Field<String> joinedField = joinedTable.field( identityColumn );
+ Condition joinCondition = joinedField.eq( entitiesTable.field( valueIdentityColumn ) );
+ from = from.join( joinedTable ).on( joinCondition );
+ }
+ return from.where( identityColumn.eq( reference.identity().toString() ) ).getQuery();
+ }
+
+ public void fetchAssociations( Record record, Consumer<AssociationValue> consume )
+ {
+ AssociationValue value = new AssociationValue();
+ value.name = record.getValue( nameColumn );
+ value.position = record.getValue( indexColumn );
+ value.reference = record.getValue( referenceColumn );
+ consume.accept( value );
+ }
+
+ public List<Table<Record>> getTableJoins( EntityDescriptor entityDescriptor )
+ {
+ return entityDescriptor
+ .mixinTypes()
+ .map( ( Class<?> type ) -> types.tableFor( type, entityDescriptor ) )
+ .collect( Collectors.toList() );
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java
index 8737936..95a0fd5 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqDslContext.java
@@ -1,3 +1,20 @@
+/*
+ * 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.jooq;
import java.lang.reflect.InvocationHandler;
@@ -6,7 +23,6 @@ import javax.sql.DataSource;
import org.apache.polygene.api.injection.scope.Service;
import org.apache.polygene.api.injection.scope.Uses;
import org.apache.polygene.api.mixin.Mixins;
-import org.apache.polygene.api.service.ServiceDescriptor;
import org.jooq.Configuration;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
@@ -23,13 +39,11 @@ public interface JooqDslContext extends DSLContext
{
private DSLContext dsl;
- public Mixin( @Service DataSource dataSource, @Uses ServiceDescriptor serviceDescriptor )
+ public Mixin( @Service DataSource dataSource, @Uses Settings settings, @Uses SQLDialect dialect )
{
- Settings settings = serviceDescriptor.metaInfo( Settings.class );
- SQLDialect sqlDialect = serviceDescriptor.metaInfo( SQLDialect.class );
Configuration configuration = new DefaultConfiguration()
.set( dataSource )
- .set( sqlDialect )
+ .set( dialect )
.set( settings );
dsl = DSL.using( configuration );
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
index e3a79f6..7d27cdf 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreConfiguration.java
@@ -58,5 +58,16 @@ public interface JooqEntityStoreConfiguration extends SQLConfiguration
*/
@UseDefaults( "true" )
Property<Boolean> createIfMissing();
+
+ /**
+ * The SQL dialect that is being used.
+ * <p>
+ * Typically that is matching a supporting dialect in JOOQ.
+ * See {@link org.jooq.SQLDialect} for supported values.
+ * </p>
+ * @return The property with the dialect value.
+ */
+ @UseDefaults( "" )
+ Property<String> dialect();
}
// END SNIPPET: config
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
index 8974181..a22354b 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreMixin.java
@@ -30,11 +30,9 @@ import org.apache.polygene.api.entity.EntityDescriptor;
import org.apache.polygene.api.entity.EntityReference;
import org.apache.polygene.api.identity.IdentityGenerator;
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.structure.ModuleDescriptor;
import org.apache.polygene.api.usecase.Usecase;
-import org.apache.polygene.spi.PolygeneSPI;
import org.apache.polygene.spi.entity.EntityState;
import org.apache.polygene.spi.entity.EntityStatus;
import org.apache.polygene.spi.entitystore.DefaultEntityStoreUnitOfWork;
@@ -53,19 +51,9 @@ import static org.apache.polygene.api.entity.EntityReference.parseEntityReferenc
public class JooqEntityStoreMixin
implements EntityStore, EntityStoreSPI
{
-
- @Structure
- private PolygeneSPI spi;
-
- @This
- private SqlType sqlType;
-
@This
private SqlTable sqlTable;
- @This
- private JooqDslContext jooqDslContext;
-
@Service
private IdentityGenerator identityGenerator;
@@ -103,7 +91,6 @@ public class JooqEntityStoreMixin
Map<QualifiedName, List<EntityReference>> manyAssocs = new HashMap<>();
Map<QualifiedName, Map<String, EntityReference>> namedAssocs = new HashMap<>();
result.forEach( record ->
- {
sqlTable.fetchAssociations( record, associationValue ->
{
// TODO: Perhaps introduce "preserveManyAssociationOrder" option which would have an additional column, separating 'ordinal position' and 'name position'
@@ -115,8 +102,7 @@ public class JooqEntityStoreMixin
{
addNamedAssociation( stateDescriptor, namedAssocs, associationValue );
}
- } );
- } );
+ } ) );
return new DefaultEntityState( baseEntity.version,
baseEntity.modifedAt,
@@ -155,7 +141,7 @@ public class JooqEntityStoreMixin
@Override
public StateCommitter applyChanges( EntityStoreUnitOfWork unitOfWork, Iterable<EntityState> state )
{
- return new JooqStateCommitter( unitOfWork, state );
+ return new JooqStateCommitter( unitOfWork, state, sqlTable.jooqDslContext() );
}
@Override
@@ -175,24 +161,65 @@ public class JooqEntityStoreMixin
return null;
}
- private static class JooqStateCommitter
+ private class JooqStateCommitter
implements StateCommitter
{
- public JooqStateCommitter( EntityStoreUnitOfWork unitOfWork, Iterable<EntityState> state )
- {
+ private final EntityStoreUnitOfWork unitOfWork;
+ private final Iterable<EntityState> states;
+ private final JooqDslContext dslContext;
+ JooqStateCommitter( EntityStoreUnitOfWork unitOfWork, Iterable<EntityState> states, JooqDslContext dslContext )
+ {
+ this.unitOfWork = unitOfWork;
+ this.states = states;
+ this.dslContext = dslContext;
}
@Override
public void commit()
{
+ dslContext.transaction( configuration ->
+ {
+ for( EntityState es : this.states )
+ {
+ DefaultEntityState state = (DefaultEntityState) es;
+ if( state.status() == EntityStatus.NEW )
+ {
+ newState( state );
+ }
+ if( state.status() == EntityStatus.UPDATED )
+ {
+ updateState( state );
+ }
+ if( state.status() == EntityStatus.REMOVED )
+ {
+ removeState( state );
+ }
+ }
+ } );
+ }
+
+ private void newState( DefaultEntityState state )
+ {
+ EntityReference ref = state.entityReference();
+ EntityDescriptor descriptor = state.entityDescriptor();
+ sqlTable.createNewBaseEntity( ref, descriptor, unitOfWork );
+ sqlTable.insertEntity( state );
+ }
+
+ private void updateState( DefaultEntityState state )
+ {
}
+ private void removeState( DefaultEntityState state )
+ {
+ EntityReference reference = state.entityReference();
+ }
+
@Override
public void cancel()
{
-
}
}
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java
index 0259151..511f2f0 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/JooqEntityStoreService.java
@@ -31,6 +31,6 @@ import org.apache.polygene.spi.entitystore.StateChangeNotificationConcern;
@Concerns( { StateChangeNotificationConcern.class, ConcurrentModificationCheckConcern.class } )
@Mixins( { JooqEntityStoreMixin.class } )
public interface JooqEntityStoreService
- extends EntityStore, EntityStateVersions, Configuration
+ extends EntityStore, EntityStateVersions, Configuration, SqlTable
{
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
new file mode 100644
index 0000000..fee95ef
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/MixinTable.java
@@ -0,0 +1,214 @@
+/*
+ * 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.jooq;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Method;
+import java.sql.Timestamp;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.polygene.api.association.AssociationDescriptor;
+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.api.property.PropertyDescriptor;
+import org.apache.polygene.spi.entity.ManyAssociationState;
+import org.apache.polygene.spi.entity.NamedAssociationState;
+import org.apache.polygene.spi.entitystore.helpers.DefaultEntityState;
+import org.jooq.Field;
+import org.jooq.InsertSetMoreStep;
+import org.jooq.Name;
+import org.jooq.Record;
+import org.jooq.Schema;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+
+class MixinTable
+ implements TableFields
+{
+
+ private final Table<Record> mixinTable;
+ private final Table<Record> mixinAssocsTable;
+
+ private final JooqDslContext dsl;
+ private TypesTable types;
+ private final Class<?> mixinType;
+
+ MixinTable( JooqDslContext dsl, Schema schema, TypesTable types, Class<?> mixinType,
+ EntityDescriptor descriptor )
+ {
+ this.dsl = dsl;
+ this.types = types;
+ this.mixinType = mixinType;
+ mixinTable = types.tableFor( mixinType, descriptor );
+ mixinAssocsTable = getAssocsTable( descriptor, schema );
+ }
+
+ void insertMixinState( DefaultEntityState state, String valueIdentity )
+ {
+ InsertSetMoreStep<Record> primaryTable =
+ dsl.insertInto( mixinTable )
+ .set( identityColumn, valueIdentity )
+ .set( createdColumn, new Timestamp( System.currentTimeMillis() ) )
+ .set( modifiedColumn, new Timestamp( System.currentTimeMillis() ) );
+
+ EntityDescriptor entityDescriptor = state.entityDescriptor();
+ entityDescriptor.valueType().properties()
+ .filter( this::isThisMixin )
+ .forEach( propDescriptor ->
+ {
+ QualifiedName propertyName = propDescriptor.qualifiedName();
+ Field<Object> propertyField = types.fieldOf( propDescriptor );
+ primaryTable.set( propertyField, state.propertyValueOf( propertyName ) );
+ }
+ );
+ entityDescriptor.valueType().associations()
+ .filter( this::isThisMixin )
+ .forEach( assocDescriptor ->
+ {
+ QualifiedName assocName = assocDescriptor.qualifiedName();
+ Field<String> assocField = types.fieldOf( assocDescriptor );
+ EntityReference reference = state.associationValueOf( assocName );
+ String identity = null;
+ if( reference != null )
+ {
+ identity = reference.identity().toString();
+ }
+ primaryTable.set( assocField, identity );
+ }
+ );
+
+ if( mixinAssocsTable != null )
+ {
+ entityDescriptor.valueType().manyAssociations()
+ .filter( this::isThisMixin )
+ .forEach( setManyAssociations( state, valueIdentity ) );
+
+ entityDescriptor.valueType().namedAssociations()
+ .filter( this::isThisMixin )
+ .forEach( setNamedAssociations( state, valueIdentity ) );
+ }
+ }
+
+ private Consumer<? super AssociationDescriptor> setManyAssociations( DefaultEntityState state, String valueIdentity )
+ {
+ return assocDescriptor ->
+ {
+ QualifiedName assocName = assocDescriptor.qualifiedName();
+ ManyAssociationState entityReferences = state.manyAssociationValueOf( assocName );
+ entityReferences.stream().forEach( setManyAssociation( state, assocDescriptor, valueIdentity ) );
+ };
+ }
+
+ private Consumer<? super EntityReference> setManyAssociation( DefaultEntityState state,
+ AssociationDescriptor assocDescriptor,
+ String valueIdentity )
+ {
+ QualifiedName assocName = assocDescriptor.qualifiedName();
+ Field<String> assocField = types.fieldOf( assocDescriptor );
+ InsertSetMoreStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable ).set( identityColumn, valueIdentity );
+ return ref ->
+ {
+ assocsTable.newRecord();
+ assocsTable.set( assocField, state.associationValueOf( assocName ).identity().toString() );
+ };
+ }
+
+ private Consumer<? super AssociationDescriptor> setNamedAssociations( DefaultEntityState state,
+ String valueIdentity )
+ {
+ return assocDescriptor ->
+ {
+ QualifiedName assocName = assocDescriptor.qualifiedName();
+ NamedAssociationState entityReferences = state.namedAssociationValueOf( assocName );
+ entityReferences.stream().forEach( setNamedAssociation( state, assocDescriptor, valueIdentity ) );
+ };
+ }
+
+ private Consumer<? super Map.Entry<String, EntityReference>> setNamedAssociation( DefaultEntityState state,
+ AssociationDescriptor assocDescriptor,
+ String valueIdentity )
+ {
+ QualifiedName assocName = assocDescriptor.qualifiedName();
+ Field<String> assocField = types.fieldOf( assocDescriptor );
+ InsertSetMoreStep<Record> assocsTable = dsl.insertInto( mixinAssocsTable ).set( identityColumn, valueIdentity );
+ return ref ->
+ {
+ assocsTable.newRecord();
+ assocsTable.set( assocField, state.associationValueOf( assocName ).identity().toString() );
+ };
+ }
+
+ private boolean isThisMixin( PropertyDescriptor descriptor )
+ {
+ Class<?> declaringClass = declaredIn( descriptor );
+ return mixinType.equals( declaringClass );
+ }
+
+ private boolean isThisMixin( AssociationDescriptor descriptor )
+ {
+ Class<?> declaringClass = declaredIn( descriptor );
+ return mixinType.equals( declaringClass );
+ }
+
+ private Class<?> declaredIn( PropertyDescriptor descriptor )
+ {
+ AccessibleObject accessor = descriptor.accessor();
+ if( accessor instanceof Method )
+ {
+ return ( (Method) accessor ).getDeclaringClass();
+ }
+ throw new UnsupportedOperationException( "Property declared as " + accessor.getClass() + " is not supported in this Entity Store yet." );
+ }
+
+ private Class<?> declaredIn( AssociationDescriptor descriptor )
+ {
+ AccessibleObject accessor = descriptor.accessor();
+ if( accessor instanceof Method )
+ {
+ return ( (Method) accessor ).getDeclaringClass();
+ }
+ throw new UnsupportedOperationException( "Property declared as " + accessor.getClass() + " is not supported in this Entity Store yet." );
+ }
+
+ void modifyMixinState( Class<?> mixinType, DefaultEntityState state )
+ {
+
+ }
+
+ private Table<Record> getAssocsTable( EntityDescriptor descriptor, Schema schema )
+ {
+ if( descriptor.state().manyAssociations().count() > 0
+ || descriptor.state().namedAssociations().count() > 0 )
+ {
+ Name tableName = DSL.name( schema.getName(), mixinTable.getName() + ASSOCS_TABLE_POSTFIX );
+ Table<Record> table = DSL.table( tableName );
+ int result2 = dsl.createTableIfNotExists( table )
+ .column( identityColumn )
+ .column( nameColumn )
+ .column( indexColumn )
+ .column( referenceColumn )
+ .execute();
+ return table;
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
index 1cf0c1c..2801f57 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlTable.java
@@ -17,340 +17,236 @@
*/
package org.apache.polygene.entitystore.jooq;
-import java.lang.reflect.Method;
-import java.time.Instant;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
import java.util.function.Consumer;
-import java.util.stream.Collectors;
+import javax.sql.DataSource;
+import org.apache.polygene.api.PolygeneAPI;
+import org.apache.polygene.api.composite.TransientBuilderFactory;
import org.apache.polygene.api.configuration.Configuration;
import org.apache.polygene.api.entity.EntityDescriptor;
import org.apache.polygene.api.entity.EntityReference;
+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.mixin.Mixins;
-import org.apache.polygene.api.property.Property;
-import org.apache.polygene.api.property.PropertyDescriptor;
+import org.apache.polygene.api.object.ObjectFactory;
import org.apache.polygene.api.service.ServiceActivation;
import org.apache.polygene.api.service.ServiceDescriptor;
+import org.apache.polygene.api.structure.Application;
import org.apache.polygene.api.structure.ModuleDescriptor;
-import org.apache.polygene.api.type.ValueType;
-import org.apache.polygene.api.unitofwork.NoSuchEntityTypeException;
-import org.apache.polygene.spi.entitystore.EntityNotFoundException;
-import org.jooq.Condition;
-import org.jooq.CreateTableAsStep;
-import org.jooq.Field;
+import org.apache.polygene.spi.entitystore.EntityStoreUnitOfWork;
+import org.apache.polygene.spi.entitystore.helpers.DefaultEntityState;
import org.jooq.Record;
-import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.Schema;
-import org.jooq.SelectJoinStep;
import org.jooq.SelectQuery;
-import org.jooq.Table;
+import org.jooq.conf.RenderNameStyle;
+import org.jooq.conf.Settings;
import org.jooq.impl.DSL;
+/**
+ * This class handles all the Jooq interactions.
+ * <p>
+ * <p>
+ * <p>
+ * <h1>Tables</h1>
+ * <h2>Types Table</h2>
+ * <ul>
+ * <li>identity</li>
+ * <li>table_name</li>
+ * <li>created_at</li>
+ * <li>modified_at</li>
+ * </ul>
+ * <h2>Entities Table</h2>
+ * <ul>
+ * <li>identity</li>
+ * <li>app_version</li>
+ * <li>value_id</li>
+ * <li>version</li>
+ * <li>type</li>
+ * <li>modified_at</li>
+ * <li>created_at</li>
+ * </ul>
+ * <h2>Mixin Tables</h2>
+ * <p>
+ * Each Mixin is stored in its own table. Only the following column is always present;
+ * <ul>
+ * <li>identity - this is not entity identity but the UUID of the value_id in the Entities Table above.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * Each Property of the Mixin (as defined by QualifiedName of the Property, will reside in its own column.
+ * All values in columns are (for now) serialized using a ValueSerialization service.
+ * </p>
+ * <p>
+ * Associations also has their own columns in the table, with the EntityReference.identity() stored in them.
+ * </p>
+ * <p>
+ * ManyAssociations and NamedAssociations are stored in a separate table, named <mixintable>_ASSOCS, see below.
+ * </p>
+ * <h2>Mixin_ASSOCS Table</h2>
+ * <ul>
+ * <li>identity - the value_id of the mixin value</li>
+ * <li>name - the name of the ManyAssociation or NamedAssociation</li>
+ * <li>position - for NamedAssociation this is the 'name' (i.e key) and for ManyAssociation this is the index into the list.</li>
+ * <li>reference - EntityReference.identity of that association</li>
+ * </ul>
+ */
@Mixins( SqlTable.Mixin.class )
-public interface SqlTable
+public interface SqlTable extends ServiceActivation
{
- String IDENTITY_COLUMN_NAME = "identity";
- String VALUEID_COLUMN_NAME = "value_id";
- String VERSION_COLUMN_NAME = "version";
- String APPLICATIONVERSION_COLUMN_NAME = "app_version";
- String TYPE_COLUMN_NAME = "type";
- String LASTMODIFIED_COLUMN_NAME = "modified_at";
- String CREATED_COLUMN_NAME = "created_at";
- String TABLENAME_COLUMN_NAME = "table_name";
- String ASSOCIATIONS_COLUMN_NAME = "assocations";
- String POSITION_COLUMN_NAME = "position";
-
- String createNewTableName( Class<?> type );
-
- Result<Record> createNewTable( Class<?> mixinType, EntityDescriptor descriptor );
-
- boolean isProperty( Method method );
-
- Table<Record> findTable( Class<?> type, EntityDescriptor descriptor );
-
- Table<Record> createTable( Class<?> type, EntityDescriptor descriptor );
-
- String findTableName( Class<?> type, EntityDescriptor descriptor );
-
- List<Table<Record>> getTableJoins( EntityDescriptor entityDescriptor );
-
- Result<Record> fetchTypeInfoFromTable( Class<?> entityType );
-
BaseEntity fetchBaseEntity( EntityReference reference, ModuleDescriptor module );
- EntityDescriptor findEntityDescriptor( String typeName, ModuleDescriptor module );
+ SelectQuery<Record> createGetEntityQuery( EntityDescriptor descriptor, EntityReference reference );
- Record createNewBaseEntity( EntityReference reference, EntityDescriptor descriptor );
+ void fetchAssociations( Record record, Consumer<AssociationValue> consume );
- SelectQuery<Record> createGetEntityQuery( EntityDescriptor entityDescriptor, EntityReference reference );
+ void createNewBaseEntity( EntityReference ref, EntityDescriptor descriptor, EntityStoreUnitOfWork unitOfWork );
- void fetchAssociations( Record record, Consumer<AssociationValue> consume );
+ void insertEntity( DefaultEntityState state );
+
+ JooqDslContext jooqDslContext();
class Mixin
- implements SqlTable, ServiceActivation
+ implements SqlTable, TableFields, ServiceActivation
{
+ @Structure
+ private Application application;
- @This
- JooqDslContext dsl;
+ @Structure
+ private PolygeneAPI api;
+
+ @Structure
+ private TransientBuilderFactory tbf;
+
+ @Structure
+ private ObjectFactory objectFactory;
@This
private Configuration<JooqEntityStoreConfiguration> configuration;
- @This
- private SqlType sqlType;
+ @Service
+ private DataSource datasource;
@Uses
private ServiceDescriptor serviceDescriptor;
- private Table<Record> typesTable;
- private Table<Record> entitiesTable;
- private Map<Class, Table<Record>> entityTables;
- private Field<String> identityColumn;
- private Field<String> valueIdentityColumn;
- private Field<String> typeColumn;
- private Field<String> versionColumn;
- private Field<String> applicationVersionColumn;
- private Field<Instant> modifiedColumn;
- private Field<Instant> createdColumn;
- private Field<String> tableNameColumn;
- private Field<String> assocationsColumn;
- private Field<String> positionColumn;
-
- private Schema schema;
-
- private SQLDialect dialect;
-
- @Override
- public void activateService()
- throws Exception
- {
- configuration.refresh();
- JooqEntityStoreConfiguration config = configuration.get();
-
- // Prepare jooq DSL
- dialect = serviceDescriptor.metaInfo( SQLDialect.class );
-
- String schemaName = config.schemaName().get();
- String typesTableName = config.typesTableName().get();
- String entitiesTableName = config.entitiesTableName().get();
- schema = DSL.schema( DSL.name( schemaName ) );
- typesTable = DSL.table(
- dialect.equals( SQLDialect.SQLITE )
- ? DSL.name( typesTableName )
- : DSL.name( schema.getName(), typesTableName )
- );
- entitiesTable = DSL.table(
- dialect.equals( SQLDialect.SQLITE )
- ? DSL.name( entitiesTableName )
- : DSL.name( schema.getName(), entitiesTableName ) );
+ private EntitiesTable entitiesTable;
- identityColumn = DSL.field( DSL.name( IDENTITY_COLUMN_NAME ), String.class );
- valueIdentityColumn = DSL.field( DSL.name( VALUEID_COLUMN_NAME ), String.class );
- versionColumn = DSL.field( DSL.name( VERSION_COLUMN_NAME ), String.class );
- applicationVersionColumn = DSL.field( DSL.name( APPLICATIONVERSION_COLUMN_NAME ), String.class );
- typeColumn = DSL.field( DSL.name( TYPE_COLUMN_NAME ), String.class );
- modifiedColumn = DSL.field( DSL.name( LASTMODIFIED_COLUMN_NAME ), Instant.class );
- createdColumn = DSL.field( DSL.name( CREATED_COLUMN_NAME ), Instant.class );
- tableNameColumn = DSL.field( DSL.name( TABLENAME_COLUMN_NAME ), String.class );
- assocationsColumn = DSL.field( DSL.name( ASSOCIATIONS_COLUMN_NAME ), String.class );
- positionColumn = DSL.field( DSL.name( POSITION_COLUMN_NAME ), String.class );
-
- // Eventually create schema
- if( config.createIfMissing().get() )
- {
- if( !dialect.equals( SQLDialect.SQLITE )
- && dsl.meta().getSchemas().stream().noneMatch( s -> schema.getName().equalsIgnoreCase( s.getName() ) ) )
- {
- dsl.createSchema( schema ).execute();
- }
- }
- }
+ private TypesTable types;
+ private JooqDslContext dsl;
@Override
public BaseEntity fetchBaseEntity( EntityReference reference, ModuleDescriptor module )
{
- BaseEntity result = new BaseEntity();
-
- Result<Record> baseEntityResult = dsl
- .select()
- .from( entitiesTable )
- .where( identityColumn.eq( reference.toURI() ) )
- .fetch();
-
- if( baseEntityResult.isEmpty() )
- {
- throw new EntityNotFoundException( reference );
- }
- Record baseEntity = baseEntityResult.get( 0 );
- String typeName = baseEntity.field( typeColumn ).get( baseEntity );
- result.type = findEntityDescriptor( typeName, module );
- result.version = baseEntity.field( versionColumn ).get( baseEntity );
- result.applicationVersion = baseEntity.field( applicationVersionColumn ).get( baseEntity );
- result.identity = EntityReference.parseEntityReference( baseEntity.field( identityColumn ).get( baseEntity ) ).identity();
- result.currentValueIdentity = EntityReference.parseEntityReference( baseEntity.field( valueIdentityColumn ).get( baseEntity ) ).identity();
- result.modifedAt = baseEntity.field( modifiedColumn ).get( baseEntity );
- result.createdAt = baseEntity.field( createdColumn ).get( baseEntity );
- return result;
+ return entitiesTable.fetchEntity( reference, module );
}
@Override
- public void passivateService()
- throws Exception
+ public SelectQuery<Record> createGetEntityQuery( EntityDescriptor descriptor, EntityReference reference )
{
- schema = null;
+ return entitiesTable.createGetEntityQuery( descriptor, reference );
}
- public Result<Record> fetchTypeInfoFromTable( Class<?> entityType )
- {
- return dsl
- .select()
- .from( typesTable )
- .where( identityColumn.eq( entityType.getName() ) )
- .fetch();
- }
-
- public List<Table<Record>> getTableJoins( EntityDescriptor entityDescriptor )
- {
- return entityDescriptor
- .mixinTypes()
- .map( ( Class<?> type ) -> findTable( type, entityDescriptor ) )
- .collect( Collectors.toList() );
- }
-
- public Table<Record> findTable( Class<?> type, EntityDescriptor descriptor )
+ @Override
+ public void fetchAssociations( Record record, Consumer<AssociationValue> consume )
{
- return entityTables.computeIfAbsent( type, t -> createTable( t, descriptor ) );
+ entitiesTable.fetchAssociations( record, consume );
}
- public Table<Record> createTable( Class<?> type, EntityDescriptor descriptor )
+ @Override
+ public void createNewBaseEntity( EntityReference ref, EntityDescriptor descriptor, EntityStoreUnitOfWork unitOfWork )
{
- String tableName = findTableName( type, descriptor );
- return null;
+ entitiesTable.createNewBaseEntity( ref, descriptor, unitOfWork );
}
- public String findTableName( Class<?> type, EntityDescriptor descriptor )
+ @Override
+ public void insertEntity( DefaultEntityState state )
{
- Result<Record> typeInfo = fetchTypeInfoFromTable( type );
- if( typeInfo.isEmpty() )
- {
- typeInfo = createNewTable( type, descriptor );
- }
- return typeInfo.getValue( 0, tableNameColumn );
+ entitiesTable.insertEntity( state );
}
@Override
- public String createNewTableName( Class<?> type )
+ public JooqDslContext jooqDslContext()
{
- return null;
+ return dsl;
}
- public Result<Record> createNewTable( Class<?> mixinType, EntityDescriptor descriptor )
+ @Override
+ public void activateService()
+ throws Exception
{
- String tableName = createNewTableName( mixinType );
- CreateTableAsStep<Record> table = dsl.createTable( tableName );
- Arrays.stream( mixinType.getDeclaredMethods() )
- .filter( this::isProperty )
- .forEach( method ->
- {
- PropertyDescriptor propertyDescriptor = descriptor.state().findPropertyModelByName( method.getName() );
- ValueType valueType = propertyDescriptor.valueType();
- Class<?> propertyType = valueType.primaryType();
- String propertyName = method.getName();
- table.column( propertyName, sqlType.getSqlDataTypeFor( propertyType ) );
- } );
+ JooqEntityStoreConfiguration config = this.configuration.get();
+ SQLDialect dialect = getSqlDialect( config );
- return fetchTypeInfoFromTable( mixinType );
- }
+ Settings settings = serviceDescriptor
+ .metaInfo( Settings.class )
+ .withRenderNameStyle( RenderNameStyle.QUOTED );
+ dsl = tbf.newTransient( JooqDslContext.class, settings, dialect );
- public boolean isProperty( Method method )
- {
- return Property.class.isAssignableFrom( method.getReturnType() ) && method.getParameterCount() == 0;
- }
+ String schemaName = config.schemaName().get();
+ String typesTableName = config.typesTableName().get();
+ String entitiesTableName = config.entitiesTableName().get();
+ Schema schema = DSL.schema( DSL.name( schemaName ) );
+ types = new TypesTable( dsl, schema, dialect, typesTableName );
+ entitiesTable = new EntitiesTable( dsl, schema, types, application.version(), entitiesTableName );
- public EntityDescriptor findEntityDescriptor( String typeName, ModuleDescriptor module )
- {
- try
- {
- Class<?> type = getClass().getClassLoader().loadClass( typeName );
- return module.typeLookup().lookupEntityModel( type );
- }
- catch( ClassNotFoundException e )
+ // Eventually create schema
+ if( config.createIfMissing().get() )
{
- throw new NoSuchEntityTypeException( typeName, module.name(), module.typeLookup() );
+ if( !dialect.equals( SQLDialect.SQLITE )
+ && dsl.meta().getSchemas().stream().noneMatch( s -> schema.getName().equalsIgnoreCase( s.getName() ) ) )
+ {
+ dsl.createSchema( schema ).execute();
+ }
+
+ dsl.createTableIfNotExists( DSL.name( schemaName, typesTableName ) )
+ .column( identityColumn )
+ .column( tableNameColumn )
+ .column( createdColumn )
+ .column( modifiedColumn )
+ .execute();
+
+ dsl.createTableIfNotExists( DSL.name( schemaName, entitiesTableName ) )
+ .column( identityColumn )
+ .column( applicationVersionColumn )
+ .column( valueIdentityColumn )
+ .column( versionColumn )
+ .column( typeNameColumn )
+ .column( modifiedColumn )
+ .column( createdColumn )
+ .execute();
}
+ datasource.getConnection().commit();
}
@Override
- public Record createNewBaseEntity( EntityReference reference, EntityDescriptor descriptor )
+ public void passivateService()
+ throws Exception
{
- return null;
+
}
- /**
- * Builds the SELECT statement for a given entity.
- * <p>
- * Example; If we have the following entity
- * </p>
- * <code><pre>
- * public interface LegalEntity
- * {
- * Property<String> registration();
- * }
- * <p>
- * public interface Person extends LegalEntity
- * {
- * Property<String> name();
- * <p>
- * @Optional
- * Association<Person> spouse();
- * <p>
- * ManyAssocation<Person> children();
- * }
- * </pre></code>
- * <p>
- * and we do a simple;
- * <code><pre>
- * Person p = uow.get( Person.class, "niclas" );
- * </pre></code>
- * <p>
- * then the generated query will be
- * </p>
- * <code><pre>
- * SELECT * FROM ENTITIES
- * JOIN Person ON identity = ENTITIES.value_id
- * JOIN LegalEntity ON identity = ENTITIES.value_id
- * JOIN Person_Assoc ON identity = ENTITIES.value_id
- * WHERE ENTITIES.identity = '123'
- * </pre></code>
- *
- * @param entityDescriptor The descriptor of the entity type to be built.
- * @return The SELECT query that can be executed to retrieve the entity.
- */
- public SelectQuery<Record> createGetEntityQuery( EntityDescriptor entityDescriptor, EntityReference reference )
+ private SQLDialect getSqlDialect( JooqEntityStoreConfiguration config )
{
- SelectJoinStep<Record> from = dsl.select().from( entitiesTable );
- List<Table<Record>> joins = getTableJoins( entityDescriptor );
- for( Table<Record> joinedTable : joins )
+ SQLDialect dialect = null;
+ String dialectString = config.dialect().get();
+ if( dialectString.length() == 0 )
{
- Field<String> joinedField = joinedTable.field( identityColumn );
- Condition joinCondition = joinedField.eq( entitiesTable.field( valueIdentityColumn ) );
- from = from.join( joinedTable ).on( joinCondition );
+ dialect = SQLDialect.DEFAULT;
}
- return from.where( identityColumn.eq( reference.identity().toString() ) ).getQuery();
- }
-
- @Override
- public void fetchAssociations( Record record, Consumer<AssociationValue> consume )
- {
- AssociationValue value = new AssociationValue();
- value.name = record.getValue( assocationsColumn );
- value.position = record.getValue( positionColumn );
- value.reference = record.getValue( this.assocationsColumn );
- consume.accept( value );
+ else
+ {
+ try
+ {
+ dialect = SQLDialect.valueOf( dialectString );
+ }
+ catch( IllegalArgumentException e )
+ {
+ throw new IllegalArgumentException( "Invalid SQLDialect: '" + dialectString + "'" );
+ }
+ }
+ return dialect;
}
}
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java
index c872d62..6b6dfdd 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/SqlType.java
@@ -24,125 +24,118 @@ import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.Period;
import java.time.ZonedDateTime;
-import org.apache.polygene.api.mixin.Mixins;
import org.jooq.DataType;
import org.jooq.impl.SQLDataType;
import org.jooq.types.Interval;
-@Mixins( SqlType.Mixin.class )
-public interface SqlType
+class SqlType
{
- DataType<?> getSqlDataTypeFor( Class<?> propertyType );
-
- class Mixin
- implements SqlType
+ @SuppressWarnings( "unchecked" )
+ static <T> DataType<T> getSqlDataTypeFor( Class<?> propertyType )
{
- public DataType<?> getSqlDataTypeFor( Class<?> propertyType )
+ if( String.class.isAssignableFrom( propertyType ) )
{
- if( String.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.VARCHAR;
- }
- if( Integer.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.INTEGER;
- }
- if( Long.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.BIGINT;
- }
- if( Boolean.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.BOOLEAN;
- }
- if( Float.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.FLOAT;
- }
- if( Double.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.DOUBLE;
- }
- if( Instant.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.TIMESTAMPWITHTIMEZONE;
- }
- if( Interval.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.VARCHAR;
- }
- if( Period.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.VARCHAR;
- }
- if( LocalDate.class.isAssignableFrom( propertyType ) )
- {
- return SQLDataType.LOCALDATE;
- }
- if( LocalTime.class.isAssignableFrom( propertyType ) )
+ return (DataType<T>) SQLDataType.VARCHAR;
+ }
+ if( Integer.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.INTEGER;
+ }
+ if( Long.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.BIGINT;
+ }
+ if( Boolean.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.BOOLEAN;
+ }
+ if( Float.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.FLOAT;
+ }
+ if( Double.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.DOUBLE;
+ }
+ if( Instant.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.TIMESTAMPWITHTIMEZONE;
+ }
+ if( Interval.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.VARCHAR;
+ }
+ if( Period.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.VARCHAR;
+ }
+ if( LocalDate.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.LOCALDATE;
+ }
+ if( LocalTime.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.LOCALTIME;
+ }
+ if( LocalDateTime.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.LOCALDATETIME;
+ }
+ if( ZonedDateTime.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.OFFSETDATETIME;
+ }
+ if( OffsetDateTime.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.OFFSETDATETIME;
+ }
+ if( Character.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.CHAR( 1 );
+ }
+ if( Short.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.INTEGER;
+ }
+ if( Byte.class.isAssignableFrom( propertyType ) )
+ {
+ return (DataType<T>) SQLDataType.INTEGER;
+ }
+ if( propertyType.isPrimitive() )
+ {
+ if( propertyType.equals( Integer.TYPE ) )
{
- return SQLDataType.LOCALTIME;
+ return (DataType<T>) SQLDataType.INTEGER;
}
- if( LocalDateTime.class.isAssignableFrom( propertyType ) )
+ if( propertyType.equals( Long.TYPE ) )
{
- return SQLDataType.LOCALDATETIME;
+ return (DataType<T>) SQLDataType.BIGINT;
}
- if( ZonedDateTime.class.isAssignableFrom( propertyType ) )
+ if( propertyType.equals( Boolean.TYPE ) )
{
- return SQLDataType.OFFSETDATETIME;
+ return (DataType<T>) SQLDataType.BOOLEAN;
}
- if( OffsetDateTime.class.isAssignableFrom( propertyType ) )
+ if( propertyType.equals( Float.TYPE ) )
{
- return SQLDataType.OFFSETDATETIME;
+ return (DataType<T>) SQLDataType.FLOAT;
}
- if( Character.class.isAssignableFrom( propertyType ) )
+ if( propertyType.equals( Double.TYPE ) )
{
- return SQLDataType.CHAR( 1 );
+ return (DataType<T>) SQLDataType.DOUBLE;
}
- if( Short.class.isAssignableFrom( propertyType ) )
+ if( propertyType.equals( Character.TYPE ) )
{
- return SQLDataType.INTEGER;
+ return (DataType<T>) SQLDataType.CHAR( 1 );
}
- if( Byte.class.isAssignableFrom( propertyType ) )
+ if( propertyType.equals( Short.TYPE ) )
{
- return SQLDataType.INTEGER;
+ return (DataType<T>) SQLDataType.INTEGER;
}
- if( propertyType.isPrimitive() )
+ if( propertyType.equals( Byte.TYPE ) )
{
- if( propertyType.equals( Integer.TYPE ) )
- {
- return SQLDataType.INTEGER;
- }
- if( propertyType.equals( Long.TYPE ) )
- {
- return SQLDataType.BIGINT;
- }
- if( propertyType.equals( Boolean.TYPE ) )
- {
- return SQLDataType.BOOLEAN;
- }
- if( propertyType.equals( Float.TYPE ) )
- {
- return SQLDataType.FLOAT;
- }
- if( propertyType.equals( Double.TYPE ) )
- {
- return SQLDataType.DOUBLE;
- }
- if( propertyType.equals( Character.TYPE ) )
- {
- return SQLDataType.CHAR( 1 );
- }
- if( propertyType.equals( Short.TYPE ) )
- {
- return SQLDataType.INTEGER;
- }
- if( propertyType.equals( Byte.TYPE ) )
- {
- return SQLDataType.INTEGER;
- }
+ return (DataType<T>) SQLDataType.INTEGER;
}
- return SQLDataType.VARCHAR;
}
+ return (DataType<T>) SQLDataType.VARCHAR;
}
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java
new file mode 100644
index 0000000..2454ae4
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TableFields.java
@@ -0,0 +1,69 @@
+/*
+ * 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.jooq;
+
+import java.sql.Timestamp;
+import org.jooq.Field;
+
+import static org.apache.polygene.entitystore.jooq.TypesTable.makeField;
+
+public interface TableFields
+{
+ // Common in all tables
+ String IDENTITY_COLUMN_NAME = "identity";
+ String CREATED_COLUMN_NAME = "created_at";
+ String LASTMODIFIED_COLUMN_NAME = "modified_at";
+
+ // Types Table
+ String TABLENAME_COLUMN_NAME = "table_name";
+
+ // Entities Table
+ String VALUEID_COLUMN_NAME = "value_id";
+ String TYPE_COLUMN_NAME = "type";
+ String VERSION_COLUMN_NAME = "version";
+ String APPLICATIONVERSION_COLUMN_NAME = "app_version";
+
+ // Mixin Tables
+ String NAME_COLUMN_NAME = "name";
+ String INDEX_COLUMN_NAME = "index"; // either index in ManyAssociation or name in NamedAssociation
+ String REFERENCE_COLUMN_NAME = "reference";
+ String ASSOCS_TABLE_POSTFIX = "_ASSOCS";
+
+
+ // Common Fields
+ Field<String> identityColumn = makeField( IDENTITY_COLUMN_NAME, String.class );
+ Field<Timestamp> createdColumn = makeField( CREATED_COLUMN_NAME, Timestamp.class );
+ Field<Timestamp> modifiedColumn = makeField( LASTMODIFIED_COLUMN_NAME, Timestamp.class );
+
+ // Types Table
+ Field<String> tableNameColumn = makeField( TABLENAME_COLUMN_NAME, String.class );
+
+ // Entities Table
+ Field<String> valueIdentityColumn = makeField( VALUEID_COLUMN_NAME, String.class );
+ Field<String> typeNameColumn = makeField( TYPE_COLUMN_NAME, String.class );
+ Field<String> versionColumn = makeField( VERSION_COLUMN_NAME, String.class );
+ Field<String> applicationVersionColumn = makeField( APPLICATIONVERSION_COLUMN_NAME, String.class );
+
+ // Mixin Tables
+
+ // The _ASSOCS table
+ Field<String> nameColumn = makeField( NAME_COLUMN_NAME, String.class );
+ Field<String> referenceColumn = makeField( REFERENCE_COLUMN_NAME, String.class );
+ Field<String> indexColumn = makeField( INDEX_COLUMN_NAME, String.class );
+
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java
new file mode 100644
index 0000000..4672d4f
--- /dev/null
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/TypesTable.java
@@ -0,0 +1,187 @@
+/*
+ * 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.jooq;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.sql.Timestamp;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.polygene.api.association.AssociationDescriptor;
+import org.apache.polygene.api.common.QualifiedName;
+import org.apache.polygene.api.entity.EntityDescriptor;
+import org.apache.polygene.api.property.Property;
+import org.apache.polygene.api.property.PropertyDescriptor;
+import org.apache.polygene.api.util.Classes;
+import org.jooq.CreateTableColumnStep;
+import org.jooq.DataType;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Result;
+import org.jooq.SQLDialect;
+import org.jooq.Schema;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+
+public class TypesTable
+ implements TableFields
+{
+ private final Map<Class<?>, Table<Record>> mixinTablesCache = new ConcurrentHashMap<>();
+ private final Map<Class<?>, Table<Record>> mixinAssocsTablesCache = new ConcurrentHashMap<>();
+
+ private final Table<Record> typesTable;
+ private final SQLDialect dialect;
+ private final Schema schema;
+
+ private final JooqDslContext dsl;
+
+ TypesTable( JooqDslContext dsl, Schema schema,
+ SQLDialect dialect,
+ String typesTablesName
+ )
+ {
+ this.schema = schema;
+ this.dialect = dialect;
+ typesTable = tableOf( typesTablesName );
+ this.dsl = dsl;
+ }
+
+ static <T> Field<T> makeField( String columnName, Class<T> type )
+ {
+ return DSL.field( DSL.name( columnName ), type );
+ }
+
+ Table<Record> tableOf( String tableName )
+ {
+ return DSL.table(
+ dialect.equals( SQLDialect.SQLITE )
+ ? DSL.name( tableName )
+ : DSL.name( schema.getName(), tableName ) );
+ }
+
+ String tableNameOf( Class<?> mixinType )
+ {
+ Result<Record> typeInfo = fetchTypeInfoFromTable( mixinType );
+ if( typeInfo.isEmpty() )
+ {
+ return null;
+ }
+ return typeInfo.getValue( 0, tableNameColumn );
+ }
+
+ Table<Record> tableFor( Class<?> type, EntityDescriptor descriptor )
+ {
+ return mixinTablesCache.computeIfAbsent( type, t ->
+ {
+ String tableName = tableNameOf( t );
+ if( tableName == null )
+ {
+ Result<Record> newMixinTable = createNewMixinTable( type, descriptor );
+ return tableOf( newMixinTable.getValue( 0, tableNameColumn ) );
+ }
+ return tableOf( tableName );
+ } );
+ }
+
+ private Result<Record> fetchTypeInfoFromTable( Class<?> mixinTableName )
+ {
+ return dsl.select()
+ .from( typesTable )
+ .where( identityColumn.eq( mixinTableName.getName() ) )
+ .fetch();
+ }
+
+ private Result<Record> createNewMixinTable( Class<?> mixinType, EntityDescriptor descriptor )
+ {
+ String mixinTypeName = mixinType.getName();
+ String tableName = createNewTableName( mixinType );
+ CreateTableColumnStep primaryTable = dsl.createTable( tableName ).column( identityColumn );
+ descriptor.state().properties().forEach(
+ property ->
+ {
+ QualifiedName qualifiedName = property.qualifiedName();
+ if( qualifiedName.toNamespace().equals( mixinTypeName ) )
+ {
+ primaryTable.column( fieldOf( property ) );
+ }
+ } );
+ descriptor.state().associations().forEach(
+ assoc ->
+ {
+ QualifiedName qualifiedName = assoc.qualifiedName();
+ if( qualifiedName.toNamespace().equals( mixinTypeName ) )
+ {
+ primaryTable.column( fieldOf( assoc ) );
+ }
+ } );
+
+ int result3 = dsl.insertInto( typesTable )
+ .set( identityColumn, mixinTypeName )
+ .set( tableNameColumn, tableName )
+ .set( createdColumn, new Timestamp( System.currentTimeMillis() ) )
+ .set( modifiedColumn, new Timestamp( System.currentTimeMillis() ) )
+ .execute();
+ return fetchTypeInfoFromTable( mixinType );
+ }
+
+ private String createNewTableName( Class<?> mixinType )
+ {
+ String typeName = mixinType.getSimpleName();
+ String postFix = "";
+ int counter = 0;
+ boolean found = false;
+ do
+ {
+ found = checkForTableNamed( typeName + postFix );
+ postFix = "_" + counter++;
+ } while( found );
+ return typeName;
+ }
+
+ private boolean checkForTableNamed( String tableName )
+ {
+ return dsl.select()
+ .from( typesTable )
+ .where( tableNameColumn.eq( tableName ) )
+ .fetch().size() > 0;
+ }
+
+ private boolean isProperty( Method method )
+ {
+ return Property.class.isAssignableFrom( method.getReturnType() ) && method.getParameterCount() == 0;
+ }
+
+ Field<Object> fieldOf( PropertyDescriptor descriptor )
+ {
+ String propertyName = descriptor.qualifiedName().name();
+ return DSL.field( DSL.name( propertyName ), dataTypeOf( descriptor ) );
+ }
+
+ Field<String> fieldOf( AssociationDescriptor descriptor )
+ {
+ String propertyName = descriptor.qualifiedName().name();
+ return DSL.field( DSL.name( propertyName ), DSL.getDataType( String.class ) );
+ }
+
+ private <T> DataType<T> dataTypeOf( PropertyDescriptor property )
+ {
+ Type type = property.type();
+ Class<?> rawType = Classes.RAW_CLASS.apply( type );
+ return SqlType.getSqlDataTypeFor( rawType );
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/60d2eebd/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java
index 8a986a9..c251efe 100644
--- a/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java
+++ b/extensions/entitystore-jooq/src/main/java/org/apache/polygene/entitystore/jooq/assembly/JooqEntityStoreAssembler.java
@@ -25,6 +25,7 @@ import org.apache.polygene.bootstrap.Assembler;
import org.apache.polygene.bootstrap.Assemblers;
import org.apache.polygene.bootstrap.AssemblyException;
import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.jooq.JooqDslContext;
import org.apache.polygene.entitystore.jooq.JooqEntityStoreConfiguration;
import org.apache.polygene.entitystore.jooq.JooqEntityStoreService;
import org.jooq.SQLDialect;
@@ -32,8 +33,9 @@ import org.jooq.conf.RenderNameStyle;
import org.jooq.conf.Settings;
/**
- * MySQL EntityStore assembly.
+ * JOOQ EntityStore assembly.
*/
+@SuppressWarnings( "WeakerAccess" )
public class JooqEntityStoreAssembler extends Assemblers.VisibilityIdentityConfig<JooqEntityStoreAssembler>
implements Assembler
{
@@ -49,11 +51,12 @@ public class JooqEntityStoreAssembler extends Assemblers.VisibilityIdentityConfi
}
String identity = ( hasIdentity() ? identity() : DEFAULT_ENTITYSTORE_IDENTITY ).toString();
+ module.transients( JooqDslContext.class );
module.services( JooqEntityStoreService.class )
.identifiedBy( identity )
.visibleIn( visibility() )
- .setMetaInfo( getSQLDialect() )
+ .instantiateOnStartup()
.setMetaInfo( settings );
if( hasConfig() )
[09/11] polygene-java git commit: Remove a warning
Posted by ni...@apache.org.
Remove a warning
Signed-off-by: niclas <ni...@hedhman.org>
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/914ed582
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/914ed582
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/914ed582
Branch: refs/heads/es-jooq
Commit: 914ed5828496c508216fe7d49151725fde01b70b
Parents: 0f58a7d
Author: niclas <ni...@hedhman.org>
Authored: Fri Jun 9 14:39:40 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Fri Jun 9 14:39:40 2017 +0800
----------------------------------------------------------------------
.../polygene/runtime/composite/FragmentInvocationHandler.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/914ed582/core/runtime/src/main/java/org/apache/polygene/runtime/composite/FragmentInvocationHandler.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/FragmentInvocationHandler.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/FragmentInvocationHandler.java
index f0dfca6..3525664 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/FragmentInvocationHandler.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/FragmentInvocationHandler.java
@@ -50,7 +50,7 @@ abstract class FragmentInvocationHandler
this.method = method;
}
- protected Throwable cleanStackTrace( Throwable throwable, Object proxy, Method method )
+ Throwable cleanStackTrace( Throwable throwable, Object proxy, Method method )
{
if( compactLevel == CompactLevel.off )
{