Ejemplo n.º 1
0
 protected Map<String, String> setupKeyToLowerMap(boolean dbNameKey) {
   final Map<String, String> map;
   if (dbNameKey) {
     map = newConcurrentHashMap(getTableDbName().toLowerCase(), getTablePropertyName());
   } else {
     map = newConcurrentHashMap(getTablePropertyName().toLowerCase(), getTableDbName());
   }
   final Method[] methods = this.getClass().getMethods();
   final String columnInfoMethodPrefix = "column";
   try {
     for (Method method : methods) {
       final String name = method.getName();
       if (!name.startsWith(columnInfoMethodPrefix)) {
         continue;
       }
       final ColumnInfo columnInfo = (ColumnInfo) method.invoke(this);
       final String dbName = columnInfo.getColumnDbName();
       final String propertyName = columnInfo.getPropertyName();
       if (dbNameKey) {
         map.put(dbName.toLowerCase(), propertyName);
       } else {
         map.put(propertyName.toLowerCase(), dbName);
       }
     }
     return Collections.unmodifiableMap(map);
   } catch (Exception e) {
     throw new IllegalStateException(e);
   }
 }
Ejemplo n.º 2
0
 protected <ENTITY extends Entity> void doConvertToEntity(
     ENTITY entity, Map<String, ? extends Object> columnMap, List<ColumnInfo> columnInfoList) {
   entity.clearModifiedInfo();
   final MapStringValueAnalyzer analyzer = new MapStringValueAnalyzer(columnMap);
   for (ColumnInfo columnInfo : columnInfoList) {
     final String columnName = columnInfo.getColumnDbName();
     final String propertyName = columnInfo.getPropertyName();
     final String uncapPropName = initUncap(propertyName);
     final Class<?> nativeType = columnInfo.getObjectNativeType();
     if (analyzer.init(columnName, uncapPropName, propertyName)) {
       final Object value;
       if (String.class.isAssignableFrom(nativeType)) {
         value = analyzer.analyzeString(nativeType);
       } else if (Number.class.isAssignableFrom(nativeType)) {
         value = analyzer.analyzeNumber(nativeType);
       } else if (Date.class.isAssignableFrom(nativeType)) {
         value = analyzer.analyzeDate(nativeType);
       } else if (Boolean.class.isAssignableFrom(nativeType)) {
         value = analyzer.analyzeBoolean(nativeType);
       } else if (byte[].class.isAssignableFrom(nativeType)) {
         value = analyzer.analyzeBinary(nativeType);
       } else if (UUID.class.isAssignableFrom(nativeType)) {
         value = analyzer.analyzeUUID(nativeType);
       } else {
         value = analyzer.analyzeOther(nativeType);
       }
       columnInfo.write(entity, value);
     }
   }
 }
Ejemplo n.º 3
0
 /** {@inheritDoc} */
 public String findDbName(String flexibleName) {
   assertStringNotNullAndNotTrimmedEmpty("flexibleName", flexibleName);
   final ColumnInfo columnInfoMap = getColumnInfoFlexibleMap().get(flexibleName);
   if (columnInfoMap != null) {
     return columnInfoMap.getColumnDbName();
   }
   final String tableDbName = getTableDbNameFlexibleMap().get(flexibleName);
   if (tableDbName != null) {
     return tableDbName;
   }
   throwDBMetaNotFoundException("The DB name was not found.", "Flexible Name", flexibleName);
   return null; // unreachable
 }
Ejemplo n.º 4
0
 // -----------------------------------------------------
 //                                       Write Converter
 //                                       ---------------
 // these are static to avoid the FindBugs headache
 // (implementations of PropertyGateway can be static class)
 protected static void ccls(ColumnInfo columnInfo, Object code) { // checkClassification
   // old style, for compatibility, check only on entity after Java8
   if (code == null) {
     return; // no check null value which means no existence on DB
   }
   final ClassificationMeta meta = columnInfo.getClassificationMeta();
   if (meta == null) { // no way (just in case)
     return;
   }
   final ClassificationUndefinedHandlingType undefinedHandlingType = meta.undefinedHandlingType();
   if (!undefinedHandlingType.isChecked()) { // basically no way (not called if no check)
     return;
   }
   final Classification classification = gcls(columnInfo, code);
   if (classification == null) {
     final String tableDbName = columnInfo.getDBMeta().getTableDbName();
     final String columnDbName = columnInfo.getColumnDbName();
     FunCustodial.handleUndefinedClassificationCode(tableDbName, columnDbName, meta, code);
   }
 }
Ejemplo n.º 5
0
 protected Map<String, Object> doConvertToColumnValueMap(Entity entity, boolean pkOnly) {
   final Map<String, Object> valueMap = newLinkedHashMap();
   final List<ColumnInfo> columnInfoList;
   if (pkOnly) {
     columnInfoList = getPrimaryUniqueInfo().getUniqueColumnList();
   } else {
     columnInfoList = getColumnInfoList();
   }
   final Set<String> specifiedProperties = entity.myspecifiedProperties();
   final boolean nonSpChecked = !specifiedProperties.isEmpty();
   for (ColumnInfo columnInfo : columnInfoList) {
     final String columnName = columnInfo.getColumnDbName();
     final Object value;
     if (nonSpChecked
         && !specifiedProperties.contains(columnInfo.getPropertyName())) { // non-specified column
       value = null; // to avoid non-specified check
     } else {
       value = columnInfo.read(entity);
     }
     valueMap.put(columnName, value);
   }
   return valueMap;
 }