@Override public void delete(T t) { PersistenceManager pm = getPersistenceManager(); if (t.getKey() != null) { T atachedT = pm.getObjectById(getPersistentClass(), t.getKey()); pm.deletePersistent(atachedT); } }
@Override public void save(T t) { PersistenceManager pm = getPersistenceManager(); if (t.getKey() == null) { pm.makePersistent(t); } else { T atachedT = pm.getObjectById(getPersistentClass(), t.getKey()); rewrite(t, atachedT); } }
/** * Helper method that takes a List of {@link KeyValue} and presents it as a Map containing * KeyValue values * * @param <T> the key type * @param collection collection of {@link KeyValue} * @return a Map<T,Z> where keys of the KeyValues in the collection are mapped to their respective * KeyValue object */ public static <T extends KeyValue> Map<String, T> getKeyValueCollectionAsLookupTable( List<T> collection) { Map<String, T> map = new HashMap<String, T>(collection.size()); for (T kv : collection) { map.put(kv.getKey(), kv); } return map; }
public void writeJson(JsonGenerator g) throws JsonGenerationException, IOException { g.writeStartObject(); g.writeBooleanField(SUCCESS, success); g.writeStringField(MESSAGE, message); g.writeArrayFieldStart(DATA); if (null != list && !list.isEmpty()) { for (T model : list) { // write model data g.writeStartObject(); g.writeStringField("key", model.getKey()); g.writeStringField("label", model.getLabel()); g.writeEndObject(); } } g.writeEndArray(); // write model data end g.writeEndObject(); g.flush(); g.close(); }
public static <T extends INode> T findByNativePath(List<T> nodes, String searchFor) { for (T node : nodes) { if (node.getKey().getPath().getNativePath().equals(searchFor)) return node; } return null; }
@Override public int compareTo(T o) { return this.key.intValue() - o.getKey().intValue(); }
@Override public final boolean isNull(T aTuple) { return aTuple.getKey() == 0; }
public GenericLoadableDetachableModel(GenericDAO<T> dao, T object) { this(dao, object.getKey()); }