-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caad54d
commit a92e67a
Showing
59 changed files
with
534 additions
and
127 deletions.
There are no files selected for viewing
6 changes: 2 additions & 4 deletions
6
src/main/java/code/shubham/TemplateServiceJavaSpringBootApplication.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
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
6 changes: 3 additions & 3 deletions
6
...mmons/dao/entities/PersistenceConfig.java → ...hubham/commons/dao/PersistenceConfig.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
19 changes: 19 additions & 0 deletions
19
src/main/java/code/shubham/commons/dao/UserIdAuditorAware.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,19 @@ | ||
package code.shubham.commons.dao; | ||
|
||
import code.shubham.commons.contexts.UserIDContextHolder; | ||
import org.springframework.data.domain.AuditorAware; | ||
|
||
import java.util.Optional; | ||
|
||
public class UserIdAuditorAware implements AuditorAware<Long> { | ||
|
||
@Override | ||
public Optional<Long> getCurrentAuditor() { | ||
final Optional<Long> userId = Optional.ofNullable(UserIDContextHolder.get()); | ||
if (userId.isPresent()) | ||
return userId; | ||
|
||
return Optional.ofNullable(-1L); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/code/shubham/commons/dao/address/entities/City.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,29 @@ | ||
package code.shubham.commons.dao.address.entities; | ||
|
||
import code.shubham.commons.dao.base.entities.BaseAbstractDistributedIdEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@SuperBuilder | ||
@Builder | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
@Entity | ||
@Table(name = "cities") | ||
public class City extends BaseAbstractDistributedIdEntity { | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@Column | ||
private Long stateId; | ||
|
||
@Column(nullable = false, updatable = false) | ||
private Long countryId; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/code/shubham/commons/dao/address/entities/Country.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,23 @@ | ||
package code.shubham.commons.dao.address.entities; | ||
|
||
import code.shubham.commons.dao.base.entities.BaseAbstractDistributedIdEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@SuperBuilder | ||
@Builder | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
@Entity | ||
@Table(name = "countries") | ||
public class Country extends BaseAbstractDistributedIdEntity { | ||
|
||
@Column(nullable = false, unique = true) | ||
private String name; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/code/shubham/commons/dao/address/entities/State.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,26 @@ | ||
package code.shubham.commons.dao.address.entities; | ||
|
||
import code.shubham.commons.dao.base.entities.BaseAbstractDistributedIdEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@SuperBuilder | ||
@Builder | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
@Entity | ||
@Table(name = "cities") | ||
public class State extends BaseAbstractDistributedIdEntity { | ||
|
||
@Column(nullable = false, unique = true) | ||
private String name; | ||
|
||
@Column(nullable = false, updatable = false) | ||
private Long countryId; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/code/shubham/commons/dao/address/repositories/CityRepository.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,10 @@ | ||
package code.shubham.commons.dao.address.repositories; | ||
|
||
import code.shubham.commons.dao.address.entities.City; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CityRepository extends JpaRepository<City, Long> { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/code/shubham/commons/dao/address/repositories/CountryRepository.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,10 @@ | ||
package code.shubham.commons.dao.address.repositories; | ||
|
||
import code.shubham.commons.dao.address.entities.Country; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CountryRepository extends JpaRepository<Country, Long> { | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/code/shubham/commons/dao/base/entities/BaseAbstractDistributedIdEntity.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,47 @@ | ||
package code.shubham.commons.dao.base.entities; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
@SuperBuilder | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@MappedSuperclass | ||
public abstract class BaseAbstractDistributedIdEntity implements Serializable { | ||
|
||
private static final long serialVersionUID = 8953224502234813513L; | ||
|
||
@JsonIgnore | ||
@Id | ||
@GeneratedValue(generator = "distributed-id") | ||
@GenericGenerator(name = "distributed-id", | ||
strategy = "code.shubham.commons.generators.id.hibernate.DistributedIDGenerator") | ||
private Long id; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
final BaseAbstractDistributedIdEntity that = (BaseAbstractDistributedIdEntity) o; | ||
return this.id.equals(that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
} |
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
19 changes: 0 additions & 19 deletions
19
src/main/java/code/shubham/commons/dao/entities/UserIdAuditorAware.java
This file was deleted.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
src/main/java/code/shubham/commons/generators/id/IDGenerator.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,7 @@ | ||
package code.shubham.commons.generators.id; | ||
|
||
public interface IDGenerator<Type> { | ||
|
||
Type generate(); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/code/shubham/commons/generators/id/constants/Constants.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,13 @@ | ||
package code.shubham.commons.generators.id.constants; | ||
|
||
public class Constants { | ||
|
||
public static final long SIGN_BIT_LENGTH = 1l; | ||
|
||
public static final long EPOCH_BIT_LENGTH = 41l; | ||
|
||
public static final long NODE_ID_BIT_LENGTH = 10l; | ||
|
||
public static final long SEQUENCE_BIT_LENGTH = 12l; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/code/shubham/commons/generators/id/hibernate/DistributedIDGenerator.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,14 @@ | ||
package code.shubham.commons.generators.id.hibernate; | ||
|
||
import code.shubham.commons.generators.id.implementations.SnowflakeSequenceIdGenerator; | ||
import org.hibernate.engine.spi.SharedSessionContractImplementor; | ||
import org.hibernate.id.IdentifierGenerator; | ||
|
||
public class DistributedIDGenerator implements IdentifierGenerator { | ||
|
||
@Override | ||
public Object generate(final SharedSessionContractImplementor sharedSessionContractImplementor, final Object o) { | ||
return SnowflakeSequenceIdGenerator.getInstance().generate(); | ||
} | ||
|
||
} |
Oops, something went wrong.