Search in sources :

Example 1 with AugmenterConfig

use of org.jumpmind.pos.persist.model.AugmenterConfig in project openpos-framework by JumpMind.

the class DatabaseSchema method createAugmentedFieldsMetaData.

private static void createAugmentedFieldsMetaData(ModelClassMetaData meta, List<Column> columns, IDatabasePlatform databasePlatform, AugmenterHelper augmenterHelper) {
    if (augmenterHelper != null) {
        List<AugmenterConfig> configs = augmenterHelper.getAugmenterConfigs(meta.getClazz());
        for (AugmenterConfig config : configs) {
            meta.getAugmenterConfigs().add(config);
            for (AugmenterModel augmenterModel : config.getAugmenters()) {
                meta.getAugmentedFieldNames().add(augmenterModel.getName());
                Column column = new Column();
                column.setName(alterCaseToMatchDatabaseDefaultCase(config.getPrefix(), databasePlatform) + alterCaseToMatchDatabaseDefaultCase(camelToSnakeCase(augmenterModel.getName()), databasePlatform));
                column.setDefaultValue(augmenterModel.getDefaultValue());
                column.setSize(augmenterModel.getSize() != null ? Integer.toString(augmenterModel.getSize()) : "32");
                column.setTypeCode(Types.VARCHAR);
                columns.add(column);
            }
        }
    }
}
Also used : Column(org.jumpmind.db.model.Column) IndexColumn(org.jumpmind.db.model.IndexColumn) AugmenterConfig(org.jumpmind.pos.persist.model.AugmenterConfig) AugmenterModel(org.jumpmind.pos.persist.model.AugmenterModel)

Example 2 with AugmenterConfig

use of org.jumpmind.pos.persist.model.AugmenterConfig in project openpos-framework by JumpMind.

the class ModelValidator method checkAugmentedFields.

protected static void checkAugmentedFields(ModelClassMetaData meta) {
    if (CollectionUtils.size(meta.getAugmenterConfigs()) > 1) {
        Map<String, Integer> augmenterNameCounts = new HashMap<>();
        for (AugmenterConfig config : meta.getAugmenterConfigs()) {
            for (String name : config.getAugmenterNames()) {
                Integer count = augmenterNameCounts.get(name);
                if (count == null) {
                    count = 1;
                } else {
                    count++;
                }
                augmenterNameCounts.put(name, count);
            }
        }
        for (Map.Entry<String, Integer> entry : augmenterNameCounts.entrySet()) {
            if (entry.getValue() > 1) {
                throw new PersistException("Duplicate augmenter name " + entry.getKey() + " found on model " + meta.getClazz());
            }
        }
    }
}
Also used : PersistException(org.jumpmind.pos.persist.PersistException) AugmenterConfig(org.jumpmind.pos.persist.model.AugmenterConfig)

Example 3 with AugmenterConfig

use of org.jumpmind.pos.persist.model.AugmenterConfig in project openpos-framework by JumpMind.

the class DatabaseSchema method getAugmentedColumnsToFields.

private Map<String, String> getAugmentedColumnsToFields(Class<?> entityClass) {
    Map<String, String> columnsToAugmentedFields = new CaseInsensitiveMap<>();
    List<AugmenterConfig> configs = augmenterHelper.getAugmenterConfigs(entityClass);
    for (AugmenterConfig config : configs) {
        for (String augmenterName : config.getAugmenterNames()) {
            columnsToAugmentedFields.put(config.getPrefix() + camelToSnakeCase(augmenterName), augmenterName);
        }
    }
    return columnsToAugmentedFields;
}
Also used : CaseInsensitiveMap(org.apache.commons.collections4.map.CaseInsensitiveMap) AugmenterConfig(org.jumpmind.pos.persist.model.AugmenterConfig)

Aggregations

AugmenterConfig (org.jumpmind.pos.persist.model.AugmenterConfig)3 CaseInsensitiveMap (org.apache.commons.collections4.map.CaseInsensitiveMap)1 Column (org.jumpmind.db.model.Column)1 IndexColumn (org.jumpmind.db.model.IndexColumn)1 PersistException (org.jumpmind.pos.persist.PersistException)1 AugmenterModel (org.jumpmind.pos.persist.model.AugmenterModel)1