Package net.datacrow.core.objects

Examples of net.datacrow.core.objects.DcField


      addEntries(sql, module);
      return sql.toString();
    }
   
    public String toSQL(int[] fields, boolean order, boolean includeMod) {
        DcField field;
       
        DcModule m = DcModules.get(getModule());
        int[] queryFields = fields == null || fields.length == 0 ? m.getFieldIndices() : fields;
       
        Collection<DcModule> modules = new ArrayList<DcModule>();
        if (m.isAbstract())
          modules.addAll(DcModules.getPersistentModules(m));
        else
          modules.add(m);
       
        StringBuffer sql = new StringBuffer();
       
        int columnCounter = 0;
        int moduleCounter = 0;
        if (m.isAbstract()) {
          sql.append("SELECT MODULEIDX");
          for (int idx : queryFields) {
        field = m.getField(idx);
        if (!field.isUiOnly()) {
          sql.append(", ");
          sql.append(field.getDatabaseFieldName());
          columnCounter++;
        }
      }
         
          sql.append(" FROM (");
        }
       
        for (DcModule module : modules) {
          columnCounter = 0;
          if (moduleCounter > 0)
        sql.append(" UNION ");
     
        sql.append(" SELECT ");
           
           if (m.isAbstract() || includeMod) {
            sql.append(module.getIndex());
            sql.append(" AS MODULEIDX ");
            columnCounter++;
          }
     
      if (m.isAbstract()) {
        for (DcField abstractField : m.getFields()) {
          if (!abstractField.isUiOnly()) {
            if (columnCounter > 0) sql.append(", ");
            sql.append(abstractField.getDatabaseFieldName());
            columnCounter++;
          }
        }
      } else {
        for (int idx : queryFields) {
          field = m.getField(idx);
          if (!field.isUiOnly()) {
            if (columnCounter > 0) sql.append(", ");
            sql.append(field.getDatabaseFieldName());
            columnCounter++;
          }
        }
      }
     
View Full Code Here


    Object value;
        int operator;
        int counter2;
        int counter = 0;
        String queryValue = null;
        DcField field;
       
        DcModule m = DcModules.get(getModule());
       
        for (DataFilterEntry entry : getEntries()) {
         
          if (!m.isAbstract()) {
            entryModule = DcModules.get(entry.getModule());
              if (entry.getModule() != getModule()) {
                  childEntries.add(entry);
                  continue;
              }
          } else {
            entryModule = module;
          }
           
            field = entryModule.getField(entry.getField());
           
            if (    field.isUiOnly() &&
                    field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION &&
                    field.getValueType() != DcRepository.ValueTypes._PICTURE)
                continue;
           
            hasConditions = true;
           
            operator = entry.getOperator().getIndex();
            value = entry.getValue() != null ? Utilities.getQueryValue(entry.getValue(), field) : null;
           
            if (value != null) {
                queryValue = String.valueOf(value);
                if (field.getValueType() == DcRepository.ValueTypes._DATE ||
                    field.getValueType() == DcRepository.ValueTypes._STRING) {
                    queryValue = queryValue.replaceAll("\'", "''");
                }
            }
           
            if (counter > 0) sql.append(entry.isAnd() ? " AND " : " OR ");
           
            if (counter == 0) sql.append(" WHERE ");
           
           
            boolean useUpper = field.getValueType() == DcRepository.ValueTypes._STRING &&
                field.getIndex() != DcObject._ID &&
                field.getValueType() != DcRepository.ValueTypes._DCOBJECTREFERENCE &&
                field.getValueType() != DcRepository.ValueTypes._DCPARENTREFERENCE &&
                field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION;
           
            if (field.getValueType() == DcRepository.ValueTypes._STRING) {
                if (useUpper) sql.append("UPPER(");
                sql.append(field.getDatabaseFieldName());
                if (useUpper) sql.append(")");
            } else if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION ||
                       field.getValueType() == DcRepository.ValueTypes._PICTURE) {
                sql.append("ID");
            } else {
                sql.append(field.getDatabaseFieldName());
            }
           
            if (field.getValueType() == DcRepository.ValueTypes._PICTURE) {
               
                if (operator == Operator.IS_EMPTY.getIndex())
                    sql.append(" NOT");
               
                DcModule picModule = DcModules.get(DcModules._PICTURE);
                sql.append(" IN (SELECT OBJECTID FROM " + picModule.getTableName() +
                           " WHERE " + picModule.getField(Picture._B_FIELD).getDatabaseFieldName() +
                           " = '" + field.getDatabaseFieldName() + "')");
               
            } else if ( operator == Operator.CONTAINS.getIndex() ||
                        operator == Operator.DOES_NOT_CONTAIN.getIndex() ||
                       (operator == Operator.EQUAL_TO.getIndex() && field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) ||
                       (operator == Operator.NOT_EQUAL_TO.getIndex() && field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION)) {

                if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
                    if (operator == Operator.DOES_NOT_CONTAIN.getIndex() ||
                        operator == Operator.NOT_EQUAL_TO.getIndex())
                        sql.append(" NOT");

                    sql.append(" IN (");
                   
                    DcModule mapping = DcModules.get(DcModules.getMappingModIdx(entryModule.getIndex(), field.getReferenceIdx(), field.getIndex()));
                  sql.append("SELECT ");
                    sql.append(mapping.getField(DcMapping._A_PARENT_ID).getDatabaseFieldName());
                    sql.append(" FROM ");
                    sql.append(mapping.getTableName());
                    sql.append(" WHERE ");
View Full Code Here

   
    private void addOrderBy(StringBuffer sql) {
      int counter = 0;
        DcModule module = DcModules.get(getModule());
        DcModule referenceMod;
        DcField field = module.getField(module.getDefaultSortFieldIdx());
        if (order != null && order.length > 0) {
            for (DcField orderOn : order) {
                if (orderOn != null) {
                  sql.append(counter == 0 ? " ORDER BY " : ", ");
                  if (orderOn.getValueType() == DcRepository.ValueTypes._DCOBJECTREFERENCE ||
                      orderOn.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {

                      referenceMod = DcModules.get(orderOn.getReferenceIdx());
                        sql.append(referenceMod.getTableName());
                        sql.append(".");
                        sql.append(referenceMod.getField(referenceMod.getSystemDisplayFieldIdx()).getDatabaseFieldName());
                  } else if (!orderOn.isUiOnly() && orderOn.getDatabaseFieldName() != null) {
                      sql.append(orderOn.getDatabaseFieldName());
                  }
                  counter++;
                }
            }
           
            if (counter > 0)
              sql.append(getSortOrder() == _SORTORDER_ASCENDING ? "" : " DESC");
           
        } else if (field != null && !field.isUiOnly()) {
            sql.append(" ORDER BY ");
            sql.append(module.getField(module.getDefaultSortFieldIdx()).getDatabaseFieldName());
        }
    }
View Full Code Here

  }
 
  public void save() {
    int[] picOrder = new int[table.getRowCount()];
    for (int i = 0; i < table.getRowCount(); i++) {
      DcField field = (DcField) table.getValueAt(i, 0);
      picOrder[i] = field.getIndex();
    }
    DcModules.get(module).setSetting(DcRepository.ModuleSettings.stCardViewPictureOrder, picOrder);
  }
View Full Code Here

                GridBagConstraints.CENTER, GridBagConstraints.NONE,
                new Insets(0, 5, 5, 5), 0, 0));
       
        Collection<DcField> fields = new ArrayList<DcField>();
        for (int fieldIdx : DcModules.get(module).getSettings().getIntArray(DcRepository.ModuleSettings.stCardViewPictureOrder)) {
            DcField field = DcModules.get(module).getField(fieldIdx);
            if (field.getValueType() == DcRepository.ValueTypes._PICTURE && !fields.contains(field))
                fields.add(field);
        }

        for (DcField field : DcModules.get(module).getFields()) {
            if (field.getValueType() == DcRepository.ValueTypes._PICTURE && !fields.contains(field))
                fields.add(field);
        }
       
        for (DcField field : fields)
            table.addRow(new Object[] {field});
View Full Code Here

        if (order == _SORTORDER_DESCENDING) {
            o1 = dco2.getValue(field);
            o2 = dco1.getValue(field);
        }
       
        DcField fld = dco1.getField(field);
        if (o1 instanceof Number && o2 instanceof Number &&
            fld.getValueType() == DcRepository.ValueTypes._BIGINTEGER ||
            fld.getValueType() == DcRepository.ValueTypes._DOUBLE ||
            fld.getValueType() == DcRepository.ValueTypes._LONG) {
       
            Number n1 = (Number) o1;
            Number n2 = (Number) o2;
           
            return (int) (n1.longValue() - n2.longValue());

        } else if (fld.getValueType() == DcRepository.ValueTypes._DATE) {
            Date d1 = (Date) o1;
            Date d2 = (Date) o2;
       
            return d1.compareTo(d2);
View Full Code Here

       
        if (module.getChildIndex() > -1)
            setChild(module.getChildIndex());
       
        for (XmlField xmlField : module.getFields())
            addField(new DcField(xmlField, getIndex()));
       
        initializeFields();
        initializeMultiReferenceFields();
        initializeSettings();
        initializeProperties();
View Full Code Here

    /**
     * Retrieves the field definition for the given index.
     * @param index The field index.
     */
    public DcField getField(int index) {
        DcField field = fields.get(index);
        return field == null ? getSystemField(index) : field;
    }
View Full Code Here

     * Applies the field settings on this module.
     */
    public void applySettings() {
        try {
            for (DcFieldDefinition definition : getFieldDefinitions().getDefinitions()) {
               DcField field = getField(definition.getIndex());
   
               field.setRequired(definition.isRequired());
               field.setEnabled(definition.isEnabled());
           }
        } catch (Exception e) {
            logger.error("Error while applying settings on module " + getName(), e);
        }
    }   
View Full Code Here

        for (DcField field : getFields()) {
           
            if (field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION)
                continue;
           
            DcField fld = new DcField(
                    field.getIndex() + 100000000,
                    field.getModule(),
                    field.getSystemName() + "_persist",
                    false,
                    false,
View Full Code Here

TOP

Related Classes of net.datacrow.core.objects.DcField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.