Ejemplo n.º 1
0
 /**
  * This method must be used to obtain the dir allocation context for a particular value of the
  * context name. The context name must be an item defined in the Configuration object for which we
  * want to control the dir allocations (e.g., <code>mapred.local.dir</code>). The method will
  * create a context for that name if it doesn't already exist.
  */
 private AllocatorPerContext obtainContext(String contextCfgItemName) {
   synchronized (contexts) {
     AllocatorPerContext l = contexts.get(contextCfgItemName);
     if (l == null) {
       contexts.put(contextCfgItemName, (l = new AllocatorPerContext(contextCfgItemName)));
     }
     return l;
   }
 }
Ejemplo n.º 2
0
 static Map getTokensToChangeDollarsAndNL() {
   if (tokensToChangeDollarsAndNL == null) {
     tokensToChangeDollarsAndNL = new HashMap();
     tokensToChangeDollarsAndNL.put("${", "o.");
     tokensToChangeDollarsAndNL.put("}", "");
     tokensToChangeDollarsAndNL.put("\n", "");
   }
   return tokensToChangeDollarsAndNL;
 }
Ejemplo n.º 3
0
  public String getQualifiedColumn(String modelProperty) throws XavaException {
    PropertyMapping propertyMapping = (PropertyMapping) propertyMappings.get(modelProperty);
    if (propertyMapping != null && propertyMapping.hasFormula()) return getColumn(modelProperty);

    String tableColumn = getTableColumn(modelProperty, true);
    if (Is.emptyString(tableColumn)) return "'" + modelProperty + "'";
    if (referencePropertyWithFormula) {
      referencePropertyWithFormula = false;
      return tableColumn;
    }
    // for calculated fields or created by multiple converter

    if (modelProperty.indexOf('.') >= 0) {
      if (tableColumn.indexOf('.') < 0) return tableColumn;
      String reference = modelProperty.substring(0, modelProperty.lastIndexOf('.'));
      if (tableColumn.startsWith(getTableToQualifyColumn() + ".")) {
        String member = modelProperty.substring(modelProperty.lastIndexOf('.') + 1);
        if (getMetaModel().getMetaReference(reference).getMetaModelReferenced().isKey(member))
          return tableColumn;
      }

      // The next code uses the alias of the table instead of its name. In order to
      // support multiple references to the same model
      if (reference.indexOf('.') >= 0) {
        if (getMetaModel().getMetaProperty(modelProperty).isKey()) {
          reference = reference.substring(0, reference.lastIndexOf('.'));
        }
        reference = reference.replaceAll("\\.", "_");
      }
      return "T_" + reference + tableColumn.substring(tableColumn.lastIndexOf('.'));
    } else {
      return getTableToQualifyColumn() + "." + tableColumn;
    }
  }
Ejemplo n.º 4
0
 private void setupDefaultConverters() throws XavaException {
   Iterator it = propertyMappings.values().iterator();
   while (it.hasNext()) {
     PropertyMapping propertyMapping = (PropertyMapping) it.next();
     propertyMapping.setDefaultConverter();
   }
 }
Ejemplo n.º 5
0
 private static Map getArgumentsToHQL() {
   if (argumentsToHQL == null) {
     argumentsToHQL = new HashMap();
     for (int i = 0; i < 30; i++) {
       argumentsToHQL.put("{" + i + "}", ":arg" + i);
     }
   }
   return argumentsToHQL;
 }
Ejemplo n.º 6
0
 private static Map getArgumentsJBoss11ToEJBQL() {
   if (argumentsJBoss11ToEJBQL == null) {
     argumentsJBoss11ToEJBQL = new HashMap();
     for (int i = 0; i < 30; i++) {
       argumentsJBoss11ToEJBQL.put("{" + i + "}", "?" + (i + 1));
     }
   }
   return argumentsJBoss11ToEJBQL;
 }
Ejemplo n.º 7
0
 public void addPropertyMapping(PropertyMapping propertyMapping) throws XavaException {
   propertyMappings.put(propertyMapping.getProperty(), propertyMapping);
   modelProperties.add(propertyMapping.getProperty());
   // To keep order
   tableColumns.add(propertyMapping.getColumn());
   if (propertyMapping.hasFormula() && !getMetaModel().isAnnotatedEJB3()) {
     propertyMapping.getMetaProperty().setReadOnly(true);
   }
 }
Ejemplo n.º 8
0
  /** @return Not null */
  public ReferenceMapping getReferenceMapping(String name)
      throws XavaException, ElementNotFoundException {

    ReferenceMapping r =
        referenceMappings == null ? null : (ReferenceMapping) referenceMappings.get(name);
    if (r == null) {
      throw new ElementNotFoundException("reference_mapping_not_found", name, getModelName());
    }
    return r;
  }
Ejemplo n.º 9
0
 private PropertyMapping getMappingForColumn(String column) throws XavaException {
   if (propertyMappings == null) {
     throw new ElementNotFoundException("mapping_not_found_no_property_mappings", column);
   }
   Iterator it = propertyMappings.values().iterator();
   while (it.hasNext()) {
     PropertyMapping propertyMapping = (PropertyMapping) it.next();
     if (propertyMapping.getColumn().equalsIgnoreCase(column)) {
       return propertyMapping;
     }
   }
   throw new ElementNotFoundException("mapping_for_column_not_found", column);
 }
Ejemplo n.º 10
0
 /** @throws XavaException If it does not have a overlapped property, or any other problem. */
 public String getOverlappingPropertyForReference(String reference, String propertyOfReference)
     throws XavaException {
   String column =
       getReferenceMapping(reference).getColumnForReferencedModelProperty(propertyOfReference);
   if (propertyMappings == null) {
     throw new XavaException("reference_property_not_overlapped", propertyOfReference, reference);
   }
   Iterator it = propertyMappings.values().iterator();
   while (it.hasNext()) {
     PropertyMapping mapping = (PropertyMapping) it.next();
     if (column.equalsIgnoreCase(mapping.getColumn())) return mapping.getProperty();
   }
   throw new XavaException("reference_property_not_overlapped", propertyOfReference, reference);
 }
Ejemplo n.º 11
0
 public List namesToMetaProperties(Collection names) throws XavaException {
   List metaProperties = new ArrayList();
   Iterator it = names.iterator();
   int i = -1;
   while (it.hasNext()) {
     i++;
     String name = (String) it.next();
     MetaProperty metaPropertyTab = null;
     try {
       MetaProperty metaProperty = getMetaModel().getMetaProperty(name).cloneMetaProperty();
       metaProperty.setQualifiedName(name);
       String labelId = null;
       if (representCollection()) {
         labelId = getId() + "." + name;
         // If there is no specific translation for the collection,
         // we take the translation from the default tab.
         if (!Labels.existsExact(labelId)) {
           labelId = getIdForDefaultTab() + ".properties." + name;
         }
       } else {
         labelId = getId() + ".properties." + name;
       }
       if (Labels.exists(labelId)) {
         metaProperty.setLabelId(labelId);
       } else if (metaPropertiesTab != null) {
         // By now only the label overwritten from the property of tab
         metaPropertyTab = (MetaProperty) metaPropertiesTab.get(name);
         if (metaPropertyTab != null) {
           metaProperty = metaProperty.cloneMetaProperty();
           metaProperty.setLabel(metaPropertyTab.getLabel());
         }
       }
       metaProperties.add(metaProperty);
     } catch (ElementNotFoundException ex) {
       MetaProperty notInEntity = new MetaProperty();
       notInEntity.setName(name);
       notInEntity.setTypeName("java.lang.Object");
       if (metaPropertyTab != null) {
         notInEntity.setLabel(metaPropertyTab.getLabel());
       }
       metaProperties.add(notInEntity);
     }
   }
   return metaProperties;
 }
Ejemplo n.º 12
0
  /** @return Not null */
  public PropertyMapping getPropertyMapping(String name)
      throws XavaException, ElementNotFoundException {
    int i = name.indexOf('.');
    if (i >= 0) {
      String rName = name.substring(0, i);
      String pName = name.substring(i + 1);

      if (isReferenceNameInReferenceMappings(rName)) {
        return getReferenceMapping(rName).getReferencedMapping().getPropertyMapping(pName);
      } else {
        // by embedded references: address.city -> address_city
        return getPropertyMapping(name.replace(".", "_"));
      }
    }

    PropertyMapping p =
        propertyMappings == null ? null : (PropertyMapping) propertyMappings.get(name);
    if (p == null) {
      throw new ElementNotFoundException("property_mapping_not_found", name, getModelName());
    }
    return p;
  }
Ejemplo n.º 13
0
 public void addReferenceMapping(ReferenceMapping referenceMapping) throws XavaException {
   if (referenceMappings == null) referenceMappings = new HashMap();
   referenceMappings.put(referenceMapping.getReference(), referenceMapping);
   referenceMapping.setContainer(this);
 }
Ejemplo n.º 14
0
 public boolean hasReferenceMapping(MetaReference metaReference) {
   if (referenceMappings == null) return false;
   return referenceMappings.containsKey(metaReference.getName());
 }
Ejemplo n.º 15
0
 public boolean hasPropertyMapping(String memberName) {
   return propertyMappings.containsKey(memberName);
 }
Ejemplo n.º 16
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();
  }
Ejemplo n.º 17
0
 public void addMetaProperty(MetaProperty metaProperty) {
   if (metaPropertiesTab == null) {
     metaPropertiesTab = new HashMap();
   }
   metaPropertiesTab.put(metaProperty.getName(), metaProperty);
 }
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      Locales.setCurrent(request);
      if (Users.getCurrent() == null) { // for a bug in websphere portal 5.1 with Domino LDAP
        Users.setCurrent((String) request.getSession().getAttribute("xava.user"));
      }
      request.getParameter("application"); // for a bug in websphere 5.1
      request.getParameter("module"); // for a bug in websphere 5.1
      Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab");
      int[] selectedRowsNumber =
          (int[]) request.getSession().getAttribute("xava_selectedRowsReportTab");
      Map[] selectedKeys = (Map[]) request.getSession().getAttribute("xava_selectedKeysReportTab");
      int[] selectedRows = getSelectedRows(selectedRowsNumber, selectedKeys, tab);
      request.getSession().removeAttribute("xava_selectedRowsReportTab");
      Integer columnCountLimit =
          (Integer) request.getSession().getAttribute("xava_columnCountLimitReportTab");
      request.getSession().removeAttribute("xava_columnCountLimitReportTab");

      setDefaultSchema(request);
      String user = (String) request.getSession().getAttribute("xava_user");
      request.getSession().removeAttribute("xava_user");
      Users.setCurrent(user);
      String uri = request.getRequestURI();
      if (uri.endsWith(".pdf")) {
        InputStream is;
        JRDataSource ds;
        Map parameters = new HashMap();
        synchronized (tab) {
          tab.setRequest(request);
          parameters.put("Title", tab.getTitle());
          parameters.put("Organization", getOrganization());
          parameters.put("Date", getCurrentDate());
          for (String totalProperty : tab.getTotalPropertiesNames()) {
            parameters.put(totalProperty + "__TOTAL__", getTotal(request, tab, totalProperty));
          }
          TableModel tableModel = getTableModel(request, tab, selectedRows, false, true, null);
          tableModel.getValueAt(0, 0);
          if (tableModel.getRowCount() == 0) {
            generateNoRowsPage(response);
            return;
          }
          is = getReport(request, response, tab, tableModel, columnCountLimit);
          ds = new JRTableModelDataSource(tableModel);
        }
        JasperPrint jprint = JasperFillManager.fillReport(is, parameters, ds);
        response.setContentType("application/pdf");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".pdf\"");
        JasperExportManager.exportReportToPdfStream(jprint, response.getOutputStream());
      } else if (uri.endsWith(".csv")) {
        String csvEncoding = XavaPreferences.getInstance().getCSVEncoding();
        if (!Is.emptyString(csvEncoding)) {
          response.setCharacterEncoding(csvEncoding);
        }
        response.setContentType("text/x-csv");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".csv\"");
        synchronized (tab) {
          tab.setRequest(request);
          response
              .getWriter()
              .print(
                  TableModels.toCSV(
                      getTableModel(request, tab, selectedRows, true, false, columnCountLimit)));
        }
      } else {
        throw new ServletException(
            XavaResources.getString("report_type_not_supported", "", ".pdf .csv"));
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new ServletException(XavaResources.getString("report_error"));
    } finally {
      request.getSession().removeAttribute("xava_reportTab");
    }
  }
Ejemplo n.º 19
0
 private Collection getPropertyMappings() {
   return propertyMappings.values();
 }
Ejemplo n.º 20
0
 private Collection getReferenceMappings() {
   return referenceMappings == null ? Collections.EMPTY_LIST : referenceMappings.values();
 }
Ejemplo n.º 21
0
 /**
  * Method to check whether a context is valid
  *
  * @param contextCfgItemName
  * @return true/false
  */
 public static boolean isContextValid(String contextCfgItemName) {
   synchronized (contexts) {
     return contexts.containsKey(contextCfgItemName);
   }
 }