Esempio n. 1
1
 private boolean containsColumn(Collection columns, String column) {
   if (columns.contains(column)) return true;
   for (Iterator it = columns.iterator(); it.hasNext(); ) {
     if (((String) it.next()).equalsIgnoreCase(column)) return true;
   }
   return false;
 }
Esempio n. 2
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);
   }
 }
Esempio n. 3
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();
 }
Esempio n. 4
0
 private Collection getTableColumns(Collection propertyNames) throws XavaException {
   Collection tableColumns = new ArrayList();
   Iterator it = propertyNames.iterator();
   while (it.hasNext()) {
     String name = (String) it.next();
     try {
       tableColumns.add(getMapping().getQualifiedColumn(name));
     } catch (ElementNotFoundException ex) {
       tableColumns.add("0"); // It will be replaced
     }
   }
   return tableColumns;
 }
Esempio n. 5
0
 /** @return Of <tt>String</tt> and not null. */
 public Collection getOverlappingPropertiesOfReference(String reference) throws XavaException {
   Collection overlappingPropertiesOfReference = new ArrayList();
   Iterator it = getReferenceMapping(reference).getDetails().iterator();
   while (it.hasNext()) {
     ReferenceMappingDetail d = (ReferenceMappingDetail) it.next();
     if (containsColumn(getColumns(), d.getColumn())) {
       String property = getMappingForColumn(d.getColumn()).getProperty();
       if (!property.startsWith(reference + "_")) {
         overlappingPropertiesOfReference.add(d.getReferencedModelProperty());
       }
     }
   }
   return overlappingPropertiesOfReference;
 }
Esempio n. 6
0
 /** @return Not null, read only and of type <tt>String</tt>. */
 public Collection getHiddenTableColumns() throws XavaException {
   if (hiddenTableColumns == null) {
     hiddenTableColumns = getTableColumns(getHiddenPropertiesNames());
     hiddenTableColumns.addAll(getCmpFieldsColumnsInMultipleProperties());
   }
   return hiddenTableColumns;
 }
Esempio n. 7
0
 public Collection getReferenceMappingsWithConverter() {
   if (referenceMappingsWithConverter == null) {
     referenceMappingsWithConverter = new ArrayList();
     Iterator it = getReferenceMappings().iterator();
     while (it.hasNext()) {
       ReferenceMapping referenceMapping = (ReferenceMapping) it.next();
       Collection mrd = referenceMapping.getDetails();
       Iterator itd = mrd.iterator();
       while (itd.hasNext()) {
         ReferenceMappingDetail referenceMappingDetail = (ReferenceMappingDetail) itd.next();
         if (referenceMappingDetail.hasConverter()) {
           referenceMappingsWithConverter.add(referenceMapping);
         }
       }
     }
   }
   return referenceMappingsWithConverter;
 }
Esempio n. 8
0
 public Collection getCmpFieldsColumnsInMultipleProperties() throws XavaException {
   Collection cmpFieldsColumnsInMultipleProperties = new ArrayList();
   Iterator it = getMetaProperties().iterator();
   String table = getMapping().getTableToQualifyColumn();
   while (it.hasNext()) {
     MetaProperty p = (MetaProperty) it.next();
     PropertyMapping mapping = p.getMapping();
     if (mapping != null) {
       if (mapping.hasMultipleConverter()) {
         Iterator itFields = mapping.getCmpFields().iterator();
         while (itFields.hasNext()) {
           CmpField field = (CmpField) itFields.next();
           cmpFieldsColumnsInMultipleProperties.add(table + "." + field.getColumn());
         }
       }
     }
   }
   return cmpFieldsColumnsInMultipleProperties;
 }
Esempio n. 9
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. 10
0
 /** @return Not null, read only and of type <tt>MetaProperty</tt>. */
 public Collection getMetaPropertiesHiddenCalculated() throws XavaException {
   if (metaPropertiesHiddenCalculated == null) {
     metaPropertiesHiddenCalculated = new ArrayList();
     Iterator it = getMetaPropertiesHidden().iterator();
     while (it.hasNext()) {
       MetaProperty metaProperty = (MetaProperty) it.next();
       if (metaProperty.isCalculated()) {
         metaPropertiesHiddenCalculated.add(metaProperty);
       }
     }
   }
   return metaPropertiesHiddenCalculated;
 }
Esempio n. 11
0
 // assert(!areAllProperties());
 private List createPropertiesNames() {
   StringTokenizer st = new StringTokenizer(removeTotalProperties(properties), ",;");
   List result = new ArrayList();
   while (st.hasMoreTokens()) {
     String name = st.nextToken().trim();
     if (name.endsWith("+")) {
       name = name.substring(0, name.length() - 1);
       if (sumPropertiesNames == null) sumPropertiesNames = new HashSet();
       sumPropertiesNames.add(name);
     }
     result.add(name);
   }
   return result;
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 public Collection getPropertyMappingsNotInModel() throws XavaException {
   Collection names = new ArrayList(getModelProperties());
   names.removeAll(getMetaModel().getPropertiesNames());
   if (names.isEmpty()) return Collections.EMPTY_LIST;
   Collection result = new ArrayList();
   for (Iterator it = names.iterator(); it.hasNext(); ) {
     String name = (String) it.next();
     if (name.indexOf('_') < 0) {
       result.add(getPropertyMapping(name));
     }
   }
   return result;
 }
Esempio n. 14
0
  public Collection getCmpFields() throws XavaException {
    Collection r = new ArrayList();
    Collection mappedColumns = new HashSet();
    for (Iterator it = getPropertyMappings().iterator(); it.hasNext(); ) {
      PropertyMapping pMapping = (PropertyMapping) it.next();
      r.addAll(pMapping.getCmpFields());
      mappedColumns.add(pMapping.getColumn());
    }
    for (Iterator it = getReferenceMappings().iterator(); it.hasNext(); ) {
      ReferenceMapping rMapping = (ReferenceMapping) it.next();
      for (Iterator itFields = rMapping.getCmpFields().iterator(); itFields.hasNext(); ) {
        CmpField field = (CmpField) itFields.next();
        if (!mappedColumns.contains(field.getColumn())) {
          r.add(field);
          mappedColumns.add(field.getColumn());
        }
      }
    }

    return r;
  }
Esempio n. 15
0
 public void addMetaRowStyle(MetaRowStyle style) {
   if (rowStyles == null) rowStyles = new ArrayList();
   rowStyles.add(style);
 }