public String getKeyColumnsAsString() throws XavaException { StringBuffer r = new StringBuffer(); Collection columns = new HashSet(); for (Iterator it = getMetaModel().getAllKeyPropertiesNames().iterator(); it.hasNext(); ) { String pr = (String) it.next(); String column = getColumn(pr); if (columns.contains(column)) continue; columns.add(column); r.append(column); r.append(' '); } return r.toString().trim(); }
/** * Transforms ${address.street} in ${address_street} if address if an aggregate of container * model. * * @param condition * @return */ private String transformAggregateProperties(String condition) { int i = condition.indexOf("${"); if (i < 0) return condition; StringBuffer result = new StringBuffer(condition.substring(0, i + 2)); while (i >= 0) { int f = condition.indexOf("}", i); String property = condition.substring(i + 2, f); String transformedProperty = transformAgregateProperty(property); result.append(transformedProperty); i = condition.indexOf("${", f); if (i >= 0) result.append(condition.substring(f, i)); else result.append(condition.substring(f)); } return result.toString(); }
private String transformAgregateProperty(String property) { StringBuffer result = new StringBuffer(); StringTokenizer st = new StringTokenizer(property, "."); String member = ""; while (st.hasMoreTokens()) { String token = st.nextToken(); result.append(token); if (!st.hasMoreTokens()) break; member = member + token; try { MetaReference ref = getMetaModel().getMetaReference(member); if (ref.isAggregate()) result.append('_'); else result.append('.'); } catch (XavaException ex) { result.append('.'); } member = member + "."; } return result.toString(); }
public String getEJBQLCondition() throws XavaException { StringBuffer sb = new StringBuffer("SELECT OBJECT(o) FROM "); sb.append(getMetaModel().getName()); sb.append(" o"); if (!Is.emptyString(this.condition)) { sb.append(" WHERE "); String attributesCondition = getMetaModel().getMapping().changePropertiesByCMPAttributes(this.condition); sb.append(Strings.change(attributesCondition, getArgumentsJBoss11ToEJBQL())); } if (!Is.emptyString(this.order)) { sb.append(" ORDER BY "); sb.append(getMetaModel().getMapping().changePropertiesByCMPAttributes(this.order)); } return sb.toString(); }
private InputStream getReport( HttpServletRequest request, HttpServletResponse response, Tab tab, TableModel tableModel, Integer columnCountLimit) throws ServletException, IOException { StringBuffer suri = new StringBuffer(); suri.append("/xava/jasperReport"); suri.append("?language="); suri.append(Locales.getCurrent().getLanguage()); suri.append("&widths="); suri.append(Arrays.toString(getWidths(tableModel))); if (columnCountLimit != null) { suri.append("&columnCountLimit="); suri.append(columnCountLimit); } response.setCharacterEncoding(XSystem.getEncoding()); return Servlets.getURIAsStream(request, response, suri.toString()); }
private String getHQLCondition(boolean order) throws XavaException { StringBuffer sb = new StringBuffer("from "); sb.append(getMetaModel().getName()); sb.append(" as o"); if (!Is.emptyString(this.condition)) { sb.append(" where "); String condition = transformAggregateProperties(getCondition()); condition = Strings.change(condition, getArgumentsToHQL()); sb.append(Strings.change(condition, getTokensToChangeDollarsAndNL())); } if (order && !Is.emptyString(this.order)) { sb.append(" order by "); sb.append( Strings.change( transformAggregateProperties(this.order), getTokensToChangeDollarsAndNL())); } return sb.toString(); }
public String getHQLCountSentence() throws XavaException { StringBuffer sb = new StringBuffer("select count(*) "); sb.append(getHQLCondition(false)); return sb.toString(); }
private String createSelect() throws XavaException { if (hasBaseCondition()) { String baseCondition = getBaseCondition(); if (baseCondition.trim().toUpperCase().startsWith("SELECT ")) { return baseCondition; } } // basic select StringBuffer select = new StringBuffer("select "); Iterator itProperties = getPropertiesNames().iterator(); while (itProperties.hasNext()) { String property = (String) itProperties.next(); if (Strings.isModelName(property)) select.append("0"); // the property is a table name not column name else { select.append("${"); select.append(property); select.append('}'); } if (itProperties.hasNext()) select.append(", "); } Iterator itHiddenProperties = getHiddenPropertiesNames().iterator(); while (itHiddenProperties.hasNext()) { select.append(", "); select.append("${"); select.append(itHiddenProperties.next()); select.append('}'); } select.append(" from ${"); select.append(getModelName()); select.append('}'); select.append(' '); if (hasBaseCondition()) { select.append(" where "); select.append(getBaseCondition()); } return select.toString(); }