Search in sources :

Example 1 with DBSAttributeEnumerable

use of org.jkiss.dbeaver.model.struct.DBSAttributeEnumerable in project dbeaver by dbeaver.

the class AbstractMockValueGenerator method generateValue.

@Override
public Object generateValue(DBRProgressMonitor monitor) throws DBException, IOException {
    if (isFirstRun) {
        isFirstRun = false;
        isUnique = DBUtils.checkUnique(monitor, dbsEntity, attribute);
        if (isUnique && (attribute instanceof DBSAttributeEnumerable)) {
            uniqueValues = new HashSet<>();
            Collection<DBDLabelValuePair> valuePairs = readColumnValues(monitor, dbsEntity.getDataSource(), (DBSAttributeEnumerable) attribute, UNIQUE_VALUES_SET_SIZE);
            for (DBDLabelValuePair pair : valuePairs) {
                uniqueValues.add(pair.getValue());
            }
        }
    }
    if (isUnique) {
        int attempts = 0;
        Object value = null;
        while (value == null || uniqueValues.contains(value)) {
            if (attempts > UNIQUE_VALUE_GEN_ATTEMPTS) {
                throw new DBException("\n      Can't generate appropriate unique value for the '" + attribute.getName() + "' <" + attribute.getFullTypeName() + "> attribute.\n" + "      Try to change the generator or its parameters.\n");
            }
            if (monitor.isCanceled()) {
                return null;
            }
            value = generateOneValue(monitor);
            attempts++;
        }
        uniqueValues.add(value);
        return value;
    } else {
        return generateOneValue(monitor);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSAttributeEnumerable(org.jkiss.dbeaver.model.struct.DBSAttributeEnumerable) DBDLabelValuePair(org.jkiss.dbeaver.model.data.DBDLabelValuePair)

Aggregations

DBException (org.jkiss.dbeaver.DBException)1 DBDLabelValuePair (org.jkiss.dbeaver.model.data.DBDLabelValuePair)1 DBSAttributeEnumerable (org.jkiss.dbeaver.model.struct.DBSAttributeEnumerable)1