ClusterDao extends AbstractXpipeConsoleDAO { @DalTransaction public ClusterTbl createCluster(final ClusterTbl cluster) throws DalException { ClusterTbl clusterWithSameName = queryHandler.handleQuery(new DalQuery<ClusterTbl>() { @Override public ClusterTbl doQuery() throws DalException { return clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL); } }); if(null != clusterWithSameName) throw new BadRequestException("Duplicated cluster name"); cluster.setCreateTime(new Date()); queryHandler.handleInsert(new DalQuery<Integer>() { @Override public Integer doQuery() throws DalException { return clusterTblDao.insert(cluster); } }); ClusterTbl newCluster = clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL); if (!ClusterType.lookup(newCluster.getClusterType()).supportMultiActiveDC()) { DcTbl activeDc = dcTblDao.findByPK(cluster.getActivedcId(), DcTblEntity.READSET_FULL); DcClusterTbl protoDcCluster = dcClusterTblDao.createLocal(); protoDcCluster.setDcId(activeDc.getId()) .setClusterId(newCluster.getId()); queryHandler.handleInsert(new DalQuery<Integer>() { @Override public Integer doQuery() throws DalException { return dcClusterTblDao.insert(protoDcCluster); } }); } return newCluster; }  @DalTransaction ClusterTbl createCluster(final ClusterTbl cluster); @DalTransaction void updateCluster(ClusterTbl cluster); @DalTransaction void deleteCluster(final ClusterTbl cluster); @DalTransaction int bindDc(final ClusterTbl cluster, final DcTbl dc, SetinelTbl sentinel); @DalTransaction int unbindDc(final ClusterTbl cluster, final DcTbl dc); @DalTransaction ClusterTbl findClusterAndOrgByName(final String clusterName); List<ClusterTbl> findAllClusterWithOrgInfo(); List<ClusterTbl> findClusterWithOrgInfoByClusterType(String type); List<ClusterTbl> findClustersWithOrgInfoByActiveDcId(final long dcId); List<ClusterTbl> findAllByDcId(final long dcId); List<ClusterTbl> findClustersWithName(List<String> clusterNames);  }
@Test public void testCreateCluster() throws DalException { ClusterTbl newCluster = clusterDao.createCluster(clusterTbl); Assert.assertEquals(clusterTbl.getId(), newCluster.getId()); }