Search in sources :

Example 16 with NotSupportYetException

use of io.seata.common.exception.NotSupportYetException in project seata by seata.

the class BeanUtils method objectToMap.

/**
 * object to map
 *
 * @param object the object
 * @return the map
 */
public static Map<String, String> objectToMap(Object object) {
    if (object == null) {
        return null;
    }
    Map<String, String> map = new HashMap<>(16);
    Field[] fields = object.getClass().getDeclaredFields();
    try {
        for (Field field : fields) {
            boolean accessible = field.isAccessible();
            field.setAccessible(true);
            if (field.getType() == Date.class) {
                Date date = (Date) field.get(object);
                if (date != null) {
                    map.put(field.getName(), String.valueOf(date.getTime()));
                }
            } else {
                map.put(field.getName(), field.get(object) == null ? "" : field.get(object).toString());
            }
            field.setAccessible(accessible);
        }
    } catch (IllegalAccessException e) {
        throw new NotSupportYetException("object " + object.getClass().toString() + " to map failed:" + e.getMessage());
    }
    return map;
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) NotSupportYetException(io.seata.common.exception.NotSupportYetException) Date(java.util.Date)

Aggregations

NotSupportYetException (io.seata.common.exception.NotSupportYetException)16 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)6 SQLJoinTableSource (com.alibaba.druid.sql.ast.statement.SQLJoinTableSource)6 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)6 ArrayList (java.util.ArrayList)4 List (java.util.List)3 MySqlOutputVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor)2 OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)2 PGOutputVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor)2 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)2 ParametersHolder (io.seata.sqlparser.ParametersHolder)2 SQLRecognizer (io.seata.sqlparser.SQLRecognizer)2 Field (java.lang.reflect.Field)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 StringJoiner (java.util.StringJoiner)2 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)1 PreparedStatementProxy (io.seata.rm.datasource.PreparedStatementProxy)1