Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6B37118A85 for ; Wed, 16 Dec 2015 06:17:39 +0000 (UTC) Received: (qmail 62912 invoked by uid 500); 16 Dec 2015 06:17:39 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 62863 invoked by uid 500); 16 Dec 2015 06:17:39 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 62713 invoked by uid 99); 16 Dec 2015 06:17:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Dec 2015 06:17:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E19BAE0B2E; Wed, 16 Dec 2015 06:17:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@zest.apache.org Date: Wed, 16 Dec 2015 06:17:46 -0000 Message-Id: In-Reply-To: <0b77afe66b1d4c059412da98c8184cce@git.apache.org> References: <0b77afe66b1d4c059412da98c8184cce@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [9/9] zest-java git commit: ZEST-132, ZEST-97 UnitOfWorkFactory as a customizable Service UnitOfWork as a customizable Transient Class can be a Transient directly, with itself as both the Composite Type and the Mixin. SideEffects declarations ZEST-132, ZEST-97 UnitOfWorkFactory as a customizable Service UnitOfWork as a customizable Transient Class can be a Transient directly, with itself as both the Composite Type and the Mixin. SideEffects declarations on methods. Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/a5be013f Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/a5be013f Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/a5be013f Branch: refs/heads/ZEST-132 Commit: a5be013f39cba9642114e01486cdff0c355569f2 Parents: 6138c30 Author: Niclas Hedhman Authored: Wed Dec 16 14:17:22 2015 +0800 Committer: Niclas Hedhman Committed: Wed Dec 16 14:17:27 2015 +0800 ---------------------------------------------------------------------- .../zest/api/configuration/Configuration.java | 7 +- .../zest/api/entity/EntityBuilderTemplate.java | 2 +- .../org/apache/zest/api/structure/Module.java | 15 +- .../java/org/apache/zest/api/type/HasTypes.java | 6 + .../org/apache/zest/api/type/ValueType.java | 1 + .../apache/zest/api/unitofwork/UnitOfWork.java | 7 +- .../zest/api/unitofwork/UnitOfWorkTemplate.java | 2 +- .../unitofwork/concern/UnitOfWorkConcern.java | 20 +- .../java/org/apache/zest/api/OperatorsTest.java | 8 +- .../api/injection/scope/StateFieldTest.java | 4 +- .../zest/api/property/PropertyErrorTest.java | 2 +- .../apache/zest/api/unitofwork/RemovalTest.java | 4 +- .../zest/api/value/DocumentationSupport.java | 67 +- .../zest/api/value/ValueCompositeTest.java | 6 +- .../apache/zest/bootstrap/ModuleAssembly.java | 36 +- .../unitofwork/DefaultUnitOfWorkAssembler.java | 55 ++ .../apache/zest/bootstrap/ClassScannerTest.java | 2 + .../apache/zest/runtime/ZestRuntimeImpl.java | 2 +- .../association/ManyAssociationModel.java | 5 +- .../association/ManyAssociationsModel.java | 2 +- .../association/NamedAssociationModel.java | 5 +- .../association/NamedAssociationsModel.java | 2 +- .../bootstrap/CompositeAssemblyImpl.java | 141 +++- .../runtime/bootstrap/ModuleAssemblyImpl.java | 12 +- .../zest/runtime/composite/CompositeModel.java | 5 +- .../composite/TransientBuilderInstance.java | 2 +- .../runtime/composite/TransientClassLoader.java | 3 +- .../zest/runtime/entity/EntityInstance.java | 5 +- .../apache/zest/runtime/entity/EntityModel.java | 2 +- .../runtime/entity/EntityStateInstance.java | 9 +- .../runtime/injection/InjectedFieldsModel.java | 23 +- .../StructureInjectionProviderFactory.java | 2 +- .../zest/runtime/service/ServicesModel.java | 12 + .../zest/runtime/structure/LayerInstance.java | 3 +- .../zest/runtime/structure/ModuleInstance.java | 136 +--- .../runtime/structure/ModuleUnitOfWork.java | 769 ------------------ .../zest/runtime/structure/TypeLookup.java | 526 ------------- .../zest/runtime/structure/TypeLookupImpl.java | 538 +++++++++++++ .../runtime/structure/UsedLayersInstance.java | 3 +- .../unitofwork/EntityBuilderInstance.java | 3 +- .../zest/runtime/unitofwork/EntityFunction.java | 46 ++ .../runtime/unitofwork/ModuleUnitOfWork.java | 777 +++++++++++++++++++ .../unitofwork/UnitOfWorkFactoryMixin.java | 100 +++ .../runtime/unitofwork/UnitOfWorkInstance.java | 40 +- .../runtime/value/ValueBuilderInstance.java | 2 +- .../value/ValueBuilderWithPrototype.java | 2 +- .../runtime/value/ValueBuilderWithState.java | 2 +- .../zest/runtime/value/ValueStateInstance.java | 11 +- .../apache/zest/api/common/OptionalTest.java | 6 +- .../zest/api/common/PropertyErrorTest.java | 2 +- .../zest/api/common/PropertyTypeTest.java | 2 +- .../org/apache/zest/api/common/RemovalTest.java | 4 +- .../zest/api/common/ValueCompositeTest.java | 2 +- ...faceCollisionWithRelatedReturnTypesTest.java | 18 +- .../qi377/SetAssociationInSideEffectTest.java | 2 +- .../apache/zest/regression/qi382/Qi382Test.java | 10 +- .../apache/zest/regression/qi383/Qi383Test.java | 2 +- .../apache/zest/regression/qi59/IssueTest.java | 4 +- .../apache/zest/regression/qi94/IssueTest.java | 2 +- .../org/apache/zest/runtime/ZestAPITest.java | 2 +- .../org/apache/zest/runtime/ZestSPITest.java | 4 +- .../AppliesToOrConditionQI241Test.java | 6 +- .../association/AssociationAssignmentTest.java | 4 +- .../association/AssociationEqualityTest.java | 18 +- .../runtime/composite/TransientAsClassTest.java | 22 +- .../composite/TransientClassLoaderTest.java | 30 + .../runtime/concerns/GenericConcernTest.java | 2 +- .../zest/runtime/entity/AggregatedTest.java | 10 +- .../entity/EntityBuilderWithStateTest.java | 68 +- .../entity/EntityCompositeEqualityTest.java | 2 +- .../zest/runtime/entity/EntityCreationTest.java | 4 +- .../zest/runtime/entity/EntityTypeTest.java | 2 +- .../runtime/entity/EntityVisibilityTest.java | 58 +- .../zest/runtime/entity/LifecycleTest.java | 4 +- .../entity/associations/AssociationTest.java | 2 +- .../associations/ImmutableAssociationTest.java | 8 +- .../ConstructorInjectionOfThisTest.java | 2 + .../injection/UnitOfWorkInjectionTest.java | 10 +- .../TransientInstantiationTests.java | 1 - .../zest/runtime/mixin/AssemblyMixinTest.java | 4 +- .../zest/runtime/mixin/AssemblyRoleTest.java | 6 +- .../runtime/objects/ObjectVisibilityTest.java | 35 +- .../runtime/property/ImmutablePropertyTest.java | 2 +- .../runtime/query/IterableQuerySourceTest.java | 6 +- .../zest/runtime/query/NonQueryableTest.java | 4 +- .../runtime/service/AvailableServiceTest.java | 4 + .../zest/runtime/service/ConfigurationTest.java | 6 +- .../runtime/service/ServiceVisibilityTest.java | 33 +- .../structure/TypeToCompositeLookupTest.java | 26 +- .../transients/TransientVisibilityTest.java | 44 +- .../unitofwork/AutoCloseableUoWTest.java | 6 +- .../unitofwork/PrivateEntityUnitOfWorkTest.java | 51 +- .../zest/runtime/unitofwork/RemovalTest.java | 20 +- .../unitofwork/UnitOfWorkFactoryTest.java | 2 +- .../zest/runtime/value/ValueComposite2Test.java | 2 + .../ValueInjectionDeserializationTest.java | 4 +- .../zest/runtime/value/ValueVisibilityTest.java | 35 +- .../runtime/value/ValueWithAssociationTest.java | 12 +- .../visibility/VisibilityInUnitOfWorkTest.java | 55 +- .../helpers/JSONMapEntityStoreMixin.java | 2 +- .../helpers/MapEntityStoreMixin.java | 2 +- .../org/apache/zest/spi/module/ModelModule.java | 107 --- .../org/apache/zest/spi/module/ModuleSpi.java | 7 + .../apache/zest/spi/structure/ModelModule.java | 107 +++ .../apache/zest/spi/structure/TypeLookup.java | 125 +++ .../zest/test/AbstractZestScenarioTest.java | 25 +- .../org/apache/zest/test/AbstractZestTest.java | 13 +- .../zest/test/cache/AbstractCachePoolTest.java | 1 - .../test/entity/AbstractEntityStoreTest.java | 42 +- .../test/indexing/AbstractAnyQueryTest.java | 2 +- .../org/apache/zest/test/indexing/TestData.java | 15 +- .../layered/assembly/AccountModule.java | 1 + .../indexing/layered/assembly/ConfigModule.java | 1 + .../indexing/layered/assembly/FamilyModule.java | 1 + .../layered/assembly/PersistenceModule.java | 1 + .../layered/assembly/TestExecutionModule.java | 1 + .../layered/assembly/TestSuite1Module.java | 1 + .../layered/assembly/TestSuite2Module.java | 1 + .../layered/assembly/TestSuite3Module.java | 1 + ...AbstractValueCompositeSerializationTest.java | 4 +- .../prefs/PreferencesEntityStoreMixin.java | 2 +- .../entitystore/sql/SQLEntityStoreMixin.java | 2 +- .../sql/DerbySQLEntityStoreTest.java | 2 +- .../entitystore/sql/MySQLEntityStoreTest.java | 2 +- .../sql/PostgreSQLEntityStoreTest.java | 2 +- .../ElasticSearchQueryMultimoduleTest.java | 2 + .../index/elasticsearch/ElasticSearchTest.java | 4 +- .../index/elasticsearch/ImmenseTermTest.java | 6 +- .../apache/zest/index/rdf/ContainsAllTest.java | 12 +- .../org/apache/zest/index/rdf/ContainsTest.java | 12 +- .../apache/zest/index/rdf/MultiLayeredTest.java | 3 +- .../zest/index/rdf/RDFPerformanceTest.java | 16 +- .../index/rdf/RdfNamedQueryMultimoduleTest.java | 3 + .../zest/index/rdf/RdfQueryMultimoduleTest.java | 4 + .../org/apache/zest/index/rdf/RdfQueryTest.java | 2 + .../zest/index/rdf/qi173/Qi173IssueTest.java | 6 +- .../zest/index/rdf/qi64/AbstractIssueTest.java | 2 +- .../withPropagationMandatory/IssueTest.java | 8 +- .../qi64/withPropagationRequired/IssueTest.java | 10 +- .../withPropagationRequiresNew/IssueTest.java | 10 +- .../zest/index/rdf/qi66/Qi66IssueTest.java | 4 +- .../zest/index/rdf/qi95/Qi95IssueTest.java | 13 +- .../zest/index/solr/SolrQueryServiceTest.java | 4 +- .../support/skeletons/AbstractSQLQuerying.java | 8 +- .../postgresql/PostgreSQLDBIntegrityTest.java | 10 +- .../metrics/yammer/NoMetricsInstalledTest.java | 4 +- .../apache/zest/metrics/yammer/YammerTest.java | 4 +- .../apache/zest/migration/MigrationTest.java | 10 +- .../zest/index/reindexer/ReindexerTest.java | 4 +- .../zest/library/alarm/AlarmPointFactory.java | 29 +- .../apache/zest/library/alarm/AlarmProxy.java | 20 +- .../library/alarm/AlarmHistoryImplTest.java | 6 +- .../zest/library/alarm/AlarmPointImplTest.java | 6 +- .../zest/library/alarm/AlarmProxyTest.java | 2 +- .../zest/library/alarm/AlarmServiceTest.java | 6 +- .../library/alarm/ExtendedAlarmModelTest.java | 8 +- .../library/alarm/SimpleAlarmModelTest.java | 8 +- .../library/alarm/StandardAlarmModelTest.java | 8 +- .../conversion/values/ValueToEntityMixin.java | 22 +- .../conversion/values/EntityToValueTest.java | 10 +- .../values/NestedValuesConversionTest.java | 2 +- .../conversion/values/ValueToEntityTest.java | 26 +- .../source/jdbm/JdbmEventStoreServiceTest.java | 4 +- .../server/DomainEventSourceResourceSample.java | 2 +- .../application/ApplicationEventTest.java | 6 +- .../eventsourcing/domain/DomainEventTest.java | 2 +- .../source/helper/DomainEventTrackerTest.java | 2 +- .../domain/source/helper/EventRouterTest.java | 2 + .../domain/source/helper/EventsTest.java | 2 + .../source/helper/UnitOfWorkRouterTest.java | 2 + .../library/scala/HelloWorldCompositeTest.java | 6 +- .../zest/library/logging/DebuggingTest.java | 2 +- .../zest/library/logging/TracingTest.java | 8 +- .../rdf/entity/EntitySerializerTest.java | 2 +- .../rdf/entity/EntityTypeSerializerTest.java | 2 +- .../ContextResourceClientFactoryTest.java | 15 +- .../rest/client/ContinuousIntegrationTest.java | 3 +- .../rest/server/api/ContextResource.java | 24 +- .../library/rest/server/api/ContextRestlet.java | 21 +- .../requestreader/DefaultRequestReader.java | 74 +- .../library/rest/admin/RestApplication.java | 23 +- .../zest/library/rest/admin/RestTest.java | 56 +- .../zest/library/scheduler/Scheduler.java | 3 - .../library/scheduler/SchedulesHandler.java | 19 +- .../defaults/DefaultScheduleFactoryMixin.java | 16 +- .../library/scheduler/internal/Execution.java | 14 +- .../scheduler/internal/SchedulerMixin.java | 8 +- .../library/scheduler/internal/TaskRunner.java | 12 +- .../library/scheduler/CronScheduleTest.java | 2 +- .../zest/library/scheduler/SchedulerTest.java | 14 +- .../domain/passwords/PasswordRealmMixin.java | 67 +- .../library/shiro/domain/permissions/Role.java | 6 +- .../shiro/domain/permissions/RoleFactory.java | 6 +- .../zest/library/shiro/PasswordDomainTest.java | 9 +- .../library/shiro/PermissionsDomainTest.java | 9 +- .../sql/liquibase/LiquibaseServiceTest.java | 3 + .../AbstractDataSourceServiceImporterMixin.java | 12 +- .../DataSourceConfigurationManagerService.java | 7 +- ...taSourceConfigurationManagerServiceTest.java | 9 +- .../uowfile/internal/UoWFileFactory.java | 5 +- .../zest/library/uowfile/HasUoWFileTest.java | 30 +- .../zest/library/uowfile/HasUoWFilesTest.java | 29 +- .../zest/manual/recipes/assemble/Docs.java | 3 +- .../createEntity/CarEntityFactoryMixin.java | 19 +- .../bootstrap/sampledata/BaseDataService.java | 6 +- .../infrastructure/model/EntityModel.java | 4 +- .../bootstrap/test/TestApplication.java | 18 +- .../sample_a/bootstrap/test/TestAssembler.java | 175 +++-- .../shipping/booking/BookNewCargoTest.java | 20 +- .../booking/BuildDeliverySnapshotTest.java | 31 +- .../shipping/handling/InspectCargoTest.java | 11 +- .../handling/RegisterHandlingEventTest.java | 2 +- .../sample_b/bootstrap/sampledata/BaseData.java | 26 +- .../bootstrap/sampledata/BaseDataService.java | 26 +- .../bootstrap/sampledata/SampleDataService.java | 48 +- .../infrastructure/WicketZestApplication.java | 25 +- .../sample_b/infrastructure/dci/Context.java | 17 +- .../infrastructure/model/EntityModel.java | 4 +- .../infrastructure/model/JSONModel.java | 4 +- .../infrastructure/model/ReadOnlyModel.java | 11 +- .../bootstrap/test/TestApplication.java | 31 +- .../sample_b/bootstrap/test/TestAssembler.java | 18 +- .../context/test/booking/BookNewCargoTest.java | 12 +- .../booking/routing/AssignCargoToRouteTest.java | 2 +- .../routing/RegisterNewDestinationTest.java | 2 +- .../DeriveUpdatedRouteSpecTest.java | 2 +- .../event/InspectArrivedCargoTest.java | 2 +- .../event/InspectCargoInCustomsTest.java | 2 +- .../event/InspectClaimedCargoTest.java | 2 +- .../event/InspectLoadedCargoTest.java | 2 +- .../event/InspectReceivedCargoTest.java | 2 +- .../event/InspectUnhandledCargoTest.java | 2 +- .../event/InspectUnloadedCargoTest.java | 2 +- .../parsing/ParseHandlingEventDataTest.java | 4 +- .../registration/RegisterHandlingEventTest.java | 18 +- .../moneytransfer/test/TransferMoneyTest.java | 18 +- .../moneytransfer/test/TransferMoneyTest2.java | 16 +- .../sample/forum/context/EventsService.java | 15 +- .../administration/ForumAdministration.java | 13 +- .../administration/ForumsAdministration.java | 6 +- .../zest/sample/forum/context/login/Login.java | 18 +- .../sample/forum/context/view/ViewBoard.java | 10 +- .../sample/forum/context/view/ViewPost.java | 8 +- .../zest/sample/forum/data/entity/Forums.java | 12 +- .../zest/sample/forum/data/entity/Users.java | 18 +- .../sample/forum/domainevent/DomainEvent.java | 14 +- .../zest/sample/forum/rest/ForumRestlet.java | 2 +- .../sample/forum/service/BootstrapData.java | 16 +- .../org/apache/zest/sample/sqlsupport/Main.java | 8 +- .../AbstractEntityStorePerformanceTest.java | 285 +++---- .../sql/DerbySQLEntityStorePerformanceTest.java | 6 +- .../PostgreSQLEntityStorePerformanceTest.java | 2 +- .../indexing/rdf/QueryPerformanceTest.java | 29 +- .../tree/TreeModelCellRenderer.properties | 2 +- .../zest/envisage/sample/EnvisageSample.java | 6 +- .../zest/tools/model/VisitableDetailTest.java | 24 +- .../apache/zest/tutorials/hello/HelloTest4.java | 4 +- .../demo/thirtyminutes/ThirtyMinutesDocs.java | 19 +- 258 files changed, 3560 insertions(+), 2970 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/main/java/org/apache/zest/api/configuration/Configuration.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/configuration/Configuration.java b/core/api/src/main/java/org/apache/zest/api/configuration/Configuration.java index 6521c8b..9f6acc0 100644 --- a/core/api/src/main/java/org/apache/zest/api/configuration/Configuration.java +++ b/core/api/src/main/java/org/apache/zest/api/configuration/Configuration.java @@ -36,6 +36,7 @@ import org.apache.zest.api.unitofwork.EntityTypeNotFoundException; import org.apache.zest.api.unitofwork.NoSuchEntityException; import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; import org.apache.zest.api.usecase.Usecase; import org.apache.zest.api.usecase.UsecaseBuilder; import org.apache.zest.api.value.ValueSerialization; @@ -163,7 +164,7 @@ public interface Configuration private ServiceComposite me; @Structure - private Module module; + private UnitOfWorkFactory uowf; @Service private Iterable> valueSerialization; @@ -178,7 +179,7 @@ public interface Configuration if( configuration == null ) { Usecase usecase = UsecaseBuilder.newUsecase( "Configuration:" + me.identity().get() ); - uow = module.newUnitOfWork( usecase ); + uow = uowf.newUnitOfWork( usecase ); try { configuration = this.findConfigurationInstanceFor( me, uow ); @@ -253,7 +254,7 @@ public interface Configuration { Module module = api.moduleOf( serviceComposite ); Usecase usecase = UsecaseBuilder.newUsecase( "Configuration:" + me.identity().get() ); - UnitOfWork buildUow = module.newUnitOfWork( usecase ); + UnitOfWork buildUow = module.unitOfWorkFactory().newUnitOfWork( usecase ); Class type = api.serviceDescriptorFor( serviceComposite ).types().findFirst().orElse( null ); Class configType = serviceModel.configurationType(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java b/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java index 56afa2c..850f54a 100644 --- a/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java +++ b/core/api/src/main/java/org/apache/zest/api/entity/EntityBuilderTemplate.java @@ -36,7 +36,7 @@ public abstract class EntityBuilderTemplate public T newInstance( Module module ) { - EntityBuilder builder = module.currentUnitOfWork().newEntityBuilder( type ); + EntityBuilder builder = module.unitOfWorkFactory().currentUnitOfWork().newEntityBuilder( type ); build( builder.instance() ); return builder.newInstance(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/main/java/org/apache/zest/api/structure/Module.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/structure/Module.java b/core/api/src/main/java/org/apache/zest/api/structure/Module.java index e5a0aa6..38d8803 100644 --- a/core/api/src/main/java/org/apache/zest/api/structure/Module.java +++ b/core/api/src/main/java/org/apache/zest/api/structure/Module.java @@ -16,11 +16,8 @@ package org.apache.zest.api.structure; import java.util.stream.Stream; import org.apache.zest.api.activation.ActivationEventListenerRegistration; -import org.apache.zest.api.composite.Composite; import org.apache.zest.api.composite.TransientBuilderFactory; -import org.apache.zest.api.composite.TransientComposite; import org.apache.zest.api.composite.TransientDescriptor; -import org.apache.zest.api.entity.EntityComposite; import org.apache.zest.api.entity.EntityDescriptor; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.object.ObjectDescriptor; @@ -44,7 +41,6 @@ public interface Module ObjectFactory, TransientBuilderFactory, ValueBuilderFactory, - UnitOfWorkFactory, QueryBuilderFactory, ServiceFinder { @@ -61,32 +57,43 @@ public interface Module /** * @param typeName name of a transient composite type + * * @return the descriptor for a transient composite or null if the class could not be found or the transient composite is not visible */ TransientDescriptor transientDescriptor( String typeName ); /** * @param typeName name of an entity composite type + * * @return the descriptor for an entity composite or null if the class could not be found or the entity composite is not visible */ EntityDescriptor entityDescriptor( String typeName ); /** * @param typeName name of an object type + * * @return the descriptor for an object or null if the class could not be found or the object is not visible */ ObjectDescriptor objectDescriptor( String typeName ); /** * @param typeName name of a value composite type + * * @return the descriptor for a value composite or null if the class could not be found or the value composite is not visible */ ValueDescriptor valueDescriptor( String typeName ); Stream transientComposites(); + Stream valueComposites(); + Stream serviceComposites(); + Stream entityComposites(); + Stream importedServices(); + Stream objects(); + + UnitOfWorkFactory unitOfWorkFactory(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/main/java/org/apache/zest/api/type/HasTypes.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/type/HasTypes.java b/core/api/src/main/java/org/apache/zest/api/type/HasTypes.java index 0bc0a35..0c3a0ac 100644 --- a/core/api/src/main/java/org/apache/zest/api/type/HasTypes.java +++ b/core/api/src/main/java/org/apache/zest/api/type/HasTypes.java @@ -18,6 +18,7 @@ */ package org.apache.zest.api.type; +import java.lang.reflect.Type; import java.util.stream.Stream; /** @@ -26,4 +27,9 @@ import java.util.stream.Stream; public interface HasTypes { Stream> types(); + + default boolean hasType( Type type ) + { + return types().anyMatch( type::equals ); + } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/main/java/org/apache/zest/api/type/ValueType.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/type/ValueType.java b/core/api/src/main/java/org/apache/zest/api/type/ValueType.java index dc28f10..80a2a81 100644 --- a/core/api/src/main/java/org/apache/zest/api/type/ValueType.java +++ b/core/api/src/main/java/org/apache/zest/api/type/ValueType.java @@ -14,6 +14,7 @@ */ package org.apache.zest.api.type; +import java.lang.reflect.Type; import java.util.Collections; import java.util.List; import java.util.function.Function; http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWork.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWork.java b/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWork.java index d735afa..b218e6d 100644 --- a/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWork.java +++ b/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWork.java @@ -18,6 +18,7 @@ package org.apache.zest.api.unitofwork; import java.util.Map; import java.util.function.Function; import org.apache.zest.api.association.AssociationDescriptor; +import org.apache.zest.api.common.Optional; import org.apache.zest.api.composite.AmbiguousTypeException; import org.apache.zest.api.entity.EntityBuilder; import org.apache.zest.api.entity.EntityReference; @@ -147,7 +148,7 @@ public interface UnitOfWork extends MetaInfoHolder, AutoCloseable * @throws AmbiguousTypeException If several mixins implement the given type * @throws LifecycleException if the entity cannot be created */ - T newEntity( Class type, String identity ) + T newEntity( Class type, @Optional String identity ) throws EntityTypeNotFoundException, AmbiguousTypeException, LifecycleException; /** @@ -180,7 +181,7 @@ public interface UnitOfWork extends MetaInfoHolder, AutoCloseable * @throws EntityTypeNotFoundException if no EntityComposite type of the given mixin type has been registered * @throws AmbiguousTypeException If several mixins implement the given type */ - EntityBuilder newEntityBuilder( Class type, String identity ) + EntityBuilder newEntityBuilder( Class type, @Optional String identity ) throws EntityTypeNotFoundException, AmbiguousTypeException; /** @@ -229,7 +230,7 @@ public interface UnitOfWork extends MetaInfoHolder, AutoCloseable * @throws EntityTypeNotFoundException If no mixins implements the given type * @throws AmbiguousTypeException If several mixins implement the given type */ - EntityBuilder newEntityBuilderWithState( Class type, String identity, + EntityBuilder newEntityBuilderWithState( Class type, @Optional String identity, Function propertyFunction, Function associationFunction, Function> manyAssociationFunction, http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWorkTemplate.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWorkTemplate.java b/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWorkTemplate.java index cd91cb9..2d5be61 100644 --- a/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWorkTemplate.java +++ b/core/api/src/main/java/org/apache/zest/api/unitofwork/UnitOfWorkTemplate.java @@ -58,7 +58,7 @@ public abstract class UnitOfWorkTemplate[] DEFAULT_DISCARD_CLASSES = new Class[]{ Throwable.class }; @Structure - Module module; + private UnitOfWorkFactory uowf; @Invocation - UnitOfWorkPropagation propagation; + private UnitOfWorkPropagation propagation; /** * Handles method with {@code UnitOfWorkPropagation} annotation. @@ -65,7 +65,7 @@ public class UnitOfWorkConcern UnitOfWorkPropagation.Propagation propagationPolicy = propagation.value(); if( propagationPolicy == UnitOfWorkPropagation.Propagation.REQUIRED ) { - if( module.isUnitOfWorkActive() ) + if( uowf.isUnitOfWorkActive() ) { //noinspection ConstantConditions return next.invoke( proxy, method, args ); @@ -73,12 +73,12 @@ public class UnitOfWorkConcern else { Usecase usecase = usecase(); - return invokeWithCommit( proxy, method, args, module.newUnitOfWork( usecase ) ); + return invokeWithCommit( proxy, method, args, uowf.newUnitOfWork( usecase ) ); } } else if( propagationPolicy == UnitOfWorkPropagation.Propagation.MANDATORY ) { - if( !module.isUnitOfWorkActive() ) + if( !uowf.isUnitOfWorkActive() ) { throw new IllegalStateException( "UnitOfWork was required but there is no available unit of work." ); } @@ -86,7 +86,7 @@ public class UnitOfWorkConcern else if( propagationPolicy == UnitOfWorkPropagation.Propagation.REQUIRES_NEW ) { Usecase usecase = usecase(); - return invokeWithCommit( proxy, method, args, module.newUnitOfWork( usecase ) ); + return invokeWithCommit( proxy, method, args, uowf.newUnitOfWork( usecase ) ); } //noinspection ConstantConditions return next.invoke( proxy, method, args ); @@ -132,7 +132,7 @@ public class UnitOfWorkConcern currentUnitOfWork.complete(); return result; } - catch( UndeclaredThrowableException e) + catch( UndeclaredThrowableException e ) { Throwable undeclared = e.getUndeclaredThrowable(); if( undeclared instanceof ConcurrentEntityModificationException ) @@ -173,9 +173,9 @@ public class UnitOfWorkConcern { throw e; } - module.currentUnitOfWork().discard(); + uowf.currentUnitOfWork().discard(); Thread.sleep( initialDelay + retry * delayFactor ); - return module.newUnitOfWork( usecase() ); + return uowf.newUnitOfWork( usecase() ); } /** http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java b/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java index 0f917d6..2214433 100644 --- a/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java +++ b/core/api/src/test/java/org/apache/zest/api/OperatorsTest.java @@ -19,6 +19,8 @@ package org.apache.zest.api; import java.util.function.Predicate; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; +import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.junit.Assert; import org.junit.Test; import org.apache.zest.api.activation.ActivationException; @@ -58,10 +60,12 @@ public class OperatorsTest module.values( TestValue.class ); module.forMixin( TestEntity.class ).declareDefaults().foo().set( "Bar" ); module.forMixin( TestValue.class ).declareDefaults().bar().set( "Xyz" ); + new DefaultUnitOfWorkAssembler().assemble( module ); } }; - UnitOfWork uow = assembler.module().newUnitOfWork(); + UnitOfWorkFactory uowf = assembler.module().unitOfWorkFactory(); + UnitOfWork uow = uowf.newUnitOfWork(); try { @@ -70,7 +74,7 @@ public class OperatorsTest TestEntity testEntity = entityBuilder.newInstance(); uow.complete(); - uow = assembler.module().newUnitOfWork(); + uow = uowf.newUnitOfWork(); Iterable entities = Iterables.iterable( testEntity = uow.get( testEntity ) ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/test/java/org/apache/zest/api/injection/scope/StateFieldTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/injection/scope/StateFieldTest.java b/core/api/src/test/java/org/apache/zest/api/injection/scope/StateFieldTest.java index 02fc6ae..a1c80de 100644 --- a/core/api/src/test/java/org/apache/zest/api/injection/scope/StateFieldTest.java +++ b/core/api/src/test/java/org/apache/zest/api/injection/scope/StateFieldTest.java @@ -46,7 +46,7 @@ public class StateFieldTest public void givenEntityWithFieldPropertiesWhenUpdatedThenReturnCorrect() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); try { PersonEntity charles = unitOfWork.newEntity( PersonEntity.class ); @@ -67,7 +67,7 @@ public class StateFieldTest unitOfWork.complete(); - unitOfWork = module.newUnitOfWork(); + unitOfWork = uowf.newUnitOfWork(); charles = unitOfWork.get( charles ); daniel = unitOfWork.get( daniel ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/test/java/org/apache/zest/api/property/PropertyErrorTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/property/PropertyErrorTest.java b/core/api/src/test/java/org/apache/zest/api/property/PropertyErrorTest.java index 22488fa..b4969a1 100644 --- a/core/api/src/test/java/org/apache/zest/api/property/PropertyErrorTest.java +++ b/core/api/src/test/java/org/apache/zest/api/property/PropertyErrorTest.java @@ -40,7 +40,7 @@ public class PropertyErrorTest public void givenEntityWithNonOptionPropertyWhenInstantiatedThenException() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); try { PersonEntity person = unitOfWork.newEntity( PersonEntity.class ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/test/java/org/apache/zest/api/unitofwork/RemovalTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/unitofwork/RemovalTest.java b/core/api/src/test/java/org/apache/zest/api/unitofwork/RemovalTest.java index 9f80c4f..745cfb2 100644 --- a/core/api/src/test/java/org/apache/zest/api/unitofwork/RemovalTest.java +++ b/core/api/src/test/java/org/apache/zest/api/unitofwork/RemovalTest.java @@ -43,7 +43,7 @@ public class RemovalTest public void givenEntityIsCreatedAndUnitOfWorkIsNotCompletedWhenEntityIsRemoveThenSuccessfulRemoval() throws Exception { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { EntityBuilder builder = uow.newEntityBuilder( TestEntity.class, "123" ); @@ -62,7 +62,7 @@ public class RemovalTest public void givenStandardPidRegulatorWhenNoChangeInInputExpectOutputToGoTowardsMinimum() throws Exception { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); PidRegulator regulator = null; try { http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/test/java/org/apache/zest/api/value/DocumentationSupport.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/value/DocumentationSupport.java b/core/api/src/test/java/org/apache/zest/api/value/DocumentationSupport.java index 43acbc2..e85e2fc 100644 --- a/core/api/src/test/java/org/apache/zest/api/value/DocumentationSupport.java +++ b/core/api/src/test/java/org/apache/zest/api/value/DocumentationSupport.java @@ -28,25 +28,23 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.Function; -import org.junit.Before; -import org.junit.Test; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.property.Property; import org.apache.zest.api.structure.Application; import org.apache.zest.api.structure.Module; import org.apache.zest.api.type.CollectionType; -import org.apache.zest.bootstrap.ApplicationAssembler; -import org.apache.zest.bootstrap.ApplicationAssembly; -import org.apache.zest.bootstrap.ApplicationAssemblyFactory; import org.apache.zest.bootstrap.Assembler; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.Energy4Java; import org.apache.zest.bootstrap.ModuleAssembly; +import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.apache.zest.io.Inputs; import org.apache.zest.io.Outputs; import org.apache.zest.io.Transforms; import org.apache.zest.test.AbstractZestTest; import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationAssembler; +import org.junit.Before; +import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -82,6 +80,7 @@ public class DocumentationSupport module.values( SomeValue.class ); // (2) // END SNIPPET: default new OrgJsonValueSerializationAssembler().assemble( module ); // (3) + new DefaultUnitOfWorkAssembler().assemble( module ); // START SNIPPET: default } // END SNIPPET: default @@ -101,6 +100,7 @@ public class DocumentationSupport // START SNIPPET: default } + // END SNIPPET: default // START SNIPPET: service @Service @@ -217,56 +217,39 @@ public class DocumentationSupport public void assembledWithValuesModuleSerialization() throws Exception { - Application app = new Energy4Java().newApplication( new ApplicationAssembler() - { - @Override - public ApplicationAssembly assemble( ApplicationAssemblyFactory applicationFactory ) - throws AssemblyException - { - Assembler[][][] pancakes = new Assembler[][][] + Application app = new Energy4Java().newApplication( applicationFactory -> { + Assembler[][][] pancakes = new Assembler[][][] { { { - new Assembler() - { - @Override - public void assemble( ModuleAssembly valuesModule ) - throws AssemblyException - { - valuesModule.layer().setName( "SINGLE-Layer" ); - valuesModule.setName( "VALUES-Module" ); + valuesModule -> { + valuesModule.layer().setName( "SINGLE-Layer" ); + valuesModule.setName( "VALUES-Module" ); - valuesModule.values( SomeValue.class ); - } + valuesModule.values( SomeValue.class ); + new DefaultUnitOfWorkAssembler().assemble( valuesModule ); } }, { - new Assembler() - { - @Override - public void assemble( ModuleAssembly servicesModule ) - throws AssemblyException - { - servicesModule.setName( "SERVICES-Module" ); + servicesModule -> { + servicesModule.setName( "SERVICES-Module" ); - Function valuesModuleFinder = new Function() + Function valuesModuleFinder = new Function() + { + @Override + public Module apply( Application app1 ) { - @Override - public Module apply( Application app ) - { - return app.findModule( "SINGLE-Layer", "VALUES-Module" ); - } - }; - new OrgJsonValueSerializationAssembler(). - withValuesModuleFinder( valuesModuleFinder ). - assemble( servicesModule ); - } + return app1.findModule( "SINGLE-Layer", "VALUES-Module" ); + } + }; + new OrgJsonValueSerializationAssembler(). + withValuesModuleFinder( valuesModuleFinder ). + assemble( servicesModule ); } } } }; - return applicationFactory.newApplicationAssembly( pancakes ); - } + return applicationFactory.newApplicationAssembly( pancakes ); } ); app.activate(); try http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/api/src/test/java/org/apache/zest/api/value/ValueCompositeTest.java ---------------------------------------------------------------------- diff --git a/core/api/src/test/java/org/apache/zest/api/value/ValueCompositeTest.java b/core/api/src/test/java/org/apache/zest/api/value/ValueCompositeTest.java index 89f75df..b5499c4 100644 --- a/core/api/src/test/java/org/apache/zest/api/value/ValueCompositeTest.java +++ b/core/api/src/test/java/org/apache/zest/api/value/ValueCompositeTest.java @@ -184,7 +184,7 @@ public class ValueCompositeTest builder.prototype().number().set( 42L ); SomeValue some = builder.newInstance(); - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); try { EntityBuilder entityBuilder = unitOfWork.newEntityBuilder( SomeEntity.class ); @@ -213,7 +213,7 @@ public class ValueCompositeTest builder.prototype().number().set( 42L ); SomeValue some = builder.newInstance(); - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); AssociationValue associationValue; try { @@ -229,7 +229,7 @@ public class ValueCompositeTest unitOfWork.complete(); - unitOfWork = module.newUnitOfWork(); + unitOfWork = uowf.newUnitOfWork(); AssociationValue newAssociationValue = module.newValueFromSerializedState( AssociationValue.class, json ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ModuleAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ModuleAssembly.java b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ModuleAssembly.java index f99c506..bdd8828 100644 --- a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ModuleAssembly.java +++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ModuleAssembly.java @@ -23,6 +23,7 @@ import java.util.function.Predicate; import org.apache.zest.api.activation.Activator; import org.apache.zest.api.structure.Module; import org.apache.zest.api.type.HasTypes; +import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; /** * The ModuleAssembly is used to register any information about * what the module should contain, such as composites, @@ -77,10 +78,42 @@ public interface ModuleAssembly * * @return the assembly */ - @SuppressWarnings({ "unchecked", "varargs" }) + @SuppressWarnings( { "unchecked", "varargs" } ) ModuleAssembly withActivators( Class>... activators ); /** + * Adds the default UnitOfWorkFactory to this Module. + *

+ * In versions <3.0, UnitOfWork was built into the Core Runtime, and couldn't be custom made. In 3.0, the + * UnitOfWorkFactory is a regular Service that the Module instance will look up on demand. + *

+ *

+ * Typically, this method should be called, and it should be called first in the Assembler, so that + * it is possible to add Concerns and SideEffects to the default implementation of either the + * {@link org.apache.zest.api.unitofwork.UnitOfWorkFactory} or the + * {@link org.apache.zest.api.unitofwork.UnitOfWork}. + *

+ *

+ * Internally, this method is the equivalent of; + *

+ *

+     *     new DefaultUnitOfWorkAssembler().assemble( module );
+     * 
+     * 
+ *

+ * and the {@link DefaultUnitOfWorkAssembler} does the equivalent of + *

+ *

+     *     module.services( UnitOfWorkFactory.class ).withMixins( UnitOfWorkFactoryMixin.class );
+     *     module.transients( UnitOfWork.class ).withMixins( ModuleUnitOfWork.class );
+     * 
+ * albeit those Mixins are in the Core Runtime and since Core Runtime is not a direct dependency of any + * other module, the classes are loaded with reflection. This may change in the future. + */ + ModuleAssembly withDefaultUnitOfWorkFactory() + throws AssemblyException; + + /** * Declare a list of TransientComposites for this Module. Use the TransientDeclaration that is returned to * declare further settings. Note that the TransientDeclaration works on all of the types specified. * @@ -160,7 +193,6 @@ public interface ModuleAssembly */ ConfigurationDeclaration configurations( Predicate specification ); - /** * Declare a list of object classes for this Module. Use the ObjectDeclaration that is returned to * declare further settings. Note that the ObjectDeclaration works on all of the types specified. http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java new file mode 100644 index 0000000..14171cd --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java @@ -0,0 +1,55 @@ +/* + * 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.zest.bootstrap.unitofwork; + +import org.apache.zest.api.unitofwork.UnitOfWork; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; +import org.apache.zest.bootstrap.Assembler; +import org.apache.zest.bootstrap.AssemblyException; +import org.apache.zest.bootstrap.ModuleAssembly; + +public class DefaultUnitOfWorkAssembler + implements Assembler +{ + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + Class factoryMixin = loadMixinClass( "org.apache.zest.runtime.unitofwork.UnitOfWorkFactoryMixin" ); + module.services( UnitOfWorkFactory.class ).withMixins( factoryMixin ); + + Class uowMixin = loadMixinClass( "org.apache.zest.runtime.unitofwork.ModuleUnitOfWork" ); + module.transients( UnitOfWork.class ).withMixins( uowMixin ); + } + + private Class loadMixinClass( String name ) + throws AssemblyException + { + try + { + return getClass().getClassLoader().loadClass( name ); + } + catch( ClassNotFoundException e ) + { + throw new AssemblyException( "Default UnitOfWorkFactory mixin is not present in the system." ); + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/bootstrap/src/test/java/org/apache/zest/bootstrap/ClassScannerTest.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/ClassScannerTest.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/ClassScannerTest.java index fc7147b..90b6d5a 100644 --- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/ClassScannerTest.java +++ b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/ClassScannerTest.java @@ -18,6 +18,7 @@ */ package org.apache.zest.bootstrap; +import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.junit.Assert; import org.junit.Test; import org.apache.zest.api.activation.ActivationException; @@ -48,6 +49,7 @@ public class ClassScannerTest for( Class aClass : filter( matches( ".*Value" ), findClasses( TestValue.class ) ) ) { module.values( aClass ); + new DefaultUnitOfWorkAssembler().assemble( module ); } } }; http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java index ac931fa..ce9a239 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java @@ -62,7 +62,7 @@ import org.apache.zest.runtime.property.PropertyInstance; import org.apache.zest.runtime.service.ImportedServiceReferenceInstance; import org.apache.zest.runtime.service.ServiceInstance; import org.apache.zest.runtime.service.ServiceReferenceInstance; -import org.apache.zest.runtime.structure.ModuleUnitOfWork; +import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork; import org.apache.zest.runtime.value.ValueInstance; import org.apache.zest.spi.ZestSPI; import org.apache.zest.spi.entity.EntityState; http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationModel.java index 57c6790..cdc3198 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationModel.java @@ -44,13 +44,10 @@ import org.apache.zest.functional.Visitor; import org.apache.zest.runtime.composite.ValueConstraintsInstance; import org.apache.zest.runtime.model.Binder; import org.apache.zest.runtime.model.Resolution; -import org.apache.zest.runtime.structure.ModuleUnitOfWork; +import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork; import org.apache.zest.runtime.unitofwork.BuilderEntityState; import org.apache.zest.spi.entity.EntityState; -import static org.apache.zest.functional.Iterables.empty; -import static org.apache.zest.functional.Iterables.first; - /** * Model for a ManyAssociation. * http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationsModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationsModel.java index 11d188d..0df3b35 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationsModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/association/ManyAssociationsModel.java @@ -27,7 +27,7 @@ import org.apache.zest.api.association.ManyAssociation; import org.apache.zest.api.common.QualifiedName; import org.apache.zest.functional.HierarchicalVisitor; import org.apache.zest.functional.VisitableHierarchy; -import org.apache.zest.runtime.structure.ModuleUnitOfWork; +import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork; import org.apache.zest.runtime.value.ValueStateInstance; import org.apache.zest.spi.entity.EntityState; http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationModel.java index 0b0f340..a930f48 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationModel.java @@ -45,13 +45,10 @@ import org.apache.zest.functional.Visitor; import org.apache.zest.runtime.composite.ValueConstraintsInstance; import org.apache.zest.runtime.model.Binder; import org.apache.zest.runtime.model.Resolution; -import org.apache.zest.runtime.structure.ModuleUnitOfWork; +import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork; import org.apache.zest.runtime.unitofwork.BuilderEntityState; import org.apache.zest.spi.entity.EntityState; -import static org.apache.zest.functional.Iterables.empty; -import static org.apache.zest.functional.Iterables.first; - /** * Model for a NamedAssociation. * http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationsModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationsModel.java index ad536d1..6c1783b 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationsModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/association/NamedAssociationsModel.java @@ -28,7 +28,7 @@ import org.apache.zest.api.association.NamedAssociation; import org.apache.zest.api.common.QualifiedName; import org.apache.zest.functional.HierarchicalVisitor; import org.apache.zest.functional.VisitableHierarchy; -import org.apache.zest.runtime.structure.ModuleUnitOfWork; +import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork; import org.apache.zest.runtime.value.ValueStateInstance; import org.apache.zest.spi.entity.EntityState; http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java index 9190d67f..c7308f7 100755 --- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/CompositeAssemblyImpl.java @@ -18,9 +18,31 @@ */ package org.apache.zest.runtime.bootstrap; +import java.lang.annotation.Annotation; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Proxy; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; import java.util.function.Function; -import org.apache.zest.api.common.*; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.zest.api.common.MetaInfo; import org.apache.zest.api.common.Optional; +import org.apache.zest.api.common.QualifiedName; +import org.apache.zest.api.common.UseDefaults; +import org.apache.zest.api.common.Visibility; import org.apache.zest.api.composite.InvalidCompositeException; import org.apache.zest.api.concern.Concerns; import org.apache.zest.api.constraint.Constraint; @@ -42,24 +64,40 @@ import org.apache.zest.api.util.Classes; import org.apache.zest.api.util.Fields; import org.apache.zest.bootstrap.StateDeclarations; import org.apache.zest.functional.HierarchicalVisitorAdapter; -import org.apache.zest.runtime.composite.*; +import org.apache.zest.runtime.composite.AbstractConstraintModel; +import org.apache.zest.runtime.composite.CompositeConstraintModel; +import org.apache.zest.runtime.composite.CompositeMethodModel; +import org.apache.zest.runtime.composite.CompositeMethodsModel; +import org.apache.zest.runtime.composite.ConcernModel; +import org.apache.zest.runtime.composite.ConcernsModel; +import org.apache.zest.runtime.composite.ConstraintModel; +import org.apache.zest.runtime.composite.ConstraintsModel; +import org.apache.zest.runtime.composite.Genericpredicate; +import org.apache.zest.runtime.composite.MixinModel; +import org.apache.zest.runtime.composite.MixinsModel; +import org.apache.zest.runtime.composite.SideEffectModel; +import org.apache.zest.runtime.composite.SideEffectsModel; +import org.apache.zest.runtime.composite.StateModel; +import org.apache.zest.runtime.composite.ValueConstraintsInstance; +import org.apache.zest.runtime.composite.ValueConstraintsModel; import org.apache.zest.runtime.injection.Dependencies; import org.apache.zest.runtime.injection.DependencyModel; import org.apache.zest.runtime.property.PropertiesModel; import org.apache.zest.runtime.property.PropertyModel; -import java.lang.annotation.Annotation; -import java.lang.reflect.*; -import java.util.*; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - import static java.util.stream.Stream.concat; -import static org.apache.zest.api.util.Annotations.*; -import static org.apache.zest.api.util.Classes.*; -import static org.apache.zest.functional.Iterables.*; +import static org.apache.zest.api.util.Annotations.hasAnnotation; +import static org.apache.zest.api.util.Annotations.isType; +import static org.apache.zest.api.util.Annotations.type; +import static org.apache.zest.api.util.Classes.classHierarchy; +import static org.apache.zest.api.util.Classes.interfacesOf; +import static org.apache.zest.api.util.Classes.isAssignableFrom; +import static org.apache.zest.api.util.Classes.typeOf; +import static org.apache.zest.api.util.Classes.typesOf; +import static org.apache.zest.api.util.Classes.wrapperClass; +import static org.apache.zest.functional.Iterables.filter; +import static org.apache.zest.functional.Iterables.first; +import static org.apache.zest.functional.Iterables.iterable; import static org.apache.zest.runtime.legacy.Specifications.translate; /** @@ -211,8 +249,9 @@ public abstract class CompositeAssemblyImpl interfacesOf( mixinModel.mixinClass() ) .map( Classes.RAW_CLASS ) - .filter( clazz -> Stream.of( Initializable.class, Lifecycle.class, InvocationHandler.class ).noneMatch( c -> c - .equals( clazz ) ) ) + .filter( clazz -> Stream.of( Initializable.class, Lifecycle.class, InvocationHandler.class ) + .noneMatch( c -> c + .equals( clazz ) ) ) .forEach( thisDependencies::add ); // // Implement @This references @@ -220,7 +259,6 @@ public abstract class CompositeAssemblyImpl // filter( new DependencyModel.ScopeSpecification( This.class ), // methodComposite.dependencies() ) ); - // Iterable> map1 = map( new DependencyModel.InjectionTypeFunction(), // filter( new DependencyModel.ScopeSpecification( This.class ), // mixinModel.dependencies() ) ); @@ -257,10 +295,10 @@ public abstract class CompositeAssemblyImpl mixinDeclarations( thisDependency ) ); List> singleton = Collections.singletonList( thisDependency ); implementMixinType( singleton, - toList(typeConstraintClasses), - toList(typeConcernClasses), - toList(typeSideEffectClasses), - toList(typeMixinClasses) + toList( typeConstraintClasses ), + toList( typeConcernClasses ), + toList( typeSideEffectClasses ), + toList( typeMixinClasses ) ); } ); } @@ -393,15 +431,15 @@ public abstract class CompositeAssemblyImpl List> constraintClasses ) { - List annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor); - boolean optional = annotations.stream().anyMatch(isType(Optional.class)); + List annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor ); + boolean optional = annotations.stream().anyMatch( isType( Optional.class ) ); ValueConstraintsModel valueConstraintsModel = constraintsFor( - annotations.stream(), - GenericPropertyInfo.propertyTypeOf(accessor), - ((Member) accessor).getName(), - optional, - constraintClasses, - accessor); + annotations.stream(), + GenericPropertyInfo.propertyTypeOf( accessor ), + ( (Member) accessor ).getName(), + optional, + constraintClasses, + accessor ); ValueConstraintsInstance valueConstraintsInstance = null; if( valueConstraintsModel.isConstrained() ) { @@ -552,7 +590,7 @@ public abstract class CompositeAssemblyImpl concernClasses.forEach( concern -> { if( helper.appliesTo( concern, method, types, mixinClass ) ) { - concernsFor.add( helper.getConcernModel( concern ) ); + addConcernIfNotExists( concernsFor, helper.getConcernModel( concern ) ); } else { @@ -564,7 +602,7 @@ public abstract class CompositeAssemblyImpl Method mixinMethod = mixinClass.getMethod( method.getName(), method.getParameterTypes() ); if( helper.appliesTo( concern, mixinMethod, types, mixinClass ) ) { - concernsFor.add( helper.getConcernModel( concern ) ); + addConcernIfNotExists( concernsFor, helper.getConcernModel( concern ) ); } } catch( NoSuchMethodException e ) @@ -586,7 +624,8 @@ public abstract class CompositeAssemblyImpl { if( helper.appliesTo( concern, method, types, mixinClass ) ) { - concernsFor.add( helper.getConcernModel( concern ) ); + ConcernModel concernModel = helper.getConcernModel( concern ); + addConcernIfNotExists( concernsFor, concernModel ); } } } @@ -602,6 +641,14 @@ public abstract class CompositeAssemblyImpl } } + private void addConcernIfNotExists( List concernsFor, ConcernModel concernModel ) + { + if( !concernsFor.contains( concernModel ) ) + { + concernsFor.add( concernModel ); + } + } + private SideEffectsModel sideEffectsFor( Method method, Class mixinClass, Stream> sideEffectClasses @@ -609,9 +656,10 @@ public abstract class CompositeAssemblyImpl { List sideEffectsFor = new ArrayList<>(); sideEffectClasses.forEach( sideEffect -> { + SideEffectModel sideEffectModel = helper.getSideEffectModel( sideEffect ); if( helper.appliesTo( sideEffect, method, types, mixinClass ) ) { - sideEffectsFor.add( helper.getSideEffectModel( sideEffect ) ); + addSideEffectIfNotExists( sideEffectsFor, sideEffectModel ); } else { @@ -623,7 +671,7 @@ public abstract class CompositeAssemblyImpl Method mixinMethod = mixinClass.getMethod( method.getName(), method.getParameterTypes() ); if( helper.appliesTo( sideEffect, mixinMethod, types, mixinClass ) ) { - sideEffectsFor.add( helper.getSideEffectModel( sideEffect ) ); + addSideEffectIfNotExists( sideEffectsFor, sideEffectModel ); } } catch( NoSuchMethodException e ) @@ -634,6 +682,25 @@ public abstract class CompositeAssemblyImpl } } ); + // Check annotations on method that have @Concerns annotations themselves + for( Annotation annotation : method.getAnnotations() ) + { + @SuppressWarnings( "raw" ) + SideEffects sideEffects = annotation.annotationType().getAnnotation( SideEffects.class ); + if( sideEffects != null ) + { + for( Class sideEffect : sideEffects.value() ) + { + if( helper.appliesTo( sideEffect, method, types, mixinClass ) ) + { + SideEffectModel sideEffectModel = helper.getSideEffectModel( sideEffect ); + addSideEffectIfNotExists( sideEffectsFor, sideEffectModel ); + } + } + } + } + + if( sideEffectsFor.isEmpty() ) { return SideEffectsModel.EMPTY_SIDEEFFECTS; @@ -644,6 +711,14 @@ public abstract class CompositeAssemblyImpl } } + private void addSideEffectIfNotExists( List sideEffectsFor, SideEffectModel sideEffectModel ) + { + if( !sideEffectsFor.contains( sideEffectModel ) ) + { + sideEffectsFor.add( sideEffectModel ); + } + } + @SuppressWarnings( "unchecked" ) private Stream> constraintDeclarations( Class type ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java index b1d60d6..c06a811 100755 --- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java @@ -57,6 +57,7 @@ import org.apache.zest.bootstrap.TransientAssembly; import org.apache.zest.bootstrap.TransientDeclaration; import org.apache.zest.bootstrap.ValueAssembly; import org.apache.zest.bootstrap.ValueDeclaration; +import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.apache.zest.functional.Iterables; import org.apache.zest.runtime.activation.ActivatorsModel; import org.apache.zest.runtime.composite.TransientModel; @@ -145,6 +146,14 @@ public final class ModuleAssemblyImpl } @Override + public ModuleAssembly withDefaultUnitOfWorkFactory() + throws AssemblyException + { + new DefaultUnitOfWorkAssembler().assemble( this ); + return this; + } + + @Override @SuppressWarnings( { "raw", "unchecked" } ) public ValueDeclaration values( Class... valueTypes ) { @@ -603,7 +612,8 @@ public final class ModuleAssemblyImpl private String generateId( Stream> serviceTypes ) { // Find service identity that is not yet used - Class serviceType = serviceTypes.findFirst().orElse( null ); // Use the first, which *SHOULD* be the main serviceType + Class serviceType = serviceTypes.findFirst() + .orElse( null ); // Use the first, which *SHOULD* be the main serviceType int idx = 0; String id = serviceType.getSimpleName(); boolean invalid; http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java index e7f477e..7bd02ef 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeModel.java @@ -145,8 +145,8 @@ public abstract class CompositeModel @Override public Stream dependencies() { - return Stream.of( mixinsModel, compositeMethodsModel ).flatMap( Dependencies::dependencies ); -// return Iterables.flatten( mixinsModel.dependencies(), compositeMethodsModel.dependencies() ); + Stream models = Stream.of( this.mixinsModel, compositeMethodsModel ); + return models.flatMap( Dependencies::dependencies ); } @Override @@ -219,7 +219,6 @@ public abstract class CompositeModel Class mainType = first( types ); if( mainType.isInterface() ) { - try { return Composite.class.cast( proxyConstructor.newInstance( invocationHandler ) ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java index 78be044..2b0570c 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientBuilderInstance.java @@ -19,7 +19,7 @@ import org.apache.zest.api.composite.CompositeInstance; import org.apache.zest.api.composite.TransientBuilder; import org.apache.zest.api.composite.TransientDescriptor; import org.apache.zest.runtime.property.PropertyInstance; -import org.apache.zest.spi.module.ModelModule; +import org.apache.zest.spi.structure.ModelModule; import org.apache.zest.spi.module.ModuleSpi; /** http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java index 384f4fc..53f0a6b 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/TransientClassLoader.java @@ -19,6 +19,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; +import org.apache.zest.api.composite.Composite; import org.apache.zest.api.entity.Lifecycle; import org.apache.zest.api.mixin.Initializable; import org.apache.zest.api.util.Methods; @@ -160,7 +161,7 @@ import static org.objectweb.asm.Type.getInternalName; AnnotationVisitor av0; // Class definition start - cw.visit( JDK_VERSION, ACC_PUBLIC + ACC_SUPER, classSlash, null, baseClassSlash, null ); + cw.visit( JDK_VERSION, ACC_PUBLIC + ACC_SUPER, classSlash, null, baseClassSlash, new String[] { "org/apache/zest/api/composite/Composite" } ); // Composite reference { http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java index 3f55ba5..15c8524 100755 --- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityInstance.java @@ -35,7 +35,6 @@ import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkException; import org.apache.zest.runtime.composite.CompositeMethodInstance; import org.apache.zest.runtime.composite.MixinsInstance; -import org.apache.zest.runtime.structure.ModuleUnitOfWork; import org.apache.zest.spi.entity.EntityState; import org.apache.zest.spi.entity.EntityStatus; import org.apache.zest.spi.module.ModuleSpi; @@ -54,7 +53,7 @@ public final class EntityInstance } private final EntityComposite proxy; - private final ModuleUnitOfWork uow; + private final UnitOfWork uow; private final ModuleSpi moduleInstance; private final EntityModel entityModel; private final EntityReference identity; @@ -63,7 +62,7 @@ public final class EntityInstance private Object[] mixins; private EntityStateInstance state; - public EntityInstance( ModuleUnitOfWork uow, + public EntityInstance( UnitOfWork uow, ModuleSpi moduleInstance, EntityModel entityModel, EntityState entityState http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java index 42b33b6..bac3936 100755 --- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityModel.java @@ -31,7 +31,7 @@ import org.apache.zest.api.unitofwork.EntityCompositeAlreadyExistsException; import org.apache.zest.api.util.Annotations; import org.apache.zest.runtime.composite.CompositeMethodsModel; import org.apache.zest.runtime.composite.CompositeModel; -import org.apache.zest.runtime.structure.ModuleUnitOfWork; +import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork; import org.apache.zest.spi.entity.EntityState; import org.apache.zest.spi.entitystore.EntityAlreadyExistsException; import org.apache.zest.spi.entitystore.EntityStoreException; http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java index 0028c5a..c0a5cba 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/entity/EntityStateInstance.java @@ -62,14 +62,7 @@ public final class EntityStateInstance this.stateModel = stateModel; this.entityState = entityState; - entityFunction = new BiFunction() - { - @Override - public Object apply( EntityReference entityReference, Type type ) - { - return uow.get( Classes.RAW_CLASS.apply( type ), entityReference.identity() ); - } - }; + entityFunction = ( entityReference, type ) -> uow.get( Classes.RAW_CLASS.apply( type ), entityReference.identity() ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java index 18126eb..ba9ac8d 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/InjectedFieldsModel.java @@ -57,23 +57,24 @@ public final class InjectedFieldsModel Type genericType = field.getGenericType(); if( genericType instanceof ParameterizedType ) { - genericType = new ParameterizedTypeInstance( ( (ParameterizedType) genericType ).getActualTypeArguments(), ( (ParameterizedType) genericType ) - .getRawType(), ( (ParameterizedType) genericType ).getOwnerType() ); + Type[] actualTypeArguments = ( (ParameterizedType) genericType ).getActualTypeArguments(); + Type rawType = ( (ParameterizedType) genericType ).getRawType(); + Type ownerType = ( (ParameterizedType) genericType ).getOwnerType(); + genericType = new ParameterizedTypeInstance( actualTypeArguments, rawType, ownerType ); - for( int i = 0; i < ( (ParameterizedType) genericType ).getActualTypeArguments().length; i++ ) + for( int i = 0; i < actualTypeArguments.length; i++ ) { - Type type = ( (ParameterizedType) genericType ).getActualTypeArguments()[ i ]; + Type type = actualTypeArguments[ i ]; if( type instanceof TypeVariable ) { type = Classes.resolveTypeVariable( (TypeVariable) type, field.getDeclaringClass(), fragmentClass ); - ( (ParameterizedType) genericType ).getActualTypeArguments()[ i ] = type; + actualTypeArguments[ i ] = type; } } } boolean optional = DependencyModel.isOptional( injectionAnnotation, field.getAnnotations() ); - DependencyModel dependencyModel = new DependencyModel( injectionAnnotation, genericType, fragmentClass, optional, field - .getAnnotations() ); + DependencyModel dependencyModel = new DependencyModel( injectionAnnotation, genericType, fragmentClass, optional, field.getAnnotations() ); InjectedFieldModel injectedFieldModel = new InjectedFieldModel( field, dependencyModel ); this.fields.add( injectedFieldModel ); } @@ -82,14 +83,6 @@ public final class InjectedFieldsModel public Stream dependencies() { return fields.stream().flatMap( Dependencies::dependencies ); -// return Iterables.map( new Function() -// { -// @Override -// public DependencyModel apply( InjectedFieldModel injectedFieldModel ) -// { -// return injectedFieldModel.dependency(); -// } -// }, fields ); } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java index ad05b64..1fbb3a3 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/injection/provider/StructureInjectionProviderFactory.java @@ -81,7 +81,7 @@ public final class StructureInjectionProviderFactory } else if( clazz.equals( UnitOfWorkFactory.class ) ) { - return context.module(); + return context.module().unitOfWorkFactory(); } else if( clazz.equals( QueryBuilderFactory.class ) ) { http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java index 2fbfb32..4635d42 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/service/ServicesModel.java @@ -68,4 +68,16 @@ public class ServicesModel { return serviceModels.stream(); } + + public boolean contains( Class type ) + { + for( ServiceModel model : serviceModels ) + { + if( model.hasType( type ) ) + { + return true; + } + } + return false; + } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/structure/LayerInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/structure/LayerInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/structure/LayerInstance.java index 338f8cf..dec81c1 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/structure/LayerInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/structure/LayerInstance.java @@ -21,7 +21,6 @@ import org.apache.zest.api.activation.ActivationEventListener; import org.apache.zest.api.activation.ActivationException; import org.apache.zest.api.activation.PassivationException; import org.apache.zest.api.common.Visibility; -import org.apache.zest.api.composite.ModelDescriptor; import org.apache.zest.api.composite.TransientDescriptor; import org.apache.zest.api.entity.EntityDescriptor; import org.apache.zest.api.object.ObjectDescriptor; @@ -30,7 +29,7 @@ import org.apache.zest.api.structure.Layer; import org.apache.zest.api.structure.Module; import org.apache.zest.api.value.ValueDescriptor; import org.apache.zest.runtime.activation.ActivationDelegate; -import org.apache.zest.spi.module.ModelModule; +import org.apache.zest.spi.structure.ModelModule; /** * Instance of a Zest application layer. Contains a list of modules which are managed by this layer.