Skip to content

Commit

Permalink
revert all queries
Browse files Browse the repository at this point in the history
maintain subquery for selectMany1
 Please enter the commit message for your changes. Lines starting
  • Loading branch information
hilpitome committed Jul 31, 2024
1 parent 2d9e9c7 commit f3da741
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "configs"]
path = configs
url = [email protected]:opensrp/opensrp-server-configs.git
1 change: 1 addition & 0 deletions configs
Submodule configs added at c9552e
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<artifactId>opensrp-server-core</artifactId>
<packaging>jar</packaging>
<version>2.14.9-SNAPSHOT</version>
<version>2.14.10-ALPHA-SNAPSHOT</version>
<name>opensrp-server-core</name>
<description>OpenSRP Server Core module</description>
<url>https://github.com/OpenSRP/opensrp-server-core</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,85 +98,85 @@ private void updateServerVersion(org.opensrp.domain.postgres.Stock pgStock, Stoc
throw new IllegalStateException();
}
}

@Transactional
@Override
public void update(Stock entity) {
if (entity == null) {
return;
}

Long id = retrievePrimaryKey(entity);
if (id == null) { // Stock not added
throw new IllegalStateException();
}

setRevision(entity);
org.opensrp.domain.postgres.Stock pgStock = convert(entity, id);
if (pgStock == null) {
throw new IllegalStateException();
}



int rowsAffected = stockMapper.updateByPrimaryKeyAndGenerateServerVersion(pgStock);
if (rowsAffected < 1) {
throw new IllegalStateException();
}
updateServerVersion(pgStock, entity);

StockMetadata stockMetadata = createMetadata(entity, id);
if (stockMetadata == null) {
throw new IllegalStateException();
}

StockMetadataExample stockMetadataExample = new StockMetadataExample();
stockMetadataExample.createCriteria().andStockIdEqualTo(id);
stockMetadata.setId(stockMetadataMapper.selectByExample(stockMetadataExample).get(0).getId());
stockMetadataMapper.updateByPrimaryKey(stockMetadata);

}

@Override
public List<Stock> getAll() {
List<org.opensrp.domain.postgres.Stock> stocks = stockMetadataMapper.selectMany(new StockMetadataExample(), 0,
DEFAULT_FETCH_SIZE);
return convert(stocks);
}

@Override
public void safeRemove(Stock entity) {
if (entity == null) {
return;
}

Long id = retrievePrimaryKey(entity);
if (id == null) {
return;
}

StockMetadataExample stockMetadataExample = new StockMetadataExample();
stockMetadataExample.createCriteria().andStockIdEqualTo(id);
int rowsAffected = stockMetadataMapper.deleteByExample(stockMetadataExample);
if (rowsAffected < 1) {
return;
}

stockMapper.deleteByPrimaryKey(id);

}

@Override
public List<Stock> findAllByProviderid(String providerid) {
StockMetadataExample stockMetadataExample = new StockMetadataExample();
stockMetadataExample.createCriteria().andProviderIdEqualTo(providerid);
return convert(stockMetadataMapper.selectMany(stockMetadataExample, 0, DEFAULT_FETCH_SIZE));
}

/**
* implements the method equivalent in couch repository that return stocks matching stock type
* id
*
*
* @param stockType the stock type
* @param stockTypeId the stock type id
* @return list of stock of a particluar stock type id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@
</sql>

<select id="selectByDocumentId" parameterType="java.lang.String"
resultMap="BaseEventResultMap">
resultMap="BaseEventResultMap">
select
<include refid="Base_Event_Column_List" />
from core.event e
where e.id = (select em.event_id from core.event_metadata em
where em.document_id = #{documentId,jdbcType=VARCHAR} and em.date_deleted is null)
from core.event_metadata em
join core.event e on em.event_id = e.id
where em.document_id = #{documentId,jdbcType=VARCHAR} and em.date_deleted is null
</select>

<select id="selectPrimaryKey" parameterType="org.opensrp.domain.postgres.EventMetadataExample"
resultType="java.lang.Long">
resultType="java.lang.Long">
select event_id
from core.event_metadata em
<if test="_parameter != null">
Expand All @@ -105,51 +105,57 @@
</if>
<include refid="Base_Event_Column_List" />
from core.event e
where e.id in (select em.event_id from core.event_metadata em
where e.id in (
select em.event_id
from core.event_metadata em
<if test="_parameter != null">
<include refid="Event_Example_Where_Clause" />
</if>)
</if>
)
<if test="orderByClause != null">
order by em.${orderByClause}
order by e.${orderByClause}
</if>
</select>



<select id="selectNotInOpenMRSByServerVersion" parameterType="map"
resultMap="BaseEventResultMap">
resultMap="BaseEventResultMap">
select
<include refid="Base_Event_Column_List" />
from core.event e
where e.id in (select em.event_id from core.event_metadata em
where (em.openmrs_uuid is null or em.openmrs_uuid = '')
and em.server_version between #{from,jdbcType=BIGINT} and #{to,jdbcType=BIGINT}
and em.date_deleted is null)
from core.event_metadata em
join core.event e on em.event_id = e.id
where ( em.openmrs_uuid is null or em.openmrs_uuid ='' )
and em.server_version between #{from,jdbcType=BIGINT} and #{to,jdbcType=BIGINT}
and em.date_deleted is null
LIMIT #{limit}
</select>

<select id="selectNotInOpenMRSByServerVersionAndType" parameterType="map"
resultMap="BaseEventResultMap">
resultMap="BaseEventResultMap">
select
<include refid="Base_Event_Column_List" />
from core.event e
where e.id in (select em.event_id from core.event_metadata em
where (em.openmrs_uuid is null or em.openmrs_uuid = '')
and em.event_type = #{eventType,jdbcType=VARCHAR}
and em.server_version between #{from,jdbcType=BIGINT} and #{to,jdbcType=BIGINT}
and em.date_deleted is null)
from core.event_metadata em
join core.event e on em.event_id = e.id
where ( em.openmrs_uuid is null or em.openmrs_uuid ='' )
and em.event_type = #{eventType,jdbcType=VARCHAR}
and em.server_version between #{from,jdbcType=BIGINT} and #{to,jdbcType=BIGINT}
and em.date_deleted is null
LIMIT #{limit}
</select>


<select id="selectManyWithRowBounds" resultMap="BaseEventResultMap">
select
<if test="example.distinct">
distinct
</if>
<include refid="Base_Event_Column_List" />
from core.event e
where e.id in (select em.event_id from core.event_metadata em
from core.event_metadata em
inner join core.event e on em.event_id = e.id
<if test="_parameter != null">
<include refid="Rowbounds_Example_Where_Clause" />
</if>)
</if>
<if test="example.orderByClause != null">
order by em.${example.orderByClause}
</if>
Expand Down Expand Up @@ -191,10 +197,10 @@
resultMap="BaseEventResultMap">
select
<include refid="Base_Event_Column_List" />
from core.event e
where e.id = (select em.event_id from core.event_metadata em
where em.base_entity_id = #{baseEntityId,jdbcType=VARCHAR} and
em.plan_identifier = #{planIdentifier,jdbcType=VARCHAR})
from core.event_metadata em
join core.event e on em.event_id = e.id
where em.base_entity_id= #{baseEntityId,jdbcType=VARCHAR} and
em.plan_identifier = #{planIdentifier,jdbcType=VARCHAR}
</select>

</mapper>

0 comments on commit f3da741

Please sign in to comment.