Examples of PersistentProperty


Examples of com.cathive.fx.guice.PersistentProperty

    @Override
    public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) {
        for (final Field field : typeLiteral.getRawType().getDeclaredFields()) {
            if (field.isAnnotationPresent(PersistentProperty.class)) {
                final PersistentProperty annotation = field.getAnnotation(PersistentProperty.class);
                typeEncounter.register(new PersistentPropertyMembersInjector<T>(field, annotation));
            }
        }
    }
View Full Code Here

Examples of com.spaceprogram.simplejpa.PersistentProperty

        long start = System.currentTimeMillis();
        em.invokeEntityListener(o, newObject ? PrePersist.class : PreUpdate.class);
        AnnotationInfo ai = em.getFactory().getAnnotationManager().getAnnotationInfo(o);

        UpdateCondition expected = null;
        PersistentProperty versionField = null;
        Long nextVersion = -1L;

        String domainName;
        if (ai.getRootClass() != null) {
            domainName = em.getOrCreateDomain(ai.getRootClass());
        } else {
            domainName = em.getOrCreateDomain(o.getClass());
        }
        // Item item = DomainHelper.findItemById(this.em.getSimpleDb(),
        // domainName, id);
        // now set attributes
        List<ReplaceableAttribute> attsToPut = new ArrayList<ReplaceableAttribute>();
        List<Attribute> attsToDelete = new ArrayList<Attribute>();
        if (ai.getDiscriminatorValue() != null) {
            attsToPut.add(new ReplaceableAttribute(EntityManagerFactoryImpl.DTYPE, ai.getDiscriminatorValue(), true));
        }

        LazyInterceptor interceptor = null;
        if (o instanceof Factory) {
            Factory factory = (Factory) o;
            /*
             * for (Callback callback2 : factory.getCallbacks()) {
             * if(logger.isLoggable(Level.FINER)) logger.finer("callback=" +
             * callback2); if (callback2 instanceof LazyInterceptor) {
             * interceptor = (LazyInterceptor) callback2; } }
             */
            interceptor = (LazyInterceptor) factory.getCallback(0);
        }

        for (PersistentProperty field : ai.getPersistentProperties()) {
            Object ob = field.getProperty(o);

            String columnName = field.getColumnName();
            if (ob == null) {
                attsToDelete.add(new Attribute(columnName, null));
                continue;
            }
            if (field.isForeignKeyRelationship()) {
                // store the id of this object
                if (Collection.class.isAssignableFrom(field.getRawClass())) {
                    for (Object each : (Collection) ob) {
                        String id2 = em.getId(each);
                        attsToPut.add(new ReplaceableAttribute(columnName, id2, true));
                    }
                } else {
                    String id2 = em.getId(ob);
                    attsToPut.add(new ReplaceableAttribute(columnName, id2, true));

                    /* check if we should persist this */
                    boolean persistRelationship = false;
                    ManyToOne a = field.getGetter().getAnnotation(ManyToOne.class);
                    if (a != null && null != a.cascade()) {
                        CascadeType[] cascadeType = a.cascade();
                        for (CascadeType type : cascadeType) {
                            if (CascadeType.ALL == type || CascadeType.PERSIST == type) {
                                persistRelationship = true;
                            }
                        }
                    }
                    if (persistRelationship) {
                        em.persist(ob);
                    }
                }
            } else if (field.isVersioned()) {
                Long curVersion = Long.parseLong("" + ob);
                nextVersion = (1 + curVersion);

                attsToPut.add(new ReplaceableAttribute(columnName, em.padOrConvertIfRequired(nextVersion), true));

                if (curVersion > 0) {
                    expected = new UpdateCondition(columnName, em.padOrConvertIfRequired(curVersion), true);
                } else {
                    expected = new UpdateCondition().withName(columnName).withExists(false);
                }

                versionField = field;
            } else if (field.isInverseRelationship()) {
                // FORCING BI-DIRECTIONAL RIGHT NOW SO JUST IGNORE
                // ... except for cascading persistence down to all items in the
                // OneToMany collection
                /* check if we should persist this */
                boolean persistRelationship = false;
                OneToMany a = field.getGetter().getAnnotation(OneToMany.class);
                CascadeType[] cascadeType = a.cascade();
                for (CascadeType type : cascadeType) {
                    if (CascadeType.ALL == type || CascadeType.PERSIST == type) {
                        persistRelationship = true;
                    }
                }
                if (persistRelationship) {
                    if (ob instanceof Collection) {
                        // it's OneToMany, so this should always be the case,
                        // shouldn't it?
                        for (Object _item : (Collection) ob) {
                            // persist each item in the collection
                            em.persist(_item);
                        }
                    }
                }

            } else if (field.isLob()) {
                // store in s3
                AmazonS3 s3 = null;
                // todo: need to make sure we only store to S3 if it's changed,
                // too slow.
                logger.fine("putting lob to s3");
                long start3 = System.currentTimeMillis();
                s3 = em.getS3Service();
                String bucketName = em.getS3BucketName();
                String s3ObjectId = id + "-" + field.getFieldName();

                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream(bos);
                out.writeObject(ob);
                byte[] contentBytes = bos.toByteArray();
                out.close();
                InputStream input = new ByteArrayInputStream(contentBytes);

                s3.putObject(bucketName, s3ObjectId, input, null);

                em.statsS3Put(System.currentTimeMillis() - start3);
                logger.finer("setting lobkeyattribute=" + columnName + " - " + s3ObjectId);
                attsToPut.add(new ReplaceableAttribute(columnName, s3ObjectId, true));
            } else if (field.getEnumType() != null) {
                String toSet = getEnumValue(field, o);
                attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
            } else if (field.isId()) {
                continue;
            } else if (Collection.class.isInstance(ob)) {
                for (Object each : ((Collection) ob)) {
                    String toSet = each != null ? em.padOrConvertIfRequired(each) : "";
                    // todo: throw an exception if this is going to exceed
                    // maximum size, suggest using @Lob
                    attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
                }
            } else {
                String toSet = ob != null ? em.padOrConvertIfRequired(ob) : "";
                // todo: throw an exception if this is going to exceed maximum
                // size, suggest using @Lob
                attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
            }
        }

        // Now finally send it for storage (If have attributes to add)
        long start2 = System.currentTimeMillis();
        long duration2;
        if (!attsToPut.isEmpty()) {
            this.em.getSimpleDb().putAttributes(
                    new PutAttributesRequest().withDomainName(domainName).withItemName(id).withAttributes(attsToPut)
                            .withExpected(expected));
            duration2 = System.currentTimeMillis() - start2;
            if (logger.isLoggable(Level.FINE))
                logger.fine("putAttributes time=" + (duration2));
            em.statsAttsPut(attsToPut.size(), duration2);

            if (null != versionField)
                versionField.setProperty(o, nextVersion);
        }

        /*
         * Check for nulled attributes so we can send a delete call. Don't
         * delete attributes if this is a new object AND don't delete atts if
View Full Code Here

Examples of com.spaceprogram.simplejpa.PersistentProperty

        long start = System.currentTimeMillis();
        em.invokeEntityListener(o, newObject ? PrePersist.class : PreUpdate.class);
        AnnotationInfo ai = em.getFactory().getAnnotationManager().getAnnotationInfo(o);

        UpdateCondition expected = null;
        PersistentProperty versionField = null;
        Integer nextVersion = -1;

        String domainName;
        if (ai.getRootClass() != null) {
            domainName = em.getOrCreateDomain(ai.getRootClass());
        } else {
            domainName = em.getOrCreateDomain(o.getClass());
        }
        // Item item = DomainHelper.findItemById(this.em.getSimpleDb(),
        // domainName, id);
        // now set attributes
        List<ReplaceableAttribute> attsToPut = new ArrayList<ReplaceableAttribute>();
        List<Attribute> attsToDelete = new ArrayList<Attribute>();
        if (ai.getDiscriminatorValue() != null) {
            attsToPut.add(new ReplaceableAttribute(EntityManagerFactoryImpl.DTYPE, ai.getDiscriminatorValue(), true));
        }

        LazyInterceptor interceptor = null;
        if (o instanceof Factory) {
            Factory factory = (Factory) o;
            /*
             * for (Callback callback2 : factory.getCallbacks()) {
             * if(logger.isLoggable(Level.FINER)) logger.finer("callback=" +
             * callback2); if (callback2 instanceof LazyInterceptor) {
             * interceptor = (LazyInterceptor) callback2; } }
             */
            interceptor = (LazyInterceptor) factory.getCallback(0);
        }

        for (PersistentProperty field : ai.getPersistentProperties()) {
            Object ob = field.getProperty(o);

            String columnName = field.getColumnName();
            if (ob == null) {
                attsToDelete.add(new Attribute(columnName, null));
                continue;
            }
            if (field.isForeignKeyRelationship()) {
                // store the id of this object
                if (Collection.class.isAssignableFrom(field.getRawClass())) {
                    for (Object each : (Collection) ob) {
                        String id2 = em.getId(each);
                        attsToPut.add(new ReplaceableAttribute(columnName, id2, true));
                    }
                } else {
                    String id2 = em.getId(ob);
                    attsToPut.add(new ReplaceableAttribute(columnName, id2, true));

                    /* check if we should persist this */
                    boolean persistRelationship = false;
                    ManyToOne a = field.getGetter().getAnnotation(ManyToOne.class);
                    if (a != null && null != a.cascade()) {
                        CascadeType[] cascadeType = a.cascade();
                        for (CascadeType type : cascadeType) {
                            if (CascadeType.ALL == type || CascadeType.PERSIST == type) {
                                persistRelationship = true;
                            }
                        }
                    }
                    if (persistRelationship) {
                        em.persist(ob);
                    }
                }
            } else if (field.isVersioned()) {
                Integer curVersion = Integer.parseInt("" + ob);
                nextVersion = (1 + curVersion);

                attsToPut.add(new ReplaceableAttribute(columnName, em.padOrConvertIfRequired(nextVersion), true));

                if (curVersion > 0)
                    expected = new UpdateCondition(columnName, em.padOrConvertIfRequired(curVersion), true);

                versionField = field;
            } else if (field.isInverseRelationship()) {
                // FORCING BI-DIRECTIONAL RIGHT NOW SO JUST IGNORE
                // ... except for cascading persistence down to all items in the
                // OneToMany collection
                /* check if we should persist this */
                boolean persistRelationship = false;
                OneToMany a = field.getGetter().getAnnotation(OneToMany.class);
                CascadeType[] cascadeType = a.cascade();
                for (CascadeType type : cascadeType) {
                    if (CascadeType.ALL == type || CascadeType.PERSIST == type) {
                        persistRelationship = true;
                    }
                }
                if (persistRelationship) {
                    if (ob instanceof Collection) {
                        // it's OneToMany, so this should always be the case,
                        // shouldn't it?
                        for (Object _item : (Collection) ob) {
                            // persist each item in the collection
                            em.persist(_item);
                        }
                    }
                }
            } else if (field.isJsonLob()) {
                AmazonS3 s3 = em.getS3Service();

                long start3 = System.currentTimeMillis();
                String bucketName = em.getS3BucketName();
                String classRef = ai.getRootClass().getName().replace('.', '/');
                long lobTimestamp = System.currentTimeMillis() / 1000;
                String s3ObjectId = String.format("%s/%s/%08X.json", classRef, id + "-" + field.getFieldName(),
                        lobTimestamp);

                byte[] contentBytes = getJsonPayload(ob);

                InputStream input = new ByteArrayInputStream(contentBytes);

                s3.putObject(bucketName, s3ObjectId, input, null);

                em.statsS3Put(System.currentTimeMillis() - start3);
                logger.finer("setting lobkeyattribute=" + columnName + " - " + s3ObjectId);
                attsToPut.add(new ReplaceableAttribute(columnName, s3ObjectId, true));
            } else if (field.isLob()) {
                // store in s3
                AmazonS3 s3 = null;
                // todo: need to make sure we only store to S3 if it's changed,
                // too slow.
                logger.fine("putting lob to s3");
                long start3 = System.currentTimeMillis();
                s3 = em.getS3Service();
                String bucketName = em.getS3BucketName();
                String s3ObjectId = id + "-" + field.getFieldName();

                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream(bos);
                out.writeObject(ob);
                byte[] contentBytes = bos.toByteArray();
                out.close();
                InputStream input = new ByteArrayInputStream(contentBytes);

                s3.putObject(bucketName, s3ObjectId, input, null);

                em.statsS3Put(System.currentTimeMillis() - start3);
                logger.finer("setting lobkeyattribute=" + columnName + " - " + s3ObjectId);
                attsToPut.add(new ReplaceableAttribute(columnName, s3ObjectId, true));
            } else if (field.getEnumType() != null) {
                String toSet = getEnumValue(field, o);
                attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
            } else if (field.isId()) {
                continue;
            } else if (Collection.class.isInstance(ob)) {
                for (Object each : ((Collection) ob)) {
                    String toSet = each != null ? em.padOrConvertIfRequired(each) : "";
                    // todo: throw an exception if this is going to exceed
                    // maximum size, suggest using @Lob
                    attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
                }
            } else {
                String toSet = ob != null ? em.padOrConvertIfRequired(ob) : "";
                // todo: throw an exception if this is going to exceed maximum
                // size, suggest using @Lob
                attsToPut.add(new ReplaceableAttribute(columnName, toSet, true));
            }
        }

        // Now finally send it for storage (If have attributes to add)
        long start2 = System.currentTimeMillis();
        long duration2;
        if (!attsToPut.isEmpty()) {
            this.em.getSimpleDb().putAttributes(
                    new PutAttributesRequest().withDomainName(domainName).withItemName(id).withAttributes(attsToPut)
                            .withExpected(expected));
            duration2 = System.currentTimeMillis() - start2;
            if (logger.isLoggable(Level.FINE))
                logger.fine("putAttributes time=" + (duration2));
            em.statsAttsPut(attsToPut.size(), duration2);

            if (null != versionField)
                versionField.setProperty(o, nextVersion);
        }

        /*
         * Check for nulled attributes so we can send a delete call. Don't
         * delete attributes if this is a new object AND don't delete atts if
View Full Code Here

Examples of org.springframework.data.mapping.PersistentProperty

    @Override
    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected T createPersistentProperty(final Field field, final PropertyDescriptor descriptor,
        final BasicPersistentEntity<Object, T> owner, final SimpleTypeHolder simpleTypeHolder) {

      PersistentProperty prop = mock(PersistentProperty.class);

      when(prop.getTypeInformation()).thenReturn(owner.getTypeInformation());
      when(prop.getName()).thenReturn(field == null ? descriptor.getName() : field.getName());
      when(prop.getPersistentEntityType()).thenReturn(Collections.EMPTY_SET);

      try {
        Thread.sleep(200);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
View Full Code Here

Examples of org.springframework.data.mapping.PersistentProperty

        + " is not a Document. Make sure the document class is annotated with @Document(indexName=\"foo\")");
    return elasticsearchConverter.getMappingContext().getPersistentEntity(clazz);
  }

  private String getPersistentEntityId(Object entity) {
    PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty();
    if (idProperty != null) {
      Method getter = idProperty.getGetter();
      if (getter != null) {
        try {
          Object id = getter.invoke(entity);
          if (id != null) {
            return String.valueOf(id);
View Full Code Here

Examples of org.springframework.data.mapping.PersistentProperty

    }
    return null;
  }

  private void setPersistentEntityId(Object entity, String id) {
    PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty();
    // Only deal with String because ES generated Ids are strings !
    if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
      Method setter = idProperty.getSetter();
      if (setter != null) {
        try {
          setter.invoke(entity, id);
        } catch (Throwable t) {
          t.printStackTrace();
View Full Code Here

Examples of org.springframework.data.mapping.PersistentProperty

        this.persistentEntity = persistentEntity;
    }

    @Override
    protected void visitInternal(DefaultFieldSetConfigurationUnit configurationUnit) {
        PersistentProperty idProperty = persistentEntity.getIdProperty();
        PersistentFieldMetadata primaryKeyField = getPersistentField(configurationUnit.getFields(), idProperty.getName());

        if (primaryKeyField != null) {
            primaryKeyField.setPrimaryKey(true);
        } else {
            configurationUnit.addField(keyField(capitalize(idProperty.getName()), idProperty.getName()));
        }

        configurationUnit.doWithPersistentFields(new FieldHandler<PersistentFieldMetadata>() {
            @Override
            public void doWithField(PersistentFieldMetadata persistentField) {
                PersistentProperty persistentProperty = persistentEntity.getPersistentProperty(persistentField.getField());
                persistentField.setPersistentProperty(persistentProperty);
            }
        });
    }
View Full Code Here

Examples of org.springframework.data.mapping.PersistentProperty

    @Override
    protected void visitInternal(FiltersConfigurationUnit configurationUnit) {
        configurationUnit.doWithFilters(new FilterHandler<FilterMetadata>() {
            @Override
            public void doWithFilter(FilterMetadata filter) {
                PersistentProperty persistentProperty = persistentEntity.getPersistentProperty(filter.getFieldName());
                filter.setPersistentProperty(persistentProperty);
            }
        });
    }
View Full Code Here

Examples of org.springframework.data.mapping.PersistentProperty

        MappingContext mappingContext = validationContext.getMappingContext();
        final LightAdminConfiguration lightAdminConfiguration = validationContext.getLightAdminConfiguration();

        final PersistentEntity persistentEntity = mappingContext.getPersistentEntity(domainType);

        PersistentProperty persistentProperty = persistentEntity.getPersistentProperty(fieldMetadata.getField());

        if (persistentProperty == null) {
            return newArrayList(validationContext.notPersistableFieldProblem(fieldMetadata.getName()));
        }

        if (!isSupportedAttributeType(PersistentPropertyType.forPersistentProperty(persistentProperty))) {
            return newArrayList(validationContext.notSupportedTypeFieldProblem(fieldMetadata.getName()));
        }

        if (!isOfFileReferenceType(persistentProperty)) {
            return emptyList();
        }

        Annotation annotation = persistentProperty.findAnnotation(FileReference.class);

        FileReference fileReference = (FileReference) annotation;

        if (isEmpty(fileReference.baseDirectory())) {
            if (lightAdminConfiguration.getFileStorageDirectory() != null) {
View Full Code Here

Examples of org.springframework.data.mapping.PersistentProperty

        if (entity == null) {
            return null;
        }

        PersistentEntity persistentEntity = domainTypeAdministrationConfiguration.getPersistentEntity();
        PersistentProperty idProperty = persistentEntity.getIdProperty();

        BeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(entity);

        return String.valueOf(beanWrapper.getPropertyValue(idProperty.getName()));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.