mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 17:26:44 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -37,32 +37,28 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Single Table Inheritance pattern :
|
||||
* Single Table Inheritance pattern : <br>
|
||||
* It maps each instance of class in an inheritance tree into a single table. <br>
|
||||
*
|
||||
* <p>In case of current project, in order to specify the Single Table Inheritance to Hibernate we
|
||||
* annotate the main Vehicle root class with @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
* due to which a single root <b>Vehicle</b> class table will be created in the database and it will
|
||||
* have columns for all the fields of it's subclasses(Car, Freighter, Train, Truck). <br>
|
||||
* Additional to that, a new separate <b>"vehicle_id"</b> column would be added to the Vehicle table
|
||||
* to save the type of the subclass object that is being stored in the database. This value is
|
||||
* specified by the @DiscriminatorValue annotation value for each subclass in case of Hibernate.
|
||||
* <br>
|
||||
* It maps each instance of class in an inheritance tree into a single table.
|
||||
* <br>
|
||||
* <p>
|
||||
* In case of current project, in order to specify the Single Table Inheritance to Hibernate
|
||||
* we annotate the main Vehicle root class with @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
* due to which a single root <b>Vehicle</b> class table will be created
|
||||
* in the database and it will have columns for all the fields of
|
||||
* it's subclasses(Car, Freighter, Train, Truck). <br>
|
||||
* Additional to that, a new separate <b>"vehicle_id"</b> column would be added
|
||||
* to the Vehicle table to save the type of the subclass object that
|
||||
* is being stored in the database. This value is specified by the @DiscriminatorValue annotation
|
||||
* value for each subclass in case of Hibernate. <br>
|
||||
* </p><br>
|
||||
* Below is the main Spring Boot Application class from where the Program Runs.
|
||||
* <p>
|
||||
* It implements the CommandLineRunner to run the statements at the
|
||||
* start of the application program.
|
||||
* </p>
|
||||
*
|
||||
* <p>It implements the CommandLineRunner to run the statements at the start of the application
|
||||
* program.
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@AllArgsConstructor
|
||||
public class SingleTableInheritance implements CommandLineRunner {
|
||||
|
||||
//Autowiring the VehicleService class to execute the business logic methods
|
||||
// Autowiring the VehicleService class to execute the business logic methods
|
||||
private final VehicleService vehicleService;
|
||||
|
||||
/**
|
||||
@@ -75,8 +71,7 @@ public class SingleTableInheritance implements CommandLineRunner {
|
||||
}
|
||||
|
||||
/**
|
||||
* The starting point of the CommandLineRunner
|
||||
* where the main program is run.
|
||||
* The starting point of the CommandLineRunner where the main program is run.
|
||||
*
|
||||
* @param args program runtime arguments
|
||||
*/
|
||||
@@ -97,7 +92,6 @@ public class SingleTableInheritance implements CommandLineRunner {
|
||||
Vehicle truck1 = vehicleService.saveVehicle(vehicle2);
|
||||
log.info("Vehicle 2 saved : {}\n", truck1);
|
||||
|
||||
|
||||
log.info("Fetching Vehicles :- ");
|
||||
|
||||
// Fetching the Car from DB
|
||||
@@ -114,4 +108,4 @@ public class SingleTableInheritance implements CommandLineRunner {
|
||||
List<Vehicle> allVehiclesFromDb = vehicleService.getAllVehicles();
|
||||
allVehiclesFromDb.forEach(s -> log.info(s.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,12 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* A class that extends the PassengerVehicle class
|
||||
* and provides the concrete inheritance implementation of the Car.
|
||||
* A class that extends the PassengerVehicle class and provides the concrete inheritance
|
||||
* implementation of the Car.
|
||||
*
|
||||
* @see PassengerVehicle PassengerVehicle
|
||||
* @see Vehicle Vehicle
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -55,9 +54,6 @@ public class Car extends PassengerVehicle {
|
||||
// Overridden the toString method to specify the Vehicle object
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Car{"
|
||||
+ super.toString()
|
||||
+ '}';
|
||||
return "Car{" + super.toString() + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* A class that extends the TransportVehicle class
|
||||
* and provides the concrete inheritance implementation of the Car.
|
||||
* A class that extends the TransportVehicle class and provides the concrete inheritance
|
||||
* implementation of the Car.
|
||||
*
|
||||
* @see TransportVehicle TransportVehicle
|
||||
* @see Vehicle Vehicle
|
||||
@@ -54,12 +54,6 @@ public class Freighter extends TransportVehicle {
|
||||
// Overridden the toString method to specify the Vehicle object
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Freighter{ "
|
||||
+ super.toString()
|
||||
+ " ,"
|
||||
+ "flightLength="
|
||||
+ flightLength
|
||||
+ '}';
|
||||
return "Freighter{ " + super.toString() + " ," + "flightLength=" + flightLength + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* An abstract class that extends the Vehicle class
|
||||
* and provides properties for the Passenger type of Vehicles.
|
||||
* An abstract class that extends the Vehicle class and provides properties for the Passenger type
|
||||
* of Vehicles.
|
||||
*
|
||||
* @see Vehicle
|
||||
*/
|
||||
|
||||
@@ -31,8 +31,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* A class that extends the PassengerVehicle class
|
||||
* and provides the concrete inheritance implementation of the Car.
|
||||
* A class that extends the PassengerVehicle class and provides the concrete inheritance
|
||||
* implementation of the Car.
|
||||
*
|
||||
* @see PassengerVehicle PassengerVehicle
|
||||
* @see Vehicle Vehicle
|
||||
@@ -54,9 +54,6 @@ public class Train extends PassengerVehicle {
|
||||
// Overridden the toString method to specify the Vehicle object
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Train{"
|
||||
+ super.toString()
|
||||
+ '}';
|
||||
return "Train{" + super.toString() + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* An abstract class that extends the Vehicle class
|
||||
* and provides properties for the Transport type of Vehicles.
|
||||
* An abstract class that extends the Vehicle class and provides properties for the Transport type
|
||||
* of Vehicles.
|
||||
*
|
||||
* @see Vehicle
|
||||
*/
|
||||
@@ -45,5 +45,4 @@ public abstract class TransportVehicle extends Vehicle {
|
||||
super(manufacturer, model);
|
||||
this.loadCapacity = loadCapacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* A class that extends the PassengerVehicle class
|
||||
* and provides the concrete inheritance implementation of the Car.
|
||||
* A class that extends the PassengerVehicle class and provides the concrete inheritance
|
||||
* implementation of the Car.
|
||||
*
|
||||
* @see TransportVehicle TransportVehicle
|
||||
* @see Vehicle Vehicle
|
||||
@@ -52,11 +52,6 @@ public class Truck extends TransportVehicle {
|
||||
// Overridden the toString method to specify the Vehicle object
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Truck{ "
|
||||
+ super.toString()
|
||||
+ ", "
|
||||
+ "towingCapacity="
|
||||
+ towingCapacity
|
||||
+ '}';
|
||||
return "Truck{ " + super.toString() + ", " + "towingCapacity=" + towingCapacity + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* An abstract class that is the root of the Vehicle Inheritance hierarchy
|
||||
* and basic provides properties for all the vehicles.
|
||||
* An abstract class that is the root of the Vehicle Inheritance hierarchy and basic provides
|
||||
* properties for all the vehicles.
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -65,14 +65,13 @@ public abstract class Vehicle {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vehicle{"
|
||||
+ "vehicleId="
|
||||
+ vehicleId
|
||||
+ ", manufacturer='"
|
||||
+ manufacturer
|
||||
+ '\''
|
||||
+ ", model='"
|
||||
+ model
|
||||
+ '}';
|
||||
+ "vehicleId="
|
||||
+ vehicleId
|
||||
+ ", manufacturer='"
|
||||
+ manufacturer
|
||||
+ '\''
|
||||
+ ", model='"
|
||||
+ model
|
||||
+ '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-5
@@ -29,10 +29,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* A repository that is extending the JPA Repository
|
||||
* to provide the default Spring DATA JPA methods for the Vehicle class.
|
||||
* A repository that is extending the JPA Repository to provide the default Spring DATA JPA methods
|
||||
* for the Vehicle class.
|
||||
*/
|
||||
@Repository
|
||||
public interface VehicleRepository extends JpaRepository<Vehicle, Integer> {
|
||||
|
||||
}
|
||||
public interface VehicleRepository extends JpaRepository<Vehicle, Integer> {}
|
||||
|
||||
@@ -31,9 +31,8 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* A service class that is used to provide the business logic
|
||||
* for the Vehicle class and connect to the database to
|
||||
* perform the CRUD operations on the root Vehicle class.
|
||||
* A service class that is used to provide the business logic for the Vehicle class and connect to
|
||||
* the database to perform the CRUD operations on the root Vehicle class.
|
||||
*
|
||||
* @see Vehicle
|
||||
*/
|
||||
@@ -91,5 +90,4 @@ public class VehicleService {
|
||||
public void deleteVehicle(Vehicle vehicle) {
|
||||
vehicleRepository.delete(vehicle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user