-
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.
섹션4: 프록시 패턴과 데코레이터 패턴
- Loading branch information
Showing
5 changed files
with
133 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
...편/proxy/src/main/java/hello/proxy/config/v1_proxy/concrete_proxy/ConcreteProxyConfig.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,30 @@ | ||
package hello.proxy.config.v1_proxy.concrete_proxy; | ||
|
||
import hello.proxy.app.v2.OrderControllerV2; | ||
import hello.proxy.app.v2.OrderRepositoryV2; | ||
import hello.proxy.app.v2.OrderServiceV2; | ||
import hello.proxy.trace.logtrace.LogTrace; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class ConcreteProxyConfig { | ||
|
||
@Bean | ||
public OrderControllerV2 orderControllerV2(LogTrace logTrace) { | ||
OrderControllerV2 orderControllerImpl = new OrderControllerV2(orderServiceV2(logTrace)); | ||
return new OrderControllerConcreteProxy(orderControllerImpl, logTrace); | ||
} | ||
|
||
@Bean | ||
public OrderServiceV2 orderServiceV2(LogTrace logTrace) { | ||
OrderServiceV2 orderServiceImpl = new OrderServiceV2(orderRepositoryV2(logTrace)); | ||
return new OrderServiceConcreteProxy(orderServiceImpl, logTrace); | ||
} | ||
|
||
@Bean | ||
public OrderRepositoryV2 orderRepositoryV2(LogTrace logTrace) { | ||
OrderRepositoryV2 repositoryImpl = new OrderRepositoryV2(); | ||
return new OrderRepositoryConcreteProxy(repositoryImpl, logTrace); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...rc/main/java/hello/proxy/config/v1_proxy/concrete_proxy/OrderControllerConcreteProxy.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,38 @@ | ||
package hello.proxy.config.v1_proxy.concrete_proxy; | ||
|
||
import hello.proxy.app.v2.OrderControllerV2; | ||
import hello.proxy.trace.TraceStatus; | ||
import hello.proxy.trace.logtrace.LogTrace; | ||
|
||
public class OrderControllerConcreteProxy extends OrderControllerV2 { | ||
|
||
private final OrderControllerV2 target; | ||
private final LogTrace logTrace; | ||
|
||
public OrderControllerConcreteProxy(final OrderControllerV2 target, final LogTrace logTrace) { | ||
super(null); | ||
this.target = target; | ||
this.logTrace = logTrace; | ||
} | ||
|
||
@Override | ||
public String request(final String itemId) { | ||
TraceStatus status = null; | ||
try { | ||
status = logTrace.begin("OrderController.request()"); | ||
// target 호출 | ||
String result = target.request("itemId"); | ||
logTrace.end(status); | ||
|
||
return result; | ||
} catch (Exception e) { | ||
logTrace.exception(status, e); | ||
throw e; | ||
} | ||
} | ||
|
||
@Override | ||
public String noLog() { | ||
return target.noLog(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/hello/proxy/config/v1_proxy/concrete_proxy/OrderRepositoryConcreteProxy.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 hello.proxy.config.v1_proxy.concrete_proxy; | ||
|
||
import hello.proxy.app.v2.OrderRepositoryV2; | ||
import hello.proxy.trace.TraceStatus; | ||
import hello.proxy.trace.logtrace.LogTrace; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class OrderRepositoryConcreteProxy extends OrderRepositoryV2 { | ||
|
||
private final OrderRepositoryV2 target; | ||
private final LogTrace logTrace; | ||
@Override | ||
public void save(final String itemId) { | ||
TraceStatus status = null; | ||
try { | ||
status = logTrace.begin("OrderRepository.request()"); | ||
|
||
// target 호출 | ||
target.save("itemId"); | ||
|
||
logTrace.end(status); | ||
} catch (Exception e) { | ||
logTrace.exception(status, e); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...y/src/main/java/hello/proxy/config/v1_proxy/concrete_proxy/OrderServiceConcreteProxy.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,33 @@ | ||
package hello.proxy.config.v1_proxy.concrete_proxy; | ||
|
||
import hello.proxy.app.v2.OrderServiceV2; | ||
import hello.proxy.trace.TraceStatus; | ||
import hello.proxy.trace.logtrace.LogTrace; | ||
|
||
public class OrderServiceConcreteProxy extends OrderServiceV2 { | ||
|
||
private final OrderServiceV2 target; | ||
private final LogTrace logTrace; | ||
|
||
|
||
public OrderServiceConcreteProxy(final OrderServiceV2 target, final LogTrace logTrace) { | ||
super(null); | ||
this.target = target; | ||
this.logTrace = logTrace; | ||
} | ||
|
||
@Override | ||
public void orderItem(final String itemId) { | ||
TraceStatus status = null; | ||
try { | ||
status = logTrace.begin("OrderService.orderItem()"); | ||
|
||
// target 호출 | ||
target.orderItem("itemId"); | ||
|
||
logTrace.end(status); | ||
} catch (Exception e) { | ||
logTrace.exception(status, e); | ||
} | ||
} | ||
} |