http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/ModuleUnitOfWork.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/ModuleUnitOfWork.java b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/ModuleUnitOfWork.java new file mode 100755 index 0000000..118510f --- /dev/null +++ b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/ModuleUnitOfWork.java @@ -0,0 +1,777 @@ +/* + * 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.runtime.unitofwork; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Predicate; +import org.apache.zest.api.association.AssociationDescriptor; +import org.apache.zest.api.association.AssociationStateHolder; +import org.apache.zest.api.common.QualifiedName; +import org.apache.zest.api.composite.Composite; +import org.apache.zest.api.entity.EntityBuilder; +import org.apache.zest.api.entity.EntityComposite; +import org.apache.zest.api.entity.EntityDescriptor; +import org.apache.zest.api.entity.EntityReference; +import org.apache.zest.api.entity.Identity; +import org.apache.zest.api.entity.IdentityGenerator; +import org.apache.zest.api.entity.LifecycleException; +import org.apache.zest.api.injection.scope.Service; +import org.apache.zest.api.injection.scope.Structure; +import org.apache.zest.api.injection.scope.Uses; +import org.apache.zest.api.property.Property; +import org.apache.zest.api.property.PropertyDescriptor; +import org.apache.zest.api.property.StateHolder; +import org.apache.zest.api.query.Query; +import org.apache.zest.api.query.QueryBuilder; +import org.apache.zest.api.query.QueryExecutionException; +import org.apache.zest.api.query.grammar.OrderBy; +import org.apache.zest.api.service.NoSuchServiceException; +import org.apache.zest.api.structure.Module; +import org.apache.zest.api.unitofwork.ConcurrentEntityModificationException; +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.UnitOfWorkCallback; +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.util.NullArgumentException; +import org.apache.zest.api.value.ValueBuilder; +import org.apache.zest.api.value.ValueComposite; +import org.apache.zest.functional.Iterables; +import org.apache.zest.runtime.association.AssociationInstance; +import org.apache.zest.runtime.association.ManyAssociationInstance; +import org.apache.zest.runtime.association.NamedAssociationInstance; +import org.apache.zest.runtime.composite.FunctionStateResolver; +import org.apache.zest.runtime.entity.EntityInstance; +import org.apache.zest.runtime.entity.EntityModel; +import org.apache.zest.runtime.property.PropertyModel; +import org.apache.zest.runtime.value.ValueInstance; +import org.apache.zest.spi.entity.EntityState; +import org.apache.zest.spi.entity.EntityStatus; +import org.apache.zest.spi.entity.NamedAssociationState; +import org.apache.zest.spi.entitystore.EntityStore; +import org.apache.zest.spi.structure.ModelModule; +import org.apache.zest.spi.module.ModuleSpi; +import org.apache.zest.spi.query.EntityFinder; +import org.apache.zest.spi.query.EntityFinderException; +import org.apache.zest.spi.query.QueryBuilderSPI; +import org.apache.zest.spi.query.QuerySource; + +import static org.apache.zest.api.entity.EntityReference.parseEntityReference; + +/** + * JAVADOC + */ +public class ModuleUnitOfWork + implements UnitOfWork +{ + private static final QualifiedName IDENTITY_STATE_NAME; + + static + { + try + { + IDENTITY_STATE_NAME = QualifiedName.fromAccessor( Identity.class.getMethod( "identity" ) ); + } + catch( NoSuchMethodException e ) + { + throw new InternalError( "Zest Core Runtime codebase is corrupted. Contact Zest team: ModuleUnitOfWork" ); + } + } + + @Uses + private UnitOfWorkInstance uow; + + @Structure + private ModuleSpi module; + + @Service + private UnitOfWorkFactory unitOfWorkFactory; + + public Module module() + { + return module; + } + + public UnitOfWorkInstance instance() + { + return uow; + } + + @Override + public UnitOfWorkFactory unitOfWorkFactory() + { + return unitOfWorkFactory; + } + + @Override + public long currentTime() + { + return uow.currentTime(); + } + + @Override + public Usecase usecase() + { + return uow.usecase(); + } + + @Override + public <T> T metaInfo( Class<T> infoType ) + { + return uow.metaInfo().get( infoType ); + } + + @Override + public void setMetaInfo( Object metaInfo ) + { + uow.metaInfo().set( metaInfo ); + } + + @Override + @SuppressWarnings( { "raw", "unchecked" } ) + public <T> Query<T> newQuery( QueryBuilder<T> queryBuilder ) + { + QueryBuilderSPI queryBuilderSPI = (QueryBuilderSPI) queryBuilder; + + return queryBuilderSPI.newQuery( new UoWQuerySource( this ) ); + } + + @Override + public <T> T newEntity( Class<T> type ) + throws EntityTypeNotFoundException, LifecycleException + { + return newEntity( type, null ); + } + + @Override + public <T> T newEntity( Class<T> type, String identity ) + throws EntityTypeNotFoundException, LifecycleException + { + return newEntityBuilder( type, identity ).newInstance(); + } + + @Override + public <T> EntityBuilder<T> newEntityBuilder( Class<T> type ) + throws EntityTypeNotFoundException + { + return newEntityBuilder( type, null ); + } + + @Override + public <T> EntityBuilder<T> newEntityBuilder( Class<T> type, String identity ) + throws EntityTypeNotFoundException + { + ModelModule<EntityDescriptor> model = module.typeLookup().lookupEntityModel( type ); + + if( model == null ) + { + throw new EntityTypeNotFoundException( type.getName(), + module.name(), + module.findVisibleEntityTypes().map( ModelModule.toStringFunction ) + ); + } + + EntityStore entityStore = ((ModuleSpi) model.module()).entityStore(); + + // Generate id if necessary + if( identity == null ) + { + IdentityGenerator idGen = ((ModuleSpi) model.module()).identityGenerator(); + if( idGen == null ) + { + throw new NoSuchServiceException( IdentityGenerator.class.getName(), model.module().name() ); + } + identity = idGen.generate( model.model().types().findFirst().orElse( null ) ); + } + EntityBuilder<T> builder; + + builder = new EntityBuilderInstance<>( model, + this, + uow.getEntityStoreUnitOfWork( entityStore ), + identity ); + return builder; + } + + @Override + public <T> EntityBuilder<T> newEntityBuilderWithState( + Class<T> type, + Function<PropertyDescriptor, Object> propertyFunction, + Function<AssociationDescriptor, EntityReference> associationFunction, + Function<AssociationDescriptor, Iterable<EntityReference>> manyAssociationFunction, + Function<AssociationDescriptor, Map<String, EntityReference>> namedAssociationFunction + ) + throws EntityTypeNotFoundException + { + return newEntityBuilderWithState( type, null, + propertyFunction, + associationFunction, + manyAssociationFunction, + namedAssociationFunction ); + } + + @Override + public <T> EntityBuilder<T> newEntityBuilderWithState( + Class<T> type, String identity, + Function<PropertyDescriptor, Object> propertyFunction, + Function<AssociationDescriptor, EntityReference> associationFunction, + Function<AssociationDescriptor, Iterable<EntityReference>> manyAssociationFunction, + Function<AssociationDescriptor, Map<String, EntityReference>> namedAssociationFunction + ) + throws EntityTypeNotFoundException + { + NullArgumentException.validateNotNull( "propertyFunction", propertyFunction ); + NullArgumentException.validateNotNull( "associationFunction", associationFunction ); + NullArgumentException.validateNotNull( "manyAssociationFunction", manyAssociationFunction ); + NullArgumentException.validateNotNull( "namedAssociationFunction", namedAssociationFunction ); + + ModelModule<EntityDescriptor> model = module.typeLookup().lookupEntityModel( type ); + + if( model == null ) + { + throw new EntityTypeNotFoundException( type.getName(), + module.name(), + module.findVisibleEntityTypes().map( ModelModule.toStringFunction ) + ); + } + + EntityStore entityStore = model.module().entityStore(); + + FunctionStateResolver stateResolver = new FunctionStateResolver( + propertyFunction, associationFunction, manyAssociationFunction, namedAssociationFunction + ); + + if( identity == null ) + { + // Use identity from StateResolver if available + PropertyModel identityModel = (PropertyModel) model.model().state().findPropertyModelByQualifiedName( IDENTITY_STATE_NAME ); + identity = (String) stateResolver.getPropertyState( identityModel ); + if( identity == null ) + { + // Generate identity + IdentityGenerator idGen = model.module().identityGenerator(); + if( idGen == null ) + { + throw new NoSuchServiceException( IdentityGenerator.class.getName(), model.module().name() ); + } + identity = idGen.generate( model.model().types().findFirst().orElse( null )); + } + } + + return new EntityBuilderInstance<>( model, + this, + uow.getEntityStoreUnitOfWork( entityStore ), + identity, + stateResolver ); + } + + @Override + public <T> T get( Class<T> type, String identity ) + throws EntityTypeNotFoundException, NoSuchEntityException + { + Iterable<ModelModule<EntityDescriptor>> models = module.typeLookup().lookupEntityModels( type ); + + if( !models.iterator().hasNext() ) + { + throw new EntityTypeNotFoundException( type.getName(), + module.name(), + ((ModuleSpi) module).findVisibleEntityTypes().map( ModelModule.toStringFunction ) + ); + } + + return uow.get( parseEntityReference( identity ), this, models, type ); + } + + @Override + @SuppressWarnings( "unchecked" ) + public <T> T get( T entity ) + throws EntityTypeNotFoundException + { + EntityComposite entityComposite = (EntityComposite) entity; + EntityInstance compositeInstance = EntityInstance.entityInstanceOf( entityComposite ); + ModelModule<EntityDescriptor> model = new ModelModule<>( compositeInstance.module(), compositeInstance.entityModel() ); + Class<T> type = (Class<T>) compositeInstance.types().findFirst().orElse( null ); + return uow.get( compositeInstance.identity(), this, Collections.singletonList( model ), type ); + } + + @Override + public void remove( Object entity ) + throws LifecycleException + { + uow.checkOpen(); + + EntityComposite entityComposite = (EntityComposite) entity; + + EntityInstance compositeInstance = EntityInstance.entityInstanceOf( entityComposite ); + + if( compositeInstance.status() == EntityStatus.NEW ) + { + compositeInstance.remove( this ); + uow.remove( compositeInstance.identity() ); + } + else if( compositeInstance.status() == EntityStatus.LOADED || compositeInstance.status() == EntityStatus.UPDATED ) + { + compositeInstance.remove( this ); + } + else + { + throw new NoSuchEntityException( compositeInstance.identity(), compositeInstance.types(), usecase() ); + } + } + + @SuppressWarnings( "DuplicateThrows" ) + @Override + public void complete() + throws UnitOfWorkCompletionException, ConcurrentEntityModificationException + { + uow.complete(); + } + + @Override + public void discard() + { + uow.discard(); + } + + @Override + public void close() + { + discard(); + } + + @Override + public boolean isOpen() + { + return uow.isOpen(); + } + + @Override + public boolean isPaused() + { + return uow.isPaused(); + } + + @Override + public void pause() + { + uow.pause(); + } + + @Override + public void resume() + { + uow.resume(); + } + + @Override + public void addUnitOfWorkCallback( UnitOfWorkCallback callback ) + { + uow.addUnitOfWorkCallback( callback ); + } + + @Override + public void removeUnitOfWorkCallback( UnitOfWorkCallback callback ) + { + uow.removeUnitOfWorkCallback( callback ); + } + + @Override + public boolean equals( Object o ) + { + if( this == o ) + { + return true; + } + if( o == null || getClass() != o.getClass() ) + { + return false; + } + + ModuleUnitOfWork that = (ModuleUnitOfWork) o; + + return uow.equals( that.uow ); + } + + @Override + public int hashCode() + { + return uow.hashCode(); + } + + @Override + public String toString() + { + return uow.toString(); + } + + public void addEntity( EntityInstance instance ) + { + uow.addEntity( instance ); + } + + @Override + public <T extends Identity> T toValue( Class<T> primaryType, T entityComposite ) + { + Function<PropertyDescriptor, Object> propertyFunction = new ToValuePropertyMappingFunction( entityComposite ); + Function<AssociationDescriptor, EntityReference> assocationFunction = new ToValueAssociationMappingFunction<>( entityComposite ); + Function<AssociationDescriptor, Iterable<EntityReference>> manyAssocFunction = new ToValueManyAssociationMappingFunction<>( entityComposite ); + Function<AssociationDescriptor, Map<String, EntityReference>> namedAssocFunction = new ToValueNameAssociationMappingFunction<>( entityComposite ); + + @SuppressWarnings( "unchecked" ) + ValueBuilder<T> builder = module().newValueBuilderWithState( + primaryType, propertyFunction, assocationFunction, manyAssocFunction, namedAssocFunction ); + return builder.newInstance(); + } + + @Override + public <T extends Identity> T toEntity( Class<T> primaryType, T valueComposite ) + { + Function<PropertyDescriptor, Object> propertyFunction = new ToEntityPropertyMappingFunction<>( valueComposite ); + Function<AssociationDescriptor, EntityReference> assocationFunction = new ToEntityAssociationMappingFunction<>( valueComposite ); + Function<AssociationDescriptor, Iterable<EntityReference>> manyAssocFunction = new ToEntityManyAssociationMappingFunction<>( valueComposite ); + Function<AssociationDescriptor, Map<String, EntityReference>> namedAssocFunction = new ToEntityNameAssociationMappingFunction<>( valueComposite ); + + String identity = valueComposite.identity().get(); + try + { + T entity = get( primaryType, identity ); + // If successful, then this entity is to by modified. + EntityInstance instance = EntityInstance.entityInstanceOf( (EntityComposite) entity ); + EntityState state = instance.entityState(); + FunctionStateResolver stateResolver = new FunctionStateResolver( propertyFunction, + assocationFunction, + manyAssocFunction, + namedAssocFunction ); + EntityModel model = (EntityModel) EntityInstance.entityInstanceOf( (EntityComposite) entity ).descriptor(); + stateResolver.populateState( model, state ); + return entity; + } + catch( NoSuchEntityException e ) + { + EntityBuilder<T> entityBuilder = newEntityBuilderWithState( primaryType, + identity, + propertyFunction, + assocationFunction, + manyAssocFunction, + namedAssocFunction ); + return entityBuilder.newInstance(); + } + } + + private static class UoWQuerySource implements QuerySource + { + private final ModuleUnitOfWork moduleUnitOfWork; + + private UoWQuerySource( ModuleUnitOfWork moduleUnitOfWork ) + { + this.moduleUnitOfWork = moduleUnitOfWork; + } + + @Override + public <T> T find( Class<T> resultType, + Predicate<Composite> whereClause, + Iterable<OrderBy> orderBySegments, + Integer firstResult, + Integer maxResults, + Map<String, Object> variables + ) + { + final EntityFinder entityFinder = moduleUnitOfWork.module().findService( EntityFinder.class ).get(); + + try + { + final EntityReference foundEntity = entityFinder.findEntity( resultType, whereClause, variables == null ? Collections + .<String, Object>emptyMap() : variables ); + if( foundEntity != null ) + { + try + { + return moduleUnitOfWork.get( resultType, foundEntity.identity() ); + } + catch( NoSuchEntityException e ) + { + return null; // Index is out of sync - entity has been removed + } + } + // No entity was found + return null; + } + catch( EntityFinderException e ) + { + throw new QueryExecutionException( "Finder caused exception", e ); + } + } + + @Override + public <T> long count( Class<T> resultType, + Predicate<Composite> whereClause, + Iterable<OrderBy> orderBySegments, + Integer firstResult, + Integer maxResults, + Map<String, Object> variables + ) + { + final EntityFinder entityFinder = moduleUnitOfWork.module().findService( EntityFinder.class ).get(); + + try + { + return entityFinder.countEntities( resultType, whereClause, variables == null ? Collections.<String, Object>emptyMap() : variables ); + } + catch( EntityFinderException e ) + { + e.printStackTrace(); + return 0; + } + } + + @Override + public <T> Iterator<T> iterator( final Class<T> resultType, + Predicate<Composite> whereClause, + Iterable<OrderBy> orderBySegments, + Integer firstResult, + Integer maxResults, + Map<String, Object> variables + ) + { + final EntityFinder entityFinder = moduleUnitOfWork.module().findService( EntityFinder.class ).get(); + + try + { + final Iterator<EntityReference> foundEntities = entityFinder.findEntities( resultType, + whereClause, + Iterables.toArray( OrderBy.class, orderBySegments ), + firstResult, + maxResults, + variables == null ? Collections + .<String, Object>emptyMap() : variables ) + .iterator(); + + return new Iterator<T>() + { + @Override + public boolean hasNext() + { + return foundEntities.hasNext(); + } + + @Override + public T next() + { + final EntityReference foundEntity = foundEntities.next(); + try + { + return moduleUnitOfWork.get( resultType, foundEntity.identity() ); + } + catch( NoSuchEntityException e ) + { + // Index is out of sync - entity has been removed + return null; + } + } + + @Override + public void remove() + { + throw new UnsupportedOperationException(); + } + }; + } + catch( EntityFinderException e ) + { + throw new QueryExecutionException( "Query '" + toString() + "' could not be executed", e ); + } + } + + @Override + public String toString() + { + return "UnitOfWork( " + moduleUnitOfWork.usecase().name() + " )"; + } + } + + private class ToValuePropertyMappingFunction + implements Function<PropertyDescriptor, Object> + { + private Object entity; + + public ToValuePropertyMappingFunction( Object entity ) + { + this.entity = entity; + } + + @Override + public Object apply( PropertyDescriptor propertyDescriptor ) + { + EntityState entityState = EntityInstance.entityInstanceOf( (EntityComposite) entity ).entityState(); + return entityState.propertyValueOf( propertyDescriptor.qualifiedName() ); + } + } + + private class ToValueAssociationMappingFunction<T> + implements Function<AssociationDescriptor, EntityReference> + { + private final T entity; + + public ToValueAssociationMappingFunction( T entity ) + { + this.entity = entity; + } + + @Override + public EntityReference apply( AssociationDescriptor associationDescriptor ) + { + EntityState entityState = EntityInstance.entityInstanceOf( (EntityComposite) entity ).entityState(); + return entityState.associationValueOf( associationDescriptor.qualifiedName() ); + } + } + + private class ToValueManyAssociationMappingFunction<T> + implements Function<AssociationDescriptor, Iterable<EntityReference>> + { + private final T entity; + + public ToValueManyAssociationMappingFunction( T entity ) + { + this.entity = entity; + } + + @Override + public Iterable<EntityReference> apply( AssociationDescriptor associationDescriptor ) + { + EntityState entityState = EntityInstance.entityInstanceOf( (EntityComposite) entity ).entityState(); + return entityState.manyAssociationValueOf( associationDescriptor.qualifiedName() ); + } + } + + private class ToValueNameAssociationMappingFunction<T> + implements Function<AssociationDescriptor, Map<String, EntityReference>> + { + private final T entity; + + public ToValueNameAssociationMappingFunction( T entity ) + { + this.entity = entity; + } + + @Override + public Map<String, EntityReference> apply( AssociationDescriptor associationDescriptor ) + { + Map<String, EntityReference> result = new HashMap<>(); + EntityState entityState = EntityInstance.entityInstanceOf( (EntityComposite) entity ).entityState(); + final NamedAssociationState state = entityState.namedAssociationValueOf( associationDescriptor.qualifiedName() ); + for( String name : state ) + { + result.put( name, state.get( name ) ); + } + return result; + } + } + + private class ToEntityPropertyMappingFunction<T> + implements Function<PropertyDescriptor, Object> + { + private final T value; + + public ToEntityPropertyMappingFunction( T value ) + { + this.value = value; + } + + @Override + public Object apply( PropertyDescriptor propertyDescriptor ) + { + StateHolder state = ValueInstance.valueInstanceOf( (ValueComposite) value ).state(); + Property<Object> property = state.propertyFor( propertyDescriptor.accessor() ); + return property.get(); + } + } + + private class ToEntityAssociationMappingFunction<T> + implements Function<AssociationDescriptor, EntityReference> + { + + private final T value; + + public ToEntityAssociationMappingFunction( T value ) + { + this.value = value; + } + + @Override + public EntityReference apply( AssociationDescriptor associationDescriptor ) + { + AssociationStateHolder state = ValueInstance.valueInstanceOf( (ValueComposite) value ).state(); + AssociationInstance<T> association = (AssociationInstance<T>) state.associationFor( associationDescriptor.accessor() ); + return association.getAssociationState().get(); + } + } + + private class ToEntityManyAssociationMappingFunction<T> + implements Function<AssociationDescriptor, Iterable<EntityReference>> + { + + private final T value; + + public ToEntityManyAssociationMappingFunction( T valueComposite ) + { + this.value = valueComposite; + } + + @Override + public Iterable<EntityReference> apply( AssociationDescriptor associationDescriptor ) + { + AssociationStateHolder state = ValueInstance.valueInstanceOf( (ValueComposite) value ).state(); + ManyAssociationInstance<T> association = + (ManyAssociationInstance<T>) state.manyAssociationFor( associationDescriptor.accessor() ); + return association.getManyAssociationState(); + } + } + + private class ToEntityNameAssociationMappingFunction<T> + implements Function<AssociationDescriptor, Map<String, EntityReference>> + { + private final T value; + + public ToEntityNameAssociationMappingFunction( T valueComposite ) + { + this.value = valueComposite; + } + + @Override + public Map<String, EntityReference> apply( AssociationDescriptor associationDescriptor ) + { + AssociationStateHolder state = ValueInstance.valueInstanceOf( (ValueComposite) value ).state(); + NamedAssociationInstance<T> association = + (NamedAssociationInstance<T>) state.namedAssociationFor( associationDescriptor.accessor() ); + HashMap<String, EntityReference> result = new HashMap<>(); + for( Map.Entry<String, EntityReference> entry : association.getEntityReferences() ) + { + result.put( entry.getKey(), entry.getValue() ); + } + return result; + } + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkFactoryMixin.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkFactoryMixin.java b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkFactoryMixin.java new file mode 100644 index 0000000..3a69e29 --- /dev/null +++ b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkFactoryMixin.java @@ -0,0 +1,100 @@ +/* + * 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.runtime.unitofwork; + +import java.util.Stack; +import org.apache.zest.api.common.Optional; +import org.apache.zest.api.composite.TransientBuilderFactory; +import org.apache.zest.api.entity.EntityComposite; +import org.apache.zest.api.injection.scope.Structure; +import org.apache.zest.api.injection.scope.Uses; +import org.apache.zest.api.metrics.MetricsProvider; +import org.apache.zest.api.unitofwork.UnitOfWork; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; +import org.apache.zest.api.usecase.Usecase; +import org.apache.zest.runtime.entity.EntityInstance; +import org.apache.zest.spi.module.ModuleSpi; + +public class UnitOfWorkFactoryMixin + implements UnitOfWorkFactory +{ + @Structure + private TransientBuilderFactory tbf; + + @Structure + private ModuleSpi module; + + // Implementation of UnitOfWorkFactory + @Override + public UnitOfWork newUnitOfWork() + { + return newUnitOfWork( Usecase.DEFAULT ); + } + + @Override + public UnitOfWork newUnitOfWork( long currentTime ) + { + return newUnitOfWork( Usecase.DEFAULT, currentTime ); + } + + @Override + public UnitOfWork newUnitOfWork( Usecase usecase ) + { + return newUnitOfWork( usecase == null ? Usecase.DEFAULT : usecase, System.currentTimeMillis() ); + } + + @Override + public UnitOfWork newUnitOfWork( Usecase usecase, long currentTime ) + { + UnitOfWorkInstance unitOfWorkInstance = new UnitOfWorkInstance( usecase, currentTime, metricsProvider() ); + return tbf.newTransient( UnitOfWork.class, unitOfWorkInstance ); + } + + private MetricsProvider metricsProvider() + { + return module.metricsProvider(); + } + + @Override + public boolean isUnitOfWorkActive() + { + Stack<UnitOfWorkInstance> stack = UnitOfWorkInstance.getCurrent(); + return !stack.isEmpty(); + } + + @Override + public UnitOfWork currentUnitOfWork() + { + Stack<UnitOfWorkInstance> stack = UnitOfWorkInstance.getCurrent(); + if( stack.size() == 0 ) + { + throw new IllegalStateException( "No current UnitOfWork active" ); + } + return tbf.newTransient( UnitOfWork.class, stack.peek() ); + } + + @Override + public UnitOfWork getUnitOfWork( EntityComposite entity ) + { + EntityInstance instance = EntityInstance.entityInstanceOf( entity ); + return instance.unitOfWork(); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java index fc0810b..3a65c9f 100755 --- a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java @@ -1,20 +1,23 @@ /* - * Copyright (c) 2007-2013, Niclas Hedhman. All Rights Reserved. + * 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 * - * Licensed 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 * - * 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. * - * 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.runtime.unitofwork; import java.util.ArrayList; @@ -37,6 +40,7 @@ import org.apache.zest.api.type.HasTypes; import org.apache.zest.api.unitofwork.ConcurrentEntityModificationException; 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.UnitOfWorkCallback; import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; import org.apache.zest.api.unitofwork.UnitOfWorkException; @@ -44,7 +48,6 @@ import org.apache.zest.api.unitofwork.UnitOfWorkOptions; import org.apache.zest.api.usecase.Usecase; import org.apache.zest.runtime.entity.EntityInstance; import org.apache.zest.runtime.entity.EntityModel; -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.entitystore.ConcurrentEntityStateModificationException; @@ -53,8 +56,8 @@ import org.apache.zest.spi.entitystore.EntityStore; import org.apache.zest.spi.entitystore.EntityStoreUnitOfWork; import org.apache.zest.spi.entitystore.StateCommitter; import org.apache.zest.spi.metrics.DefaultMetric; -import org.apache.zest.spi.module.ModelModule; import org.apache.zest.spi.module.ModuleSpi; +import org.apache.zest.spi.structure.ModelModule; import static org.apache.zest.api.unitofwork.UnitOfWorkCallback.UnitOfWorkStatus.COMPLETED; import static org.apache.zest.api.unitofwork.UnitOfWorkCallback.UnitOfWorkStatus.DISCARDED; @@ -123,7 +126,7 @@ public final class UnitOfWorkInstance } public <T> T get( EntityReference identity, - ModuleUnitOfWork uow, + UnitOfWork uow, Iterable<ModelModule<EntityDescriptor>> potentialModels, Class<T> mixinType ) @@ -175,10 +178,8 @@ public final class UnitOfWorkInstance ); } } - // Create instance entityInstance = new EntityInstance( uow, module, model, entityState ); - instanceCache.put( identity, entityInstance ); } else @@ -390,10 +391,7 @@ public final class UnitOfWorkInstance // Notify explicitly registered callbacks if( callbacks != null ) { - for( UnitOfWorkCallback callback : callbacks ) - { - callback.beforeCompletion(); - } + callbacks.forEach( UnitOfWorkCallback::beforeCompletion ); } // Notify entities http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderInstance.java index 9f72fe2..45e9282 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderInstance.java @@ -21,7 +21,7 @@ import org.apache.zest.api.value.ValueBuilder; import org.apache.zest.api.value.ValueDescriptor; import org.apache.zest.runtime.composite.StateResolver; import org.apache.zest.runtime.structure.ModuleInstance; -import org.apache.zest.spi.module.ModelModule; +import org.apache.zest.spi.structure.ModelModule; /** * Implementation of ValueBuilder http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithPrototype.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithPrototype.java b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithPrototype.java index a878ab2..eafd07a 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithPrototype.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithPrototype.java @@ -38,7 +38,7 @@ import org.apache.zest.runtime.composite.MixinsModel; import org.apache.zest.runtime.composite.StateResolver; import org.apache.zest.runtime.composite.UsesInstance; import org.apache.zest.runtime.injection.InjectionContext; -import org.apache.zest.spi.module.ModelModule; +import org.apache.zest.spi.structure.ModelModule; import org.apache.zest.runtime.structure.ModuleInstance; /** http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithState.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithState.java b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithState.java index db97002..69c06c4 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithState.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueBuilderWithState.java @@ -18,7 +18,7 @@ import org.apache.zest.api.common.ConstructionException; import org.apache.zest.api.value.ValueBuilder; import org.apache.zest.api.value.ValueDescriptor; import org.apache.zest.runtime.composite.StateResolver; -import org.apache.zest.spi.module.ModelModule; +import org.apache.zest.spi.structure.ModelModule; import org.apache.zest.runtime.structure.ModuleInstance; public class ValueBuilderWithState<T> implements ValueBuilder<T> http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueStateInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueStateInstance.java b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueStateInstance.java index ed0083b..313567e 100644 --- a/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueStateInstance.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/value/ValueStateInstance.java @@ -35,7 +35,8 @@ import org.apache.zest.runtime.composite.StateResolver; import org.apache.zest.runtime.property.PropertyInfo; import org.apache.zest.runtime.property.PropertyInstance; import org.apache.zest.runtime.structure.ModuleInstance; -import org.apache.zest.spi.module.ModelModule; +import org.apache.zest.runtime.unitofwork.EntityFunction; +import org.apache.zest.spi.structure.ModelModule; /** * TODO @@ -65,6 +66,8 @@ public final class ValueStateInstance StateResolver stateResolver ) { + EntityFunction entityFunction = new EntityFunction( currentModule.unitOfWorkFactory() ); + ValueModel valueModel = (ValueModel) compositeModelModule.model(); this.properties = new LinkedHashMap<>(); valueModel.state().properties().forEach( propertyDescriptor -> { @@ -80,7 +83,7 @@ public final class ValueStateInstance EntityReference value = stateResolver.getAssociationState( associationDescriptor ); AssociationInstance<Object> associationInstance1 = new AssociationInstance<>( builderInfo, - currentModule.getEntityFunction(), + entityFunction, new ReferenceProperty( value ) ); associations.put( associationDescriptor.accessor(), associationInstance1 ); } ); @@ -93,7 +96,7 @@ public final class ValueStateInstance ManyAssociationValueState manyAssociationState = new ManyAssociationValueState( value ); ManyAssociationInstance<Object> associationInstance = new ManyAssociationInstance<>( builderInfo, - currentModule.getEntityFunction(), + entityFunction, manyAssociationState ); manyAssociations.put( associationDescriptor.accessor(), associationInstance ); } ); @@ -106,7 +109,7 @@ public final class ValueStateInstance NamedAssociationValueState namedAssociationState = new NamedAssociationValueState( value ); NamedAssociationInstance<Object> associationInstance = new NamedAssociationInstance<>( builderInfo, - currentModule.getEntityFunction(), + entityFunction, namedAssociationState ); namedAssociations.put( associationDescriptor.accessor(), associationInstance ); } ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/api/common/OptionalTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/api/common/OptionalTest.java b/core/runtime/src/test/java/org/apache/zest/api/common/OptionalTest.java index 355ee8e..ed1b8c3 100644 --- a/core/runtime/src/test/java/org/apache/zest/api/common/OptionalTest.java +++ b/core/runtime/src/test/java/org/apache/zest/api/common/OptionalTest.java @@ -95,7 +95,7 @@ public class OptionalTest public void givenOptionalAssociationWhenOptionalMissingThenNoException() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); try { TestComposite4 ref = unitOfWork.newEntity( TestComposite4.class ); @@ -116,7 +116,7 @@ public class OptionalTest public void givenOptionalAssociationWhenOptionalSetThenNoException() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); try { TestComposite4 ref = unitOfWork.newEntity( TestComposite4.class ); @@ -138,7 +138,7 @@ public class OptionalTest public void givenMandatoryAssociationWhenMandatoryMissingThenException() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); try { TestComposite4 ref = unitOfWork.newEntity( TestComposite4.class ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/api/common/PropertyErrorTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/api/common/PropertyErrorTest.java b/core/runtime/src/test/java/org/apache/zest/api/common/PropertyErrorTest.java index 1201329..6add3eb 100644 --- a/core/runtime/src/test/java/org/apache/zest/api/common/PropertyErrorTest.java +++ b/core/runtime/src/test/java/org/apache/zest/api/common/PropertyErrorTest.java @@ -41,7 +41,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/runtime/src/test/java/org/apache/zest/api/common/PropertyTypeTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/api/common/PropertyTypeTest.java b/core/runtime/src/test/java/org/apache/zest/api/common/PropertyTypeTest.java index 4bcc88a..e3f5a7e 100644 --- a/core/runtime/src/test/java/org/apache/zest/api/common/PropertyTypeTest.java +++ b/core/runtime/src/test/java/org/apache/zest/api/common/PropertyTypeTest.java @@ -49,7 +49,7 @@ public class PropertyTypeTest public void givenEntityWithPropertyConstraintsWhenInstantiatedThenPropertiesWork() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); try { EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/api/common/RemovalTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/api/common/RemovalTest.java b/core/runtime/src/test/java/org/apache/zest/api/common/RemovalTest.java index 76b80bf..8b33ac0 100644 --- a/core/runtime/src/test/java/org/apache/zest/api/common/RemovalTest.java +++ b/core/runtime/src/test/java/org/apache/zest/api/common/RemovalTest.java @@ -44,7 +44,7 @@ public class RemovalTest public void givenEntityIsCreatedAndUnitOfWorkIsNotCompletedWhenEntityIsRemoveThenSuccessfulRemoval() throws Exception { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); EntityBuilder<TestEntity> builder = uow.newEntityBuilder( TestEntity.class, "123" ); builder.instance().test().set( "habba" ); TestEntity test = builder.newInstance(); @@ -56,7 +56,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/runtime/src/test/java/org/apache/zest/api/common/ValueCompositeTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/api/common/ValueCompositeTest.java b/core/runtime/src/test/java/org/apache/zest/api/common/ValueCompositeTest.java index 77d1a96..42360ad 100644 --- a/core/runtime/src/test/java/org/apache/zest/api/common/ValueCompositeTest.java +++ b/core/runtime/src/test/java/org/apache/zest/api/common/ValueCompositeTest.java @@ -183,7 +183,7 @@ public class ValueCompositeTest builder.prototype().number().set( 42L ); SomeValue some = builder.newInstance(); - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); EntityBuilder<SomeEntity> entityBuilder = unitOfWork.newEntityBuilder( SomeEntity.class ); entityBuilder.instance().someValue().set( some ); SomeEntity entity = entityBuilder.newInstance(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java b/core/runtime/src/test/java/org/apache/zest/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java index 0524c64..4688883 100644 --- a/core/runtime/src/test/java/org/apache/zest/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java +++ b/core/runtime/src/test/java/org/apache/zest/regression/qi377/InterfaceCollisionWithRelatedReturnTypesTest.java @@ -52,14 +52,14 @@ public class InterfaceCollisionWithRelatedReturnTypesTest throws UnitOfWorkCompletionException { String identity; - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { Company startUp = uow.newEntity( Company.class ); startUp.name().set( "Acme" ); identity = ( (Identity) startUp ).identity().get(); uow.complete(); } - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { Company startUp = uow.get( Company.class, identity ); assertThat( startUp.name().get(), equalTo( "Acme" ) ); @@ -77,7 +77,7 @@ public class InterfaceCollisionWithRelatedReturnTypesTest throws UnitOfWorkCompletionException { String identity; - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { Company startUp = uow.newEntity( Company.class ); Employee niclas = uow.newEntity( Employee.class ); @@ -87,7 +87,7 @@ public class InterfaceCollisionWithRelatedReturnTypesTest uow.complete(); } - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { Company startUp = uow.get( Company.class, identity ); Employee niclas = startUp.lead().get(); @@ -104,7 +104,7 @@ public class InterfaceCollisionWithRelatedReturnTypesTest @Test public void shouldBeAbleToSetLeadToTheSalesTeam() { - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { SalesTeam startUp = uow.newEntity( SalesTeam.class ); Employee niclas = uow.newEntity( Employee.class ); @@ -116,7 +116,7 @@ public class InterfaceCollisionWithRelatedReturnTypesTest @Test public void shouldBeAbleToSetLeadToTheResearchTeam() { - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { ResearchTeam startUp = uow.newEntity( ResearchTeam.class ); Employee niclas = uow.newEntity( Employee.class ); @@ -128,7 +128,7 @@ public class InterfaceCollisionWithRelatedReturnTypesTest @Test public void shouldBeAbleToAddEmployeesToTheCompany() { - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { Company startUp = uow.newEntity( Company.class ); Employee niclas = uow.newEntity( Employee.class ); @@ -142,7 +142,7 @@ public class InterfaceCollisionWithRelatedReturnTypesTest @Test public void shouldBeAbleToAddEmployeesToTheSalesTeam() { - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { SalesTeam startUp = uow.newEntity( SalesTeam.class ); Employee niclas = uow.newEntity( Employee.class ); @@ -154,7 +154,7 @@ public class InterfaceCollisionWithRelatedReturnTypesTest @Test public void shouldBeAbleToAddEmployeesToTheResearchTeam() { - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { ResearchTeam startUp = uow.newEntity( ResearchTeam.class ); Employee niclas = uow.newEntity( Employee.class ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/regression/qi377/SetAssociationInSideEffectTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/regression/qi377/SetAssociationInSideEffectTest.java b/core/runtime/src/test/java/org/apache/zest/regression/qi377/SetAssociationInSideEffectTest.java index a2933be..7564016 100644 --- a/core/runtime/src/test/java/org/apache/zest/regression/qi377/SetAssociationInSideEffectTest.java +++ b/core/runtime/src/test/java/org/apache/zest/regression/qi377/SetAssociationInSideEffectTest.java @@ -56,7 +56,7 @@ public class SetAssociationInSideEffectTest @Test public void whenSettingAnAssociationInASideEffectExpectItToWork() { - try( UnitOfWork uow = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Purchase Steinway" ) ) ) + try( UnitOfWork uow = uowf.newUnitOfWork( UsecaseBuilder.newUsecase( "Purchase Steinway" ) ) ) { Pianist chris = uow.newEntity( Pianist.class, "Chris" ); Steinway modelD = uow.newEntity( Steinway.class, "ModelD-274" ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java b/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java index ea2ebc1..ca655f8 100644 --- a/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java +++ b/core/runtime/src/test/java/org/apache/zest/regression/qi382/Qi382Test.java @@ -17,6 +17,7 @@ */ package org.apache.zest.regression.qi382; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; import org.junit.Test; import org.apache.zest.api.association.Association; import org.apache.zest.api.entity.EntityBuilder; @@ -26,7 +27,6 @@ import org.apache.zest.api.entity.LifecycleException; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.This; import org.apache.zest.api.mixin.Mixins; -import org.apache.zest.api.structure.Module; import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; import org.apache.zest.api.value.ValueSerialization; @@ -56,12 +56,12 @@ public class Qi382Test extends AbstractZestTest public void givenCreationOfTwoEntitiesWhenAssigningOneToOtherExpectCompletionToSucceed() throws UnitOfWorkCompletionException { - try( UnitOfWork unitOfWork = module.newUnitOfWork() ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork() ) { Car car = unitOfWork.newEntity( Car.class, "Ferrari" ); unitOfWork.complete(); } - try( UnitOfWork unitOfWork = module.newUnitOfWork() ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork() ) { Car car = unitOfWork.get( Car.class, "Ferrari" ); assertThat( car, notNullValue() ); @@ -81,13 +81,13 @@ public class Qi382Test extends AbstractZestTest private Car me; @Structure - private Module module; + private UnitOfWorkFactory uowf; @Override public void create() throws LifecycleException { - UnitOfWork unitOfWork = module.currentUnitOfWork(); + UnitOfWork unitOfWork = uowf.currentUnitOfWork(); EntityBuilder<Person> builder = unitOfWork.newEntityBuilder( Person.class, "Niclas" ); builder.instance().car().set( me ); builder.newInstance(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/regression/qi383/Qi383Test.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/regression/qi383/Qi383Test.java b/core/runtime/src/test/java/org/apache/zest/regression/qi383/Qi383Test.java index c4461cb..f3bcd2f 100644 --- a/core/runtime/src/test/java/org/apache/zest/regression/qi383/Qi383Test.java +++ b/core/runtime/src/test/java/org/apache/zest/regression/qi383/Qi383Test.java @@ -44,7 +44,7 @@ public class Qi383Test extends AbstractZestTest public void givenUnitOfWorkInProgressWhenAddingSameEntityTwiceExpectException() throws UnitOfWorkCompletionException { - try( UnitOfWork unitOfWork = module.newUnitOfWork() ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork() ) { unitOfWork.newEntity( Car.class, "Ferrari" ); unitOfWork.newEntity( Car.class, "Ford" ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/regression/qi59/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/regression/qi59/IssueTest.java b/core/runtime/src/test/java/org/apache/zest/regression/qi59/IssueTest.java index 0363137..29baada 100644 --- a/core/runtime/src/test/java/org/apache/zest/regression/qi59/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/zest/regression/qi59/IssueTest.java @@ -42,7 +42,7 @@ public class IssueTest @Test public void givenEntityWithConstrainedPropertyWhenInvalidPropertyValueSetThenThrowException() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { @@ -62,7 +62,7 @@ public class IssueTest @Test public void givenEntityWithComplexConstrainedPropertyWhenInvalidPropertyValueSetThenThrowException() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/regression/qi94/IssueTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/regression/qi94/IssueTest.java b/core/runtime/src/test/java/org/apache/zest/regression/qi94/IssueTest.java index d799ddc..18bc396 100644 --- a/core/runtime/src/test/java/org/apache/zest/regression/qi94/IssueTest.java +++ b/core/runtime/src/test/java/org/apache/zest/regression/qi94/IssueTest.java @@ -44,7 +44,7 @@ public class IssueTest @Test public void entityBuilderAssociationTypeIsNotNull() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { EntityBuilder<Item> builder = uow.newEntityBuilder( Item.class ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/ZestAPITest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/ZestAPITest.java b/core/runtime/src/test/java/org/apache/zest/runtime/ZestAPITest.java index df40a4d..a9f7dfa 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/ZestAPITest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/ZestAPITest.java @@ -45,7 +45,7 @@ public class ZestAPITest public void testGetModuleOfComposite() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); TestEntity testEntity = unitOfWork.newEntity( TestEntity.class ); api.moduleOf( testEntity ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/ZestSPITest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/ZestSPITest.java b/core/runtime/src/test/java/org/apache/zest/runtime/ZestSPITest.java index d171396..76f2433 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/ZestSPITest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/ZestSPITest.java @@ -53,7 +53,7 @@ public class ZestSPITest public void givenEntityWhenGettingStateThenGetCorrectState() throws Exception { - UnitOfWork unitOfWork = module.newUnitOfWork(); + UnitOfWork unitOfWork = uowf.newUnitOfWork(); TestEntity testEntity; try { @@ -72,7 +72,7 @@ public class ZestSPITest unitOfWork.discard(); } - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { testEntity = uow.get( testEntity ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/appliesto/AppliesToOrConditionQI241Test.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/appliesto/AppliesToOrConditionQI241Test.java b/core/runtime/src/test/java/org/apache/zest/runtime/appliesto/AppliesToOrConditionQI241Test.java index 7054b37..f2ec635 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/appliesto/AppliesToOrConditionQI241Test.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/appliesto/AppliesToOrConditionQI241Test.java @@ -57,7 +57,7 @@ public class AppliesToOrConditionQI241Test @Test public void testMultiConcerns1() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { @@ -76,7 +76,7 @@ public class AppliesToOrConditionQI241Test @Test public void testMultiConcerns2() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { @@ -95,7 +95,7 @@ public class AppliesToOrConditionQI241Test @Test public void testMultiConcernsBoth() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationAssignmentTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationAssignmentTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationAssignmentTest.java index d0c7147..8e9f338 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationAssignmentTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationAssignmentTest.java @@ -56,7 +56,7 @@ public class AssociationAssignmentTest extends AbstractZestTest public void givenAssignmentOfAssociationAtCreationWhenDereferencingAssocationExpectCorrectValue() throws Exception { - UnitOfWork work = module.newUnitOfWork(); + UnitOfWork work = uowf.newUnitOfWork(); TheAssociatedType entity1 = work.newEntity( TheAssociatedType.class ); EntityBuilder<TheMainType> builder = work.newEntityBuilder( TheMainType.class ); builder.instance().assoc().set( entity1 ); @@ -67,7 +67,7 @@ public class AssociationAssignmentTest extends AbstractZestTest assertThat(id1, notNullValue()); assertThat(id2, notNullValue()); - work = module.newUnitOfWork(); + work = uowf.newUnitOfWork(); TheMainType entity3 = work.get(TheMainType.class, id2 ); TheAssociatedType entity4 = entity3.assoc().get(); assertThat( entity4.identity().get(), equalTo(id1)); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationEqualityTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationEqualityTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationEqualityTest.java index ab5222f..4ffc14b 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationEqualityTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/association/AssociationEqualityTest.java @@ -84,7 +84,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationDescriptorEqualityExpectEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { AnEntity anEntity = uow.newEntity( AnEntity.class ); @@ -127,7 +127,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfTheSameTypeAndDifferentStateWhenTestingAssociationDescriptorEqualityExpectEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { SomeWithAssociations some = buildSomeWithAssociation( uow.newEntity( AnEntity.class ) ); @@ -168,7 +168,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfDifferentTypeAndSameStateWhenTestingAssociationDescriptorEqualityExpectNotEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { AnEntity anEntity = uow.newEntity( AnEntity.class ); @@ -214,7 +214,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfSameTypeAndDifferentStateWhenTestingAssociationStateEqualityExpectNotEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { SomeWithAssociations some = buildSomeWithAssociation( uow.newEntity( AnEntity.class ) ); @@ -248,7 +248,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfDifferentTypesAndSameStateWhenTestingAssociationStateEqualityExpectEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { AnEntity anEntity = uow.newEntity( AnEntity.class ); @@ -287,7 +287,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfTheSameTypeAndSameStateWhenTestingAssociationEqualityExpectEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { AnEntity anEntity = uow.newEntity( AnEntity.class ); @@ -323,7 +323,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfTheSameTypeAndDifferentStateWhenTestingAssociationEqualityExpectNotEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { SomeWithAssociations some = buildSomeWithAssociation( uow.newEntity( AnEntity.class ) ); @@ -357,7 +357,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfDifferentTypesAndSameStateWhenTestingAssociationEqualityExpectNotEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { AnEntity anEntity = uow.newEntity( AnEntity.class ); @@ -393,7 +393,7 @@ public class AssociationEqualityTest @Test public void givenValuesOfDifferentTypesAndDifferentStateWhenTestingAssociationEqualityExpectNotEquals() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { SomeWithAssociations some = buildSomeWithAssociation( uow.newEntity( AnEntity.class ) ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientAsClassTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientAsClassTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientAsClassTest.java index 226dd47..5d7839b 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientAsClassTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientAsClassTest.java @@ -18,6 +18,10 @@ */ package org.apache.zest.runtime.composite; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import org.apache.zest.api.concern.ConcernOf; +import org.apache.zest.api.concern.Concerns; import org.junit.Ignore; import org.junit.Test; import org.apache.zest.bootstrap.AssemblyException; @@ -30,15 +34,27 @@ import static org.junit.Assert.assertThat; /** * Test for QI-298. */ -@Ignore( "Awaiting QI-298" ) public class TransientAsClassTest extends AbstractZestTest { + public static class UnderTestConcern extends ConcernOf<InvocationHandler> + implements InvocationHandler + { + + @Override + public Object invoke( Object proxy, Method method, Object[] args ) + throws Throwable + { + return next.invoke( proxy, method, args ) + " bar"; + } + } + + @Concerns(UnderTestConcern.class) public static class UnderTest { public String foo() { - return "bar"; + return "foo"; } } @@ -53,6 +69,6 @@ public class TransientAsClassTest public void test() { UnderTest underTest = module.newTransient( UnderTest.class ); - assertThat( underTest.foo(), equalTo( "bar" ) ); + assertThat( underTest.foo(), equalTo( "foo bar" ) ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientClassLoaderTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientClassLoaderTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientClassLoaderTest.java new file mode 100644 index 0000000..56808b3 --- /dev/null +++ b/core/runtime/src/test/java/org/apache/zest/runtime/composite/TransientClassLoaderTest.java @@ -0,0 +1,30 @@ +/* + * 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.runtime.composite; + +public class TransientClassLoaderTest +{ + + public void givenTransientWhenLoadingClassExpectSubclassGenerated() + { +// new TransientClassLoader( getClass().getClassLoader() ).loadFragmentClass( mainType ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/concerns/GenericConcernTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/concerns/GenericConcernTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/concerns/GenericConcernTest.java index 9a951d9..d243c64 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/concerns/GenericConcernTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/concerns/GenericConcernTest.java @@ -42,7 +42,7 @@ public class GenericConcernTest @Test public void testNestedUnitOfWork() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); Some some = module.newTransient( Some.class ); some.doStuff(); uow.discard(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java index 58bacd2..abf5c66 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/AggregatedTest.java @@ -54,7 +54,7 @@ public class AggregatedTest CompanyEntity companyEntity; PersonEntity personEntity, personEntity2; EmployeeEntity employeeEntity, employeeEntity2; - try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Creation" ) ) ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork( UsecaseBuilder.newUsecase( "Creation" ) ) ) { { EntityBuilder<PersonEntity> builder = unitOfWork.newEntityBuilder( PersonEntity.class ); @@ -100,7 +100,7 @@ public class AggregatedTest unitOfWork.complete(); } - try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Removal" ) ) ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork( UsecaseBuilder.newUsecase( "Removal" ) ) ) { companyEntity = unitOfWork.get( companyEntity ); unitOfWork.remove( companyEntity ); @@ -108,7 +108,7 @@ public class AggregatedTest unitOfWork.complete(); } - try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "No 1st employee" ) ) ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork( UsecaseBuilder.newUsecase( "No 1st employee" ) ) ) { unitOfWork.get( employeeEntity ); fail( "Should not work" ); @@ -118,7 +118,7 @@ public class AggregatedTest // Expected } - try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "No 2nd employee" ) ) ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork( UsecaseBuilder.newUsecase( "No 2nd employee" ) ) ) { unitOfWork.get( employeeEntity2 ); fail( "Should not work" ); @@ -128,7 +128,7 @@ public class AggregatedTest // Expected } - try( UnitOfWork unitOfWork = module.newUnitOfWork( UsecaseBuilder.newUsecase( "Persons not removed" ) ) ) + try( UnitOfWork unitOfWork = uowf.newUnitOfWork( UsecaseBuilder.newUsecase( "Persons not removed" ) ) ) { unitOfWork.get( personEntity ); unitOfWork.get( personEntity2 ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityBuilderWithStateTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityBuilderWithStateTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityBuilderWithStateTest.java index 2f23f8a..cd501d1 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityBuilderWithStateTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityBuilderWithStateTest.java @@ -17,11 +17,9 @@ package org.apache.zest.runtime.entity; import java.util.Arrays; import java.util.Collections; -import java.util.Map; -import java.util.function.Function; +import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.junit.Test; import org.apache.zest.api.association.Association; -import org.apache.zest.api.association.AssociationDescriptor; import org.apache.zest.api.association.ManyAssociation; import org.apache.zest.api.association.NamedAssociation; import org.apache.zest.api.common.Optional; @@ -29,7 +27,6 @@ import org.apache.zest.api.entity.EntityBuilder; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.entity.Identity; import org.apache.zest.api.property.Property; -import org.apache.zest.api.property.PropertyDescriptor; import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException; import org.apache.zest.bootstrap.AssemblyException; @@ -52,6 +49,7 @@ public class EntityBuilderWithStateTest { new EntityTestAssembler().assemble( module ); module.entities( SomeEntity.class ); + new DefaultUnitOfWorkAssembler().assemble( module ); } @Test @@ -59,7 +57,7 @@ public class EntityBuilderWithStateTest throws UnitOfWorkCompletionException { final String associatedIdentity; - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { EntityBuilder<SomeEntity> builder = uow.newEntityBuilder( SomeEntity.class ); builder.instance().prop().set( "Associated" ); @@ -67,60 +65,40 @@ public class EntityBuilderWithStateTest associatedIdentity = entity.identity().get(); uow.complete(); } - try( UnitOfWork uow = module.newUnitOfWork() ) + try( UnitOfWork uow = uowf.newUnitOfWork() ) { SomeEntity entity = uow.newEntityBuilderWithState( SomeEntity.class, - new Function<PropertyDescriptor, Object>() - { - @Override - public Object apply( PropertyDescriptor descriptor ) + descriptor -> { + if( "prop".equals( descriptor.qualifiedName().name() ) ) { - if( "prop".equals( descriptor.qualifiedName().name() ) ) - { - return "Foo"; - } - return null; + return "Foo"; } + return null; }, - new Function<AssociationDescriptor, EntityReference>() - { - @Override - public EntityReference apply( AssociationDescriptor descriptor ) + descriptor -> { + if( "ass".equals( descriptor.qualifiedName().name() ) ) { - if( "ass".equals( descriptor.qualifiedName().name() ) ) - { - return EntityReference.parseEntityReference( associatedIdentity ); - } - return null; + return EntityReference.parseEntityReference( associatedIdentity ); } + return null; }, - new Function<AssociationDescriptor, Iterable<EntityReference>>() - { - @Override - public Iterable<EntityReference> apply( AssociationDescriptor descriptor ) + descriptor -> { + if( "manyAss".equals( descriptor.qualifiedName().name() ) ) { - if( "manyAss".equals( descriptor.qualifiedName().name() ) ) - { - return Arrays.asList( EntityReference.parseEntityReference( associatedIdentity ) ); - } - return null; + return Arrays.asList( EntityReference.parseEntityReference( associatedIdentity ) ); } + return null; }, - new Function<AssociationDescriptor, Map<String, EntityReference>>() - { - @Override - public Map<String, EntityReference> apply( AssociationDescriptor descriptor ) + descriptor -> { + if( "namedAss".equals( descriptor.qualifiedName().name() ) ) { - if( "namedAss".equals( descriptor.qualifiedName().name() ) ) - { - return Collections.singletonMap( - "foo", - EntityReference.parseEntityReference( associatedIdentity ) - ); - } - return null; + return Collections.singletonMap( + "foo", + EntityReference.parseEntityReference( associatedIdentity ) + ); } + return null; } ).newInstance(); assertThat( entity.prop().get(), equalTo( "Foo" ) ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCompositeEqualityTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCompositeEqualityTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCompositeEqualityTest.java index 980a3dd..f451f70 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCompositeEqualityTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCompositeEqualityTest.java @@ -49,7 +49,7 @@ public class EntityCompositeEqualityTest throws Exception { super.setUp(); - unitOfWork = this.module.newUnitOfWork(); + unitOfWork = this.uowf.newUnitOfWork(); myCompositeBuilder = unitOfWork.newEntityBuilder( MyComposite.class ); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java index d514312..d4b7f43 100755 --- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityCreationTest.java @@ -79,7 +79,7 @@ public class EntityCreationTest @Test public void doTestUseUowNewEntity() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); SomeEntity entity = uow.newEntity( SomeEntity.class ); uow.discard(); } @@ -87,7 +87,7 @@ public class EntityCreationTest @Test public void doTestUseEntityBuilder() { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); EntityBuilder<SomeEntity> builder = uow.newEntityBuilder( SomeEntity.class ); SomeEntity entity = builder.newInstance(); uow.discard(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/a5be013f/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityTypeTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityTypeTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityTypeTest.java index 2c15fdc..4a7c1d8 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityTypeTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/entity/EntityTypeTest.java @@ -34,7 +34,7 @@ public class EntityTypeTest public void givenSubclassedEntityWhenRequestingSuperclassExpectResolutionToWork() throws Exception { - UnitOfWork uow = module.newUnitOfWork(); + UnitOfWork uow = uowf.newUnitOfWork(); try { EntityBuilder<Rst> builder3 = uow.newEntityBuilder( Rst.class, "123" );
