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;
}
}
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();
}
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);
}
}
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);
}
Aggregations