Example #1
0
 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();
 }
 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();
 }
Example #6
0
 private String changePropertiesByColumns(String source, boolean qualified) throws XavaException {
   StringBuffer r = new StringBuffer(source);
   int i = r.toString().indexOf("${");
   int f = 0;
   while (i >= 0) {
     f = r.toString().indexOf("}", i + 2);
     if (f < 0) break;
     String property = r.substring(i + 2, f);
     String column = "0"; // thus it remained if it is calculated
     if (!getMetaModel().isCalculated(property)) {
       column =
           Strings.isModelName(property)
               ? getTable(property)
               : qualified ? getQualifiedColumn(property) : getColumn(property);
     }
     r.replace(i, f + 1, column);
     i = r.toString().indexOf("${");
   }
   return r.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();
 }
Example #8
0
 public String changePropertiesByCMPAttributes(String source) throws XavaException {
   StringBuffer r = new StringBuffer(source);
   int i = r.toString().indexOf("${");
   int f = 0;
   while (i >= 0) {
     f = r.toString().indexOf("}", i + 2);
     if (f < 0) break;
     String property = r.substring(i + 2, f);
     String cmpAttribute = null;
     if (property.indexOf('.') >= 0) {
       cmpAttribute = "o._" + Strings.firstUpper(Strings.change(property, ".", "_"));
     } else {
       MetaProperty metaProperty = getMetaModel().getMetaProperty(property);
       if (metaProperty.getMapping().hasConverter()) {
         cmpAttribute = "o._" + Strings.firstUpper(property);
       } else {
         cmpAttribute = "o." + property;
       }
     }
     r.replace(i, f + 1, cmpAttribute);
     i = r.toString().indexOf("${");
   }
   return r.toString();
 }
 public String getHQLCountSentence() throws XavaException {
   StringBuffer sb = new StringBuffer("select count(*) ");
   sb.append(getHQLCondition(false));
   return sb.toString();
 }
Example #10
0
 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();
 }