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

database-rider / database-rider / #911

27 Oct 2024 07:44PM CUT coverage: 83.964% (+0.01%) from 83.951%
#911

push

web-flow
#610 fix support for parent classes hierarchy (#612)

* refs #610 fix annotation support for parent classes hierarchy

---------

Co-authored-by: Lee <hosing.lee@hsl-it-solutions.nl>

9 of 9 new or added lines in 1 file covered. (100.0%)

3084 of 3673 relevant lines covered (83.96%)

0.84 hits per line

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

32.56
/rider-core/src/main/java/com/github/database/rider/core/dataset/builder/BuilderUtil.java
1
package com.github.database.rider.core.dataset.builder;
2

3
import com.github.database.rider.core.api.configuration.Orthography;
4
import com.github.database.rider.core.configuration.DBUnitConfig;
5
import org.dbunit.dataset.Column;
6
import org.dbunit.dataset.datatype.DataType;
7
import org.eclipse.persistence.internal.jpa.metamodel.AttributeImpl;
8
import org.hibernate.SessionFactory;
9
import org.hibernate.persister.entity.AbstractEntityPersister;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

13
import javax.persistence.metamodel.Attribute;
14
import java.math.BigDecimal;
15
import java.util.Date;
16

17
import static com.github.database.rider.core.util.ClassUtils.isOnClasspath;
18
import static com.github.database.rider.core.util.EntityManagerProvider.em;
19
import static com.github.database.rider.core.util.EntityManagerProvider.isEntityManagerActive;
20

21
public class BuilderUtil {
×
22

23
    private static final Logger LOGGER = LoggerFactory.getLogger(BuilderUtil.class.getName());
1✔
24
    private static final DBUnitConfig config = DBUnitConfig.fromGlobalConfig();
1✔
25

26
    public static String convertColumnCase(Column column, DBUnitConfig config) {
27
        return convertCase(column.getColumnName(), config);
1✔
28
    }
29

30
    public static String convertCase(String value, DBUnitConfig config) {
31
        if (value != null && config != null && !config.isCaseSensitiveTableNames()) {
1✔
32
            if (Orthography.UPPERCASE == config.getCaseInsensitiveStrategy()) {
1✔
33
                value = value.toUpperCase();
1✔
34
            } else {
35
                value = value.toLowerCase();
×
36
            }
37
        }
38
        return value;
1✔
39
    }
40

41
    public static String getColumnNameFromMetaModel(Attribute column) {
42
        String columnName = null;
1✔
43
        try {
44
            if (isEclipseLinkOnClasspath()) {
1✔
45
                columnName = ((AttributeImpl) column).getMapping().getField().getName();
1✔
46
            } else if (isHibernateOnClasspath() && isEntityManagerActive()) {
×
47
                AbstractEntityPersister entityMetadata = (AbstractEntityPersister) em().getEntityManagerFactory().unwrap(SessionFactory.class).getClassMetadata(column.getJavaMember().getDeclaringClass());
×
48
                columnName = entityMetadata.getPropertyColumnNames(column.getName())[0];
×
49
            }
50
        } catch (Exception e) {
×
51
            LOGGER.error("Could not extract database column name from column {} and type {}", column.getName(), column.getDeclaringType().getJavaType().getName(), e);
×
52
        }
1✔
53
        if (columnName == null) {
1✔
54
            columnName = convertCase(column.getName(), config);
×
55
        }
56
        return columnName;
1✔
57
    }
58

59
    public static boolean isHibernateOnClasspath() {
60
        return isOnClasspath("org.hibernate.Session");
×
61
    }
62

63
    public static boolean isEclipseLinkOnClasspath() {
64
        return isOnClasspath("org.eclipse.persistence.mappings.DirectToFieldMapping");
1✔
65
    }
66

67
    /**
68
     * @param value column value
69
     * @return resolved datatype
70
     * @deprecated use <code>DataType.UNKNOWN</code> instead of this method. See https://github.com/database-rider/database-rider/pull/154#issuecomment-527622138
71
     */
72
    public static DataType resolveColumnDataType(Object value) {
73
        DataType columnType = DataType.UNKNOWN;
×
74
        if (value == null) {
×
75
            return columnType;
×
76
        }
77
        if (value instanceof Integer) {
×
78
            columnType = DataType.INTEGER;
×
79
        }
80
        if (value instanceof Long) {
×
81
            columnType = DataType.BIGINT_AUX_LONG;
×
82
        }
83
        if (value instanceof Double) {
×
84
            columnType = DataType.DOUBLE;
×
85
        }
86
        if (value instanceof Float) {
×
87
            columnType = DataType.FLOAT;
×
88
        }
89
        if (value instanceof Date) {
×
90
            columnType = DataType.DATE;
×
91
        }
92
        if (value instanceof Boolean) {
×
93
            columnType = DataType.BOOLEAN;
×
94
        }
95
        if (value instanceof BigDecimal) {
×
96
            columnType = DataType.DECIMAL;
×
97
        }
98
        if (value instanceof Number) {
×
99
            columnType = DataType.NUMERIC;
×
100
        }
101
        return columnType;
×
102
    }
103

104
}
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

© 2025 Coveralls, Inc