6,800.26
전일대비 16.25 ( -0.24% )
23,111.46
전일대비 54.05 (+ 0.23% )
48,114.26
전일대비 302.30 ( -0.62% )
리플렉션을 통해 객체의 메타데이터 (properties, class) 를 확인이 가능하다.
/**
* ReflectionClass
*/
class A
{
private $message = "Hello world";
public function __construct($message)
{
$this->message = $message;
}
}
class B extends A
{
}
// 특정 클래스 "A" 에 대하여 private 의 properties 가져오기
$refClass = new ReflectionClass('\A');
var_dump($refClass->getProperties(ReflectionProperty::IS_PRIVATE));
==> array(1) { [0]=> object(ReflectionProperty)#2 (2) { ["name"]=> string(7) "message" ["class"]=> string(1) "A" } }
// B 클래스가 A 클래스의 자식클래스인지 확인
$refClassB = new ReflectionClass('\B');
var_dump($refClassB->isSubclassOf('\A'));
==> bool(true)
// "message" 이름의 property 정보
$messageProperty = $refClass->getProperty('message');
var_dump($messageProperty);
=> object(ReflectionProperty)#3 (2) { ["name"]=> string(7) "message" ["class"]=> string(1) "A" }
Java 에는 Converter 라는 인터페이스가 있다. 해당 인터페이스는 A 타입 -> B 타입으로 변경을 할 때 사용한다. (ex. String -> Integer)
소스로 예를 들자면 "127.0.0.1:8080" 형태의 String 을 DTO 객체로 변환을 아래와 같이 처리가 가능하다.
1) IpPort DTO
import lombok.Getter;2) String -> IpPort DTO Converter
@Getter
@EqualsAndHashCode
public class IpPort {
private String ip;
private int port;
public IpPort(String ip, int port) {
this.ip = ip;
this.port = port;
}
}
3) 사용import hello.typeconverter.type.IpPort;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.converter.Converter;
@Slf4j
public class StringToIpPortConverter implements Converter<String, IpPort> {
@Override
public IpPort convert(String source) {
log.info("convert source={}", source);
// 127.0.0.1:8080
String[] split = source.split(":");
String ip = split[0];
int port = Integer.parseInt(split[1]);
return new IpPort(ip, port);
}
}
@Test
void StringToIpPort() {
StringToIpPortConverter converter = new StringToIpPortConverter();
String source = "127.0.0.1:8080";
IpPort result = converter.convert(source);
assertThat(result).isEqualTo(new IpPort("127.0.0.1", 8080));
}
간략요약하자면
UPDATE, DELETE 를 한다고 해서 Postgresql 은 물리적인 공간이 사라지는 것은 아니다. (Live Tuple -> Dead Tuple 이 되는 것임)
따라서 물리적인 공간을 지우기 위해서는 "vacuum" 이라는 것을 제공한다.
- auto vacuum : https://nrise.github.io/posts/postgresql-autovacuum/ 참조
- alter table vauum (* 컬럼타입을 변경하는 것만으로도 full vacuum 과 동일한 효과)
회사 업무 중, 업데이트 일자에 대한 컬럼을 추가해야 하는 경우가 생겼다.
초기에는 컬럼추가하는 것은 자원낭비 및 추가개발이 필요하여 등록일자 (ins_timestamp) 컬럼을 업데이트 하는 것이 어떨까 생각했다.
하지만 등록일자를 업데이트 하는 것은 다른 의미의 컬럼을 이용하는 것이기 때문에 올바르지 않은 컬럼 사용이라 판단이 들어 진행하지 않았다.
생각보다 문제는 간단하게 해소되었다.
위와 같이 진행하면 UPDATE 쿼리가 실행되는 시점에 해당 컬럼 upd_timstamp 에 현 시점의 timestamp 로 자동 update 가 된다.
다들 참고 하기를..
블로그 개발에서 사용한 DB 쿼리는 아래와 같습니다.
CREATE TABLE t_member(
no bigint(20) primary key auto_increment,
email varbinary(128) null,
member_id varchar(20) not null,
password varbinary(128) not null,
tel varbinary(128) not null,
name varbinary(32) not null,
is_delete varchar(2) null
);
/* 블로그 카테고리 정보 */
CREATE TABLE t_blog_category(
no bigint(20) primary key auto_increment,
name varchar(20) not null,
parent_no bigint(20) null,
member_no bigint(20) null,
FOREIGN KEY (parent_no) REFERENCES t_blog_category (no),
FOREIGN KEY (member_no) REFERENCES t_member (no)
);
/* 블로그 컨텐츠정보 */
CREATE TABLE t_blog(
no bigint(20) primary key auto_increment,
contents text not null,
ins_timestamp timestamp null,
upd_timestamp timestamp null,
member_no bigint(20),
category_no bigint(20),
FOREIGN KEY (member_no) REFERENCES t_member (no),
FOREIGN KEY (category_no) REFERENCES t_blog_category (no)
);
ALTER TABLE t_blog ADD COLUMN title VARCHAR(50);