/** * This method exists to force immediate load from DB. Example; * <code> Person.find("name = ?", "Smith").load();</code>. * It is not possible to call other methods after load(). The load() method should be the last to be called in the chain: * <code> Person.find("name = ?", "Smith").limit(10).load();</code>. * This: will generate exception: <code> Person.find("name = ?", "Smith").load().limit();</code>. * * @return fully loaded list. */ //TODO: write test, and also test for exception. public <E extends Model> LazyList<E> load() { if (hydrated()) { throw new DBException("load() must be the last on the chain of methods"); } hydrate(); return (LazyList<E>) this; }
private void collect(Collection results, String attributeName) { hydrate(); for (Model model : delegate) { results.add(model.get(attributeName)); } }
/** * Dumps content of list to a stream. Use for debugging. * @param out */ public void dump(OutputStream out){ hydrate(); PrintWriter p = new PrintWriter(out); for(Model m : delegate){ p.write(m.toString()); p.write('\n'); } p.flush(); }
/** * This method exists to force immediate load from DB. Example; * <code> Person.find("name = ?", "Smith").load();</code>. * It is not possible to call other methods after load(). The load() method should be the last to be called in the chain: * <code> Person.find("name = ?", "Smith").limit(10).load();</code>. * This: will generate exception: <code> Person.find("name = ?", "Smith").load().limit();</code>. * * @return fully loaded list. */ //TODO: write test, and also test for exception. public <E extends Model> LazyList<E> load() { if (hydrated()) { throw new DBException("load() must be the last on the chain of methods"); } hydrate(); return (LazyList<E>) this; }
/** * Converts the resultset to list of maps, where each map represents a row in the resultset keyed off column names. * * @return list of maps, where each map represents a row in the resultset keyed off column names. */ public List<Map<String, Object>> toMaps() { hydrate(); List<Map<String, Object>> maps = new ArrayList<>(delegate.size()); for (T t : delegate) { maps.add(t.toMap()); } return maps; }
/** * This method exists to force immediate load from DB. Example; * <code> Person.find("name = ?", "Smith").load();</code>. * It is not possible to call other methods after load(). The load() method should be the last to be called in the chain: * <code> Person.find("name = ?", "Smith").limit(10).load();</code>. * This: will generate exception: <code> Person.find("name = ?", "Smith").load().limit();</code>. * * @return fully loaded list. */ //TODO: write test, and also test for exception. public <E extends Model> LazyList<E> load() { if (hydrated()) { throw new DBException("load() must be the last on the chain of methods"); } hydrate(); return (LazyList<E>) this; }
private void collect(Collection results, String attributeName, String filterAttribute, Object filterValue) { hydrate(); for (Model model : delegate) { if (model.get(filterAttribute).equals(filterValue)) { results.add(model.get(attributeName)); } } }
/** * Generates JSON from content of this list * * @param pretty true if you want pretty format, false if not * @param attrs attributes to include, not providing any will include all. * @return generated JSON */ public String toJson(boolean pretty, String ... attrs) { hydrate(); StringBuilder sb = new StringBuilder(); sb.append('['); if (pretty) sb.append('\n'); for (int i = 0; i < delegate.size(); i++) { if (i > 0) { sb.append(','); if (pretty) { sb.append('\n'); } } delegate.get(i).toJsonP(sb, pretty, (pretty ? " " : ""), attrs); } if (pretty) { sb.append('\n'); } sb.append(']'); return sb.toString(); }
/** * Generates a XML document from content of this list. * * @param pretty pretty format (human readable), or one line text. * @param declaration true to include XML declaration at the top * @param attrs list of attributes to include. No arguments == include all attributes. * @return generated XML. */ public String toXml(boolean pretty, boolean declaration, String... attrs) { String topNode = Inflector.pluralize(Inflector.underscore(metaModel.getModelClass().getSimpleName())); hydrate(); StringBuilder sb = new StringBuilder(); if(declaration) { sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (pretty) sb.append('\n'); } sb.append('<').append(topNode).append('>'); if (pretty) { sb.append('\n'); } for (T t : delegate) { t.toXmlP(sb, pretty, pretty ? " " : "", attrs); } sb.append("</").append(topNode).append('>'); if (pretty) { sb.append('\n'); } return sb.toString(); }
private void collect(Collection results, String attributeName) { hydrate(); for (Model model : delegate) { results.add(model.get(attributeName)); } }
private void collect(Collection results, String attributeName) { hydrate(); for (Model model : delegate) { results.add(model.get(attributeName)); } }
/** * Converts the resultset to list of maps, where each map represents a row in the resultset keyed off column names. * * @return list of maps, where each map represents a row in the resultset keyed off column names. */ public List<Map> toMaps(){ hydrate(); List<Map> maps = new ArrayList<Map>(delegate.size()); for (T t : delegate) { maps.add(t.toMap()); } return maps; }
/** * Dumps content of list to a stream. Use for debugging. * @param out */ public void dump(OutputStream out){ hydrate(); PrintWriter p = new PrintWriter(out); for(Model m : delegate){ p.write(m.toString()); p.write('\n'); } p.flush(); } }
/** * Converts the resultset to list of maps, where each map represents a row in the resultset keyed off column names. * * @return list of maps, where each map represents a row in the resultset keyed off column names. */ public List<Map<String, Object>> toMaps() { hydrate(); List<Map<String, Object>> maps = new ArrayList<>(delegate.size()); for (T t : delegate) { maps.add(t.toMap()); } return maps; }
/** * Dumps content of list to a stream. Use for debugging. * @param out */ public void dump(OutputStream out){ hydrate(); PrintWriter p = new PrintWriter(out); for(Model m : delegate){ p.write(m.toString()); p.write('\n'); } p.flush(); }
private void collect(Collection results, String attributeName, String filterAttribute, Object filterValue) { hydrate(); for (Model model : delegate) { if (model.get(filterAttribute).equals(filterValue)) { results.add(model.get(attributeName)); } } }
/** * Generates JSON from content of this list * * @param pretty true if you want pretty format, false if not * @param attrs attributes to include, not providing any will include all. * @return generated JSON */ public String toJson(boolean pretty, String ... attrs) { hydrate(); StringBuilder sb = new StringBuilder(); sb.append('['); if (pretty) sb.append('\n'); for (int i = 0; i < delegate.size(); i++) { if (i > 0) { sb.append(','); if (pretty) { sb.append('\n'); } } delegate.get(i).toJsonP(sb, pretty, (pretty ? " " : ""), attrs); } if (pretty) { sb.append('\n'); } sb.append(']'); return sb.toString(); }
private void collect(Collection results, String attributeName, String filterAttribute, Object filterValue) { hydrate(); for (Model model : delegate) { if (model.get(filterAttribute).equals(filterValue)) { results.add(model.get(attributeName)); } } }
/** * Generates JSON from content of this list * * @param pretty true if you want pretty format, false if not * @param attrs attributes to include, not providing any will include all. * @return generated JSON */ public String toJson(boolean pretty, String ... attrs) { hydrate(); StringBuilder sb = new StringBuilder(); sb.append('['); if (pretty) sb.append('\n'); for (int i = 0; i < delegate.size(); i++) { if (i > 0) { sb.append(','); if (pretty) { sb.append('\n'); } } delegate.get(i).toJsonP(sb, pretty, (pretty ? " " : ""), attrs); } if (pretty) { sb.append('\n'); } sb.append(']'); return sb.toString(); }
/** * Generates a XML document from content of this list. * * @param pretty pretty format (human readable), or one line text. * @param declaration true to include XML declaration at the top * @param attrs list of attributes to include. No arguments == include all attributes. * @return generated XML. */ public String toXml(boolean pretty, boolean declaration, String... attrs) { String topNode = Inflector.pluralize(Inflector.underscore(metaModel.getModelClass().getSimpleName())); hydrate(); StringBuilder sb = new StringBuilder(); if(declaration) { sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (pretty) sb.append('\n'); } sb.append('<').append(topNode).append('>'); if (pretty) { sb.append('\n'); } for (T t : delegate) { t.toXmlP(sb, pretty, pretty ? " " : "", attrs); } sb.append("</").append(topNode).append('>'); if (pretty) { sb.append('\n'); } return sb.toString(); }