All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sqlancer.common.schema.AbstractRowValue Maven / Gradle / Ivy

Go to download

SQLancer finds logic bugs in Database Management Systems through automatic testing

There is a newer version: 2.0.0
Show newest version
package sqlancer.common.schema;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public abstract class AbstractRowValue, C extends AbstractTableColumn, O> {

    private final T tables;
    private final Map values;

    protected AbstractRowValue(T tables, Map values) {
        this.tables = tables;
        this.values = values;
    }

    public T getTable() {
        return tables;
    }

    public Map getValues() {
        return values;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        int i = 0;
        for (C c : tables.getColumns()) {
            if (i++ != 0) {
                sb.append(", ");
            }
            sb.append(values.get(c));
        }
        return sb.toString();
    }

    public String getRowValuesAsString() {
        List columnsToCheck = tables.getColumns();
        return getRowValuesAsString(columnsToCheck);
    }

    public String getRowValuesAsString(List columnsToCheck) {
        StringBuilder sb = new StringBuilder();
        Map expectedValues = getValues();
        for (int i = 0; i < columnsToCheck.size(); i++) {
            if (i != 0) {
                sb.append(", ");
            }
            O expectedColumnValue = expectedValues.get(columnsToCheck.get(i));
            sb.append(expectedColumnValue);
        }
        return sb.toString();
    }

    public String asStringGroupedByTables() {
        StringBuilder sb = new StringBuilder();
        List columnList = getValues().keySet().stream().collect(Collectors.toList());
        List> tableList = columnList.stream().map(c -> c.getTable()).distinct().sorted()
                .collect(Collectors.toList());
        for (int j = 0; j < tableList.size(); j++) {
            if (j != 0) {
                sb.append("\n");
            }
            AbstractTable t = tableList.get(j);
            sb.append("-- " + t.getName() + "\n");
            List columnsForTable = columnList.stream().filter(c -> c.getTable().equals(t))
                    .collect(Collectors.toList());
            for (int i = 0; i < columnsForTable.size(); i++) {
                if (i != 0) {
                    sb.append("\n");
                }
                sb.append("--\t");
                sb.append(columnsForTable.get(i));
                sb.append("=");
                sb.append(getValues().get(columnsForTable.get(i)));
            }
        }
        return sb.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy