batch get archive by ids and versions

This commit is contained in:
Mengyi Zhou 2015-12-10 15:12:05 +08:00
parent db4b2b920e
commit 12b81c03fb
4 changed files with 101 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package com.ctrip.zeus.service.model;
import com.ctrip.zeus.model.entity.Group;
import com.ctrip.zeus.model.entity.Archive;
import com.ctrip.zeus.model.entity.Slb;
import java.util.List;
/**
@ -42,4 +43,8 @@ public interface ArchiveService {
Archive getVsArchive(Long vsId, int version) throws Exception;
Archive getLatestVsArchive(Long vsId) throws Exception;
List<Archive> getVsArchives(Long[] vsIds, Integer[] versions) throws Exception;
List<Archive> getGroupArchives(Long[] groupIds, Integer[] versions) throws Exception;
}

View file

@ -141,4 +141,42 @@ public class ArchiveServiceImpl implements ArchiveService {
MetaVsArchiveDo d = archiveVsDao.findMaxVersionByVs(vsId, ArchiveVsEntity.READSET_FULL);
return new Archive().setId(d.getVsId()).setContent(d.getContent()).setVersion(d.getVersion());
}
@Override
public List<Archive> getVsArchives(Long[] vsIds, Integer[] versions) throws Exception {
String[] pairs = new String[vsIds.length];
for (int i = 0; i < pairs.length; i++) {
pairs[i] = vsIds[i] + "," + versions[i];
}
List<MetaVsArchiveDo> list = archiveVsDao.findAllByVsAndVersion(vsIds, pairs, ArchiveVsEntity.READSET_IDONLY);
Long[] ids = new Long[list.size()];
for (int i = 0; i < ids.length; i++) {
ids[i] = list.get(i).getId();
}
list = archiveVsDao.findAllByIds(ids, ArchiveVsEntity.READSET_FULL);
List<Archive> result = new ArrayList<>(list.size());
for (MetaVsArchiveDo d : list) {
result.add(new Archive().setId(d.getVsId()).setContent(d.getContent()).setVersion(d.getVersion()));
}
return result;
}
@Override
public List<Archive> getGroupArchives(Long[] groupIds, Integer[] versions) throws Exception {
String[] pairs = new String[groupIds.length];
for (int i = 0; i < pairs.length; i++) {
pairs[i] = groupIds[i] + "," + versions[i];
}
List<ArchiveGroupDo> list = archiveGroupDao.findAllByGroupAndVersion(groupIds, pairs, ArchiveGroupEntity.READSET_IDONLY);
Long[] ids = new Long[list.size()];
for (int i = 0; i < ids.length; i++) {
ids[i] = list.get(i).getId();
}
list = archiveGroupDao.findAllByIds(ids, ArchiveGroupEntity.READSET_FULL);
List<Archive> result = new ArrayList<>(list.size());
for (ArchiveGroupDo d : list) {
result.add(C.toGroupArchive(d));
}
return result;
}
}

View file

@ -88,7 +88,23 @@
</entity>
<entity name="archive-group" table="archive_group" alias="ag" do-class="ArchiveGroupDo">
<var name="ids" value-type="Long[]"/>
<var name="pairs" value-type="String[]"/>
<readsets>
<readset name="IDONLY">
<member name="id"/>
</readset>
</readsets>
<query-defs>
<query name="find-all-by-ids" type="SELECT" multiple="true">
<param name="ids"/>
<statement>
<![CDATA[
SELECT <FIELDS/>
FROM <TABLE/>
WHERE <FIELD name='id'/> in <IN>${ids}</IN>
]]>
</statement>
</query>
<query name="delete-by-group" type="DELETE">
<param name="group-id"/>
<statement>
@ -144,6 +160,19 @@
]]>
</statement>
</query>
<query name="find-all-by-group-and-version" type="SELECT" multiple="true">
<param name="ids"/>
<param name="pairs"/>
<statement>
<![CDATA[
SELECT <FIELDS/>
FROM (
SELECT id, concat(group_id, ',', version) as g_v FROM archive_group
WHERE group_id in <IN>${ids}</IN> ) ag
WHERE ag.g_v in <IN>${pairs}</IN>
]]>
</statement>
</query>
<query name="delete-by-group-id-less-than-version" type="DELETE">
<param name="group-id"/>
<param name="version"/>

View file

@ -28,7 +28,23 @@
</entity>
<entity name="archive-vs" table="archive_vs" alias="av" do-class="MetaVsArchiveDo">
<var name="ids" value-type="Long[]"/>
<var name="pairs" value-type="String[]"/>
<readsets>
<readset name="IDONLY">
<member name="id"/>
</readset>
</readsets>
<query-defs>
<query name="find-all-by-ids" type="SELECT" multiple="true">
<param name="ids"/>
<statement>
<![CDATA[
SELECT <FIELDS/>
FROM <TABLE/>
WHERE <FIELD name='id'/> in <IN>${ids}</IN>
]]>
</statement>
</query>
<query name="insert-or-update" type="INSERT">
<statement>
<![CDATA[
@ -63,6 +79,19 @@
]]>
</statement>
</query>
<query name="find-all-by-vs-and-version" type="SELECT" multiple="true">
<param name="ids"/>
<param name="pairs"/>
<statement>
<![CDATA[
SELECT <FIELDS/>
FROM (
SELECT id, concat(vs_id, ',', version) as vs_v FROM archive_vs
WHERE vs_id in <IN>${ids}</IN> ) av
WHERE av.vs_v in <IN>${pairs}</IN>
]]>
</statement>
</query>
<query name="find-max-version-by-vses" type="SELECT" multiple="true">
<param name="ids"/>
<statement>