Commit e2b5bb3c authored by Sheng Wang's avatar Sheng Wang
Browse files

remove CosmosEntityClient

parent 74567c2f
Pipeline #24472 failed with stages
in 8 minutes and 56 seconds
......@@ -12,105 +12,105 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.wd.azure.cosmosdb;
import com.azure.cosmos.CosmosContainer;
import org.opengroup.osdu.wd.core.dataaccess.interfaces.IEntityDBClient;
import org.opengroup.osdu.wd.core.models.EntityDtoReturn;
import org.opengroup.osdu.wd.core.models.EntityDto;
import org.opengroup.osdu.wd.core.models.Relationship;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
@Service
@ConditionalOnProperty(name = "app.entity.source", havingValue = "cosmosdb", matchIfMissing = true)
public class CosmosEntityClient implements IEntityDBClient {
@Autowired
private CosmosInit cosmosInit;
private ReentrantLock mutex = new ReentrantLock();
@Override
public EntityDtoReturn saveEntity(EntityDto dto, List<Relationship> relationships) {
CosmosContainer container = cosmosInit.createOrGetEntityContainer(dto.getEntityType());
CosmosEntity entity = new CosmosEntity(dto, relationships);
try {
mutex.lock();
//Optional<Entity> existingEntity = CosmosFacade.findItem(container, id, entityId, Entity.class);
CosmosFacade.upsertItem(container, entity);
} finally {
mutex.unlock();
}
return new EntityDtoReturn(dto, null);
}
@Override
public EntityDtoReturn getLatestEntityVersion(String entityType, String entityId) {
CosmosContainer container = cosmosInit.getEntityContainer(entityType);
Optional<CosmosEntity> res = CosmosFacade.findLatestItem(container, entityId, CosmosEntity.class);
if (res == null || !res.isPresent())
return null;
return res.get().ToEntityDtoReturn();
}
@Override
public EntityDtoReturn getSpecificEntityVersion(String entityType, String entityId, long version) {
CosmosContainer container = cosmosInit.getEntityContainer(entityType);
String id = String.format("%s_%s", entityId, version);
Optional<CosmosEntity> res = CosmosFacade.findItem(container, id, entityId, CosmosEntity.class);
if (res == null || !res.isPresent())
return null;
return res.get().ToEntityDtoReturn();
}
@Override
public List<Long> getEntityVersionNumbers(String entityType, String entityId) {
CosmosContainer container = cosmosInit.getEntityContainer(entityType);
List<Long> res = CosmosFacade.findVersions(container, entityId);
return res;
}
@Override
public long deleteEntity(String entityType, String entityId) {
CosmosContainer container = cosmosInit.getEntityContainer(entityType);
int cnt = CosmosFacade.deleteEntity(container, entityId);
return cnt;
}
@Override
public long purgeEntity(String entityType, String entityId) {
CosmosContainer container = cosmosInit.getEntityContainer(entityType);
int cnt = CosmosFacade.purgeEntity(container, entityId, entityId);
return cnt;
}
@Override
public long deleteEntityVersion(String entityType, String entityId, long version) {
CosmosContainer container = cosmosInit.getEntityContainer(entityType);
String id = String.format("%s_%s", entityId, version);
int cnt = CosmosFacade.deleteItem(container, id, entityId);
return cnt;
}
@Override
public long purgeEntityVersion(String entityType, String entityId, long version) {
CosmosContainer container = cosmosInit.getEntityContainer(entityType);
String id = String.format("%s_%s", entityId, version);
int cnt = CosmosFacade.purgeItem(container, id, entityId);
return cnt;
}
}
//package org.opengroup.osdu.wd.azure.cosmosdb;
//
//import com.azure.cosmos.CosmosContainer;
//import org.opengroup.osdu.wd.core.dataaccess.interfaces.IEntityDBClient;
//import org.opengroup.osdu.wd.core.models.EntityDtoReturn;
//import org.opengroup.osdu.wd.core.models.EntityDto;
//import org.opengroup.osdu.wd.core.models.Relationship;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//import java.util.Optional;
//import java.util.concurrent.locks.ReentrantLock;
//
//@Service
//@ConditionalOnProperty(name = "app.entity.source", havingValue = "cosmosdb", matchIfMissing = true)
//public class CosmosEntityClient implements IEntityDBClient {
//
// @Autowired
// private CosmosInit cosmosInit;
//
// private ReentrantLock mutex = new ReentrantLock();
//
// @Override
// public EntityDtoReturn saveEntity(EntityDto dto, List<Relationship> relationships) {
// CosmosContainer container = cosmosInit.createOrGetEntityContainer(dto.getEntityType());
//
// CosmosEntity entity = new CosmosEntity(dto, relationships);
// try {
// mutex.lock();
// //Optional<Entity> existingEntity = CosmosFacade.findItem(container, id, entityId, Entity.class);
// CosmosFacade.upsertItem(container, entity);
// } finally {
// mutex.unlock();
// }
// return new EntityDtoReturn(dto, null);
// }
//
// @Override
// public EntityDtoReturn getLatestEntityVersion(String entityType, String entityId) {
// CosmosContainer container = cosmosInit.getEntityContainer(entityType);
//
// Optional<CosmosEntity> res = CosmosFacade.findLatestItem(container, entityId, CosmosEntity.class);
// if (res == null || !res.isPresent())
// return null;
// return res.get().ToEntityDtoReturn();
// }
//
// @Override
// public EntityDtoReturn getSpecificEntityVersion(String entityType, String entityId, long version) {
// CosmosContainer container = cosmosInit.getEntityContainer(entityType);
//
// String id = String.format("%s_%s", entityId, version);
// Optional<CosmosEntity> res = CosmosFacade.findItem(container, id, entityId, CosmosEntity.class);
// if (res == null || !res.isPresent())
// return null;
// return res.get().ToEntityDtoReturn();
// }
//
// @Override
// public List<Long> getEntityVersionNumbers(String entityType, String entityId) {
// CosmosContainer container = cosmosInit.getEntityContainer(entityType);
//
// List<Long> res = CosmosFacade.findVersions(container, entityId);
// return res;
// }
//
// @Override
// public long deleteEntity(String entityType, String entityId) {
// CosmosContainer container = cosmosInit.getEntityContainer(entityType);
//
// int cnt = CosmosFacade.deleteEntity(container, entityId);
// return cnt;
// }
//
// @Override
// public long purgeEntity(String entityType, String entityId) {
// CosmosContainer container = cosmosInit.getEntityContainer(entityType);
//
// int cnt = CosmosFacade.purgeEntity(container, entityId, entityId);
// return cnt;
// }
//
// @Override
// public long deleteEntityVersion(String entityType, String entityId, long version) {
// CosmosContainer container = cosmosInit.getEntityContainer(entityType);
//
// String id = String.format("%s_%s", entityId, version);
// int cnt = CosmosFacade.deleteItem(container, id, entityId);
// return cnt;
// }
//
// @Override
// public long purgeEntityVersion(String entityType, String entityId, long version) {
// CosmosContainer container = cosmosInit.getEntityContainer(entityType);
//
// String id = String.format("%s_%s", entityId, version);
// int cnt = CosmosFacade.purgeItem(container, id, entityId);
// return cnt;
// }
//}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment