Package com.amazonaws.services.simpledb.model

Examples of com.amazonaws.services.simpledb.model.ReplaceableAttribute


            List<Attribute> oldAtts = getOldResults.getAttributes();
            if (oldAtts.size() > 0) {
                Attribute oldAtt = oldAtts.get(0);
                List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
                atts.add(new ReplaceableAttribute(newAttributeName, oldAtt.getValue(), true));

                db.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(atts));

                db.deleteAttributes(new DeleteAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(oldAtts));
            }
View Full Code Here


        String domainName = em.getFactory().getDomainName(MyTestObject.class);
        em.getFactory().createIfNotExistDomain(domainName);
       
        String id = "abc123";
        List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
        atts.add(new ReplaceableAttribute("id", id, true));
        atts.add(new ReplaceableAttribute("nameOld", "Bullwinkle", true));
        db.putAttributes(new PutAttributesRequest()
          .withDomainName(domainName)
          .withItemName(id)
          .withAttributes(atts));
View Full Code Here

        String domainName = em.getFactory().getDomainName(MyInheritanceObject1.class);
        em.getFactory().createIfNotExistDomain(domainName);
       
        String id = "abc123";
        List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
        atts.add(new ReplaceableAttribute("id", id, true));
        atts.add(new ReplaceableAttribute(EntityManagerFactoryImpl.DTYPE, "MyInheritanceObjectOld", true));
        atts.add(new ReplaceableAttribute("fieldInSubClass2", "Bullwinkle", true));
       
        db.putAttributes(new PutAttributesRequest()
        .withDomainName(domainName)
        .withItemName(id)
        .withAttributes(atts));
View Full Code Here

    final List<ReplaceableAttribute> result = new ArrayList<ReplaceableAttribute>();
   
    for(final Map.Entry<String, List<String>> entry : attributes.entrySet()) {
      replace = true;
      for (final String value : entry.getValue()) {
        result.add(new ReplaceableAttribute(entry.getKey(), value, replace));
        replace = false;
      }
    }

    return result;
View Full Code Here

            if (fieldValueStr == null)
                continue;

            // Add attr:fieldValueStr to list.  Skip the single Id field.  Treats single Id field as the itemName key in SimpleDB.
            if (!(jsoda.getRangeField(modelName) == null && jsoda.isIdField(modelName, fieldName)))
                attrs.add(new ReplaceableAttribute(attrName, fieldValueStr, true));
        }

        return attrs;
    }
View Full Code Here

        // 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();
View Full Code Here

    private void putNewValue(String domainName, List<Item> items, String dtype, String newClassName) throws AmazonClientException {
        AmazonSimpleDB db = factory.getSimpleDb();
        for (Item item : items) {
            List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();

            atts.add(new ReplaceableAttribute(dtype, newClassName, true));
            db.putAttributes(new PutAttributesRequest(domainName, item.getName(), atts));
        }
    }
View Full Code Here

            List<Attribute> oldAtts = getOldResults.getAttributes();
            if (oldAtts.size() > 0) {
                Attribute oldAtt = oldAtts.get(0);
                List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
                atts.add(new ReplaceableAttribute(newAttributeName, oldAtt.getValue(), true));

                db.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(atts));

                db.deleteAttributes(new DeleteAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(oldAtts));
            }
View Full Code Here

    @Override
    public void addOrUpdate(Cluster cluster) {
        List<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>();
        Map<String, String> fieldToValueMap = cluster.getFieldToValueMap();
        for (Map.Entry<String, String> entry : fieldToValueMap.entrySet()) {
            attrs.add(new ReplaceableAttribute(entry.getKey(), StringUtils.left(entry.getValue(), MAX_ATTR_SIZE),
                    true));
        }
        PutAttributesRequest putReqest = new PutAttributesRequest(domain, getSimpleDBItemName(cluster), attrs);
        LOGGER.debug(String.format("Saving cluster %s to SimpleDB domain %s",
                cluster.getName(), domain));
View Full Code Here

    /** {@inheritDoc} */
    @Override
    public void recordEvent(Event evt) {
        String evtTime = String.valueOf(evt.eventTime().getTime());
        List<ReplaceableAttribute> attrs = new LinkedList<ReplaceableAttribute>();
        attrs.add(new ReplaceableAttribute(Keys.id.name(), evt.id(), true));
        attrs.add(new ReplaceableAttribute(Keys.eventTime.name(), evtTime, true));
        attrs.add(new ReplaceableAttribute(Keys.region.name(), evt.region(), true));
        attrs.add(new ReplaceableAttribute(Keys.recordType.name(), "MonkeyEvent", true));
        attrs.add(new ReplaceableAttribute(Keys.monkeyType.name(), enumToValue(evt.monkeyType()), true));
        attrs.add(new ReplaceableAttribute(Keys.eventType.name(), enumToValue(evt.eventType()), true));
        for (Map.Entry<String, String> pair : evt.fields().entrySet()) {
            if (pair.getValue() == null || pair.getValue().equals("") || Keys.KEYSET.contains(pair.getKey())) {
                continue;
            }
            attrs.add(new ReplaceableAttribute(pair.getKey(), pair.getValue(), true));
        }
        // Let pk contain the timestamp so that the same resource can have multiple events.
        String pk = String.format("%s-%s-%s-%s", evt.monkeyType().name(), evt.id(), region, evtTime);
        PutAttributesRequest putReq = new PutAttributesRequest(domain, pk, attrs);
        sdbClient().putAttributes(putReq);
View Full Code Here

TOP

Related Classes of com.amazonaws.services.simpledb.model.ReplaceableAttribute

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.