use of com.amazonaws.services.simpledb.model.Attribute in project simplejpa by appoxy.
the class EntityManagerSimpleJPA method listAllObjectsRaw.
/**
* This is mainly for debugging purposes. Will print to system out all of the items in the domain represented by the class parameter.
*
* @param c
* @throws AmazonClientException
* @throws ExecutionException
* @throws InterruptedException
*/
public void listAllObjectsRaw(Class c) throws AmazonClientException, ExecutionException, InterruptedException {
String domainName = factory.getDomainName(c);
List<Item> items = DomainHelper.listAllItems(factory.getSimpleDb(), domainName, consistentRead);
List<ItemAndAttributes> ia = ConcurrentRetriever.getAttributesFromSdb(toSdbItem(items), getExecutor(), this);
for (ItemAndAttributes itemAndAttributes : ia) {
System.out.println("item=" + itemAndAttributes.getItem().getIdentifier());
List<Attribute> atts = itemAndAttributes.getAtts();
for (Attribute att : atts) {
System.out.println("\t=" + att.getName() + "=" + att.getValue());
}
}
}
use of com.amazonaws.services.simpledb.model.Attribute in project simplejpa by appoxy.
the class ObjectBuilder method buildObject.
public static <T> T buildObject(EntityManagerSimpleJPA em, Class<T> tClass, Object id, List<Attribute> atts) {
T newInstance;
/*
Why was this here? Should we merge if it exists though?
newInstance = em.cacheGet(tClass, id);
if (newInstance != null) {
return newInstance;
}*/
AnnotationInfo ai = em.getFactory().getAnnotationManager().getAnnotationInfo(tClass);
try {
// check for DTYPE to see if it's a subclass, must be a faster way to do this you'd think?
for (Attribute att : atts) {
if (att.getName().equals(EntityManagerFactoryImpl.DTYPE)) {
logger.finest("dtype=" + att.getValue());
ai = em.getFactory().getAnnotationManager().getAnnotationInfoByDiscriminator(att.getValue());
if (ai == null) {
throw new PersistenceException(new ClassNotFoundException("Could not build object with dtype = " + att.getValue() + ". Class not found or is not an @Entity."));
}
tClass = ai.getMainClass();
// check cache again with new class
newInstance = em.cacheGet(tClass, id);
if (newInstance != null)
return newInstance;
break;
}
}
ObjectWithInterceptor owi = newEnancedInstance(em, tClass);
newInstance = (T) owi.getBean();
for (PersistentProperty field : ai.getPersistentProperties()) {
String attName = field.getFieldName();
String columnName = field.getColumnName();
if (field.isForeignKeyRelationship()) {
// lazy it up
Set<String> keys = getForeignKeys(em, field, columnName, atts);
logger.finest("keys=" + keys);
if (keys == null || keys.isEmpty()) {
continue;
}
// todo: stick a cache in here and check the cache for the instance before creating the lazy loader.
logger.finest("creating new lazy loading instance for field " + field.getFieldName() + " of class " + tClass.getSimpleName() + " with id " + id);
// Object toSet = newLazyLoadingInstance(retType, keys);
owi.getInterceptor().putForeignKey(attName, keys);
} else if (field.isInverseRelationship()) {
Class typeInList = field.getPropertyClass();
// todo: should this return null if there are no elements??
// LazyList lazyList = new LazyList(this, newInstance, annotation.mappedBy(), id, typeInList, factory.getAnnotationManager().getAnnotationInfo(typeInList));
List<PersistentProperty.OrderClause> orderBy = null;
if (List.class.isAssignableFrom(field.getRawClass())) {
orderBy = field.getOrderClauses();
}
LazyList lazyList = new LazyList(em, typeInList, oneToManyQuery(em, attName, field.getMappedBy(), id, typeInList, orderBy));
// Class retType = field.getReturnType();
// todo: assuming List for now, handle other collection types
field.setProperty(newInstance, lazyList);
} else if (field.isLob()) {
// handled in Proxy
String lobKeyAttributeName = field.getColumnName();
String lobKeyVal = getValueToSet(atts, lobKeyAttributeName, columnName);
logger.finest("lobkeyval to set on interceptor=" + lobKeyVal + " - fromatt=" + lobKeyAttributeName);
// TODO add multivalue support for LOB keys
if (lobKeyVal != null)
owi.getInterceptor().putForeignKey(attName, Collections.singleton(lobKeyVal));
} else if (field.getEnumType() != null) {
String val = getValueToSet(atts, attName, columnName);
if (val != null) {
Object enumVal = getEnumValue(field, val);
field.setProperty(newInstance, enumVal);
}
} else if (field.isId()) {
field.setProperty(newInstance, id);
} else {
Collection<String> val = getValuesToSet(atts, attName, columnName);
if (val != null && !val.isEmpty()) {
em.setFieldValue(tClass, newInstance, field, val);
}
}
}
} catch (Exception e) {
throw new PersistenceException(e);
}
em.cachePut(id, newInstance);
return newInstance;
}
use of com.amazonaws.services.simpledb.model.Attribute in project simplejpa by appoxy.
the class ConcurrentRetriever method getSerially.
private static List<ItemAndAttributes> getSerially(List<SdbItem> items) throws AmazonClientException {
List<ItemAndAttributes> ret = new ArrayList<ItemAndAttributes>();
for (SdbItem item : items) {
// logger.fine("item=" + item.getIdentifier());
List<Attribute> atts = item.getAttributes();
ret.add(new ItemAndAttributes(item, atts));
}
return ret;
}
use of com.amazonaws.services.simpledb.model.Attribute in project SimianArmy by Netflix.
the class SimpleDBRecorder method findEvents.
/**
* Find events.
*
* @param queryMap
* the query map
* @param after
* the start time to query for all events after
* @return the list
*/
protected List<Event> findEvents(Map<String, String> queryMap, long after) {
StringBuilder query = new StringBuilder(String.format("select * from `%s` where region = '%s'", domain, region));
for (Map.Entry<String, String> pair : queryMap.entrySet()) {
query.append(String.format(" and %s = '%s'", pair.getKey(), pair.getValue()));
}
query.append(String.format(" and eventTime > '%d'", after));
// always return with most recent record first
query.append(" order by eventTime desc");
List<Event> list = new LinkedList<Event>();
SelectRequest request = new SelectRequest(query.toString());
request.setConsistentRead(Boolean.TRUE);
SelectResult result = new SelectResult();
do {
result = sdbClient().select(request.withNextToken(result.getNextToken()));
for (Item item : result.getItems()) {
Map<String, String> fields = new HashMap<String, String>();
Map<String, String> res = new HashMap<String, String>();
for (Attribute attr : item.getAttributes()) {
if (Keys.KEYSET.contains(attr.getName())) {
res.put(attr.getName(), attr.getValue());
} else {
fields.put(attr.getName(), attr.getValue());
}
}
String eid = res.get(Keys.id.name());
String ereg = res.get(Keys.region.name());
MonkeyType monkeyType = valueToEnum(MonkeyType.class, res.get(Keys.monkeyType.name()));
EventType eventType = valueToEnum(EventType.class, res.get(Keys.eventType.name()));
long eventTime = Long.parseLong(res.get(Keys.eventTime.name()));
list.add(new BasicRecorderEvent(monkeyType, eventType, ereg, eid, eventTime).addFields(fields));
}
} while (result.getNextToken() != null);
return list;
}
use of com.amazonaws.services.simpledb.model.Attribute in project SimianArmy by Netflix.
the class SimpleDBConformityClusterTracker method parseCluster.
/**
* Parses a SimpleDB item into a cluster.
* @param item the item from SimpleDB
* @return the cluster for the SimpleDB item
*/
protected Cluster parseCluster(Item item) {
Map<String, String> fieldToValue = new HashMap<String, String>();
for (Attribute attr : item.getAttributes()) {
String name = attr.getName();
String value = attr.getValue();
if (name != null && value != null) {
fieldToValue.put(name, value);
}
}
return Cluster.parseFieldToValueMap(fieldToValue);
}
Aggregations