Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojiebao committed Feb 27, 2024
1 parent fada86d commit 5ebec02
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

/** This exception is thrown when an entity is not found. */
public class NoSuchEntityException extends RuntimeException {
/** The no such an entity message for the exception. */
public static final String NO_SUCH_AN_ENTITY_MESSAGE = "No such an entity: %s";
/** The no such entity message for the exception. */
public static final String NO_SUCH_ENTITY_MESSAGE = "No such entity: %s";

/**
* Constructs a new NoSuchEntityException.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,36 @@ public static CatalogMetaService getInstance() {
private CatalogMetaService() {}

public CatalogEntity getCatalogByIdentifier(NameIdentifier identifier) {
checkCatalogNamespaceWithIdentifier(identifier);
NameIdentifier.checkCatalog(identifier);
String metalakeName = identifier.namespace().level(0);
String catalogName = identifier.name();
Long metalakeId =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeIdMetaByName(metalakeName));
if (metalakeId == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, identifier.namespace().toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, identifier.namespace().toString());
}
CatalogPO catalogPO =
SessionUtils.getWithoutCommit(
CatalogMetaMapper.class,
mapper -> mapper.selectCatalogMetaByMetalakeIdAndName(metalakeId, catalogName));
if (catalogPO == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, identifier.toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, identifier.toString());
}
return POConverters.fromCatalogPO(catalogPO, identifier.namespace());
}

public List<CatalogEntity> listCatalogsByNamespace(Namespace namespace) {
checkCatalogNamespace(namespace);
Namespace.checkCatalog(namespace);
String metalakeName = namespace.level(0);
Long metalakeId =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeIdMetaByName(metalakeName));
if (metalakeId == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, namespace.toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, namespace.toString());
}
List<CatalogPO> catalogPOS =
SessionUtils.getWithoutCommit(
Expand All @@ -75,14 +75,14 @@ public List<CatalogEntity> listCatalogsByNamespace(Namespace namespace) {

public void insertCatalog(CatalogEntity catalogEntity, boolean overwrite) {
try {
checkCatalogNamespaceWithIdentifier(catalogEntity.nameIdentifier());
NameIdentifier.checkCatalog(catalogEntity.nameIdentifier());
Long metalakeId =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class,
mapper -> mapper.selectMetalakeIdMetaByName(catalogEntity.namespace().level(0)));
if (metalakeId == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, catalogEntity.namespace().toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, catalogEntity.namespace().toString());
}
SessionUtils.doWithCommit(
CatalogMetaMapper.class,
Expand All @@ -103,24 +103,23 @@ public void insertCatalog(CatalogEntity catalogEntity, boolean overwrite) {
// SQL violates the constraints of `primary key` and `unique key`.
// We simply think that the entity already exists at this time.
throw new EntityAlreadyExistsException(
String.format(
"Catalog entity: %s already exists", catalogEntity.nameIdentifier().name()));
String.format("Catalog entity: %s already exists", catalogEntity.nameIdentifier()));
}
throw re;
}
}

public <E extends Entity & HasIdentifier> CatalogEntity updateCatalog(
NameIdentifier identifier, Function<E, E> updater) throws IOException {
checkCatalogNamespaceWithIdentifier(identifier);
NameIdentifier.checkCatalog(identifier);
String metalakeName = identifier.namespace().level(0);
String catalogName = identifier.name();
Long metalakeId =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeIdMetaByName(metalakeName));
if (metalakeId == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, identifier.namespace().toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, identifier.namespace().toString());
}

CatalogPO oldCatalogPO =
Expand All @@ -129,7 +128,7 @@ public <E extends Entity & HasIdentifier> CatalogEntity updateCatalog(
mapper -> mapper.selectCatalogMetaByMetalakeIdAndName(metalakeId, catalogName));
if (oldCatalogPO == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, identifier.toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, identifier.toString());
}

CatalogEntity oldCatalogEntity =
Expand Down Expand Up @@ -157,15 +156,15 @@ public <E extends Entity & HasIdentifier> CatalogEntity updateCatalog(
}

public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) {
checkCatalogNamespaceWithIdentifier(identifier);
NameIdentifier.checkCatalog(identifier);
String metalakeName = identifier.namespace().level(0);
String catalogName = identifier.name();
Long metalakeId =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeIdMetaByName(metalakeName));
if (metalakeId == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, identifier.namespace().toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, identifier.namespace().toString());
}
Long catalogId =
SessionUtils.getWithoutCommit(
Expand All @@ -190,14 +189,4 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) {
}
return true;
}

private void checkCatalogNamespaceWithIdentifier(NameIdentifier identifier) {
Preconditions.checkArgument(
identifier.hasNamespace() && identifier.namespace().levels().length == 1,
"Only support one level namespace");
}

private void checkCatalogNamespace(Namespace namespace) {
Preconditions.checkArgument(namespace.levels().length == 1, "Only support one level namespace");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ public List<BaseMetalake> listMetalakes() {
}

public BaseMetalake getMetalakeByIdentifier(NameIdentifier ident) {
NameIdentifier.checkMetalake(ident);
MetalakePO metalakePO =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeMetaByName(ident.name()));
if (metalakePO == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, ident.toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, ident.toString());
}
return POConverters.fromMetalakePO(metalakePO);
}

public void insertMetalake(BaseMetalake baseMetalake, boolean overwrite) {
try {
NameIdentifier.checkMetalake(baseMetalake.nameIdentifier());
SessionUtils.doWithCommit(
MetalakeMetaMapper.class,
mapper -> {
Expand All @@ -77,21 +79,21 @@ public void insertMetalake(BaseMetalake baseMetalake, boolean overwrite) {
// SQL violates the constraints of `primary key` and `unique key`.
// We simply think that the entity already exists at this time.
throw new EntityAlreadyExistsException(
String.format(
"Metalake entity: %s already exists", baseMetalake.nameIdentifier().name()));
String.format("Metalake entity: %s already exists", baseMetalake.nameIdentifier()));
}
throw re;
}
}

public <E extends Entity & HasIdentifier> BaseMetalake updateMetalake(
NameIdentifier ident, Function<E, E> updater) throws IOException {
NameIdentifier.checkMetalake(ident);
MetalakePO oldMetalakePO =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeMetaByName(ident.name()));
if (oldMetalakePO == null) {
throw new NoSuchEntityException(
NoSuchEntityException.NO_SUCH_AN_ENTITY_MESSAGE, ident.toString());
NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE, ident.toString());
}

BaseMetalake oldMetalakeEntity = POConverters.fromMetalakePO(oldMetalakePO);
Expand All @@ -116,6 +118,7 @@ public <E extends Entity & HasIdentifier> BaseMetalake updateMetalake(
}

public boolean deleteMetalake(NameIdentifier ident, boolean cascade) {
NameIdentifier.checkMetalake(ident);
Long metalakeId =
SessionUtils.getWithoutCommit(
MetalakeMetaMapper.class, mapper -> mapper.selectMetalakeIdMetaByName(ident.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
import java.sql.Statement;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -206,7 +208,10 @@ public void testPutAndList() throws IOException {
entityStore.put(metalake1, false);
entityStore.put(metalake2, false);
List<BaseMetalake> metalakes =
entityStore.list(metalake1.namespace(), BaseMetalake.class, Entity.EntityType.METALAKE);
entityStore.list(metalake1.namespace(), BaseMetalake.class, Entity.EntityType.METALAKE)
.stream()
.sorted(Comparator.comparing(BaseMetalake::id))
.collect(Collectors.toList());
assertNotNull(metalakes);
assertEquals(2, metalakes.size());
assertTrue(checkMetalakeEquals(metalake1, metalakes.get(0)));
Expand All @@ -227,7 +232,10 @@ public void testPutAndList() throws IOException {
entityStore.put(catalog1, false);
entityStore.put(catalog2, false);
List<CatalogEntity> catalogEntities =
entityStore.list(catalog1.namespace(), CatalogEntity.class, Entity.EntityType.CATALOG);
entityStore.list(catalog1.namespace(), CatalogEntity.class, Entity.EntityType.CATALOG)
.stream()
.sorted(Comparator.comparing(CatalogEntity::id))
.collect(Collectors.toList());
assertNotNull(catalogEntities);
assertEquals(2, catalogEntities.size());
assertTrue(checkCatalogEquals(catalog1, catalogEntities.get(0)));
Expand Down

0 comments on commit 5ebec02

Please sign in to comment.