Search in sources :

Example 11 with MetaControlBean

use of com.varsql.core.db.MetaControlBean in project varsql by varsqlinfo.

the class DatabaseServiceImpl method dbObjectList.

/**
 * @Method Name  : dbObjectList
 * @Method 설명 : db object 목록 보기 (table, view 등등)
 * @작성자   : ytkim
 * @작성일   : 2017. 11. 16.
 * @변경이력  :
 * @param databaseParamInfo
 * @return
 * @throws Exception
 */
@Cacheable(cacheNames = CacheInfo.CACHE_KEY_OBJECTYPE_METADATA, key = "@" + CacheInfo.CACHE_KEY_OBJECTYPE_METADATA + ".dbObjectTypeKey(#databaseParamInfo)", condition = "@" + CacheInfo.CACHE_KEY_OBJECTYPE_METADATA + ".dbObjectListCondition(#databaseParamInfo)")
public ResponseResult dbObjectList(DatabaseParamInfo databaseParamInfo) {
    MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(databaseParamInfo.getDbType());
    ResponseResult result = new ResponseResult();
    String objectType = databaseParamInfo.getObjectType();
    try {
        String[] objectNames = databaseParamInfo.getObjectNames();
        if (ObjectType.TABLE.getObjectTypeId().equals(objectType) && databaseParamInfo.isLazyLoad()) {
            if (databaseParamInfo.getCustom() != null && "Y".equals(databaseParamInfo.getCustom().get("allMetadata"))) {
                result.setItemList(dbMetaEnum.getDBObjectMeta(ObjectType.getDBObjectType(objectType).getObjectTypeId(), databaseParamInfo, objectNames));
            } else {
                result.setItemList(dbMetaEnum.getDBObjectList(ObjectType.getDBObjectType(objectType).getObjectTypeId(), databaseParamInfo));
            }
        } else {
            result.setItemList(dbMetaEnum.getDBObjectMeta(ObjectType.getDBObjectType(objectType).getObjectTypeId(), databaseParamInfo, objectNames));
        }
    } catch (Exception e) {
        logger.error("dbObjectList objectType : [{}]", objectType);
        logger.error("dbObjectList ", e);
        if (e instanceof DBMetadataException) {
            result.setResultCode(((DBMetadataException) e).getErrorCode());
            result.setMessage(e.getMessage());
        } else {
            try {
                result.setItemList(MetaControlFactory.getDbInstanceFactory(DBType.OTHER).getDBObjectMeta(ObjectType.getDBObjectType(objectType).getObjectTypeId(), databaseParamInfo));
            } catch (Exception subE) {
                logger.error("dbObjectList serverName : [{}]", objectType);
                logger.error("dbObjectList ", subE);
                throw subE;
            }
        }
    }
    return result;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) MetaControlBean(com.varsql.core.db.MetaControlBean) SQLException(java.sql.SQLException) DBMetadataException(com.varsql.core.exception.DBMetadataException) DBMetadataException(com.varsql.core.exception.DBMetadataException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 12 with MetaControlBean

use of com.varsql.core.db.MetaControlBean 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)

Aggregations

MetaControlBean (com.varsql.core.db.MetaControlBean)12 ResponseResult (com.vartech.common.app.beans.ResponseResult)10 DBMetadataException (com.varsql.core.exception.DBMetadataException)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DatabaseInfo (com.varsql.core.db.valueobject.DatabaseInfo)2 DatabaseParamInfo (com.varsql.core.db.valueobject.DatabaseParamInfo)2 DDLCreateOption (com.varsql.core.db.valueobject.ddl.DDLCreateOption)2 DBConnectionEntity (com.varsql.web.model.entity.db.DBConnectionEntity)2 EnumMapperValue (com.vartech.common.app.beans.EnumMapperValue)2 ModelMap (org.springframework.ui.ModelMap)2 ProgressInfo (com.varsql.core.common.beans.ProgressInfo)1 VarsqlFileType (com.varsql.core.common.code.VarsqlFileType)1 BlankConstants (com.varsql.core.common.constants.BlankConstants)1 VarsqlConstants (com.varsql.core.common.constants.VarsqlConstants)1 SecurityUtil (com.varsql.core.common.util.SecurityUtil)1 SQLWriter (com.varsql.core.data.writer.SQLWriter)1 DBType (com.varsql.core.db.DBType)1 MetaControlFactory (com.varsql.core.db.MetaControlFactory)1