Search in sources :

Example 1 with BaseObjectInfo

use of com.varsql.core.db.valueobject.BaseObjectInfo in project varsql by varsqlinfo.

the class DbDiffServiceImpl method objectList.

/**
 * @param objectType
 * @Method Name  : objectList
 * @Method 설명 : object list
 * @작성자   : ytkim
 * @작성일   : 2018. 12. 19.
 * @변경이력  :
 * @param paramMap
 * @return
 */
public ResponseResult objectList(String vconnid, String schema, String objectType) {
    ResponseResult resultObject = new ResponseResult();
    DBConnectionEntity vtConnRVO = dbConnectionEntityRepository.findByVconnid(vconnid);
    if (vtConnRVO == null) {
        resultObject.setResultCode(RequestResultCode.ERROR);
        resultObject.setItemList(null);
    } else {
        DatabaseParamInfo dpi = getDatabaseParamInfo(vtConnRVO);
        dpi.setSchema(schema);
        dpi.setObjectType(objectType);
        MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(vtConnRVO.getDbTypeDriverProvider().getDbType());
        String objectId = ObjectType.getDBObjectType(objectType).getObjectTypeId();
        if (ObjectType.TABLE.getObjectTypeId().equals(objectId)) {
            resultObject.setItemList(dbMetaEnum.getDBObjectMeta(objectId, dpi));
        } else {
            List<BaseObjectInfo> objectList = dbMetaEnum.getDBObjectList(objectId, dpi);
            String[] objectNameArr = new String[objectList.size()];
            int idx = 0;
            for (BaseObjectInfo boi : objectList) {
                // System.out.println("boi.getName() : "+ boi.getName());
                objectNameArr[idx] = boi.getName();
                ++idx;
            }
            resultObject.setItemList(dbMetaEnum.getDDLScript(objectId, dpi, new DDLCreateOption(), objectNameArr));
        }
    }
    return resultObject;
}
Also used : BaseObjectInfo(com.varsql.core.db.valueobject.BaseObjectInfo) ResponseResult(com.vartech.common.app.beans.ResponseResult) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) MetaControlBean(com.varsql.core.db.MetaControlBean) DatabaseParamInfo(com.varsql.core.db.valueobject.DatabaseParamInfo) DDLCreateOption(com.varsql.core.db.valueobject.ddl.DDLCreateOption)

Example 2 with BaseObjectInfo

use of com.varsql.core.db.valueobject.BaseObjectInfo in project varsql by varsqlinfo.

the class DatabaseController method dbObjectList.

/**
 * @Method Name  : dbObjectList
 * @Method 설명 : db object list
 * @작성자   : ytkim
 * @작성일   : 2017. 11. 6.
 * @변경이력  :
 * @param databaseParamInfo
 * @param mav
 * @param req
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/dbObjectList", method = RequestMethod.POST)
@ResponseBody
public ResponseResult dbObjectList(DatabaseParamInfo databaseParamInfo, HttpServletRequest req) throws Exception {
    if (databaseParamInfo.isRefresh()) {
        String cacheKey = CacheUtils.getObjectTypeKey(databaseParamInfo);
        Cache tableMetaCache = cacheManager.getCache(CacheInfo.CacheType.OBJECT_TYPE_METADATA.getCacheName());
        ValueWrapper value = tableMetaCache.get(cacheKey);
        if (value != null && databaseParamInfo.getObjectNames() != null && databaseParamInfo.getObjectNames().length > 0) {
            ResponseResult objValue = (ResponseResult) value.get();
            ResponseResult result = databaseServiceImpl.dbObjectList(databaseParamInfo);
            List<BaseObjectInfo> resultItems = result.getItems();
            HashMap<String, BaseObjectInfo> newItemInfos = new HashMap<String, BaseObjectInfo>();
            resultItems.stream().forEach(item -> {
                newItemInfos.put(item.getName(), item);
            });
            List<BaseObjectInfo> cacheItems = objValue.getItems();
            cacheItems = cacheItems.stream().map(item -> {
                if (newItemInfos.containsKey(item.getName())) {
                    return newItemInfos.get(item.getName());
                }
                return item;
            }).collect(Collectors.toList());
            objValue.setItemList(cacheItems);
            ;
            tableMetaCache.put(cacheKey, objValue);
            return objValue;
        } else {
            tableMetaCache.evict(cacheKey);
        }
    }
    return databaseServiceImpl.dbObjectList(databaseParamInfo);
}
Also used : BaseObjectInfo(com.varsql.core.db.valueobject.BaseObjectInfo) ValueWrapper(org.springframework.cache.Cache.ValueWrapper) HashMap(java.util.HashMap) ResponseResult(com.vartech.common.app.beans.ResponseResult) Cache(org.springframework.cache.Cache) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BaseObjectInfo (com.varsql.core.db.valueobject.BaseObjectInfo)2 ResponseResult (com.vartech.common.app.beans.ResponseResult)2 MetaControlBean (com.varsql.core.db.MetaControlBean)1 DatabaseParamInfo (com.varsql.core.db.valueobject.DatabaseParamInfo)1 DDLCreateOption (com.varsql.core.db.valueobject.ddl.DDLCreateOption)1 DBConnectionEntity (com.varsql.web.model.entity.db.DBConnectionEntity)1 HashMap (java.util.HashMap)1 Cache (org.springframework.cache.Cache)1 ValueWrapper (org.springframework.cache.Cache.ValueWrapper)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1