Example usage for com.amazonaws.services.simpledb.model GetAttributesRequest GetAttributesRequest

List of usage examples for com.amazonaws.services.simpledb.model GetAttributesRequest GetAttributesRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model GetAttributesRequest GetAttributesRequest.

Prototype

public GetAttributesRequest(String domainName, String itemName) 

Source Link

Document

Constructs a new GetAttributesRequest object.

Usage

From source file:com.aipo.aws.simpledb.SimpleDB.java

License:Open Source License

/**
 * /*from  w  w w . ja va  2s  .  c o  m*/
 * @param <M>
 * @param client
 * @param rootClass
 * @param domain
 * @param itemName
 * @return
 */
public static <M> M get(AmazonSimpleDB client, Class<M> rootClass, String domain, String itemName) {
    try {
        M model = rootClass.newInstance();
        if (model instanceof ResultItem) {
            GetAttributesResult result = client
                    .getAttributes(new GetAttributesRequest(domain, itemName).withConsistentRead(true));
            ResultItem item = (ResultItem) model;
            item.assign(itemName, result);
        }
        return model;
    } catch (InstantiationException e) {
        //
    } catch (IllegalAccessException e) {
        //
    }

    return null;
}

From source file:com.amazon.aws.demo.anonymous.sdb.SimpleDB.java

License:Open Source License

public static HashMap<String, String> getAttributesForItem(String domainName, String itemName) {
    GetAttributesRequest getRequest = new GetAttributesRequest(domainName, itemName).withConsistentRead(true);
    GetAttributesResult getResult = getInstance().getAttributes(getRequest);

    HashMap<String, String> attributes = new HashMap<String, String>(30);
    for (Object attribute : getResult.getAttributes()) {
        String name = ((Attribute) attribute).getName();
        String value = ((Attribute) attribute).getValue();

        attributes.put(name, value);// w ww  . j  a v  a 2 s.c  o m
    }

    return attributes;
}

From source file:com.dateofrock.simpledbmapper.SimpleDBMapper.java

License:Apache License

/**
 * SimpleDB????//from  ww  w.j a v  a 2 s. c  o  m
 * 
 * @param object
 *            {@link SimpleDBDomain}????POJO
 *            {@link SimpleDBVersionAttribute}
 *            ??????????????<a href=
 *            "http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/ConditionalDelete.html"
 *            >Conditional Delete</a>????
 */
public void delete(Object object) {
    String domainName = this.reflector.getDomainName(object.getClass());
    Field itemNameField = this.reflector.findItemNameField(object.getClass());
    String itemName = this.reflector.encodeItemNameAsSimpleDBFormat(object, itemNameField);

    // S3 Blob
    GetAttributesResult results = this.sdb.getAttributes(new GetAttributesRequest(domainName, itemName));
    List<Attribute> sdbAllAttrs = results.getAttributes();
    Set<Field> blobFields = this.reflector.findBlobFields(object.getClass());
    List<S3TaskResult> s3TaskResults = new ArrayList<S3TaskResult>();
    for (Field field : blobFields) {
        SimpleDBBlob blobAnnon = field.getAnnotation(SimpleDBBlob.class);
        String attributeName = blobAnnon.attributeName();
        for (Attribute attr : sdbAllAttrs) {
            if (attr.getName().equals(attributeName)) {
                S3TaskResult taskResult = new S3TaskResult(Operation.DELETE, attributeName, null, null);
                taskResult.setSimpleDBAttributeValue(attr.getValue());
                s3TaskResults.add(taskResult);
            }
        }
    }

    DeleteAttributesRequest req = new DeleteAttributesRequest(domainName, itemName);
    // version?????Conditional Delete
    Field versionField = this.reflector.findVersionAttributeField(object.getClass());
    if (versionField != null) {
        try {
            Object versionObject = versionField.get(object);
            String versionAttributeName = versionField.getAnnotation(SimpleDBVersionAttribute.class)
                    .attributeName();
            if (versionObject != null) {
                if (versionObject instanceof Long) {
                    Long currentVersion = (Long) versionObject;
                    UpdateCondition expected = new UpdateCondition();
                    expected.setName(versionAttributeName);
                    expected.setValue(currentVersion.toString());
                    req.setExpected(expected);
                } else {
                    throw new SimpleDBMapperException(
                            "version?Long???????" + versionField);
                }
            }
        } catch (Exception e) {
            throw new SimpleDBMapperException("object?version??: " + object, e);
        }
    }
    this.sdb.deleteAttributes(req);

    // S3
    for (S3TaskResult s3TaskResult : s3TaskResults) {
        this.s3.deleteObject(s3TaskResult.getBucketName(), s3TaskResult.getKey());
    }
}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>/*from w  w w  .  j  a  va2  s.c o  m*/
 * Retrieve the <code>{@link org.quartz.JobDetail}</code> for the given
 * <code>{@link org.quartz.Job}</code>.
 * </p>
 *
 * @param jobName   The name of the <code>Job</code> to be retrieved.
 * @param groupName The group name of the <code>Job</code> to be retrieved.
 * @return The desired <code>Job</code>, or null if there is no match.
 */
@Override
public JobDetail retrieveJob(SchedulingContext ctxt, String jobName, String groupName) {
    logDebug("Retrieving Job: ", groupName, ".", jobName);
    String key = JobWrapper.getJobNameKey(jobName, groupName);
    GetAttributesResult result = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(jobDomain, key).withConsistentRead(Boolean.TRUE));
    try {
        return jobDetailFromAttributes(result.getAttributes());
    } catch (IOException e) {
        log.error("Could not retrieve Job: " + groupName + "." + jobName, e);
        return null;
    }
}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>//  w  w w .  j av  a  2 s .  c  o  m
 * Retrieve the given <code>{@link org.quartz.Trigger}</code>.
 * </p>
 *
 * @param triggerName The name of the <code>Trigger</code> to be retrieved.
 * @param groupName   The group name of the <code>Trigger</code> to be retrieved.
 * @return The desired <code>Trigger</code>, or null if there is no match.
 */
@Override
public Trigger retrieveTrigger(SchedulingContext ctxt, String triggerName, String groupName) {
    logDebug("Retrieving Trigger: ", triggerName, ".", groupName);
    String key = TriggerWrapper.getTriggerNameKey(triggerName, groupName);
    GetAttributesResult result = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(triggerDomain, key).withConsistentRead(Boolean.TRUE));
    TriggerWrapper tw = null;
    try {
        tw = triggerFromAttributes(result.getAttributes());
        return tw.trigger;
    } catch (IOException e) {
        logDebug("Trigger not found: ", triggerName, ".", groupName, e);
        return null;
    }
}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>/* ww  w.jav a2s.  com*/
 * Get the current state of the identified <code>{@link Trigger}</code>.
 * </p>
 *
 * @see Trigger#STATE_NORMAL
 * @see Trigger#STATE_PAUSED
 * @see Trigger#STATE_COMPLETE
 * @see Trigger#STATE_ERROR
 * @see Trigger#STATE_BLOCKED
 * @see Trigger#STATE_NONE
 */
@Override
public int getTriggerState(SchedulingContext ctxt, String triggerName, String groupName)
        throws JobPersistenceException {
    logDebug("Finding state of Trigger: ", triggerName, ".", groupName);
    String key = TriggerWrapper.getTriggerNameKey(triggerName, groupName);

    GetAttributesResult result = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(triggerDomain, key).withConsistentRead(Boolean.TRUE));

    TriggerWrapper tw;
    try {
        tw = triggerFromAttributes(result.getAttributes());
    } catch (IOException e) {
        log.error("Error finding state of Trigger: " + triggerName + "." + groupName, e);
        return Trigger.STATE_NONE;
    }

    if (tw == null) {
        return Trigger.STATE_NONE;
    }

    switch (tw.state) {
    case TriggerWrapper.STATE_COMPLETE:
        return Trigger.STATE_COMPLETE;
    case TriggerWrapper.STATE_PAUSED:
        return Trigger.STATE_PAUSED;
    case TriggerWrapper.STATE_PAUSED_BLOCKED:
        return Trigger.STATE_PAUSED;
    case TriggerWrapper.STATE_BLOCKED:
        return Trigger.STATE_BLOCKED;
    case TriggerWrapper.STATE_ERROR:
        return Trigger.STATE_ERROR;
    default:
        return Trigger.STATE_NORMAL;
    }

}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>//from   w w w.j  av a  2s  .  c o m
 * Pause the <code>{@link Trigger}</code> with the given name.
 * </p>
 */
@Override
public void pauseTrigger(SchedulingContext ctxt, String triggerName, String groupName) {
    logDebug("Pausing Trigger: ", triggerName, ".", groupName);
    String key = TriggerWrapper.getTriggerNameKey(triggerName, groupName);
    GetAttributesResult result = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(triggerDomain, key).withConsistentRead(Boolean.TRUE));
    TriggerWrapper tw = null;

    try {
        tw = triggerFromAttributes(result.getAttributes());
    } catch (IOException e) {
        log.error("Could not create trigger for Item: " + result.toString(), e);
    }

    // does the trigger exist?
    if (tw == null || tw.trigger == null) {
        return;
    }

    // if the trigger is "complete" pausing it does not make sense...
    if (tw.state == TriggerWrapper.STATE_COMPLETE) {
        return;
    }

    if (tw.state == TriggerWrapper.STATE_BLOCKED) {
        tw.state = TriggerWrapper.STATE_PAUSED_BLOCKED;
    } else {
        tw.state = TriggerWrapper.STATE_PAUSED;
    }

    updateState(tw);

}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>//www .ja v a2 s .  c om
 * Resume (un-pause) the <code>{@link Trigger}</code> with the given name.
 * </p>
 * <p/>
 * <p>
 * If the <code>Trigger</code> missed one or more fire-times, then the
 * <code>Trigger</code>'s misfire instruction will be applied.
 * </p>
 */
@Override
public void resumeTrigger(SchedulingContext ctxt, String triggerName, String groupName) {
    logDebug("Resuming Trigger: ", triggerName, ".", groupName);
    String key = TriggerWrapper.getTriggerNameKey(triggerName, groupName);

    GetAttributesResult result = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(triggerDomain, key).withConsistentRead(Boolean.TRUE));
    TriggerWrapper tw = null;

    try {
        tw = triggerFromAttributes(result.getAttributes());
    } catch (IOException e) {
        log.error("Could not create trigger for Item: " + result.toString());
    }

    // does the trigger exist?
    if (tw == null || tw.trigger == null) {
        return;
    }

    // if the trigger is not paused resuming it does not make sense...
    if (tw.state != TriggerWrapper.STATE_PAUSED && tw.state != TriggerWrapper.STATE_PAUSED_BLOCKED) {
        return;
    }
    applyMisfire(tw);

}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>//w  ww.  ja va  2s .  c o m
 * Inform the <code>JobStore</code> that the scheduler no longer plans to
 * fire the given <code>Trigger</code>, that it had previously acquired
 * (reserved).
 * </p>
 */
@Override
public void releaseAcquiredTrigger(SchedulingContext ctxt, Trigger trigger) {
    logDebug("Releasing Trigger: ", trigger.getFullName());
    String key = TriggerWrapper.getTriggerNameKey(trigger);
    GetAttributesResult result = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(triggerDomain, key).withConsistentRead(Boolean.TRUE));
    try {
        TriggerWrapper tw = triggerFromAttributes(result.getAttributes());
        if (tw.state == TriggerWrapper.STATE_ACQUIRED) {
            tw.state = TriggerWrapper.STATE_WAITING;
            updateState(tw);
        }
    } catch (IOException e) {
        log.error("Could not release Trigger: " + trigger.getFullName(), e);
    }
}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

/**
 * <p>//  w w  w. ja v  a  2s . c  om
 * Inform the <code>JobStore</code> that the scheduler is now firing the
 * given <code>Trigger</code> (executing its associated <code>Job</code>),
 * that it had previously acquired (reserved).
 * </p>
 */
@Override
public TriggerFiredBundle triggerFired(SchedulingContext ctxt, Trigger trigger) {

    logDebug("Fired Trigger: ", trigger.getFullName());
    String key = TriggerWrapper.getTriggerNameKey(trigger);
    GetAttributesResult result = amazonSimpleDb
            .getAttributes(new GetAttributesRequest(triggerDomain, key).withConsistentRead(Boolean.TRUE));
    TriggerWrapper tw = null;
    try {
        tw = triggerFromAttributes(result.getAttributes());
    } catch (IOException e) {
        log.error("Could not load Trigger: " + trigger.getFullName(), e);
    }

    // was the trigger deleted since being acquired?
    if (tw == null || tw.trigger == null) {
        return null;
    }
    // was the trigger completed, paused, blocked, etc. since being
    // acquired?
    if (tw.state != TriggerWrapper.STATE_ACQUIRED) {
        return null;
    }

    Calendar cal = null;
    if (tw.trigger.getCalendarName() != null) {
        cal = retrieveCalendar(ctxt, tw.trigger.getCalendarName());
        if (cal == null)
            return null;
    }
    Date prevFireTime = trigger.getPreviousFireTime();
    // call triggered on our copy, and the scheduler's copy
    tw.trigger.triggered(cal);
    trigger.triggered(cal);

    try {
        removeTrigger(ctxt, trigger.getName(), trigger.getGroup());
        storeTrigger(ctxt, trigger, true);
        tw.state = TriggerWrapper.STATE_WAITING;
        updateState(tw);
    } catch (JobPersistenceException e) {
        log.error("Error while firing Trigger: " + trigger.getFullName(), e);
    }

    TriggerFiredBundle bndle = new TriggerFiredBundle(
            retrieveJob(ctxt, trigger.getJobName(), trigger.getJobGroup()), trigger, cal, false, new Date(),
            trigger.getPreviousFireTime(), prevFireTime, trigger.getNextFireTime());

    // JobDetail job = bndle.getJobDetail();
    // TODO: Handle concurrent job execution

    return bndle;
}