• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeonky / test-charm-java / 150

07 Mar 2025 12:58AM UTC coverage: 74.287% (-0.08%) from 74.367%
150

push

circleci

leeonky
Try to fix ci

7919 of 10660 relevant lines covered (74.29%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.62
/DAL-extension-jdbc/src/main/java/com/github/leeonky/dal/extensions/jdbc/JDBCExtension.java
1
package com.github.leeonky.dal.extensions.jdbc;
2

3
import com.github.leeonky.dal.DAL;
4
import com.github.leeonky.dal.runtime.Data;
5
import com.github.leeonky.dal.runtime.Extension;
6
import com.github.leeonky.dal.runtime.inspector.Dumper;
7
import com.github.leeonky.dal.runtime.inspector.DumpingBuffer;
8
import com.github.leeonky.dal.runtime.inspector.MapDumper;
9

10
import java.util.ArrayList;
11
import java.util.List;
12
import java.util.stream.Collectors;
13

14
import static java.util.stream.StreamSupport.stream;
15

16
public class JDBCExtension implements Extension {
1✔
17

18
    @Override
19
    public void extend(DAL dal) {
20
        dal.getRuntimeContextBuilder()
1✔
21
                .registerMetaProperty(CanWhere.class, "where", MetaProperties::where)
1✔
22
                .registerMetaProperty(DataBase.Table.class, "select", MetaProperties::select)
1✔
23
                .registerMetaProperty(DataBase.Row.class, "belongsTo", MetaProperties::belongsTo)
1✔
24
                .registerMetaProperty(Association.class, "on", MetaProperties::on)
1✔
25

26
                .registerMetaProperty(DataBase.Row.class, "hasMany", MetaProperties::hasMany)
1✔
27
                .registerMetaProperty(DataBase.Row.class, "hasOne", MetaProperties::hasOne)
1✔
28
                .registerMetaProperty(Association.class, "through", MetaProperties::through)
1✔
29

30
                .registerDumper(DataBase.Table.class, data -> new TableDumper())
1✔
31
                .registerDumper(DataBase.class, data -> new DataBaseDumper())
1✔
32
        ;
33
    }
1✔
34

35
    private static class TableDumper implements Dumper {
36

37
        @Override
38
        public void dump(Data data, DumpingBuffer dumpingBuffer) {
39
            List<List<String>> tableData = getData(data);
1✔
40
            if (tableData.isEmpty())
1✔
41
                dumpingBuffer.append("[]");
×
42
            else {
43
                Integer[] lengths = resolveColumnWidth(tableData);
1✔
44
                tableData.forEach(line -> {
1✔
45
                    DumpingBuffer rowBuffer = dumpingBuffer.indent().newLine().append("|");
1✔
46
                    for (int c = 0; c < line.size(); c++)
1✔
47
                        rowBuffer.append(String.format(String.format(" %%%ds |", lengths[c]), line.get(c)));
1✔
48
                });
1✔
49
            }
50
        }
1✔
51

52
        private List<List<String>> getData(Data data) {
53
            List<List<String>> tableData = new ArrayList<>();
1✔
54
            stream(((DataBase.Table<?>) data.instance()).spliterator(), false).limit(100).forEach(row -> {
1✔
55
                if (tableData.isEmpty())
1✔
56
                    tableData.add(new ArrayList<>(row.columns()));
1✔
57
                tableData.add(row.data().values().stream().map(String::valueOf).collect(Collectors.toList()));
1✔
58
            });
1✔
59
            return tableData;
1✔
60
        }
61

62
        private Integer[] resolveColumnWidth(List<List<String>> tableData) {
63
            Integer[] lengths = tableData.get(0).stream().map(String::length).toArray(Integer[]::new);
1✔
64
            tableData.stream().skip(1).forEach(row -> {
1✔
65
                for (int c = 0; c < lengths.length; c++)
1✔
66
                    lengths[c] = Math.max(lengths[c], row.get(c).length());
1✔
67
            });
1✔
68
            return lengths;
1✔
69
        }
70
    }
71

72
    private static class DataBaseDumper extends MapDumper {
73

74
        @Override
75
        protected void dumpType(Data data, DumpingBuffer dumpingBuffer) {
76
            DataBase dataBase = (DataBase) data.instance();
1✔
77
            dumpingBuffer.append("DataBase[").append(dataBase.getUrl()).append("] ");
1✔
78
        }
1✔
79

80
        @Override
81
        protected void dumpField(Data data, Object field, DumpingBuffer context) {
82
            DataBase.Table<?> table = (DataBase.Table<?>) data.getValue(field).instance();
1✔
83
            if (table.iterator().hasNext())
1✔
84
                context.append(key(field)).append(":").dumpValue(data.getValue(field));
1✔
85
        }
1✔
86
    }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc