-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE-3607] Support to sync the entities
- Loading branch information
Heng Qin
committed
May 30, 2024
1 parent
844a8e6
commit 9587cea
Showing
29 changed files
with
901 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
common/src/main/java/com/datastrato/gravitino/dto/MetadataObjectDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.datastrato.gravitino.dto; | ||
|
||
import com.datastrato.gravitino.MetadataObject; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class MetadataObjectDTO implements MetadataObject { | ||
|
||
@JsonProperty("fullName") | ||
private String fullName; | ||
|
||
@JsonProperty("type") | ||
private Type type; | ||
|
||
private String parent; | ||
private String name; | ||
|
||
/** Default constructor for Jackson deserialization. */ | ||
protected MetadataObjectDTO() {} | ||
|
||
/** | ||
* Creates a new instance of MetadataObject DTO. | ||
* | ||
* @param fullName The name of the MetadataObject DTO. | ||
* @param type The type of the meta data object. | ||
*/ | ||
protected MetadataObjectDTO(String fullName, Type type) { | ||
this.type = type; | ||
this.fullName = fullName; | ||
int index = fullName.lastIndexOf("."); | ||
|
||
if (index == -1) { | ||
this.parent = null; | ||
this.name = fullName; | ||
} else { | ||
this.parent = fullName.substring(0, index); | ||
this.name = fullName.substring(index + 1); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String parent() { | ||
return parent; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String fullName() { | ||
return fullName; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return type; | ||
} | ||
|
||
|
||
/** @return the builder for creating a new instance of MetadataObjectDTO. */ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
/** Builder for {@link MetadataObjectDTO}. */ | ||
public static class Builder { | ||
private String fullName; | ||
private Type type; | ||
|
||
/** | ||
* Sets the full name of the meta data object. | ||
* | ||
* @param fullName The full name of the meta data object. | ||
* @return The builder instance. | ||
*/ | ||
public Builder withFullName(String fullName) { | ||
this.fullName = fullName; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the type of the meta data object. | ||
* | ||
* @param type The type of the meta data object. | ||
* @return The builder instance. | ||
*/ | ||
public Builder withType(Type type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds an instance of MetadataObjectDTO using the builder's properties. | ||
* | ||
* @return An instance of MetadataObjectDTO. | ||
* @throws IllegalArgumentException If the full name or type are not set. | ||
*/ | ||
public MetadataObjectDTO build() { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(fullName), "full name cannot be null or empty"); | ||
|
||
Preconditions.checkArgument(type != null, "type cannot be null"); | ||
|
||
return new MetadataObjectDTO(fullName, type); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.