Search in sources :

Example 1 with CategoryLabelCountMap

use of com.revolsys.util.count.CategoryLabelCountMap in project com.revolsys.open by revolsys.

the class CodeTableProperty method loadId.

@Override
protected synchronized Identifier loadId(final List<Object> values, final boolean createId) {
    if (this.loadAll && !this.loadMissingCodes && !isEmpty()) {
        return null;
    }
    Identifier id = null;
    if (createId && this.loadAll && !isLoaded()) {
        loadAll();
        id = getIdentifier(values, false);
    } else {
        final Query query = new Query(this.typePath);
        final And and = new And();
        if (!values.isEmpty()) {
            int i = 0;
            for (final String fieldName : this.valueFieldNames) {
                final Object value = values.get(i);
                if (value == null) {
                    and.and(Q.isNull(fieldName));
                } else {
                    final FieldDefinition fieldDefinition = this.recordDefinition.getField(fieldName);
                    and.and(Q.equal(fieldDefinition, value));
                }
                i++;
            }
        }
        query.setWhereCondition(and);
        final Reader<Record> reader = this.recordStore.getRecords(query);
        try {
            final List<Record> codes = reader.toList();
            if (codes.size() > 0) {
                final CategoryLabelCountMap statistics = this.recordStore.getStatistics();
                if (statistics != null) {
                    statistics.getLabelCountMap("query").addCount(this.typePath, -codes.size());
                }
                addValues(codes);
            }
            id = getIdByValue(values);
            Property.firePropertyChange(this, "valuesChanged", false, true);
        } finally {
            reader.close();
        }
    }
    if (createId && id == null) {
        return newIdentifier(values);
    } else {
        return id;
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) SingleIdentifier(com.revolsys.identifier.SingleIdentifier) ListIdentifier(com.revolsys.identifier.ListIdentifier) Query(com.revolsys.record.query.Query) CategoryLabelCountMap(com.revolsys.util.count.CategoryLabelCountMap) And(com.revolsys.record.query.And) FieldDefinition(com.revolsys.record.schema.FieldDefinition) Record(com.revolsys.record.Record)

Example 2 with CategoryLabelCountMap

use of com.revolsys.util.count.CategoryLabelCountMap in project com.revolsys.open by revolsys.

the class LabelCountMapTableModel method setStatistics.

public void setStatistics(final Map<String, LabelCountMap> statisticsMap) {
    try {
        this.categoryLabelCountMap = new CategoryLabelCountMap(statisticsMap);
        for (final Entry<String, LabelCountMap> entry : statisticsMap.entrySet()) {
            final String countName = entry.getKey();
            addCountNameColumn(countName);
            final LabelCountMap labelCountMap = entry.getValue();
            for (final String label : labelCountMap.getLabels()) {
                newStatistics(countName, label);
            }
        }
    } catch (final ConcurrentModificationException e) {
    }
    refresh();
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) CategoryLabelCountMap(com.revolsys.util.count.CategoryLabelCountMap) CategoryLabelCountMap(com.revolsys.util.count.CategoryLabelCountMap) LabelCountMap(com.revolsys.util.count.LabelCountMap)

Example 3 with CategoryLabelCountMap

use of com.revolsys.util.count.CategoryLabelCountMap in project com.revolsys.open by revolsys.

the class AbstractRecordStore method setLabel.

@Override
public void setLabel(final String label) {
    this.label = label;
    final CategoryLabelCountMap statistics = getStatistics();
    if (statistics != null) {
        statistics.setPrefix(label);
    }
}
Also used : CategoryLabelCountMap(com.revolsys.util.count.CategoryLabelCountMap)

Example 4 with CategoryLabelCountMap

use of com.revolsys.util.count.CategoryLabelCountMap in project com.revolsys.open by revolsys.

the class CodeTableProperty method loadAll.

public synchronized void loadAll() {
    final long time = System.currentTimeMillis();
    if (this.threadLoading.get() != Boolean.TRUE) {
        if (this.loading) {
            while (this.loading) {
                try {
                    wait(1000);
                } catch (final InterruptedException e) {
                }
            }
            return;
        } else {
            this.threadLoading.set(Boolean.TRUE);
            this.loading = true;
            try {
                final RecordDefinition recordDefinition = this.recordStore.getRecordDefinition(this.typePath);
                final Query query = new Query(recordDefinition);
                query.setFieldNames(recordDefinition.getFieldNames());
                for (final String order : this.orderBy) {
                    query.addOrderBy(order);
                }
                try (Reader<Record> reader = this.recordStore.getRecords(query)) {
                    final List<Record> codes = reader.toList();
                    final CategoryLabelCountMap statistics = this.recordStore.getStatistics();
                    if (statistics != null) {
                        statistics.getLabelCountMap("query").addCount(this.typePath, -codes.size());
                    }
                    Collections.sort(codes, new RecordFieldComparator(this.orderBy));
                    addValues(codes);
                }
                Property.firePropertyChange(this, "valuesChanged", false, true);
            } finally {
                this.loading = false;
                this.loaded = true;
                this.threadLoading.set(null);
                this.notifyAll();
            }
        }
    }
    Dates.debugEllapsedTime(this, "Load All: " + getTypePath(), time);
}
Also used : Query(com.revolsys.record.query.Query) CategoryLabelCountMap(com.revolsys.util.count.CategoryLabelCountMap) Record(com.revolsys.record.Record) RecordFieldComparator(com.revolsys.record.comparator.RecordFieldComparator) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

CategoryLabelCountMap (com.revolsys.util.count.CategoryLabelCountMap)4 Record (com.revolsys.record.Record)2 Query (com.revolsys.record.query.Query)2 Identifier (com.revolsys.identifier.Identifier)1 ListIdentifier (com.revolsys.identifier.ListIdentifier)1 SingleIdentifier (com.revolsys.identifier.SingleIdentifier)1 RecordFieldComparator (com.revolsys.record.comparator.RecordFieldComparator)1 And (com.revolsys.record.query.And)1 FieldDefinition (com.revolsys.record.schema.FieldDefinition)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 LabelCountMap (com.revolsys.util.count.LabelCountMap)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1