org.apache.commons.lang.ObjectUtils#clone ( )源码实例Demo

下面列出了org.apache.commons.lang.ObjectUtils#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: canal-mongo   文件: DataService.java
public void insert(List<CanalEntry.Column> data, String schemaName, String tableName) {
    DBObject obj = DBConvertUtil.columnToJson(data);
    logger.debug("insert :{}", obj.toString());
    //订单库单独处理
    if (schemaName.equals("order")) {
        //保存原始数据
        if (tableName.startsWith("order_base_info")) {
            tableName = "order_base_info";
        } else if (tableName.startsWith("order_detail_info")) {
            tableName = "order_detail_info";
        } else {
            logger.info("unknown data :{}.{}:{}", schemaName, tableName, obj);
            return;
        }
        insertData(schemaName, tableName, obj, obj);
    } else {
        DBObject newObj = (DBObject) ObjectUtils.clone(obj);
        if (newObj.containsField("id")) {
            newObj.put("_id", newObj.get("id"));
            newObj.removeField("id");
        }
        insertData(schemaName, tableName, newObj, obj);
    }
}
 
源代码2 项目: canal-mongo   文件: DataService.java
public void insertData(String schemaName, String tableName, DBObject naive, DBObject complete) {
    int i = 0;
    DBObject logObj = (DBObject) ObjectUtils.clone(complete);
    //保存原始数据
    try {
        String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.INSERT.getNumber();
        i++;
        naiveMongoTemplate.getCollection(tableName).insert(naive);
        i++;
        SpringUtil.doEvent(path, complete);
        i++;
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 1, i, logObj, e);
    }
}
 
源代码3 项目: canal-mongo   文件: DataService.java
public void updateData(String schemaName, String tableName, DBObject query, DBObject obj) {
    String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.UPDATE.getNumber();
    int i = 0;
    DBObject newObj = (DBObject) ObjectUtils.clone(obj);
    DBObject logObj = (DBObject) ObjectUtils.clone(obj);
    //保存原始数据
    try {
        obj.removeField("id");
        i++;
        naiveMongoTemplate.getCollection(tableName).update(query, obj);
        i++;
        SpringUtil.doEvent(path, newObj);
        i++;
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 2, i, logObj, e);
    }
}
 
源代码4 项目: canal-mongo   文件: DataService.java
public void deleteData(String schemaName, String tableName, DBObject obj) {
    int i = 0;
    String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.DELETE.getNumber();
    DBObject newObj = (DBObject) ObjectUtils.clone(obj);
    DBObject logObj = (DBObject) ObjectUtils.clone(obj);
    //保存原始数据
    try {
        i++;
        if (obj.containsField("id")) {
            naiveMongoTemplate.getCollection(tableName).remove(new BasicDBObject("_id", obj.get("id")));
        }
        i++;
        SpringUtil.doEvent(path, newObj);
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 3, i, logObj, e);
    }
}
 
/**
 * Enforce Map keys are only Scalars and can be used as {@link String} keys in {@link Mapping}
 */
@Override
protected void constructMapping2ndStep(MappingNode node, final Map mapping) {
    ((Mapping) mapping).setSource(getSource(node));
    super.constructMapping2ndStep(node,
            new AbstractMapDecorator(mapping) {
        @Override
        public Object put(Object key, Object value) {
            if (!(key instanceof Scalar)) throw new IllegalStateException("We only support scalar map keys");
            Object scalar = ObjectUtils.clone(value);
            if (scalar instanceof Number) scalar = new Scalar(scalar.toString());
            else if (scalar instanceof Boolean) scalar = new Scalar(scalar.toString());

            return mapping.put(key.toString(), scalar);
        }
    });
}
 
源代码6 项目: rebuild   文件: ShareToManager.java
/**
 * 获取全部配置(带缓存)
 *
 * @param belongEntity
 * @param applyType
 * @return
 */
protected Object[][] getAllConfig(String belongEntity, String applyType) {
    final String cacheKey = formatCacheKey(belongEntity, applyType);
    Object[][] cached = (Object[][]) Application.getCommonCache().getx(cacheKey);

    if (cached == null) {
        List<String> sqlWhere = new ArrayList<>();
        if (belongEntity != null) {
            sqlWhere.add(String.format("belongEntity = '%s'", belongEntity));
        }
        if (applyType != null) {
            sqlWhere.add(String.format("applyType = '%s'", applyType));
        }

        String ql = String.format("select %s from %s where (1=1) order by modifiedOn desc", getConfigFields(), getConfigEntity());
        if (!sqlWhere.isEmpty()) {
            ql = ql.replace("(1=1)", StringUtils.join(sqlWhere.iterator(), " and "));
        }

        cached = Application.createQueryNoFilter(ql).array();
        Application.getCommonCache().putx(cacheKey, cached);
    }

    if (cached == null) {
        return new Object[0][];
    }

    Object[][] clone = new Object[cached.length][];
    for (int i = 0; i < cached.length; i++) {
        clone[i] = (Object[]) ObjectUtils.clone(cached[i]);
    }
    return clone;
}