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();
 }
Esempio n. 2
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 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();
 }
Esempio n. 4
0
  private void loadDatabaseMetadata() {
    if (!databaseMetadataLoaded) {
      String componentName = "UNKNOWN";
      Connection con = null;
      try {
        componentName = getMetaComponent().getName();

        con = DataSourceConnectionProvider.getByComponent(componentName).getConnection();
        DatabaseMetaData metaData = con.getMetaData();
        supportsSchemasInDataManipulation = metaData.supportsSchemasInDataManipulation();
        Collection timeDateFunctions =
            Strings.toCollection(metaData.getTimeDateFunctions().toUpperCase());

        //
        // another solution instead of the use of 'if' would be to use a xml with
        //	the information of the functions from each BBDD
        if ("DB2 UDB for AS/400".equals(metaData.getDatabaseProductName())
            || "Oracle".equals(metaData.getDatabaseProductName())
            || "PostgresSQL".equals(metaData.getDatabaseProductName())) {
          supportsTranslateFunction = true;
        }
        if ("Oracle".equals(metaData.getDatabaseProductName())
            || "PostgreSQL".equals(metaData.getDatabaseProductName())) {
          supportsYearFunction = supportsMonthFunction = false;
        } else {
          supportsYearFunction = timeDateFunctions.contains("YEAR");
          supportsMonthFunction = timeDateFunctions.contains("MONTH");
        }
        databaseMetadataLoaded = true;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("load_database_metadata_warning"));
      } finally {
        try {
          if (con != null) {
            con.close();
          }
        } catch (SQLException e) {
          log.warn(XavaResources.getString("close_connection_warning"));
        }
      }
    }
  }
Esempio n. 5
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();
 }
Esempio n. 6
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();
 }
Esempio n. 7
0
 String getCMPAttributeForColumn(String column) throws XavaException {
   PropertyMapping mapping = getMappingForColumn(column);
   if (!mapping.hasConverter()) return Strings.change(mapping.getProperty(), ".", "_");
   return "_" + Strings.change(Strings.firstUpper(mapping.getProperty()), ".", "_");
 }
Esempio n. 8
0
  private String getTableColumn(String modelProperty, boolean qualifyReferenceMappingColumn)
      throws XavaException {

    PropertyMapping propertyMapping = (PropertyMapping) propertyMappings.get(modelProperty);
    if (propertyMapping == null) {
      int idx = modelProperty.indexOf('.');
      if (idx >= 0) {
        String referenceName = modelProperty.substring(0, idx);
        String propertyName = modelProperty.substring(idx + 1);
        if (getMetaModel().getMetaReference(referenceName).isAggregate()
            && !Strings.firstUpper(referenceName).equals(getMetaModel().getContainerModelName())) {
          propertyMapping =
              (PropertyMapping) propertyMappings.get(referenceName + "_" + propertyName);
          if (propertyMapping == null) {
            int idx2 = propertyName.indexOf('.');
            if (idx2 >= 0) {
              String referenceName2 = propertyName.substring(0, idx2);
              String propertyName2 = propertyName.substring(idx2 + 1);
              return getTableColumn(
                  referenceName + "_" + referenceName2 + "." + propertyName2,
                  qualifyReferenceMappingColumn);
            } else {
              throw new ElementNotFoundException(
                  "property_mapping_not_found", referenceName + "_" + propertyName, getModelName());
            }
          }
          return propertyMapping.getColumn();
        }
        ReferenceMapping referenceMapping = getReferenceMapping(referenceName);

        if (referenceMapping.hasColumnForReferencedModelProperty(propertyName)) {
          if (qualifyReferenceMappingColumn) {
            return getTableToQualifyColumn()
                + "."
                + referenceMapping.getColumnForReferencedModelProperty(propertyName);
          } else {
            return referenceMapping.getColumnForReferencedModelProperty(propertyName);
          }
        } else {
          ModelMapping referencedMapping = referenceMapping.getReferencedMapping();

          String tableName = referencedMapping.getTableToQualifyColumn();
          boolean secondLevel = propertyName.indexOf('.') >= 0;
          String columnName = referencedMapping.getTableColumn(propertyName, secondLevel);
          boolean hasFormula = referencedMapping.getPropertyMapping(propertyName).hasFormula();

          if (qualifyReferenceMappingColumn && !secondLevel && !hasFormula) {
            return tableName + "." + columnName;
          } else if (hasFormula) {
            String formula = referencedMapping.getPropertyMapping(propertyName).getFormula();
            referencePropertyWithFormula = true;
            return qualifyFormulaWithReferenceName(
                formula, referencedMapping.getModelName(), modelProperty);
          } else {
            return columnName;
          }
        }
      }
      throw new ElementNotFoundException(
          "property_mapping_not_found", modelProperty, getModelName());
    }
    if (propertyMapping.hasFormula()) return propertyMapping.getFormula();
    return propertyMapping.getColumn();
  }
 public String getColumnName(int c) {
   return labelAsHeader
       ? getMetaProperty(c).getLabel(locale)
       : Strings.change(getMetaProperty(c).getQualifiedName(), ".", "_");
 }
 public String getArguments() {
   arguments = Strings.change(arguments, "String", "java.lang.String");
   arguments = Strings.change(arguments, "java.lang.java.lang.String", "java.lang.String");
   return arguments;
 }