Package com.amazonaws.services.simpledb.model

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


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


    logDebug("Storing Job: ", newJob.getFullName());
    ReplaceableItem item = null;
    try {
      List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
      attributes.add(new ReplaceableAttribute(JOB_NAME, newJob.getName(),
          true));
      attributes.add(new ReplaceableAttribute(JOB_GROUP, newJob
          .getGroup(), true));
      attributes.add(new ReplaceableAttribute(JOB_JOBCLASS, newJob
          .getJobClass().getName(), true));
      attributes.add(new ReplaceableAttribute(JOB_CLASS, newJob
          .getClass().getName(), true));
      if (newJob.getJobDataMap() != null) {
        attributes.add(new ReplaceableAttribute(JOB_DATA_MAP, mapper
            .writeValueAsString(newJob.getJobDataMap()), true));
      }
      item = new ReplaceableItem(JobWrapper.getJobNameKey(newJob),
          attributes);
      amazonSimpleDb.batchPutAttributes(new BatchPutAttributesRequest(
View Full Code Here

    logDebug("Storing Trigger: ", newTrigger.getFullName());
    ReplaceableItem item = null;
    try {

      List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
      attributes.add(new ReplaceableAttribute(TRIGGER_CLASS, newTrigger
          .getClass().getName(), true));
      attributes.add(new ReplaceableAttribute(TRIGGER_NAME, newTrigger
          .getName(), true));
      if (newTrigger.getCalendarName() != null) {
        attributes.add(new ReplaceableAttribute(TRIGGER_CALENDAR_NAME,
            newTrigger.getCalendarName(), true));
      }
      attributes.add(new ReplaceableAttribute(TRIGGER_GROUP, newTrigger
          .getGroup(), true));
      attributes.add(new ReplaceableAttribute(TRIGGER_JOB_GROUP,
          newTrigger.getJobGroup(), true));
      attributes.add(new ReplaceableAttribute(TRIGGER_JOB_NAME,
          newTrigger.getJobName(), true));
      attributes.add(new ReplaceableAttribute(TRIGGER_PRIORITY, String
          .valueOf(newTrigger.getPriority()), true));
      if (newTrigger.getEndTime() != null) {
        attributes.add(new ReplaceableAttribute(TRIGGER_END_TIME,
            dateFormat.format(newTrigger.getEndTime()), true));
      }
      if (newTrigger.getStartTime() != null) {
        attributes.add(new ReplaceableAttribute(TRIGGER_START_TIME,
            dateFormat.format(newTrigger.getStartTime()), true));
      }
      if (newTrigger.getNextFireTime() != null) {
        attributes.add(new ReplaceableAttribute(TRIGGER_NEXT_FIRE_TIME,
            dateFormat.format(newTrigger.getNextFireTime()), true));
      }
      item = new ReplaceableItem(
          TriggerWrapper.getTriggerNameKey(newTrigger), attributes);
      String json = mapper.writeValueAsString(newTrigger);
      attributes.add(new ReplaceableAttribute(TRIGGER_JSON_LENGTH, String
          .valueOf(json.length()), true));

      // Store the JSON representation in multiple attributes since max
      // length is 1024
      for (int i = 0; json.length() > i * MAX_ATTR_LENGTH; i++) {
        int end = Math.min((i + 1) * MAX_ATTR_LENGTH, json.length());
        attributes.add(new ReplaceableAttribute(TRIGGER_JSON
            + String.valueOf(i), json.substring(
            i * MAX_ATTR_LENGTH, end), true));
      }
      amazonSimpleDb.batchPutAttributes(new BatchPutAttributesRequest(
          triggerDomain, Collections.singletonList(item)));
View Full Code Here

  }

  private void updateState(TriggerWrapper tw) {
    logDebug("Updating state of Trigger: ", tw.trigger.getFullName());
    String key = TriggerWrapper.getTriggerNameKey(tw.trigger);
    ReplaceableAttribute attr = new ReplaceableAttribute(TRIGGER_STATE,
        String.valueOf(tw.state), true);
    amazonSimpleDb.putAttributes(new PutAttributesRequest(triggerDomain,
        key, Collections.singletonList(attr)));
  }
View Full Code Here

    protected List<ReplaceableAttribute> createAttributesToRegister(PriamInstance instance)
    {
        instance.setUpdatetime(new Date().getTime());
        List<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>();
        attrs.add(new ReplaceableAttribute(Attributes.INSTANCE_ID, instance.getInstanceId(), false));
        attrs.add(new ReplaceableAttribute(Attributes.TOKEN, instance.getToken(), true));
        attrs.add(new ReplaceableAttribute(Attributes.APP_ID, instance.getApp(), true));
        attrs.add(new ReplaceableAttribute(Attributes.ID, Integer.toString(instance.getId()), true));
        attrs.add(new ReplaceableAttribute(Attributes.AVAILABILITY_ZONE, instance.getRac(), true));
        attrs.add(new ReplaceableAttribute(Attributes.ELASTIC_IP, instance.getHostIP(), true));
        attrs.add(new ReplaceableAttribute(Attributes.HOSTNAME, instance.getHostName(), true));
        attrs.add(new ReplaceableAttribute(Attributes.LOCATION, instance.getDC(), true));
        attrs.add(new ReplaceableAttribute(Attributes.UPDATE_TS, Long.toString(instance.getUpdatetime()), true));
        return attrs;
    }
View Full Code Here

    public void logMessage(Message message, Date pickedUpTime, boolean succeeded) {
        String timestamp = message.getAttributes().get("SentTimestamp");
        String sentTimestamp = format
                .format(new Date(Long.parseLong(timestamp)));
        List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
        attributes.add(new ReplaceableAttribute("SentTimestamp", sentTimestamp,
                true));
        // All attributes are set to replace=true
        // except for PickedUpTimestamp
        // since the message could be picked up several times
        // until it is successfully processed
        // For latency we need the earliest PickedTimestamp
        attributes.add(new ReplaceableAttribute("PickedUpTimestamp", format
                .format(pickedUpTime), false));
        attributes.add(new ReplaceableAttribute("MessageBody", message
                .getBody(), true));
        if (succeeded) {
            attributes.add(new ReplaceableAttribute("ProcessedTimestamp",
                    format.format(new Date()), true));
        }
        // create an item in SimpleDB for this message
        PutAttributesRequest request = new PutAttributesRequest("sqs_log", // simpledb
                // domain
View Full Code Here

            while (itFieldName.hasNext()) {
                String key = itFieldName.next();
                JsonNode valueNode = objectNode.get(key);

                if (valueNode.isValueNode()) {
                    attributeList.add(new ReplaceableAttribute(key, valueNode.asText(), replaceP));
                } else if (valueNode.isArray()) {
                    for (int j = 0; j < valueNode.size(); j++) {
                        JsonNode scalarValueNode = valueNode.get(j);

                        attributeList.add(new ReplaceableAttribute(key, scalarValueNode.asText(), replaceP));
                    }
                }
            }
        }
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()) {
                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();
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

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.