Skip to content

Commit

Permalink
First steps to migrate to UUIDS
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed Dec 1, 2024
1 parent ca6e685 commit b316b7b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package org.jesperancinha.logistics.jpa.dao
import org.springframework.data.repository.CrudRepository
import org.springframework.data.repository.query.Param
import java.math.BigDecimal
import java.util.UUID

interface BridgeRepository : CrudRepository<Bridge, Long> {
interface BridgeRepository : CrudRepository<Bridge, UUID> {
fun findBridgeBySquareBoundary(
@Param("latWest") latWest: BigDecimal,
@Param("latEast") latEast: BigDecimal,
Expand All @@ -31,9 +32,9 @@ interface OpeningTimeRepository : CrudRepository<BridgeOpeningTime, Long> {
): List<BridgeOpeningTime>
}

interface PassengerRepository : CrudRepository<Passenger, Long>
interface ProductCargoRepository : CrudRepository<ProductCargo, Long>
interface ProductRepository : CrudRepository<Product, Long>
interface TrainRepository : CrudRepository<Train, Long>
interface TrainsLogRepository : CrudRepository<TrainLog, Long>
interface TransportPackageRepository : CrudRepository<TransportPackage, Long>
interface PassengerRepository : CrudRepository<Passenger, UUID>
interface ProductCargoRepository : CrudRepository<ProductCargo, UUID>
interface ProductRepository : CrudRepository<Product, UUID>
interface TrainRepository : CrudRepository<Train, UUID>
interface TrainsLogRepository : CrudRepository<TrainLog, UUID>
interface TransportPackageRepository : CrudRepository<TransportPackage, UUID>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jesperancinha.logistics.jpa.dao
import org.hibernate.Hibernate
import java.math.BigDecimal
import jakarta.persistence.*
import java.util.UUID

@Entity
@Table(name = "bridge")
Expand All @@ -12,7 +13,7 @@ import jakarta.persistence.*
)
data class Bridge(
@Id
@GeneratedValue(strategy = GenerationType.AUTO) val id: Long? = null,
@GeneratedValue(strategy = GenerationType.UUID) val id: UUID? = null,
val name: String? = null,
val address: String? = null,
val city: String? = null,
Expand Down Expand Up @@ -46,8 +47,8 @@ data class Bridge(
@Table(name = "bridge_logs")
data class BridgeLog(
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
val id: Long? = null,
@GeneratedValue(strategy = GenerationType.UUID)
val id: UUID? = null,

@ManyToOne(optional = false)
@JoinColumn(name = "bridgeId", nullable = true, insertable = true, updatable = true)
Expand Down Expand Up @@ -91,7 +92,7 @@ data class BridgeOpeningConflict(
data class BridgeOpeningTime(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: UUID? = null,

@Column(name = "opening_time")
val openingTime: Long? = null,
Expand Down Expand Up @@ -127,7 +128,7 @@ data class Carriage(
@Table(name = "company")
data class Company(
@Id
val id: Long? = null,
val id: UUID? = null,
val name: String? = null,
val address: String? = null,
val city: String? = null,
Expand Down Expand Up @@ -173,7 +174,7 @@ data class Container(
data class Freight(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: UUID? = null,
val name: String? = null,
val type: String? = null,

Expand Down Expand Up @@ -255,8 +256,8 @@ data class MerchandiseLog(
@Table(name = "passengers")
data class Passenger(
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
val id: Long? = null,
@GeneratedValue(strategy = GenerationType.UUID)
val id: UUID? = null,
val firstName: String? = null,
val lastName: String? = null,
val gender: String? = null
Expand All @@ -267,7 +268,7 @@ data class Passenger(
data class Product(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: UUID? = null,
val name: String? = null,
val packaging: String? = null,
val brand: String? = null,
Expand All @@ -287,7 +288,7 @@ data class Product(
data class ProductCargo(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: UUID? = null,

@ManyToOne
val product: Product? = null,
Expand All @@ -299,7 +300,7 @@ data class ProductCargo(
data class Train(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val id: UUID? = null,
val name: String? = null,
val type: String? = null,

Expand All @@ -322,8 +323,8 @@ data class Train(
@Table(name = "trains_log")
data class TrainLog(
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
val id: Long? = null,
@GeneratedValue(strategy = GenerationType.UUID)
val id: UUID? = null,

@ManyToOne(optional = false)
@JoinColumn(name = "trainId", nullable = false, updatable = true, insertable = true)
Expand All @@ -340,7 +341,7 @@ data class TrainLog(
@Table(name = "transport_package")
data class TransportPackage(
@Id
val id: Long? = null,
val id: UUID? = null,

@ManyToOne
val supplier: Company? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.fasterxml.jackson.annotation.JsonProperty
import org.jesperancinha.logistics.jpa.dao.Status
import org.jesperancinha.logistics.jpa.dao.TrainType
import java.math.BigDecimal
import java.util.UUID

data class CarrierDto(
@JsonProperty("carriageId")
val carriageId: Long,
@JsonProperty("containerId")
val containerId: Long,
@JsonProperty("packageId")
val packageId: Long,
val packageId: UUID,
@JsonProperty("weight")
val weight: Long,
@JsonProperty("products")
Expand All @@ -27,14 +28,14 @@ data class ContainerDto(

class ProductInTransitDto(
@JsonProperty("productId")
val productId: Long,
val productId: UUID,
@JsonProperty("quantity")
val quantity: Long
)

data class TrainMerchandiseDto(
@JsonProperty("id")
val id: Long?,
val id: UUID?,
@JsonProperty("name")
val name: String?,
@JsonProperty("supplierId")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.jesperancinha.logistics.sensor.collector.data

import java.math.BigDecimal
import java.util.UUID

data class BridgeLogDto(
val id: Long,
val id: UUID,
val source: String,
val type: String,
val timestamp: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jesperancinha.logistics.sensor.collector.data

import java.util.UUID

data class SupplierDto(
val id: Long,
val id: UUID,
val name: String,
val address: String,
val city: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.jesperancinha.logistics.sensor.collector.data

import java.math.BigDecimal
import java.util.UUID

data class TrainLogDto(
val id: Long,
val id: UUID,
val source: String,
val type: String,
val timestamp: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class BridgeLogisticsInitializer(
(0..200)
.map { integer: Int ->
BridgeOpeningTime(
id = integer.toLong(),
id = UUID.randomUUID(),
bridge = bridge,
openingTime =
now.plusMillis(millisToAdd * integer * 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jesperancinha.logistics.web.dto

import com.fasterxml.jackson.annotation.JsonProperty
import java.time.LocalDateTime
import java.util.UUID

data class BridgeDto(
@JsonProperty("name")
Expand Down Expand Up @@ -61,7 +62,7 @@ data class ContainerFullDto(

data class FreightDto(
@JsonProperty("id")
val id: Long,
val id: UUID,
@JsonProperty("name")
val name: String,
@JsonProperty("type")
Expand All @@ -83,7 +84,7 @@ data class ProductDto(

data class TrainDto(
@JsonProperty("id")
val id: Long,
val id: UUID,
@JsonProperty("name")
val name: String,
@JsonProperty("type")
Expand Down

0 comments on commit b316b7b

Please sign in to comment.