Java Code Examples for org.apache.commons.lang.ObjectUtils#clone()

The following examples show how to use org.apache.commons.lang.ObjectUtils#clone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataService.java    From canal-mongo with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: DataService.java    From canal-mongo with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: DataService.java    From canal-mongo with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
Source File: DataService.java    From canal-mongo with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 5
Source File: ModelConstructor.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
/**
 * 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);
        }
    });
}
 
Example 6
Source File: ShareToManager.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取全部配置(带缓存)
 *
 * @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;
}