Package info.archinnov.achilles.internal.metadata.holder

Examples of info.archinnov.achilles.internal.metadata.holder.EntityMeta


        // Given
        PropertyMeta idMeta = PropertyMetaTestBuilder.completeBean(Void.class, Long.class).propertyName("id").type(ID).accessors().build();

        PropertyMeta nameMeta = PropertyMetaTestBuilder.completeBean(Void.class, String.class).propertyName("name").type(SIMPLE).accessors().build();

        EntityMeta meta = buildEntityMeta(idMeta, nameMeta);

        RegularStatement statement = select().from("test");

        initBuilder(statement, meta, meta.getPropertyMetas(), MANAGED);

        when(daoContext.execute(any(AbstractStatementWrapper.class))).thenReturn(futureResultSet);
        when(asyncUtils.transformFuture(futureResultSet, RESULTSET_TO_ROWS, executorService)).thenReturn(futureRows);
        when(asyncUtils.transformFuture(eq(futureRows), rowsToEntitiesCaptor.capture(), eq(executorService))).thenReturn(futureEntities);
        when(asyncUtils.transformFuture(eq(futureEntities), isoEntitiesCaptor.capture(), eq(executorService))).thenReturn(futureEntities);
        when(asyncUtils.buildInterruptible(futureEntities)).thenReturn(achillesFuturesEntities);

        when(mapper.mapRowToEntityWithPrimaryKey(eq(meta), eq(row), Mockito.<Map<String, PropertyMeta>>any(), eq(MANAGED))).thenReturn(entity);
        when(contextFactory.newContext(entity)).thenReturn(context);
        when(proxifier.buildProxyWithAllFieldsLoadedExceptCounters(entity, entityFacade)).thenReturn(entity);

        // When
        final AchillesFuture<List<CompleteBean>> actual = typedQuery.asyncGet(asyncListeners);

        // Then
        assertThat(actual).isSameAs(achillesFuturesEntities);
        verify(asyncUtils).maybeAddAsyncListeners(futureEntities, asyncListeners, executorService);

        final Function<List<Row>, List<CompleteBean>> rowsToEntities = rowsToEntitiesCaptor.getValue();
        final List<CompleteBean> entities = rowsToEntities.apply(asList(row));
        assertThat(entities).containsExactly(entity);

        final List<Function<List<CompleteBean>, List<CompleteBean>>> entitiesFunctions = isoEntitiesCaptor.getAllValues();

        final List<CompleteBean> entitiesWithTriggers = entitiesFunctions.get(0).apply(asList(entity));
        assertThat(entitiesWithTriggers).containsExactly(entity);
        verify(meta.forInterception()).intercept(entity, Event.POST_LOAD);

        final List<CompleteBean> entitiesWithProxy = entitiesFunctions.get(1).apply(asList(entity));
        assertThat(entitiesWithProxy).containsExactly(entity);
    }
View Full Code Here


                .type(PropertyType.ID).accessors().build();

        PropertyMeta nameMeta = PropertyMetaTestBuilder.completeBean(Void.class, String.class).propertyName("name")
                .type(PropertyType.SIMPLE).accessors().build();

        EntityMeta meta = buildEntityMeta(idMeta, nameMeta);

        RegularStatement statement = select("id").from("test");
        initBuilder(statement, meta, meta.getPropertyMetas(), MANAGED);

        when(daoContext.execute(any(AbstractStatementWrapper.class))).thenReturn(futureResultSet);
        when(asyncUtils.transformFuture(futureResultSet, RESULTSET_TO_ROW, executorService)).thenReturn(futureRow);
        when(asyncUtils.transformFuture(eq(futureRow), rowToEntityCaptor.capture(), eq(executorService))).thenReturn(futureEntity);
        when(asyncUtils.transformFuture(eq(futureEntity), isoEntityCaptor.capture(), eq(executorService))).thenReturn(futureEntity);
        when(asyncUtils.buildInterruptible(futureEntity)).thenReturn(achillesFuturesEntity);

        when(mapper.mapRowToEntityWithPrimaryKey(eq(meta), eq(row), Mockito.<Map<String, PropertyMeta>>any(), eq(MANAGED))).thenReturn(entity);
        when(contextFactory.newContext(entity)).thenReturn(context);
        when(proxifier.buildProxyWithAllFieldsLoadedExceptCounters(entity, entityFacade)).thenReturn(entity);

        // When
        final AchillesFuture<CompleteBean> actual = typedQuery.asyncGetFirst(asyncListeners);

        // Then
        assertThat(actual).isSameAs(achillesFuturesEntity);
        verify(asyncUtils).maybeAddAsyncListeners(futureEntity, asyncListeners, executorService);

        final CompleteBean actualEntity = rowToEntityCaptor.getValue().apply(row);
        assertThat(actualEntity).isSameAs(entity);

        final List<Function<CompleteBean, CompleteBean>> captured = isoEntityCaptor.getAllValues();
        final CompleteBean applyTriggers = captured.get(0).apply(entity);
        assertThat(applyTriggers).isSameAs(entity);
        verify(meta.forInterception()).intercept(entity, Event.POST_LOAD);

        final CompleteBean proxifiedEntity = captured.get(1).apply(entity);
        assertThat(proxifiedEntity).isSameAs(entity);
    }
View Full Code Here

    public void should_bootstrap_persistence_manager_factory() throws Exception {
        // Given
        List<Class<?>> candidateClasses = Arrays.asList();
        List<Interceptor<?>> interceptors = Arrays.asList();
        Map<Class<?>, EntityMeta> entityMetaMap = ImmutableMap.<Class<?>, EntityMeta>of(CompleteBean.class,
                new EntityMeta());
        ParsingResult parsingResult = new ParsingResult(entityMetaMap, true);
        final ClassLoader classLoader = this.getClass().getClassLoader();

        // When
        when(argumentExtractor.initConfigContext(configMap)).thenReturn(configContext);
View Full Code Here

    private EntityMapper mapper = EntityMapper.Singleton.INSTANCE.get();
    private ConsistencyOverrider overrider = ConsistencyOverrider.Singleton.INSTANCE.get();
    private AsyncUtils asyncUtils = AsyncUtils.Singleton.INSTANCE.get();

    public <T> AchillesFuture<T> loadClusteredCounters(final EntityOperations context) {
        final EntityMeta entityMeta = context.getEntityMeta();
        final Object primaryKey = context.getPrimaryKey();

        final ListenableFuture<Row> futureRow = context.getClusteredCounter();
        Function<Row, T> rowToEntity = new Function<Row, T>() {
            @Override
            public T apply(Row row) {
                T entity = null;
                if (row != null) {
                    entity = entityMeta.forOperations().instanciate();
                    entityMeta.getIdMeta().forValues().setValueToField(entity, primaryKey);

                    for (PropertyMeta counterMeta : context.getAllCountersMeta()) {
                        mapper.setCounterToEntity(counterMeta, entity, row);
                    }
                }
View Full Code Here

        log.debug("Build meta data for candidate entities");
        Map<Class<?>, EntityMeta> entityMetaMap = new HashMap<>();
        boolean hasSimpleCounter = false;
        for (Class<?> entityClass : entities) {
            EntityParsingContext context = new EntityParsingContext(configContext, entityClass);
            EntityMeta entityMeta = entityParser.parseEntity(context);
            entityMetaMap.put(entityClass, entityMeta);

            hasSimpleCounter = hasSimpleCounter || (context.hasSimpleCounter() && !entityMeta.structure().isClusteredCounter());
            boolean shouldValidateBean = configContext.isClassConstrained(entityClass);
            if (shouldValidateBean) {
                configContext.addBeanValidationInterceptor(entityMeta);
            }
        }
View Full Code Here

    public void validateOrCreateTables(SchemaContext schemaContext) {
        log.debug("Start schema validation/creation");
        Map<String, TableMetadata> tableMetaDatas = schemaContext.fetchTableMetaData();

        for (Entry<Class<?>, EntityMeta> entry : schemaContext.entityMetaEntrySet()) {
            EntityMeta entityMeta = entry.getValue();
            final EntityMetaConfig metaConfig = entityMeta.config();
            String qualifiedTableName = metaConfig.getQualifiedTableName().toLowerCase();

            if (tableMetaDatas.containsKey(qualifiedTableName)) {
                TableMetadata tableMetaData = tableMetaDatas.get(qualifiedTableName);
                schemaContext.validateForEntity(entityMeta, tableMetaData);
View Full Code Here

    public void addInterceptorsToEntityMetas(List<Interceptor<?>> interceptors, Map<Class<?>,
            EntityMeta> entityMetaMap) {
        for (Interceptor<?> interceptor : interceptors) {
            Class<?> entityClass = propertyParser.inferEntityClassFromInterceptor(interceptor);
            EntityMeta entityMeta = entityMetaMap.get(entityClass);
            Validator.validateBeanMappingTrue(entityMeta != null, "The entity class '%s' is not found",
                    entityClass.getCanonicalName());
            entityMeta.forInterception().addInterceptor(interceptor);
        }
    }
View Full Code Here

        return counterDelta;
    }

    public void deleteRelatedCounters(EntityOperations context) {
        log.trace("Deleting counter values related to entity using PersistenceContext {}", context);
        EntityMeta entityMeta = context.getEntityMeta();

        for (PropertyMeta pm : entityMeta.getAllCounterMetas()) {
            context.bindForSimpleCounterDeletion(pm);
        }
    }
View Full Code Here

    public void update(EntityOperations context, Object entity) {
        log.debug("Merging entity of class {} with primary key {}", context.getEntityClass().getCanonicalName(),
                context.getPrimaryKey());

        EntityMeta entityMeta = context.getEntityMeta();

        Validator.validateNotNull(entity, "Proxy object should not be null for update");
        Validator.validateNotNull(entityMeta, "entityMeta should not be null for update");

        log.debug("Checking for dirty fields before merging");

        Object realObject = proxifier.getRealObject(entity);
        context.setEntity(realObject);

        ProxyInterceptor<Object> interceptor = proxifier.getInterceptor(entity);
        Map<Method, DirtyChecker> dirtyMap = interceptor.getDirtyMap();
        List<DirtyChecker> dirtyCheckers = new ArrayList<>(dirtyMap.values());

        if (dirtyCheckers.size() > 0) {
            pushDirtySimpleFields(context, dirtyCheckers);
            pushCollectionAndMapUpdates(context, dirtyCheckers);
            dirtyMap.clear();
        }

        if (context.isClusteredCounter()) {
            counterPersister.persistClusteredCounters(context);
        } else {
            counterPersister.persistCounters(context, entityMeta.getAllCounterMetas());
        }
        interceptor.setEntityOperations(context);
        interceptor.setTarget(realObject);
    }
View Full Code Here

        Class<?> proxyClass = factory.createProxyClass(entity.getClass(), context.getConfigContext());

        @SuppressWarnings("unchecked")
        T instance = (T) instantiator.instantiate(proxyClass);

        EntityMeta meta = context.getEntityMeta();
        for (PropertyMeta pm : meta.getAllMetasExceptCounters()) {
            Object value = pm.forValues().getValueFromField(entity);
            pm.forValues().setValueToField(instance, value);
        }

        for (PropertyMeta pm : meta.getAllCounterMetas()) {
            pm.forValues().setValueToField(entity,null);
        }

        ((Factory) instance).setCallbacks(new Callback[] {
                buildInterceptor(context, entity, alreadyLoaded),
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.internal.metadata.holder.EntityMeta

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.