package com.iplatform.gather.service;
|
|
import com.iplatform.model.po.S_host;
|
import com.iplatform.model.po.Sdc_meta_db;
|
import com.iplatform.model.po.Sdc_meta_table;
|
import com.iplatform.model.po.Sdc_store;
|
import com.walker.db.page.GenericPager;
|
import com.walker.infrastructure.utils.StringUtils;
|
import com.walker.jdbc.service.BaseServiceImpl;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
@Service
|
public class StoreServiceImpl extends BaseServiceImpl {
|
|
// private MetaDataEngine metaDataEngine;
|
// @Autowired
|
// public StoreServiceImpl(MetaDataEngine metaDataEngine){
|
// this.metaDataEngine = metaDataEngine;
|
// }
|
|
public GenericPager<Sdc_store> queryPageStore() {
|
return this.selectSplit(new Sdc_store(), null, null);
|
}
|
|
public Sdc_store queryOne(String storeId) {
|
return this.get(new Sdc_store(storeId));
|
}
|
|
public List<Sdc_meta_db> queryAllMetaDbs() {
|
List<S_host> list = this.selectAll(new S_host());
|
List<Sdc_meta_db> dbList = this.selectAll(new Sdc_meta_db());
|
|
// 把存储数据库的连接“用户名、密码”信息也写入,方面后面使用
|
for (Sdc_meta_db md : dbList) {
|
String[] hostInfo = md.getHost_info().split(StringUtils.SEPARATOR_COLON);
|
for (S_host h : list) {
|
if (h.getUrl().equals(hostInfo[0]) && h.getPort() == Integer.parseInt(hostInfo[1])) {
|
md.setUsername(h.getAuthentication());
|
md.setPassword(h.getCertification());
|
}
|
}
|
}
|
return dbList;
|
}
|
|
public List<Sdc_meta_table> queryAllMetaTables() {
|
return this.selectAll(new Sdc_meta_table());
|
}
|
|
public List<Sdc_meta_table> queryMetaTables(long dbId) {
|
Sdc_meta_table table = new Sdc_meta_table();
|
table.setDb_id(dbId);
|
return this.select(new Sdc_meta_table(), "where db_id=?", new Object[]{dbId});
|
}
|
|
/**
|
* 根据表名前缀,查询所有符合条件的表集合。如:base_custdept_ -->
|
* @param prefix
|
* @return
|
*/
|
public List<Sdc_meta_table> queryMetaTablesByName(String prefix) {
|
GenericPager<Sdc_meta_table> pager = this.selectSplit("select * from sdc_meta_table where table_name like ?"
|
, new Object[]{prefix+"%"}, 0, 1024, new Sdc_meta_table());
|
return pager.getDatas();
|
}
|
|
public GenericPager<Sdc_meta_db> queryPageMetaDbs(String storeId) {
|
return this.selectSplit("select * from sdc_meta_db where store_id=? order by create_time", new Object[]{storeId}, new Sdc_meta_db());
|
}
|
|
public GenericPager<Sdc_meta_table> queryPageMetaTables(String storeId) {
|
return this.selectSplit("select * from sdc_meta_table where store_id=? order by create_time", new Object[]{}, new Sdc_meta_table());
|
}
|
|
// public GenericPager<Sdc_meta_table> queryPageMetaTables(String storeId, long metaDbId) {
|
// // 查出来本页所有表中的数据量大小
|
// GenericPager<Sdc_meta_table> result = this.queryPageMetaTables(storeId);
|
// List<Sdc_meta_table> datas = result.getDatas();
|
//
|
// // 获取得到的数据表名字集合,为下面查询记录总数准备
|
// List<String> tableNameList = new ArrayList<String>();
|
// for (Sdc_meta_table mt : datas) {
|
// tableNameList.add(mt.getTable_name());
|
// }
|
//
|
// // 把找到的每个表的记录数设置到属性中
|
// // Address address = metaCache.getDatabaseAddress(storeId, metaDbId);
|
// TableInfo ti = null;
|
// try {
|
// Map<String, TableInfo> map = metaDataEngine.getTableRows(storeId, metaDbId, tableNameList);
|
// for (Sdc_meta_table mt : datas) {
|
// ti = map.get(mt.getTable_name());
|
// if (ti == null) {
|
// mt.setRow_count((long)-1);
|
// } else {
|
// mt.setRow_count(ti.getRows());
|
// }
|
// }
|
// } catch (Exception ex) {
|
// log.error("获取表结构元数据出现错误,可能物理表不存在", ex);
|
// for (Sdc_meta_table mt : datas) {
|
// mt.setRow_count((long)-1);
|
// }
|
// }
|
// return result;
|
// }
|
|
/**
|
* 添加记录,告诉系统,在元数据中加入了新的数据库信息
|
*
|
* @param metaDb
|
*/
|
public void execSaveMetaDb(Sdc_meta_db metaDb) {
|
this.update("update sdc_meta_db set is_using=0 where store_id=?", new Object[]{metaDb.getStore_id()});
|
this.insert(metaDb);
|
}
|
|
/**
|
* 添加表元数据信息,同时增加数据库中记录的表数量
|
*
|
* @param metaTable
|
*/
|
public void execSaveMetaTable(Sdc_meta_table metaTable) {
|
this.insert(metaTable);
|
// Sdc_meta_db db = new Sdc_meta_db(metaTable.getDb_id());
|
// db.setTable_count();
|
this.update("update sdc_meta_db set table_count=table_count+1 where id=?", new Object[]{metaTable.getDb_id()});
|
}
|
|
/**
|
* 删除存储引擎中的表记录,同时更新缓存。
|
* </p>
|
* 注意:该方法仅仅在测试时调用,在正式生产环境中是不会用到该方法。
|
*
|
* @param metaTableId
|
*/
|
public void execRemoveTable(long metaTableId) {
|
Sdc_meta_table mt = this.get(new Sdc_meta_table(metaTableId));
|
Sdc_meta_db md = this.get(new Sdc_meta_db(mt.getDb_id()));
|
this.delete(new Sdc_meta_table(metaTableId));
|
|
// 在controller中调用缓存删除,2022-09-20
|
// String[] hostPort = MetaDataUtils.getHostUrlPort(md.getHostInfo());
|
// Address address = new Address();
|
// address.setUrl(hostPort[0]);
|
// address.setPort(Integer.parseInt(hostPort[1]));
|
// address.setService(md.getDatabaseName());
|
// metaCache.removeTable(mt.getStoreId(), address, mt.getTableName());
|
}
|
|
/**
|
* 对存储项目进行编辑更新操作
|
*
|
* @param entity
|
*/
|
public void execUpdateStore(Sdc_store entity) {
|
// String storeId = entity.getId();
|
// Store store = storeDao.get(storeId);
|
// if (StringUtils.isNotEmpty(entity.getDescription())) {
|
// store.setDescription(entity.getDescription());
|
// }
|
// if (StringUtils.isNotEmpty(entity.getDefineName())) {
|
// store.setDefineName(entity.getDefineName());
|
// }
|
// store.setType(entity.getType());
|
// store.setStrategy(entity.getStrategy());
|
// store.setInnerUse(entity.getInnerUse());
|
// store.setSelectHosts(entity.getSelectHosts());
|
// store.setDatabaseType(entity.getDatabaseType());
|
// store.setDeleted(entity.getDeleted());
|
// store.setCreateTime(entity.getCreateTime());
|
// store.setCreateUser(entity.getCreateUser());
|
// storeDao.save(store);
|
this.update(entity);
|
}
|
|
}
|