Hibernate -> EclipseLink
потому что Hibernate как библиотека занимает много места
This commit is contained in:
@@ -9,9 +9,12 @@ dependencies {
|
|||||||
compile_excludeCopy project(':core')
|
compile_excludeCopy project(':core')
|
||||||
|
|
||||||
/* Spring */
|
/* Spring */
|
||||||
compile (group: 'org.springframework.data', name: 'spring-data-jpa', version: spring_data_version)
|
compile (group: 'org.springframework.data', name: 'spring-data-jpa', version: spring_data_version) {
|
||||||
|
exclude (group: 'org.hibernate', module: 'hibernate-entitymanager')
|
||||||
|
exclude (group: 'org.hibernate', module: 'hibernate-core')
|
||||||
|
}
|
||||||
|
|
||||||
/* Database */
|
/* Database */
|
||||||
compile (group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.3.6.Final')
|
|
||||||
compile (group: 'com.h2database', name: 'h2', version: '1.4.197')
|
compile (group: 'com.h2database', name: 'h2', version: '1.4.197')
|
||||||
|
compile (group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.jpa', version: '2.7.0')
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@ import lombok.NoArgsConstructor;
|
|||||||
import mc.core.EntityLocation;
|
import mc.core.EntityLocation;
|
||||||
import mc.core.h2db.H2Player;
|
import mc.core.h2db.H2Player;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
@@ -20,7 +19,6 @@ import java.util.UUID;
|
|||||||
public class H2PlayerEntity {
|
public class H2PlayerEntity {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(generator = "increment")
|
@GeneratedValue(generator = "increment")
|
||||||
@GenericGenerator(name= "increment", strategy= "increment")
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package mc.core.h2db;
|
package mc.core.h2db;
|
||||||
|
|
||||||
import mc.core.EntityLocation;
|
import mc.core.EntityLocation;
|
||||||
|
import mc.core.h2db.repository.H2PlayerEntityRepository;
|
||||||
import mc.core.h2db.service.H2PlayerService;
|
import mc.core.h2db.service.H2PlayerService;
|
||||||
import mc.core.player.Player;
|
import mc.core.player.Player;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -19,13 +21,24 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
@ContextConfiguration(classes = {TestSpringConfig.class})
|
@ContextConfiguration(classes = {TestSpringConfig.class})
|
||||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
class H2PlayerManagerTest {
|
class H2PlayerManagerTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private H2PlayerService h2PlayerService;
|
private H2PlayerService h2PlayerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private H2PlayerEntityRepository h2PlayerEntityRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private World mockWorld;
|
private World mockWorld;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private H2PlayerManager playerManager;
|
private H2PlayerManager playerManager;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void before() {
|
||||||
|
h2PlayerEntityRepository.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createPlayer() {
|
void createPlayer() {
|
||||||
final String playerName = "NEW_PLAYER";
|
final String playerName = "NEW_PLAYER";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package mc.core.h2db;
|
|||||||
|
|
||||||
import mc.core.h2db.service.H2PlayerService;
|
import mc.core.h2db.service.H2PlayerService;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
import org.eclipse.persistence.config.PersistenceUnitProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -10,6 +10,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|||||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
@@ -29,21 +30,22 @@ public class TestSpringConfig {
|
|||||||
private static final String DATABASE_USERNAME = "sa";
|
private static final String DATABASE_USERNAME = "sa";
|
||||||
private static final String DATABASE_PASSWORD = "s3cReT";
|
private static final String DATABASE_PASSWORD = "s3cReT";
|
||||||
|
|
||||||
static {
|
private Properties eclipseLinkProp() {
|
||||||
System.setProperty("org.jboss.logging.provider", "slf4j");
|
|
||||||
}
|
|
||||||
|
|
||||||
private Properties hibernateProp() {
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
|
properties.put(PersistenceUnitProperties.WEAVING, "static");
|
||||||
properties.put("hibernate.show_sql", "true");
|
|
||||||
properties.put("hibernate.format_sql", "true");
|
|
||||||
properties.put("hibernate.use_sql_comments", "true");
|
|
||||||
properties.put("hibernate.hbm2ddl.auto", "create");
|
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EclipseLinkJpaVendorAdapter getEclipseLinkJpaVendorAdapter() {
|
||||||
|
EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
|
||||||
|
vendorAdapter.setDatabasePlatform("org.eclipse.persistence.platform.database.H2Platform");
|
||||||
|
vendorAdapter.setGenerateDdl(true);
|
||||||
|
vendorAdapter.setShowSql(true);
|
||||||
|
|
||||||
|
return vendorAdapter;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean("mockWorld")
|
@Bean("mockWorld")
|
||||||
public World mockWorld() {
|
public World mockWorld() {
|
||||||
World mockWorld = mock(World.class);
|
World mockWorld = mock(World.class);
|
||||||
@@ -66,9 +68,9 @@ public class TestSpringConfig {
|
|||||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
|
||||||
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
|
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
|
||||||
entityManagerFactoryBean.setDataSource(dataSource);
|
entityManagerFactoryBean.setDataSource(dataSource);
|
||||||
entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
|
entityManagerFactoryBean.setJpaVendorAdapter(getEclipseLinkJpaVendorAdapter());
|
||||||
entityManagerFactoryBean.setPackagesToScan("mc.core.h2db.entity");
|
entityManagerFactoryBean.setPackagesToScan("mc.core.h2db.entity");
|
||||||
entityManagerFactoryBean.setJpaProperties(hibernateProp());
|
entityManagerFactoryBean.setJpaProperties(eclipseLinkProp());
|
||||||
|
|
||||||
return entityManagerFactoryBean;
|
return entityManagerFactoryBean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package mc.core.h2db.service;
|
|||||||
import mc.core.EntityLocation;
|
import mc.core.EntityLocation;
|
||||||
import mc.core.h2db.H2Player;
|
import mc.core.h2db.H2Player;
|
||||||
import mc.core.h2db.TestSpringConfig;
|
import mc.core.h2db.TestSpringConfig;
|
||||||
|
import mc.core.h2db.repository.H2PlayerEntityRepository;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -20,8 +22,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
@ContextConfiguration(classes = {TestSpringConfig.class})
|
@ContextConfiguration(classes = {TestSpringConfig.class})
|
||||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
class H2PlayerServiceTest {
|
class H2PlayerServiceTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private H2PlayerService h2PlayerService;
|
private H2PlayerService h2PlayerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private H2PlayerEntityRepository h2PlayerEntityRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
@@ -54,6 +61,11 @@ class H2PlayerServiceTest {
|
|||||||
assertEquals(expected.getWorld(), actual.getWorld());
|
assertEquals(expected.getWorld(), actual.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void before() {
|
||||||
|
h2PlayerEntityRepository.deleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void save() {
|
void save() {
|
||||||
H2Player player = buildPlayer();
|
H2Player player = buildPlayer();
|
||||||
|
|||||||
Reference in New Issue
Block a user