コード例 #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;
 }
コード例 #2
0
ファイル: MetaTab.java プロジェクト: OpenXavaEx/OpenXavaEx
 private List obtainPropertiesNamesUsedToCalculate() throws XavaException {
   Set result = new HashSet();
   Iterator itProperties = getMetaPropertiesCalculated().iterator();
   while (itProperties.hasNext()) {
     MetaProperty metaProperty = (MetaProperty) itProperties.next();
     if (!metaProperty.hasCalculator()) continue;
     MetaSetsContainer metaCalculator = metaProperty.getMetaCalculator();
     if (!metaCalculator.containsMetaSets()) continue;
     Iterator itSets = metaCalculator.getMetaSets().iterator();
     while (itSets.hasNext()) {
       MetaSet set = (MetaSet) itSets.next();
       String propertyNameFrom = set.getPropertyNameFrom();
       if (!Is.emptyString(propertyNameFrom)) {
         String qualifiedName = metaProperty.getQualifiedName();
         int idx = qualifiedName.indexOf('.');
         String ref = idx < 0 ? "" : qualifiedName.substring(0, idx + 1);
         String qualifiedPropertyNameFrom = ref + propertyNameFrom;
         if (!getPropertiesNames().contains(qualifiedPropertyNameFrom)) {
           result.add(qualifiedPropertyNameFrom);
         }
       }
     }
   }
   return new ArrayList(result);
 }
コード例 #3
0
 private void setupDefaultConverters() throws XavaException {
   Iterator it = propertyMappings.values().iterator();
   while (it.hasNext()) {
     PropertyMapping propertyMapping = (PropertyMapping) it.next();
     propertyMapping.setDefaultConverter();
   }
 }
コード例 #4
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;
 }
コード例 #5
0
ファイル: MetaTab.java プロジェクト: OpenXavaEx/OpenXavaEx
 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;
 }
コード例 #6
0
ファイル: MetaTab.java プロジェクト: OpenXavaEx/OpenXavaEx
 private List createAllPropertiesNames() throws XavaException {
   List result = new ArrayList();
   // First the properties from a possible @EmbeddedId
   for (Iterator itRef = getMetaModel().getMetaReferencesKey().iterator(); itRef.hasNext(); ) {
     MetaReference ref = (MetaReference) itRef.next();
     if (ref.isAggregate()) {
       for (Iterator itKey =
               ref.getMetaModelReferenced()
                   .getPropertiesNamesWithoutHiddenNorTransient()
                   .iterator();
           itKey.hasNext(); ) {
         result.add(ref.getName() + "." + itKey.next());
       }
     }
   }
   // Now the plain properties
   result.addAll(getMetaModel().getPropertiesNamesWithoutHiddenNorTransient());
   return result;
 }
コード例 #7
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;
  }
コード例 #8
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;
 }
コード例 #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);
 }
コード例 #10
0
ファイル: MetaTab.java プロジェクト: OpenXavaEx/OpenXavaEx
 /** @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;
 }
コード例 #11
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();
 }
コード例 #12
0
ファイル: MetaTab.java プロジェクト: OpenXavaEx/OpenXavaEx
 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;
 }
コード例 #13
0
 public boolean isReferenceOverlappingWithSomeProperty(String reference) throws XavaException {
   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 + "_")) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #14
0
ファイル: MetaTab.java プロジェクト: OpenXavaEx/OpenXavaEx
 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();
 }
コード例 #15
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;
 }
コード例 #16
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);
 }
コード例 #17
0
  /**
   * Find the columns name in the formula and replace its by qualify columns name: 'name' ->
   * 't_reference.name'
   */
  private String qualifyFormulaWithReferenceName(
      String formula, String referenceName, String modelProperty) {
    EntityMapping em = MetaComponent.get(referenceName).getEntityMapping();

    Iterator<String> it = em.getColumns().iterator();
    while (it.hasNext()) {
      String column = it.next();
      if (formula.contains(column)) {
        formula =
            formula.replace(
                column, getQualifyColumnName(modelProperty, referenceName + "." + column));
      }
    }

    return formula;
  }
コード例 #18
0
ファイル: MetaTab.java プロジェクト: OpenXavaEx/OpenXavaEx
 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;
 }