@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getName() == null) ? 0 : getName().hashCode()); hashCode = prime * hashCode + ((getAlternateNameEncoding() == null) ? 0 : getAlternateNameEncoding().hashCode()); hashCode = prime * hashCode + ((getAttributes() == null) ? 0 : getAttributes().hashCode()); return hashCode; }
public Item unmarshall(StaxUnmarshallerContext context) throws Exception { Item item = new Item(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return item; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Name", targetDepth)) { item.setName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Name/@encoding", targetDepth)) { item.setAlternateNameEncoding(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Attribute", targetDepth)) { item.withAttributes(AttributeStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return item; } } } }
/** * Constructs a new Item object. Callers should use the setter or fluent setter (with...) methods to initialize any * additional object members. * * @param name * The name of the item. * @param attributes * A list of attributes. */ public Item(String name, java.util.List<Attribute> attributes) { setName(name); setAttributes(attributes); }
assertNotNull(items.getName()); assertTrue(items.getName().equals("1")); assertNotNull(items.getAttributes()); assertTrue(items.getAttributes().size() == 2); for (Object attributesObject : items.getAttributes()) { Attribute attributes = (Attribute)attributesObject; assertNotNull(attributes.getName());
public Item unmarshall(StaxUnmarshallerContext context) throws Exception { Item item = new Item(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) return item; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("Name", targetDepth)) { item.setName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Name/@encoding", targetDepth)) { item.setAlternateNameEncoding(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Attribute", targetDepth)) { item.getAttributes().add(AttributeStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { return item; } } } }
public String getIdentifier() { return item.getName(); }
private void addProperty(Item item) { Iterator<Attribute> attrs = item.getAttributes().iterator(); String prop = ""; String value = ""; String dc = ""; while (attrs.hasNext()) { Attribute att = attrs.next(); if (att.getName().equals(Attributes.PROPERTY)) prop = att.getValue(); else if (att.getName().equals(Attributes.PROPERTY_VALUE)) value = att.getValue(); else if (att.getName().equals(Attributes.REGION)) dc = att.getValue(); } // Ignore, if not this region if (StringUtils.isNotBlank(dc) && !dc.equals(getRegion())) return; // Override only if region is specified if (data.containsKey(prop) && StringUtils.isBlank(dc)) return; data.put(prop, value); }
/** * A list of attributes. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param attributes A list of attributes. * * @return A reference to this updated object so that method calls can be chained * together. */ public Item withAttributes(Attribute... attributes) { if (getAttributes() == null) setAttributes(new java.util.ArrayList<Attribute>(attributes.length)); for (Attribute value : attributes) { getAttributes().add(value); } return this; }
/** * The name of the item. * * @param name * The name of the item. * @return Returns a reference to this object so that method calls can be chained together. */ public Item withName(String name) { setName(name); return this; }
/** * Gets the Item based on the item name field which is the same as id in SimpleJPA. * If the item doesn't exist then null is returned. * * @param db * @param domainName * @param itemName * @param consistentRead true to read consistently, false to use eventual consistency * @return * @throws AmazonClientException */ public static Item findItemById(AmazonSimpleDB db, String domainName, String itemName, boolean consistentRead) throws AmazonClientException { GetAttributesResult results = db.getAttributes(new GetAttributesRequest() .withConsistentRead(consistentRead) .withDomainName(domainName) .withItemName(itemName)); if(results.getAttributes().size() == 0) { return null; } Item item = new Item(itemName, results.getAttributes()); return item; } }
/** * <p> * </p> * * @param alternateNameEncoding * @return Returns a reference to this object so that method calls can be chained together. */ public Item withAlternateNameEncoding(String alternateNameEncoding) { setAlternateNameEncoding(alternateNameEncoding); return this; }
@Override protected List<?> buildRow(Item item) throws TranslatorException { Map<String, List<String>> valueMap = createAttributeMap(item.getAttributes()); List row = new ArrayList(); Object[] results = new Object[valueMap.size()]; int i = 0; for (String attributeName:valueMap.keySet()) { if (SimpleDBMetadataProcessor.isItemName(attributeName)) { results[i++] = item.getName(); continue; } List<String> value = valueMap.get(attributeName); results[i++] = (value.size() == 1)?value.get(0):value.toString(); } row.add(results); return row; }
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)); } }
/** * Convert a simpledb item to PriamInstance * * @param item * @return */ public PriamInstance transform(Item item) { PriamInstance ins = new PriamInstance(); for (Attribute att : item.getAttributes()) { if (att.getName().equals(Attributes.INSTANCE_ID)) ins.setInstanceId(att.getValue()); else if (att.getName().equals(Attributes.TOKEN)) ins.setToken(att.getValue()); else if (att.getName().equals(Attributes.APP_ID)) ins.setApp(att.getValue()); else if (att.getName().equals(Attributes.ID)) ins.setId(Integer.parseInt(att.getValue())); else if (att.getName().equals(Attributes.AVAILABILITY_ZONE)) ins.setRac(att.getValue()); else if (att.getName().equals(Attributes.ELASTIC_IP)) ins.setHostIP(att.getValue()); else if (att.getName().equals(Attributes.HOSTNAME)) ins.setHost(att.getValue()); else if (att.getName().equals(Attributes.LOCATION)) ins.setDC(att.getValue()); else if (att.getName().equals(Attributes.UPDATE_TS)) ins.setUpdatetime(Long.parseLong(att.getValue())); } return ins; }
/** * Constructs a new Item object. * Callers should use the setter or fluent setter (with...) methods to * initialize any additional object members. * * @param name The name of the item. * @param attributes A list of attributes. */ public Item(String name, java.util.List<Attribute> attributes) { setName(name); setAttributes(attributes); }
/** * The name of the item. * * @param name * The name of the item. * @return Returns a reference to this object so that method calls can be chained together. */ public Item withName(String name) { setName(name); return this; }
/** * <p> * </p> * * @param alternateNameEncoding * @return Returns a reference to this object so that method calls can be chained together. */ public Item withAlternateNameEncoding(String alternateNameEncoding) { setAlternateNameEncoding(alternateNameEncoding); return this; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof Item == false) return false; Item other = (Item) obj; if (other.getName() == null ^ this.getName() == null) return false; if (other.getName() != null && other.getName().equals(this.getName()) == false) return false; if (other.getAlternateNameEncoding() == null ^ this.getAlternateNameEncoding() == null) return false; if (other.getAlternateNameEncoding() != null && other.getAlternateNameEncoding().equals(this.getAlternateNameEncoding()) == false) return false; if (other.getAttributes() == null ^ this.getAttributes() == null) return false; if (other.getAttributes() != null && other.getAttributes().equals(this.getAttributes()) == false) return false; return true; }
protected List<?> buildRow(Item item) throws TranslatorException { Map<String, List<String>> valueMap = createAttributeMap(item.getAttributes()); List row = new ArrayList(); for (int i = 0; i < visitor.getProjectedColumns().size(); i++) { String columnName = visitor.getProjectedColumns().get(i); if (SimpleDBMetadataProcessor.isItemName(columnName)) { row.add(SimpleDBDataTypeManager.convertFromSimpleDBType(Arrays.asList(item.getName()), expectedColumnTypes[i])); continue; } row.add(SimpleDBDataTypeManager.convertFromSimpleDBType(valueMap.get(columnName), expectedColumnTypes[i])); } return row; }
while (iter.hasNext()) { Item item = iter.next(); updateItems.add(new ReplaceableItem(item.getName(), attributes)); count++; if (count%25 == 0) {