일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Mac
- matplotlib
- license delete
- Java
- docker
- Test
- plugin
- high level client
- TensorFlow
- flask
- token filter test
- zip 암호화
- analyzer test
- licence delete curl
- query
- 차트
- springboot
- Elasticsearch
- Python
- 900gle
- aggregation
- License
- aggs
- zip 파일 암호화
- API
- MySQL
- sort
- 파이썬
- Kafka
- ELASTIC
Archives
- Today
- Total
개발잡부
JPA 본문
반응형
jpa
package com.revu.user.config;
import com.revu.user.domain.bmw.CampaignInvitation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "bmwEntityManager",
transactionManagerRef = "bmwTransactionManager",
basePackages = "com.revu.user.domain.bmw"
)
public class BmwDBConfig {
@Autowired
private Environment env;
@Primary
@Bean(name="bmwDataSource")
public DataSource bmwDataSource(){
DriverManagerDataSource bmwDataSource = new DriverManagerDataSource();
bmwDataSource.setDriverClassName(env.getProperty("spring.kr.datasource.driver-class-name"));
bmwDataSource.setUrl(env.getProperty("spring.kr.datasource.jdbc-url"));
bmwDataSource.setUsername(env.getProperty("spring.kr.datasource.username"));
bmwDataSource.setPassword(env.getProperty("spring.kr.datasource.password"));
return bmwDataSource;
}
// @PersistenceContext(unitName = "CampaignInvitationPU")
@Bean(name = "bmwEntityManager")
public LocalContainerEntityManagerFactoryBean bmwEntityManagerFactory(EntityManagerFactoryBuilder builder) {
return builder
.dataSource(bmwDataSource())
.properties(bmWHibernateProperties())
.packages(CampaignInvitation.class)
.persistenceUnit("bmwPU")
.build();
}
@Primary
@Bean(name="bmwTransactionManager")
public PlatformTransactionManager bmwTransactionManager(@Qualifier("bmwEntityManager") EntityManagerFactory bmwEntityManagerFactory ){
return new JpaTransactionManager(bmwEntityManagerFactory);
}
private Map bmWHibernateProperties(){
Resource resource = new ClassPathResource("hibernate.properties");
try {
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
return properties.entrySet().stream().collect(Collectors.toMap(
e->e.getKey().toString(),
e->e.getValue()
));
} catch (IOException e){
return new HashMap();
}
}
}
package com.revu.user.domain.bmw;
public interface JobMapping {
Long getId();
String getValue();
}
package com.revu.user.domain.bmw;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.time.LocalDateTime;
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Entity
@Table(name = "user_meta_tag")
public class UserMetaTag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length = 10, nullable = false)
private String info;
@Column(length = 20, nullable = false)
private String type;
@Column(length = 20, nullable = false)
private String value;
@Column(length = 20, nullable = false)
private String group;
@Column(length = 10, nullable = false)
private Integer seq;
@Column(length = 1, nullable = false)
private Integer use;
@Column(length = 1, nullable = false)
private Integer input_use;
@Column(length = 20, nullable = false)
private LocalDateTime created_at;
@Column(length = 20, nullable = false)
private LocalDateTime updated_at;
@Builder
public UserMetaTag(String info, String type, String value, String group, Integer seq, Integer use, Integer input_use, LocalDateTime created_at, LocalDateTime updated_at ){
this.info = info;
this.type = type;
this.value = value;
this.group = group;
this.seq = seq;
this.use = use;
this.input_use = input_use;
this.created_at = created_at;
this.updated_at = updated_at;
}
}
package com.revu.user.domain.bmw;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserMetaTagRepository extends JpaRepository<UserMetaTag, Long> {
Page<JobMapping> findByType(String type, Pageable pageable);
}
package com.revu.user.domain;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;
@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseTimeEntity {
@CreatedDate
private LocalDateTime created_at;
@LastModifiedDate
private LocalDateTime updated_at;
}
package com.revu.user.dto;
import com.revu.user.domain.bmw.CampaignInvitation;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class CampaignInvitationDto {
private Long user_idx;
private Long campaign_id;
public CampaignInvitation toEntity() {
return CampaignInvitation.builder()
.campaign_id(campaign_id)
.user_idx(user_idx)
.build();
}
}
package com.revu.user.dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
@AllArgsConstructor(staticName = "create")
public class InvitationDto {
private Long campaign_id;
private List<Long> user_idxs;
}
반응형
'JAVA > java' 카테고리의 다른 글
[selenium] Selenium 설치 (0) | 2022.01.07 |
---|---|
AWS S3 파일업로드 테스트 (0) | 2021.10.21 |
String to JsonObject (0) | 2021.10.07 |
자바8의 java.time 패키지(LocalDate, LocalTime, LocalDateTime 등) (0) | 2020.04.28 |
Mac 에서 Homebrew 로 openjdk 설치하기 (0) | 2020.01.04 |
Comments