Package org.qi4j.spi.entity

Examples of org.qi4j.spi.entity.EntityState


                                    {
                                        @Override
                                        public void receive( Reader item )
                                            throws ReceiverThrowableType
                                        {
                                            final EntityState entity = readEntityState( uow, item );
                                            if( entity.status() == EntityStatus.UPDATED )
                                            {
                                                migrated.add( entity );

                                                // Synch back 100 at a time
                                                if( migrated.size() > 100 )
View Full Code Here


                String storeVersion = versions.get( entityState.identity() );
                if( storeVersion == null )
                {
                    EntityStoreUnitOfWork unitOfWork = store.newUnitOfWork( Usecase.DEFAULT, module, currentTime );
                    EntityState state = unitOfWork.entityStateOf( entityState.identity() );
                    storeVersion = state.version();
                    unitOfWork.discard();
                }

                if( !entityState.version().equals( storeVersion ) )
                {
View Full Code Here

                                                               module,
                                                               System.currentTimeMillis() );

        try
        {
            EntityState entityState = getEntityState( uow );

            // Check modification date
            Date lastModified = getRequest().getConditions().getModifiedSince();
            if( lastModified != null )
            {
                if( lastModified.getTime() / 1000 == entityState.lastModified() / 1000 )
                {
                    throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED );
                }
            }
View Full Code Here

    }

    private EntityState getEntityState( EntityStoreUnitOfWork unitOfWork )
        throws ResourceException
    {
        EntityState entityState;
        try
        {
            EntityReference entityReference = EntityReference.parseEntityReference( identity );
            entityState = unitOfWork.entityStateOf( entityReference );
        }
View Full Code Here

    public Representation post( Representation entityRepresentation, Variant variant )
        throws ResourceException
    {
        Usecase usecase = UsecaseBuilder.newUsecase( "Update entity" );
        EntityStoreUnitOfWork unitOfWork = entityStore.newUnitOfWork( usecase, module, System.currentTimeMillis() );
        EntityState entity = getEntityState( unitOfWork );

        Form form = new Form( entityRepresentation );

        try
        {
            final EntityDescriptor descriptor = entity.entityDescriptor();

            // Parse JSON into properties
            for( PropertyDescriptor persistentProperty : descriptor.state().properties() )
            {
                if( !persistentProperty.isImmutable() )
                {
                    String formValue = form.getFirstValue( persistentProperty.qualifiedName().name(), null );
                    if( formValue == null )
                    {
                        entity.setPropertyValue( persistentProperty.qualifiedName(), null );
                    }
                    else
                    {
                        entity.setPropertyValue(
                            persistentProperty.qualifiedName(),
                            valueSerialization.deserialize( persistentProperty.valueType(), formValue ) );
                    }
                }
            }

            for( AssociationDescriptor associationType : descriptor.state().associations() )
            {
                String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() );
                if( newStringAssociation == null || newStringAssociation.isEmpty() )
                {
                    entity.setAssociationValue( associationType.qualifiedName(), null );
                }
                else
                {
                    entity.setAssociationValue( associationType.qualifiedName(),
                                                EntityReference.parseEntityReference( newStringAssociation ) );
                }
            }
            for( AssociationDescriptor associationType : descriptor.state().manyAssociations() )
            {
                String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() );
                ManyAssociationState manyAssociation = entity.manyAssociationValueOf( associationType.qualifiedName() );
                if( newStringAssociation == null )
                {
                    // Remove "left-overs"
                    for( EntityReference entityReference : manyAssociation )
                    {
                        manyAssociation.remove( entityReference );
                    }
                    continue;
                }

                BufferedReader bufferedReader = new BufferedReader( new StringReader( newStringAssociation ) );
                String identity;

                try
                {
                    // Synchronize old and new association
                    int index = 0;
                    while( ( identity = bufferedReader.readLine() ) != null )
                    {
                        EntityReference reference = new EntityReference( identity );

                        if( manyAssociation.count() < index && manyAssociation.get( index ).equals( reference ) )
                        {
                            continue;
                        }

                        try
                        {
                            unitOfWork.entityStateOf( reference );

                            manyAssociation.remove( reference );
                            manyAssociation.add( index++, reference );
                        }
                        catch( EntityNotFoundException e )
                        {
                            // Ignore this entity - doesn't exist
                        }
                    }

                    // Remove "left-overs"
                    while( manyAssociation.count() > index )
                    {
                        manyAssociation.remove( manyAssociation.get( index ) );
                    }
                }
                catch( IOException e )
                {
                    // Ignore
                }
            }
            for( AssociationDescriptor associationType : descriptor.state().namedAssociations() )
            {
                String newStringAssociation = form.getFirstValue( associationType.qualifiedName().name() );
                NamedAssociationState namedAssociation = entity.namedAssociationValueOf( associationType.qualifiedName() );
                if( newStringAssociation == null )
                {
                    // Remove "left-overs"
                    for( String name : namedAssociation )
                    {
View Full Code Here

        {
            lock.readLock().lock();

            try
            {
               EntityState entityState = uow.entityStateOf( anIdentity );
               versions.rememberVersion( entityState.identity(), entityState.version() );
               loaded.add( entityState );
               return entityState;
            } finally
            {
               lock.readLock().unlock();
View Full Code Here

    @Override
    public EntityState newEntityState( EntityReference anIdentity, EntityDescriptor descriptor )
        throws EntityStoreException
    {
        EntityState entityState = states.get( anIdentity );
        if( entityState != null )
        {
            throw new EntityAlreadyExistsException( anIdentity );
        }
        EntityState state = entityStoreSPI.newEntityState( this, anIdentity, descriptor );
        states.put( anIdentity, state );
        return state;
    }
View Full Code Here

    @Override
    public EntityState entityStateOf( EntityReference anIdentity )
        throws EntityNotFoundException
    {

        EntityState entityState = states.get( anIdentity );
        if( entityState != null )
        {
            return entityState;
        }
        entityState = entityStoreSPI.entityStateOf( this, anIdentity );
View Full Code Here

                        // Event to play for an entity that doesn't yet exist - create a default instance
                        entity = uow.newEntity( entityType, id );
                    }

                    // check if the event has already occured
                    EntityState state = spi.entityStateOf( (EntityComposite) entity );
                    if (state.lastModified() > unitOfWorkDomainValue.timestamp().get())
                    {
                        break; // don't rerun event in this unitOfWorkDomainValue
                    }

                    playEvent( domainEventValue, entity );
View Full Code Here

    @Test
    public void testEntitySerializer() throws RDFHandlerException
    {
        EntityReference entityReference = new EntityReference( "test2" );
        EntityState entityState = entityStore.newUnitOfWork( UsecaseBuilder.newUsecase( "Test" ), module, System.currentTimeMillis() ).entityStateOf( entityReference );

        Iterable<Statement> graph = serializer.serialize( entityState );

        String[] prefixes = new String[]{ "rdf", "dc", " vc" };
        String[] namespaces = new String[]{ Rdfs.RDF, DcRdf.NAMESPACE, "http://www.w3.org/2001/vcard-rdf/3.0#" };
View Full Code Here

TOP

Related Classes of org.qi4j.spi.entity.EntityState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.