use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class MigrationClusterDao method updateStartTime.
public void updateStartTime(long id, Date date) {
MigrationClusterTbl migrationClusterTbl = new MigrationClusterTbl();
migrationClusterTbl.setId(id);
migrationClusterTbl.setStartTime(date);
queryHandler.handleUpdate(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return migrationClusterTblDao.updateStartTimeById(migrationClusterTbl, MigrationClusterTblEntity.UPDATESET_FULL);
}
});
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class MigrationShardDao method updateMigrationShard.
public void updateMigrationShard(MigrationShardTbl migrationShard) {
MigrationShardTbl proto = migrationShardDao.createLocal();
proto.setId(migrationShard.getId()).setMigrationClusterId(migrationShard.getMigrationClusterId()).setShardId(migrationShard.getShardId()).setLog(migrationShard.getLog());
final MigrationShardTbl forUpdate = proto;
queryHandler.handleUpdate(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
migrationShardDao.updateByPK(forUpdate, MigrationShardTblEntity.UPDATESET_FULL);
return null;
}
});
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class RedisDao method generateUniqueKeeperId.
private String generateUniqueKeeperId(final RedisTbl redis) {
final String runId = idGenerator.generateRunid();
// check for unique runId
DcClusterShardTbl targetDcClusterShard = queryHandler.handleQuery(new DalQuery<DcClusterShardTbl>() {
@Override
public DcClusterShardTbl doQuery() throws DalException {
return dcClusterShardTblDao.findByPK(redis.getDcClusterShardId(), DcClusterShardTblEntity.READSET_FULL);
}
});
if (null == targetDcClusterShard)
throw new BadRequestException("Cannot find related dc-cluster-shard");
List<RedisTbl> redisWithSameRunId = queryHandler.handleQuery(new DalQuery<List<RedisTbl>>() {
@Override
public List<RedisTbl> doQuery() throws DalException {
return redisTblDao.findByRunid(runId, RedisTblEntity.READSET_FULL);
}
});
if (null != redisWithSameRunId && redisWithSameRunId.size() > 0) {
for (final RedisTbl tmpRedis : redisWithSameRunId) {
DcClusterShardTbl tmpDcClusterShard = queryHandler.handleQuery(new DalQuery<DcClusterShardTbl>() {
@Override
public DcClusterShardTbl doQuery() throws DalException {
return dcClusterShardTblDao.findByPK(tmpRedis.getDcClusterShardId(), DcClusterShardTblEntity.READSET_FULL);
}
});
if (null != tmpDcClusterShard && targetDcClusterShard.getShardId() == tmpDcClusterShard.getShardId()) {
throw new ServerException("Cannot generate unque keeper id, please retry.");
}
}
}
return runId;
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class MigrationEventDao method lockCluster.
private void lockCluster(final long clusterId) {
ClusterTbl cluster = queryHandler.handleQuery(new DalQuery<ClusterTbl>() {
@Override
public ClusterTbl doQuery() throws DalException {
return clusterTblDao.findByPK(clusterId, ClusterTblEntity.READSET_FULL);
}
});
if (null == cluster)
throw new BadRequestException(String.format("Cluster:%s do not exist!", clusterId));
if (!cluster.getStatus().toLowerCase().equals(ClusterStatus.Normal.toString().toLowerCase())) {
throw new BadRequestException(String.format("Cluster:%s already under migrating tasks!Please verify it first!", cluster.getClusterName()));
} else {
cluster.setStatus(ClusterStatus.Lock.toString());
}
final ClusterTbl proto = cluster;
queryHandler.handleUpdate(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return clusterTblDao.updateByPK(proto, ClusterTblEntity.UPDATESET_FULL);
}
});
}
use of org.unidal.dal.jdbc.DalException in project x-pipe by ctripcorp.
the class ShardDao method deleteShardsBatch.
@DalTransaction
public void deleteShardsBatch(final ShardTbl shard) throws DalException {
if (null == shard)
throw new DalException("Null cannot be deleted.");
List<DcClusterShardTbl> relatedDcClusterShards = queryHandler.handleQuery(new DalQuery<List<DcClusterShardTbl>>() {
@Override
public List<DcClusterShardTbl> doQuery() throws DalException {
return dcClusterShardTblDao.findAllByShardId(shard.getId(), DcClusterShardTblEntity.READSET_FULL);
}
});
if (null != relatedDcClusterShards) {
dcClusterShardDao.deleteDcClusterShardsBatch(relatedDcClusterShards);
}
ShardTbl proto = shard;
proto.setShardName(generateDeletedName(shard.getShardName()));
queryHandler.handleDelete(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return shardTblDao.deleteShard(proto, ShardTblEntity.UPDATESET_FULL);
}
}, true);
}
Aggregations