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
@Transactional | |
public List<Employee> getEmployees() { | |
Connection connection = dataSource.getConnection(); | |
try (connection) { | |
connection.setAutoCommit(false); | |
return employeeRepository.findAll(); | |
connection.commit(); | |
} catch (SQLException e) { | |
connection.rollback(); | |
} |
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
package com.app.sr.service; | |
import com.app.sr.entity.Customer; | |
import com.app.sr.repository.CustomerRepository; | |
import com.app.sr.util.model.ApiResponse; | |
import com.app.sr.util.model.ResponseBuilder; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.stereotype.Service; |
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
package com.app.sr.controller; | |
import com.app.sr.service.CustomerService; | |
import com.app.sr.util.model.ApiResponse; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController |
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
package com.app.sr.util.model; | |
import org.springframework.http.HttpHeaders; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.stereotype.Component; | |
import java.util.Map; | |
@Component | |
public class ResponseBuilder { | |
public ResponseEntity <ApiResponse> buildResponse( |
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
package com.app.sr.util.model; | |
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | |
import org.springframework.http.HttpHeaders; | |
import org.springframework.http.ResponseEntity; | |
import java.util.Collections; | |
import java.util.Map; | |
@JsonPropertyOrder({ "httpHeaders", "httpStatusCode", "message", "data", "otherParams" }) |
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
package com.app.designPatterns.builder3; | |
public class Car { | |
private final String make; | |
private final Integer price; | |
private final Boolean sunroof; | |
private final Boolean alloyWheels; | |
private final Boolean cruiseControl; | |
private final Boolean electricSeats; |
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
package com.app.designPatterns.builder1; | |
public class BuilderApp { | |
public static void main(String[] args) { | |
Phone iphone = new PhoneBuilder().setModel("Apple").setOs("IOS").buildPhone(); | |
System.out.println(iphone); | |
Phone androidPhone = new PhoneBuilder().setModel("Nokia").setOs("Android").setCamera("32MP").buildPhone(); |
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
package com.app.designPatterns.singleton; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
public class SingletonDbManager { | |
private static SingletonDbManager instance; | |
private static Connection connection; |
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
public enum EnumInit { | |
instance; | |
} |
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
public class ThreadSafe { | |
private static volatile ThreadSafe instance; | |
private ThreadSafe() { | |
// Avoid reflection API to create objects | |
if(instance != null){ | |
throw new RuntimeException("Use getInstance method"); | |
} | |
} |