-
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.
Related to: #37
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
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
67 changes: 67 additions & 0 deletions
67
src/main/java/com/example/naverrestaurant/db/H2DbRepositoryAbstract.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,67 @@ | ||
package com.example.naverrestaurant.db; | ||
|
||
import com.example.naverrestaurant.wishlist.entity.WishListEntity; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
|
||
|
||
abstract public class H2DbRepositoryAbstract<T extends MemoryDbEntity> implements MemoryDbRepositoryIfs<T>{ | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Autowired | ||
public void setDataSource(DataSource dataSource){ | ||
this.jdbcTemplate = new JdbcTemplate(dataSource); | ||
} | ||
|
||
@Override | ||
public Optional<T> findById(int index) { | ||
String findByIdQuery = "select * from restaurant where index=? limit 1"; | ||
int findByIdParam = index; | ||
|
||
WishListEntity wishListEntity = jdbcTemplate.queryForObject(findByIdQuery, | ||
wishListEntityRowMapper(), | ||
index); | ||
|
||
return (Optional<T>) Optional.of(wishListEntity); | ||
} | ||
|
||
@Override | ||
public T save(T entity) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void deleteById(int index) { | ||
|
||
} | ||
|
||
@Override | ||
public List<T> listAll() { | ||
return null; | ||
} | ||
|
||
private RowMapper<WishListEntity> wishListEntityRowMapper(){ | ||
return ((rs, rowNum) -> { | ||
WishListEntity wishListEntity = new WishListEntity(); | ||
wishListEntity.setIndex(rs.getInt("index")); | ||
wishListEntity.setTitle(rs.getString("title")); | ||
wishListEntity.setCategory(rs.getString("category")); | ||
wishListEntity.setAddress(rs.getString("address")); | ||
wishListEntity.setRoadAddress(rs.getString("roadAddress")); | ||
wishListEntity.setHomePageLink(rs.getString("homePageLink")); | ||
wishListEntity.setImageLink(rs.getString("imageLink")); | ||
wishListEntity.setVisit(rs.getBoolean("isVisit")); | ||
wishListEntity.setVisitCount(rs.getInt("visitCount")); | ||
wishListEntity.setLastVisitDate(rs.getTimestamp("lastVisitDate").toLocalDateTime()); | ||
|
||
return wishListEntity; | ||
}); | ||
} | ||
|
||
} |
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