List of usage examples for com.amazonaws.services.simpledb.model ReplaceableItem ReplaceableItem
public ReplaceableItem(String name, java.util.List<ReplaceableAttribute> attributes)
From source file:com.kikini.logging.simpledb.SimpleDBWriter.java
License:Apache License
/** * Bulk-write the given rows to SimpleDB * //from w ww .ja v a 2s. c om * @param rows */ void writeRows(List<SimpleDBRow> rows) { if (rows.isEmpty()) return; List<SimpleDBRow> nextBatch; ListBatcher<SimpleDBRow> batchedList = new ListBatcher<SimpleDBRow>(rows, MAX_BATCH_PUT); while ((nextBatch = batchedList.nextBatch()) != null) { List<ReplaceableItem> items = new ArrayList<ReplaceableItem>(); for (SimpleDBRow row : nextBatch) { List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>(); addIfNotNull(atts, HOST_COLUMN, row.getHost()); addIfNotNull(atts, MESSAGE_COLUMN, row.getMsg()); addIfNotNull(atts, LEVEL_COLUMN, row.getLevel()); addIfNotNull(atts, THREAD_COLUMN, row.getThreadName()); addIfNotNull(atts, LOGGER_COLUMN, row.getLogger()); addIfNotNull(atts, CONTEXT_COLUMN, row.getContext()); addIfNotNull(atts, TIME_COLUMN, formatTime(row.getTime())); for (Map.Entry<String, String> mdcProperty : row.getMDCPropertyMap().entrySet()) { String mdcColumnName = MDC_COLUMN_PREFIX + mdcProperty.getKey(); addIfNotNull(atts, mdcColumnName, mdcProperty.getValue()); } // SimpleDB will not generate a key for you, so we use a random // UUID as the key for this entry items.add(new ReplaceableItem(UUID.randomUUID().toString(), atts)); } sdb.batchPutAttributes(new BatchPutAttributesRequest(dom, items)); } }
From source file:com.shelfmap.simplequery.SimpleDbUtil.java
License:Apache License
public static ReplaceableItem item(String itemName, List<ReplaceableAttribute> attrs) { return new ReplaceableItem(itemName, attrs); }
From source file:com.shelfmap.simplequery.SimpleDbUtil.java
License:Apache License
public static ReplaceableItem item(String itemName, ReplaceableAttribute... attrs) { return new ReplaceableItem(itemName, Arrays.asList(attrs)); }
From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java
License:Apache License
/** * <p>// w w w .j a v a 2s . c om * Store the given <code>{@link org.quartz.Job}</code>. * </p> * * @param newJob The <code>Job</code> to be stored. * @param replaceExisting If <code>true</code>, any <code>Job</code> existing in the * <code>JobStore</code> with the same name & group should be * over-written. * @throws ObjectAlreadyExistsException if a <code>Job</code> with the same name/group already * exists, and replaceExisting is set to false. */ @Override public void storeJob(SchedulingContext ctxt, JobDetail newJob, boolean replaceExisting) throws ObjectAlreadyExistsException { logDebug("Storing Job: ", newJob.getFullName()); 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)); } ReplaceableItem item = new ReplaceableItem(JobWrapper.getJobNameKey(newJob), attributes); amazonSimpleDb .batchPutAttributes(new BatchPutAttributesRequest(jobDomain, Collections.singletonList(item))); } catch (IOException e) { log.error("Could not store Job: " + newJob.getFullName(), e); } }
From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java
License:Apache License
/** * <p>/*from w ww . j a v a2 s. c o m*/ * Store the given <code>{@link org.quartz.Trigger}</code>. * </p> * * @param newTrigger The <code>Trigger</code> to be stored. * @param replaceExisting If <code>true</code>, any <code>Trigger</code> existing in the * <code>JobStore</code> with the same name & group should be * over-written. * @throws ObjectAlreadyExistsException if a <code>Trigger</code> with the same name/group already * exists, and replaceExisting is set to false. * @see #pauseTriggerGroup(SchedulingContext, String) */ @Override public void storeTrigger(SchedulingContext ctxt, Trigger newTrigger, boolean replaceExisting) throws JobPersistenceException { logDebug("Storing Trigger: ", newTrigger.getFullName()); 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)); } 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)); } ReplaceableItem item = new ReplaceableItem(TriggerWrapper.getTriggerNameKey(newTrigger), attributes); amazonSimpleDb.batchPutAttributes( new BatchPutAttributesRequest(triggerDomain, Collections.singletonList(item))); } catch (IOException e) { log.error("Could not store Trigger: " + newTrigger.getFullName(), e); } }
From source file:org.teiid.resource.adapter.simpledb.SimpleDBConnectionImpl.java
License:Open Source License
/** * Performs update on given domain and items * @param domainName/*from ww w. j a v a2 s. com*/ * @param items */ @Override public int performUpdate(String domainName, Map<String, Object> updateAttributes, String selectExpression) throws TranslatorException { try { List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>(); for (Map.Entry<String, Object> column : updateAttributes.entrySet()) { addAttribute(column.getKey(), column.getValue(), attributes); } List<ReplaceableItem> updateItems = new ArrayList<ReplaceableItem>(); int count = 0; String nextToken = null; do { SelectResult result = performSelect(selectExpression, nextToken); nextToken = result.getNextToken(); Iterator<Item> iter = result.getItems().iterator(); while (iter.hasNext()) { Item item = iter.next(); updateItems.add(new ReplaceableItem(item.getName(), attributes)); count++; if (count % 25 == 0) { executeBatch(domainName, updateItems); updateItems.clear(); } } executeBatch(domainName, updateItems); } while (nextToken != null); return count; } catch (AmazonServiceException e) { throw new TranslatorException(e); } catch (AmazonClientException e) { throw new TranslatorException(e); } }
From source file:org.teiid.resource.adapter.simpledb.SimpleDBConnectionImpl.java
License:Open Source License
/** * Inserts item into given domain.//from w ww .j a va 2 s. c o m * @param domainName * @param itemName * @param columnsMap * @return */ @Override public int performInsert(String domainName, List<Column> columns, Iterator<? extends List<?>> valueList) throws TranslatorException { try { if (this.domains == null) { this.domains = getDomains(); } if (!this.domains.contains(domainName)) { createDomain(domainName); } int count = 0; List<ReplaceableItem> insertItems = new ArrayList<ReplaceableItem>(); while (valueList.hasNext()) { List<?> values = valueList.next(); List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>(); String itemName = null; for (int i = 0; i < columns.size(); i++) { Column column = columns.get(i); if (SQLStringVisitor.getRecordName(column).equals(SimpleDBConnection.ITEM_NAME)) { itemName = (String) values.get(i); } else { addAttribute(SQLStringVisitor.getRecordName(column), SimpleDBDataTypeManager.convertToSimpleDBType(values.get(i), column.getJavaType()), attributes); } } if (itemName == null) { throw new TranslatorException( "ItemName() column value is not specified, it can not be null. Please provide a value."); } insertItems.add(new ReplaceableItem(itemName, attributes)); count++; if (count % 25 == 0) { executeBatch(domainName, insertItems); insertItems.clear(); } } // http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/SDB_API_BatchPutAttributes.html // TODO: 25 limit we may need to batch; but if batch atomicity is gone executeBatch(domainName, insertItems); return count; } catch (AmazonServiceException e) { throw new TranslatorException(e); } catch (AmazonClientException e) { throw new TranslatorException(e); } }
From source file:wwutil.jsoda.SimpleDBService.java
License:Mozilla Public License
private List<ReplaceableItem> buildPutItems(List dataObjs, String modelName, int offset) throws Exception { List<ReplaceableItem> items = new ArrayList<ReplaceableItem>(); for (int i = offset; i < dataObjs.size() && items.size() < MAX_PUT_ITEMS; i++) { Object dataObj = dataObjs.get(i); String idValue = makeIdValue(modelName, dataObj); items.add(new ReplaceableItem(idValue, buildAttrs(dataObj, modelName))); }// w w w . j a va2 s.co m return items; }