public T newInstance( Module module ) { EntityBuilder<T> builder = module.currentUnitOfWork().newEntityBuilder( type ); build( builder.instance() ); return builder.newInstance(); } }
protected <T> T createInstance( EntityBuilder<?> builder ) { return (T) builder.newInstance(); }
@Override public <T> T create( Class<T> entityType, Object value, Function<T, T> prototypeOpportunity ) { EntityBuilder<?> builder = doConversion( entityType, null, value ); prototypeOpportunity.map( (T) builder.instance() ); return createInstance( builder ); }
@Test public void givenPropertyIsModifiedWhenUnitOfWorkCompletesThenStoreState() throws UnitOfWorkCompletionException { TestEntity testEntity; String version; { UnitOfWork unitOfWork = module.newUnitOfWork(); EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class ); testEntity = builder.newInstance(); unitOfWork.complete(); } { UnitOfWork unitOfWork = module.newUnitOfWork(); testEntity = unitOfWork.get( testEntity ); testEntity.name().set( "Rickard" ); version = spi.entityStateOf( testEntity ).version(); unitOfWork.complete(); } { UnitOfWork unitOfWork = module.newUnitOfWork(); testEntity = unitOfWork.get( testEntity ); String newVersion = spi.entityStateOf( testEntity ).version(); assertThat( "version has changed", newVersion, not( equalTo( version ) ) ); unitOfWork.complete(); } }
@Override public <T> T create( Class<T> entityType, String identity, Object value, Function<T, T> prototypeOpportunity ) { EntityBuilder<?> builder = doConversion( entityType, identity, value ); prototypeOpportunity.map( (T) builder.instance() ); return createInstance( builder ); }
private BarEntity buildBarEntity( String cathedral ) { EntityBuilder<BarEntity> barBuilder = module.currentUnitOfWork().newEntityBuilder( BarEntity.class ); barBuilder.instance().cathedral().set( cathedral ); return barBuilder.newInstance(); }
@Test public void givenManyAssociationIsModifiedWhenUnitOfWorkCompletesThenStoreState() throws UnitOfWorkCompletionException { TestEntity testEntity; String version; { UnitOfWork unitOfWork = module.newUnitOfWork(); EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class ); testEntity = builder.newInstance(); unitOfWork.complete(); } { UnitOfWork unitOfWork = module.newUnitOfWork(); testEntity = unitOfWork.get( testEntity ); testEntity.manyAssociation().add( 0, testEntity ); version = spi.entityStateOf( testEntity ).version(); unitOfWork.complete(); } { UnitOfWork unitOfWork = module.newUnitOfWork(); testEntity = unitOfWork.get( testEntity ); String newVersion = spi.entityStateOf( testEntity ).version(); assertThat( "version has changed", newVersion, not( equalTo( version ) ) ); unitOfWork.complete(); } }
private <C, V> V tryLoadPropertiesFile( UnitOfWork buildUow, Class<C> compositeType, Class<V> configType, String identity ) throws InstantiationException { EntityBuilder<V> configBuilder = buildUow.newEntityBuilder( configType, identity ); String resourceName = identity + ".properties"; InputStream asStream = getResource( compositeType, resourceName ); if( asStream != null ) { try { PropertyMapper.map( asStream, (Composite) configBuilder.instance() ); return configBuilder.newInstance(); } catch( IOException e1 ) { InstantiationException exception = new InstantiationException( "Could not read underlying Properties file." ); exception.initCause( e1 ); throw exception; } } return null; }
@Test public void givenEntityIsNotModifiedWhenUnitOfWorkCompletesThenDontStoreState() throws UnitOfWorkCompletionException { TestEntity testEntity; String version; { UnitOfWork unitOfWork = module.newUnitOfWork(); EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class ); testEntity = builder.newInstance(); unitOfWork.complete(); } { UnitOfWork unitOfWork = module.newUnitOfWork(); testEntity = unitOfWork.get( testEntity ); version = spi.entityStateOf( testEntity ).version(); unitOfWork.complete(); } { UnitOfWork unitOfWork = module.newUnitOfWork(); testEntity = unitOfWork.get( testEntity ); String newVersion = spi.entityStateOf( testEntity ).version(); assertThat( "version has not changed", newVersion, equalTo( version ) ); unitOfWork.complete(); } }
@Override public Revocation create( X509 x509, RevocationReason reason ) { EntityBuilder<Revocation> builder = uowf.currentUnitOfWork().newEntityBuilder( Revocation.class ); Revocation revocation = builder.instance(); revocation.x509().set( x509 ); revocation.reason().set( reason ); return builder.newInstance(); }
EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class ); testEntity = builder.newInstance(); unitOfWork.complete();
@Override public X509ProfileAssignment create( KeyEscrowPolicy keyEscrowPolicy, X509Profile profile ) { EntityBuilder<X509ProfileAssignment> profileAssignmentBuilder = uowf.currentUnitOfWork().newEntityBuilder( X509ProfileAssignment.class ); X509ProfileAssignment profileAssignment = profileAssignmentBuilder.instance(); profileAssignment.keyEscrowPolicy().set( keyEscrowPolicy ); profileAssignment.x509Profile().set( profile ); return profileAssignmentBuilder.newInstance(); }
configBuilder.newInstance();
@Override public CRL create( X509CRL x509crl ) { EntityBuilder<CRL> crlBuilder = uowf.currentUnitOfWork().newEntityBuilder( CRL.class ); CRL crl = crlBuilder.instance(); crl.lastCRLNumber().set( BigInteger.ZERO ); crl = crlBuilder.newInstance(); FileWriter fileWriter = null; try { fileWriter = new FileWriter( crl.managedFile() ); fileWriter.write( cryptIO.asPEM( x509crl ).toString() ); fileWriter.flush(); return crl; } catch ( IOException ex ) { throw new QiPkiFailure( "Unable to revoke X509", ex ); } finally { try { if ( fileWriter != null ) { fileWriter.close(); } } catch ( IOException ex ) { throw new QiPkiFailure( "Unable to revoke X509", ex ); } } }
private void createLogRecord( UnitOfWork uow, LogType type, Composite composite, String category, String message, List<Serializable> params ) { if( composite instanceof ServiceComposite ) { EntityBuilder<ServiceLogRecord> builder = uow.newEntityBuilder( ServiceLogRecord.class ); ServiceLogRecord state = builder.instance(); setStandardStuff( type, composite, category, message, state, params ); state.source().set( ( (ServiceComposite) composite ).identity().get() ); ServiceLogRecord slr = builder.newInstance(); } else if( composite instanceof EntityComposite ) { EntityBuilder<EntityLogRecord> builder = uow.newEntityBuilder( EntityLogRecord.class ); EntityLogRecord state = builder.instance(); setStandardStuff( type, composite, category, message, state, params ); state.source().set( (EntityComposite) composite ); EntityLogRecord elr = builder.newInstance(); } else { EntityBuilder<CompositeLogRecord> builder = uow.newEntityBuilder( CompositeLogRecord.class ); CompositeLogRecord state = builder.instance(); setStandardStuff( type, composite, category, message, state, params ); state.source().set( composite ); CompositeLogRecord clr = builder.newInstance(); } }
private void createDebugRecord( UnitOfWork uow, Composite composite, String message, List<Serializable> params ) { if( composite instanceof ServiceComposite ) { EntityBuilder<ServiceDebugRecordEntity> builder = uow.newEntityBuilder( ServiceDebugRecordEntity.class ); ServiceDebugRecordEntity state = builder.instance(); setStandardStuff( composite, message, state, params ); state.source().set( ( (ServiceComposite) composite ).identity().get() ); ServiceDebugRecordEntity slr = builder.newInstance(); } else if( composite instanceof EntityComposite ) { EntityBuilder<EntityDebugRecordEntity> builder = uow.newEntityBuilder( EntityDebugRecordEntity.class ); EntityDebugRecordEntity state = builder.instance(); setStandardStuff( composite, message, state, params ); state.source().set( (EntityComposite) composite ); EntityDebugRecordEntity elr = builder.newInstance(); } else { EntityBuilder<CompositeDebugRecordEntity> builder = uow.newEntityBuilder( CompositeDebugRecordEntity.class ); CompositeDebugRecordEntity state = builder.instance(); setStandardStuff( composite, message, state, params ); state.source().set( composite ); CompositeDebugRecordEntity clr = builder.newInstance(); } }
Qi4j.FUNCTION_DESCRIPTOR_FOR.map( entity ).types() ), identity ); EntityBuilder<EntityTraceRecordEntity> builder = uow.newEntityBuilder( EntityTraceRecordEntity.class ); EntityTraceRecordEntity state = builder.instance(); setStandardStuff( compositeType, method, args, entryTime, durationNano, state, exception ); state.source().set( source ); EntityTraceRecordEntity etr = builder.newInstance(); // Record is created. ServiceTraceRecordEntity state = builder.instance(); setStandardStuff( compositeType, method, args, entryTime, durationNano, state, exception ); state.source().set( service.toString() ); ServiceTraceRecordEntity str = builder.newInstance(); // Record is created. CompositeTraceRecordEntity state = builder.instance(); state.source().set( object ); setStandardStuff( compositeType, method, args, entryTime, durationNano, state, exception ); CompositeTraceRecordEntity ctr = builder.newInstance(); // Record is created.
private Schedule newPersistentOnceSchedule( Task task, DateTime runAt ) { UnitOfWork uow = module.currentUnitOfWork(); EntityBuilder<OnceSchedule> builder = uow.newEntityBuilder( OnceSchedule.class ); OnceSchedule builderInstance = builder.instance(); builderInstance.task().set( task ); builderInstance.start().set( runAt ); builderInstance.identity().set( uuid.generate( CronSchedule.class ) ); OnceSchedule schedule = builder.newInstance(); logger.info( "Schedule {} created: {}", schedule.presentationString(), schedule.identity().get() ); return schedule; } }
if ( asStream != null ) { try { PropertyMapper.map( asStream, configBuilder.instance() ); } catch ( IOException e1 ) { uow.discard(); DataSourceConfiguration configEntity = configBuilder.newInstance(); config = entityToValue.convert( DataSourceConfigurationValue.class, configEntity );
@Override public EscrowedKeyPair create( AsymetricAlgorithm algorithm, Integer length ) { EntityBuilder<EscrowedKeyPair> builder = uowf.currentUnitOfWork().newEntityBuilder( EscrowedKeyPair.class ); EscrowedKeyPair ekp = builder.instance(); ekp.algorithm().set( algorithm ); ekp.length().set( length ); ekp = builder.newInstance(); KeyPair keyPair = asymGenerator.generateKeyPair( new AsymetricGeneratorParameters( algorithm, length ) ); writeToFile( cryptIO.asPEM( keyPair ), ekp.managedFile() ); return ekp; }