problems with orderstest
This commit is contained in:
parent
7526d3fd8b
commit
79bbcca648
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
374
data.trace.db
Normal file
374
data.trace.db
Normal file
@ -0,0 +1,374 @@
|
||||
2024-04-20 21:36:59.377754+04:00 database: flush
|
||||
org.h2.message.DbException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.get(DbException.java:212)
|
||||
at org.h2.message.DbException.convert(DbException.java:407)
|
||||
at org.h2.mvstore.db.Store.lambda$new$0(Store.java:122)
|
||||
at org.h2.mvstore.MVStore.handleException(MVStore.java:1546)
|
||||
at org.h2.mvstore.MVStore.panic(MVStore.java:371)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:291)
|
||||
at org.h2.mvstore.MVStore$Builder.open(MVStore.java:2035)
|
||||
at org.h2.mvstore.db.Store.<init>(Store.java:133)
|
||||
at org.h2.engine.Database.<init>(Database.java:326)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:92)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:222)
|
||||
at org.h2.engine.Engine.createSession(Engine.java:201)
|
||||
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:343)
|
||||
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:125)
|
||||
at org.h2.Driver.connect(Driver.java:59)
|
||||
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
|
||||
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
|
||||
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
|
||||
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
|
||||
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.getConnectionUrl(H2ConsoleAutoConfiguration.java:94)
|
||||
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
|
||||
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
|
||||
at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
|
||||
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
|
||||
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
|
||||
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
|
||||
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
|
||||
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
|
||||
at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
|
||||
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
|
||||
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
|
||||
at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.logDataSources(H2ConsoleAutoConfiguration.java:86)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.lambda$h2Console$0(H2ConsoleAutoConfiguration.java:69)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.withThreadContextClassLoader(H2ConsoleAutoConfiguration.java:78)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.h2Console(H2ConsoleAutoConfiguration.java:69)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140)
|
||||
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
|
||||
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1335)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1165)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
|
||||
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:210)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:201)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:96)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:85)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:266)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:240)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:52)
|
||||
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4880)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
|
||||
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
|
||||
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
|
||||
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
|
||||
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
|
||||
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:845)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
|
||||
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
|
||||
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
|
||||
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
|
||||
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
|
||||
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:240)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:433)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:921)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:437)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:105)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:499)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:218)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:188)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
|
||||
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:618)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
|
||||
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
|
||||
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
|
||||
at com.example.demo.DemoApplication.main(DemoApplication.java:39)
|
||||
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:566)
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
|
||||
... 96 more
|
||||
Caused by: org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]
|
||||
at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:996)
|
||||
at org.h2.mvstore.SingleFileStore.lockFileChannel(SingleFileStore.java:143)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:117)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:81)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:286)
|
||||
... 90 more
|
||||
2024-04-20 21:37:00.680147+04:00 database: flush
|
||||
org.h2.message.DbException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.get(DbException.java:212)
|
||||
at org.h2.message.DbException.convert(DbException.java:407)
|
||||
at org.h2.mvstore.db.Store.lambda$new$0(Store.java:122)
|
||||
at org.h2.mvstore.MVStore.handleException(MVStore.java:1546)
|
||||
at org.h2.mvstore.MVStore.panic(MVStore.java:371)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:291)
|
||||
at org.h2.mvstore.MVStore$Builder.open(MVStore.java:2035)
|
||||
at org.h2.mvstore.db.Store.<init>(Store.java:133)
|
||||
at org.h2.engine.Database.<init>(Database.java:326)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:92)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:222)
|
||||
at org.h2.engine.Engine.createSession(Engine.java:201)
|
||||
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:343)
|
||||
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:125)
|
||||
at org.h2.Driver.connect(Driver.java:59)
|
||||
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
|
||||
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
|
||||
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
|
||||
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
|
||||
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
|
||||
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:428)
|
||||
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:61)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:276)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:107)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)
|
||||
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:130)
|
||||
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
|
||||
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:238)
|
||||
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
|
||||
at org.hibernate.boot.model.relational.Database.<init>(Database.java:45)
|
||||
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getDatabase(InFlightMetadataCollectorImpl.java:223)
|
||||
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:191)
|
||||
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:170)
|
||||
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1432)
|
||||
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1503)
|
||||
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:75)
|
||||
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:390)
|
||||
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
|
||||
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)
|
||||
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:366)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1833)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
|
||||
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
|
||||
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1234)
|
||||
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:952)
|
||||
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
|
||||
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
|
||||
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
|
||||
at com.example.demo.DemoApplication.main(DemoApplication.java:39)
|
||||
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:566)
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
|
||||
... 61 more
|
||||
Caused by: org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]
|
||||
at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:996)
|
||||
at org.h2.mvstore.SingleFileStore.lockFileChannel(SingleFileStore.java:143)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:117)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:81)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:286)
|
||||
... 55 more
|
||||
2024-04-20 21:37:35.622227+04:00 database: flush
|
||||
org.h2.message.DbException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.get(DbException.java:212)
|
||||
at org.h2.message.DbException.convert(DbException.java:407)
|
||||
at org.h2.mvstore.db.Store.lambda$new$0(Store.java:122)
|
||||
at org.h2.mvstore.MVStore.handleException(MVStore.java:1546)
|
||||
at org.h2.mvstore.MVStore.panic(MVStore.java:371)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:291)
|
||||
at org.h2.mvstore.MVStore$Builder.open(MVStore.java:2035)
|
||||
at org.h2.mvstore.db.Store.<init>(Store.java:133)
|
||||
at org.h2.engine.Database.<init>(Database.java:326)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:92)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:222)
|
||||
at org.h2.engine.Engine.createSession(Engine.java:201)
|
||||
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:343)
|
||||
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:125)
|
||||
at org.h2.Driver.connect(Driver.java:59)
|
||||
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
|
||||
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
|
||||
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
|
||||
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
|
||||
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.getConnectionUrl(H2ConsoleAutoConfiguration.java:94)
|
||||
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
|
||||
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
|
||||
at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
|
||||
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
|
||||
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
|
||||
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
|
||||
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
|
||||
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
|
||||
at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
|
||||
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
|
||||
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
|
||||
at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.logDataSources(H2ConsoleAutoConfiguration.java:86)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.lambda$h2Console$0(H2ConsoleAutoConfiguration.java:69)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.withThreadContextClassLoader(H2ConsoleAutoConfiguration.java:78)
|
||||
at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.h2Console(H2ConsoleAutoConfiguration.java:69)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
|
||||
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140)
|
||||
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
|
||||
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1335)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1165)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
|
||||
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:210)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:201)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:96)
|
||||
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:85)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:266)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:240)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:52)
|
||||
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4880)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
|
||||
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
|
||||
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
|
||||
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
|
||||
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
|
||||
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:845)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
|
||||
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
|
||||
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
|
||||
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
|
||||
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
|
||||
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
|
||||
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:240)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:433)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:921)
|
||||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
|
||||
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:437)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:105)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:499)
|
||||
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:218)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:188)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)
|
||||
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:618)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
|
||||
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
|
||||
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
|
||||
at com.example.demo.DemoApplication.main(DemoApplication.java:39)
|
||||
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:566)
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
|
||||
... 96 more
|
||||
Caused by: org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]
|
||||
at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:996)
|
||||
at org.h2.mvstore.SingleFileStore.lockFileChannel(SingleFileStore.java:143)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:117)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:81)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:286)
|
||||
... 90 more
|
||||
2024-04-20 21:37:36.939049+04:00 database: flush
|
||||
org.h2.message.DbException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.get(DbException.java:212)
|
||||
at org.h2.message.DbException.convert(DbException.java:407)
|
||||
at org.h2.mvstore.db.Store.lambda$new$0(Store.java:122)
|
||||
at org.h2.mvstore.MVStore.handleException(MVStore.java:1546)
|
||||
at org.h2.mvstore.MVStore.panic(MVStore.java:371)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:291)
|
||||
at org.h2.mvstore.MVStore$Builder.open(MVStore.java:2035)
|
||||
at org.h2.mvstore.db.Store.<init>(Store.java:133)
|
||||
at org.h2.engine.Database.<init>(Database.java:326)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:92)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:222)
|
||||
at org.h2.engine.Engine.createSession(Engine.java:201)
|
||||
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:343)
|
||||
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:125)
|
||||
at org.h2.Driver.connect(Driver.java:59)
|
||||
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
|
||||
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
|
||||
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
|
||||
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
|
||||
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
|
||||
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
|
||||
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:428)
|
||||
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:61)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:276)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:107)
|
||||
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)
|
||||
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:130)
|
||||
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
|
||||
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:238)
|
||||
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
|
||||
at org.hibernate.boot.model.relational.Database.<init>(Database.java:45)
|
||||
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getDatabase(InFlightMetadataCollectorImpl.java:223)
|
||||
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:191)
|
||||
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:170)
|
||||
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1432)
|
||||
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1503)
|
||||
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:75)
|
||||
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:390)
|
||||
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409)
|
||||
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396)
|
||||
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:366)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1833)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:600)
|
||||
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)
|
||||
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
|
||||
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
|
||||
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1234)
|
||||
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:952)
|
||||
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624)
|
||||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
|
||||
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
|
||||
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
|
||||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
|
||||
at com.example.demo.DemoApplication.main(DemoApplication.java:39)
|
||||
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Внутренняя ошибка: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]"
|
||||
General error: "org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]" [50000-224]
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:566)
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
|
||||
... 61 more
|
||||
Caused by: org.h2.mvstore.MVStoreException: The file is locked: C:/4 semestr/IP/IP-Labs-4-semestr/data.mv.db [2.2.224/7]
|
||||
at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:996)
|
||||
at org.h2.mvstore.SingleFileStore.lockFileChannel(SingleFileStore.java:143)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:117)
|
||||
at org.h2.mvstore.SingleFileStore.open(SingleFileStore.java:81)
|
||||
at org.h2.mvstore.MVStore.<init>(MVStore.java:286)
|
||||
... 55 more
|
@ -1,6 +1,6 @@
|
||||
package com.example.demo;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -11,24 +11,28 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import com.example.demo.itemCategories.model.CategoriesEntity;
|
||||
import com.example.demo.itemCategories.service.CategoriesService;
|
||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
import com.example.demo.itemOrders.service.OrdersService;
|
||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
||||
import com.example.demo.itemProducts.service.ProductsService;
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
import com.example.demo.itemUsers.service.UsersService;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication implements CommandLineRunner {
|
||||
private final Logger log = LoggerFactory.getLogger(DemoApplication.class);
|
||||
|
||||
//private final UsersService userService;
|
||||
private final UsersService userService;
|
||||
private final CategoriesService categoriesService;
|
||||
private final ProductsService productsService;
|
||||
//private final OrdersService ordersService;
|
||||
private final OrdersService ordersService;
|
||||
|
||||
public DemoApplication(CategoriesService categoriesService, ProductsService productsService) {
|
||||
public DemoApplication(CategoriesService categoriesService, ProductsService productsService, UsersService userService, OrdersService ordersService) {
|
||||
|
||||
//this.userService = userService;
|
||||
this.userService = userService;
|
||||
this.categoriesService = categoriesService;
|
||||
this.productsService = productsService;
|
||||
//this.ordersService = ordersService;
|
||||
this.ordersService = ordersService;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -39,25 +43,28 @@ public class DemoApplication implements CommandLineRunner {
|
||||
public void run(String... args) throws Exception {
|
||||
if (args.length > 0 && Objects.equals("--populate", args[0])) {
|
||||
|
||||
/*log.info("Создание пользователей");
|
||||
final var user1 = userService.create(new UsersEntity(null, "Natalia", "1234"));
|
||||
final var user2 =userService.create(new UsersEntity(null, "Revengel", "4567"));*/
|
||||
log.info("Создание пользователей");
|
||||
final var user1 = userService.create(new UsersEntity("Natalia", "1234"));
|
||||
userService.create(new UsersEntity("Revengel", "4567"));
|
||||
|
||||
log.info("Создание категорий");
|
||||
final var category1 = categoriesService.create(new CategoriesEntity(null, "Ноутбуки"));
|
||||
final var category2 = categoriesService.create(new CategoriesEntity(null, "Телефоны"));
|
||||
final var category1 = categoriesService.create(new CategoriesEntity("Ноутбуки"));
|
||||
final var category2 = categoriesService.create(new CategoriesEntity("Телефоны"));
|
||||
|
||||
log.info("Создание продуктов");
|
||||
final var product1 = productsService.create(new ProductsEntity(null, category1, "Lenovo IDEA PAD 13", 15232.00));
|
||||
final var product2 = productsService.create(new ProductsEntity(null, category1, "Acer", 20300.00));
|
||||
final var product3 = productsService.create(new ProductsEntity(null, category2, "Iphone 13", 150000.00));
|
||||
/*
|
||||
final var product1 = productsService.create(new ProductsEntity(category1, "Lenovo IDEA PAD 13", 15232.00));
|
||||
final var product2 = productsService.create(new ProductsEntity(category1, "Acer", 20300.00));
|
||||
final var product3 = productsService.create(new ProductsEntity(category2, "Iphone 13", 150000.00));
|
||||
|
||||
log.info("Создание заказов");
|
||||
ordersService.create(user1.getId(), new OrdersEntity(null, product1, 3, new SimpleDateFormat("09/04/2024")));
|
||||
ordersService.create(user1.getId(), new OrdersEntity(null, product2, 2, new SimpleDateFormat("09/04/2024")));
|
||||
ordersService.create(user2.getId(), new OrdersEntity(null, product3, 1, new SimpleDateFormat("07/04/2024")));
|
||||
ordersService.create(user2.getId(), new OrdersEntity(null, product1, 4, new SimpleDateFormat("07/04/2024")));
|
||||
*/
|
||||
|
||||
final var orders = List.of(
|
||||
new OrdersEntity(product1, 3),
|
||||
new OrdersEntity(product2, 2),
|
||||
new OrdersEntity(product3, 1),
|
||||
new OrdersEntity(product1, 4));
|
||||
orders.forEach(order -> ordersService.create(user1.getId(), order));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import jakarta.persistence.Table;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name = "сategories")
|
||||
@Table(name = "categories")
|
||||
public class CategoriesEntity extends BaseEntity {
|
||||
@Column(nullable = false, unique = true, length = 50)
|
||||
private String name;
|
||||
@ -17,8 +17,7 @@ public class CategoriesEntity extends BaseEntity {
|
||||
super();
|
||||
}
|
||||
|
||||
public CategoriesEntity(Long id, String name) {
|
||||
super(id);
|
||||
public CategoriesEntity(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
|
@ -0,0 +1,69 @@
|
||||
package com.example.demo.itemOrders.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.core.configuration.Constants;
|
||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
import com.example.demo.itemOrders.service.OrdersService;
|
||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
||||
import com.example.demo.itemProducts.service.ProductsService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Constants.API_URL + "/user/{user}/order")
|
||||
public class OrdersController {
|
||||
private final OrdersService ordersService;
|
||||
private final ProductsService productsService;
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
public OrdersController(OrdersService ordersService, ProductsService productsService, ModelMapper modelMapper) {
|
||||
this.ordersService = ordersService;
|
||||
this.productsService = productsService;
|
||||
this.modelMapper = modelMapper;
|
||||
}
|
||||
|
||||
private OrdersDto toDto(OrdersEntity entity) {
|
||||
return modelMapper.map(entity, OrdersDto.class);
|
||||
}
|
||||
private OrdersEntity toEntity(OrdersDto dto) {
|
||||
final OrdersEntity entity = modelMapper.map(dto, OrdersEntity.class);
|
||||
entity.setProduct(productsService.get(dto.getProductId()));
|
||||
return entity;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<OrdersDto> getAll(@PathVariable(name = "user") Long userId, @RequestParam(name = "productId", defaultValue = "0") ProductsEntity product) {
|
||||
return ordersService.getAll(userId).stream().map(this::toDto).toList();
|
||||
}
|
||||
@GetMapping("/{id}")
|
||||
public OrdersDto get(@PathVariable(name = "user") Long userId, @PathVariable(name = "id") Long id) {
|
||||
return toDto(ordersService.get(userId, id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public OrdersDto create(@PathVariable(name = "user") Long userId, @RequestBody @Valid OrdersDto dto) {
|
||||
return toDto(ordersService.create(userId, toEntity(dto)));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public OrdersDto update(@PathVariable(name = "user") Long userId, @PathVariable(name = "id") Long id, @RequestBody OrdersDto dto) {
|
||||
return toDto(ordersService.update(userId, id, toEntity(dto)));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public OrdersDto delete(@PathVariable(name = "user") Long userId, @PathVariable(name = "id") Long id) {
|
||||
return toDto(ordersService.delete(userId, id));
|
||||
}
|
||||
}
|
60
src/main/java/com/example/demo/itemOrders/api/OrdersDto.java
Normal file
60
src/main/java/com/example/demo/itemOrders/api/OrdersDto.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.example.demo.itemOrders.api;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
public class OrdersDto {
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Long id;
|
||||
@NotNull
|
||||
private ProductsEntity product;
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Integer count;
|
||||
@NotNull
|
||||
private SimpleDateFormat date;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ProductsEntity getProduct() {
|
||||
return product;
|
||||
}
|
||||
public void setProduct(ProductsEntity product) {
|
||||
this.product = product;
|
||||
}
|
||||
public Long getProductId() {
|
||||
return product.getId();
|
||||
}
|
||||
public void setProductId(Long productId) {
|
||||
productId = product.getId();
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
public SimpleDateFormat getDate() {
|
||||
return date;
|
||||
}
|
||||
public void setDate(SimpleDateFormat date) {
|
||||
this.date = date;
|
||||
}
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
public Double getSum() {
|
||||
return count * product.getPrice();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.example.demo.itemOrders.model;
|
||||
import java.util.Objects;
|
||||
import com.example.demo.core.model.BaseEntity;
|
||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "orders")
|
||||
public class OrdersEntity extends BaseEntity {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "productId", nullable = false)
|
||||
private ProductsEntity product;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "userId", nullable = false)
|
||||
private UsersEntity user;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer count;
|
||||
|
||||
|
||||
//@Column(nullable = false)
|
||||
//private Double sum = getSum();
|
||||
|
||||
public OrdersEntity() {
|
||||
}
|
||||
public OrdersEntity(ProductsEntity product, Integer count) {
|
||||
this.product = product;
|
||||
this.count = count;
|
||||
}
|
||||
public ProductsEntity getProduct() {
|
||||
return product;
|
||||
}
|
||||
public void setProduct(ProductsEntity product) {
|
||||
this.product = product;
|
||||
}
|
||||
public UsersEntity getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(UsersEntity user) {
|
||||
this.user = user;
|
||||
if (!user.getOrders().contains(this)) {
|
||||
user.getOrders().add(this);
|
||||
}
|
||||
}
|
||||
|
||||
// public Double getSum() {
|
||||
// sum = count * product.getPrice();
|
||||
// return sum;
|
||||
// }
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, product, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || getClass() != obj.getClass())
|
||||
return false;
|
||||
final OrdersEntity other = (OrdersEntity) obj;
|
||||
return Objects.equals(other.getId(), id)
|
||||
&& Objects.equals(other.getProduct(), product)
|
||||
&& Objects.equals(other.getUser().getId(), user.getId())
|
||||
&& Objects.equals(other.getCount(), count);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.example.demo.itemOrders.repository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
//import com.example.demo.itemOrders.model.OrdersGrouped;
|
||||
|
||||
public interface OrdersRepository extends CrudRepository<OrdersEntity, Long> {
|
||||
Optional<OrdersEntity> findOneByUserIdAndId(long userId, long id);
|
||||
|
||||
List<OrdersEntity> findByUserId(long userId);
|
||||
|
||||
// select
|
||||
// tpe.name,
|
||||
// coalesce(sum(order.price), 0),
|
||||
// coalesce(sum(order.count), 0)
|
||||
// from types as tpe
|
||||
// left join orders as order on tpe.id = order.type_id and order.user_id = ?
|
||||
// group by tpe.name order by tpe.id
|
||||
// @Query("select "
|
||||
// + "u as user, "
|
||||
// + "coalesce(sum(o.sum), 0) as totalSum, "
|
||||
// + "coalesce(sum(o.count), 0) as totalCount "
|
||||
// + "from UsersEntity u left join OrderEntity o on o.user = u and o.user.id = ?1 "
|
||||
// + "group by u order by u.id")
|
||||
// List<OrdersGrouped> getOrdersTotalByUser(long userId);
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.demo.itemOrders.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.example.demo.core.error.NotFoundException;
|
||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
//import com.example.demo.itemOrders.model.OrdersGrouped;
|
||||
import com.example.demo.itemOrders.repository.OrdersRepository;
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
import com.example.demo.itemUsers.service.UsersService;
|
||||
|
||||
@Service
|
||||
public class OrdersService {
|
||||
private final OrdersRepository repository;
|
||||
private final UsersService userService;
|
||||
|
||||
public OrdersService(OrdersRepository repository, UsersService userService) {
|
||||
this.repository = repository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<OrdersEntity> getAll(long userId) {
|
||||
userService.get(userId);
|
||||
return repository.findByUserId(userId);
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public OrdersEntity get(long userId, Long id) {
|
||||
userService.get(userId);
|
||||
return repository.findOneByUserIdAndId(userId, id).orElseThrow(() -> new NotFoundException(OrdersEntity.class, id));
|
||||
}
|
||||
@Transactional
|
||||
public OrdersEntity create(long userId, OrdersEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException("Entity is null");
|
||||
}
|
||||
final UsersEntity existsUser = userService.get(userId);
|
||||
entity.setUser(existsUser);
|
||||
return repository.save(entity);
|
||||
}
|
||||
@Transactional
|
||||
public OrdersEntity update(long userId, Long id, OrdersEntity entity) {
|
||||
userService.get(userId);
|
||||
final OrdersEntity existsEntity = get(userId, id);
|
||||
existsEntity.setProduct(entity.getProduct());
|
||||
existsEntity.setCount(entity.getCount());
|
||||
return repository.save(existsEntity);
|
||||
}
|
||||
@Transactional
|
||||
public OrdersEntity delete(long userId, Long id) {
|
||||
userService.get(userId);
|
||||
final OrdersEntity existsEntity = get(userId, id);
|
||||
repository.delete(existsEntity);
|
||||
return existsEntity;
|
||||
}
|
||||
|
||||
// @Transactional(readOnly = true)
|
||||
// public List<OrdersGrouped> getTotal(long userId) {
|
||||
// //userService.get(userId);
|
||||
// return repository.getOrdersTotalByUser(userId);
|
||||
// }
|
||||
|
||||
}
|
@ -22,12 +22,10 @@ public class ProductsEntity extends BaseEntity{
|
||||
@Column(nullable = false)
|
||||
private Double price;
|
||||
|
||||
public ProductsEntity(Object object, String string) {
|
||||
super();
|
||||
public ProductsEntity() {
|
||||
}
|
||||
|
||||
public ProductsEntity(Long id, CategoriesEntity category, String name, Double price) {
|
||||
super(id);
|
||||
public ProductsEntity(CategoriesEntity category, String name, Double price) {
|
||||
this.category = category;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.example.demo.itemUsers.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.core.configuration.Constants;
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
import com.example.demo.itemUsers.service.UsersService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Constants.API_URL + "/Users")
|
||||
public class UsersController {
|
||||
private final UsersService usersService;
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
public UsersController(UsersService usersService, ModelMapper modelMapper) {
|
||||
this.usersService = usersService;
|
||||
this.modelMapper = modelMapper;
|
||||
}
|
||||
|
||||
private UsersDto toDto(UsersEntity entity) {
|
||||
return modelMapper.map(entity, UsersDto.class);
|
||||
}
|
||||
|
||||
private UsersEntity toEntity(UsersDto dto) {
|
||||
return modelMapper.map(dto, UsersEntity.class);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<UsersDto> getAll() {
|
||||
return usersService.getAll().stream().map(this::toDto).toList();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public UsersDto get(@PathVariable(name = "id") Long id) {
|
||||
return toDto(usersService.get(id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public UsersDto create(@RequestBody @Valid UsersDto dto) {
|
||||
return toDto(usersService.create(toEntity(dto)));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public UsersDto update(@PathVariable(name = "id") Long id, @RequestBody UsersDto dto) {
|
||||
return toDto(usersService.update(id, toEntity(dto)));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public UsersDto delete(@PathVariable(name = "id") Long id) {
|
||||
return toDto(usersService.delete(id));
|
||||
}
|
||||
}
|
37
src/main/java/com/example/demo/itemUsers/api/UsersDto.java
Normal file
37
src/main/java/com/example/demo/itemUsers/api/UsersDto.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.example.demo.itemUsers.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public class UsersDto {
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Long id;
|
||||
@NotBlank
|
||||
private String login;
|
||||
private String password;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.example.demo.itemUsers.model;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import com.example.demo.core.model.BaseEntity;
|
||||
//import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class UsersEntity extends BaseEntity {
|
||||
@Column(nullable = false, unique = true, length = 20)
|
||||
private String login;
|
||||
|
||||
@Column(nullable = false, length = 20)
|
||||
private String password;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
|
||||
@OrderBy("id ASC")
|
||||
private Set<OrdersEntity> orders = new HashSet<>();
|
||||
|
||||
public UsersEntity() {
|
||||
}
|
||||
|
||||
public UsersEntity(String login, String password) {
|
||||
this.login = login;
|
||||
this.password = password;
|
||||
}
|
||||
public Set<OrdersEntity> getOrders() {
|
||||
return orders;
|
||||
}
|
||||
|
||||
public void setOrder(OrdersEntity order) {
|
||||
if (order.getUser() != this) {
|
||||
order.setUser(this);
|
||||
}
|
||||
orders.add(order);
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, login, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || getClass() != obj.getClass())
|
||||
return false;
|
||||
final UsersEntity other = (UsersEntity) obj;
|
||||
return Objects.equals(other.getId(), id)
|
||||
&& Objects.equals(other.getLogin(), login)
|
||||
&& Objects.equals(other.getPassword(), password);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.example.demo.itemUsers.repository;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
|
||||
public interface UsersRepository extends CrudRepository<UsersEntity, Long> {
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.example.demo.itemUsers.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.example.demo.core.error.NotFoundException;
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
import com.example.demo.itemUsers.repository.UsersRepository;
|
||||
|
||||
@Service
|
||||
public class UsersService {
|
||||
private final UsersRepository repository;
|
||||
|
||||
public UsersService(UsersRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public List<UsersEntity> getAll() {
|
||||
return StreamSupport.stream(repository.findAll().spliterator(), false).toList();
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public UsersEntity get(Long id) {
|
||||
return repository.findById(id).orElseThrow(() -> new NotFoundException(UsersEntity.class, id));
|
||||
}
|
||||
@Transactional
|
||||
public UsersEntity create(UsersEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException("Entity is null");
|
||||
}
|
||||
return repository.save(entity);
|
||||
}
|
||||
@Transactional
|
||||
public UsersEntity update(Long id, UsersEntity entity) {
|
||||
final UsersEntity existsEntity = get(id);
|
||||
existsEntity.setLogin(entity.getLogin());
|
||||
existsEntity.setPassword(entity.getPassword());
|
||||
repository.save(existsEntity);
|
||||
return existsEntity;
|
||||
}
|
||||
@Transactional
|
||||
public UsersEntity delete(Long id) {
|
||||
final UsersEntity existsEntity = get(id);
|
||||
repository.delete(existsEntity);
|
||||
return existsEntity;
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -16,45 +17,53 @@ import com.example.demo.itemCategories.model.CategoriesEntity;
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class CategoriesServiceTests {
|
||||
@Autowired
|
||||
private CategoriesService categoriesService;
|
||||
private CategoriesService categoriesService;
|
||||
|
||||
private CategoriesEntity category;
|
||||
|
||||
@BeforeEach
|
||||
void createData() {
|
||||
removeData();
|
||||
category = categoriesService.create(new CategoriesEntity("Ноутбук"));
|
||||
categoriesService.create(new CategoriesEntity("Телефон"));
|
||||
categoriesService.create(new CategoriesEntity("Игровая приставка"));
|
||||
}
|
||||
@AfterEach
|
||||
void removeData() {
|
||||
categoriesService.getAll().forEach(item -> categoriesService.delete(item.getId()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void getTest() {
|
||||
Assertions.assertThrows(NotFoundException.class, () -> categoriesService.get(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTest() {
|
||||
categoriesService.create(new CategoriesEntity(null, "Ноутбук"));
|
||||
categoriesService.create(new CategoriesEntity(null, "Телефон"));
|
||||
final CategoriesEntity last = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
||||
Assertions.assertEquals(last, categoriesService.get(3L));
|
||||
Assertions.assertEquals(category, categoriesService.get(category.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void updateTest() {
|
||||
final String test = "TEST";
|
||||
final CategoriesEntity entity = categoriesService.get(3L);
|
||||
final CategoriesEntity entity = categoriesService.get(category.getId());
|
||||
final String oldName = entity.getName();
|
||||
final CategoriesEntity newEntity = categoriesService.update(3L, new CategoriesEntity(1L, test));
|
||||
final CategoriesEntity newEntity = categoriesService.update(category.getId(), new CategoriesEntity(test));
|
||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
||||
Assertions.assertEquals(newEntity, categoriesService.get(3L));
|
||||
Assertions.assertEquals(newEntity, categoriesService.get(newEntity.getId()));
|
||||
Assertions.assertEquals(test, newEntity.getName());
|
||||
Assertions.assertNotEquals(oldName, newEntity.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void deleteTest() {
|
||||
categoriesService.delete(3L);
|
||||
categoriesService.delete(category.getId());
|
||||
Assertions.assertEquals(2, categoriesService.getAll().size());
|
||||
final CategoriesEntity last = categoriesService.get(2L);
|
||||
Assertions.assertEquals(2L, last.getId());
|
||||
|
||||
final CategoriesEntity newEntity = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
||||
final CategoriesEntity newEntity = categoriesService.create(new CategoriesEntity("Ноутбук"));
|
||||
Assertions.assertEquals(3, categoriesService.getAll().size());
|
||||
Assertions.assertEquals(4L, newEntity.getId());
|
||||
Assertions.assertNotEquals(category.getId(), newEntity.getId());
|
||||
}
|
||||
}
|
||||
|
83
src/test/java/com/example/demo/OrdersServiceTests.java
Normal file
83
src/test/java/com/example/demo/OrdersServiceTests.java
Normal file
@ -0,0 +1,83 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import com.example.demo.core.error.NotFoundException;
|
||||
import com.example.demo.itemCategories.model.CategoriesEntity;
|
||||
import com.example.demo.itemCategories.service.CategoriesService;
|
||||
import com.example.demo.itemOrders.service.OrdersService;
|
||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
||||
import com.example.demo.itemProducts.service.ProductsService;
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
import com.example.demo.itemUsers.service.UsersService;
|
||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
|
||||
@SpringBootTest
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class OrdersServiceTests {
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
@Autowired
|
||||
private CategoriesService categoriesService;
|
||||
@Autowired
|
||||
private ProductsService productsService;
|
||||
|
||||
private OrdersEntity order;
|
||||
private UsersEntity user;
|
||||
private CategoriesEntity category;
|
||||
private ProductsEntity product;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createData() {
|
||||
user = usersService.create(new UsersEntity("Natalia", "1234"));
|
||||
category = categoriesService.create(new CategoriesEntity("Телефон"));
|
||||
product = productsService.create(new ProductsEntity(category, "Iphone 13", 150000.00));
|
||||
|
||||
order = ordersService.create(user.getId(), new OrdersEntity(product, 3));
|
||||
ordersService.create(user.getId(), new OrdersEntity(product, 2));
|
||||
ordersService.create(user.getId(), new OrdersEntity(product, 1));
|
||||
ordersService.create(user.getId(), new OrdersEntity(product, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createTest() {
|
||||
Assertions.assertEquals(4, ordersService.getAll(user.getId()).size());
|
||||
Assertions.assertEquals(order, ordersService.get(user.getId(), order.getId()));
|
||||
}
|
||||
|
||||
// @Test
|
||||
// @Order(3)
|
||||
// void updateTest() {
|
||||
// final Integer newCount = 5;
|
||||
// final OrdersEntity entity = ordersService.get(user.getId(),order.getId());
|
||||
// final Integer oldCount = entity.getCount();
|
||||
// final OrdersEntity newEntity = ordersService.update(user.getId(),order.getId(), new OrdersEntity(product, newCount));
|
||||
// Assertions.assertEquals(4, ordersService.getAll(user.getId()).size());
|
||||
// Assertions.assertEquals(newEntity, ordersService.get(user.getId(),newEntity.getId()));
|
||||
// Assertions.assertEquals(newCount, newEntity.getCount());
|
||||
// Assertions.assertNotEquals(oldCount, newEntity.getCount());
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// @Order(4)
|
||||
// void deleteTest() {
|
||||
// ordersService.delete(user.getId(),order.getId());
|
||||
// Assertions.assertEquals(3, ordersService.getAll(user.getId()).size());
|
||||
|
||||
// final OrdersEntity newEntity = ordersService.create(user.getId(), new OrdersEntity(product, 3));
|
||||
// Assertions.assertEquals(3, ordersService.getAll(user.getId()).size());
|
||||
// Assertions.assertNotEquals(order.getId(), newEntity.getId());
|
||||
// }
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -18,50 +18,60 @@ import com.example.demo.itemProducts.model.ProductsEntity;
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class ProductsServiceTests {
|
||||
@Autowired
|
||||
private ProductsService productsService;
|
||||
private ProductsService productsService;
|
||||
@Autowired
|
||||
private CategoriesService categoriesService;
|
||||
|
||||
private ProductsEntity product;
|
||||
|
||||
private CategoriesEntity category1;
|
||||
private CategoriesEntity category2;
|
||||
|
||||
@BeforeEach
|
||||
void createData() {
|
||||
removeData();
|
||||
category1 = categoriesService.create(new CategoriesEntity("Телефон"));
|
||||
category2 = categoriesService.create(new CategoriesEntity("Игровая приставка"));
|
||||
product = productsService.create(new ProductsEntity(category1, "Lenovo IDEA PAD 13", 15232.00));
|
||||
productsService.create(new ProductsEntity(category1, "Acer", 20300.00));
|
||||
productsService.create(new ProductsEntity(category2, "Iphone 13", 150000.00));
|
||||
}
|
||||
@AfterEach
|
||||
void removeData() {
|
||||
productsService.getAll().forEach(item -> productsService.delete(item.getId()));
|
||||
categoriesService.getAll().forEach(item -> categoriesService.delete(item.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTest() {
|
||||
Assertions.assertThrows(NotFoundException.class, () -> productsService.get(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTest() {
|
||||
category1 = categoriesService.create(new CategoriesEntity(null, "Телефон"));
|
||||
category2 = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
|
||||
productsService.create(new ProductsEntity(null, category1, "Lenovo IDEA PAD 13", 15232.00));
|
||||
productsService.create(new ProductsEntity(null, category1, "Acer", 20300.00));
|
||||
final ProductsEntity last = productsService.create(new ProductsEntity(null, category2, "Iphone 13", 150000.00));
|
||||
|
||||
Assertions.assertEquals(3, productsService.getAll().size());
|
||||
Assertions.assertEquals(last, productsService.get(3L));
|
||||
Assertions.assertEquals(product, productsService.get(product.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void updateTest() {
|
||||
final Double newPrice = 20000.00;
|
||||
final ProductsEntity entity = productsService.get(1L);
|
||||
final ProductsEntity entity = productsService.get(product.getId());
|
||||
final Double oldPrice = entity.getPrice();
|
||||
final ProductsEntity newEntity = productsService.update(1L,
|
||||
new ProductsEntity(1L, category1, "Lenovo IDEA PAD 13", newPrice));
|
||||
final ProductsEntity newEntity = productsService.update(product.getId(), new ProductsEntity(category1, "Lenovo IDEA PAD 13", newPrice));
|
||||
Assertions.assertEquals(3, productsService.getAll().size());
|
||||
Assertions.assertEquals(newEntity, productsService.get(1L));
|
||||
Assertions.assertEquals(newEntity, productsService.get(newEntity.getId()));
|
||||
Assertions.assertEquals(newPrice, newEntity.getPrice());
|
||||
Assertions.assertNotEquals(oldPrice, newEntity.getPrice());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void deleteTest() {
|
||||
productsService.delete(3L);
|
||||
productsService.delete(product.getId());
|
||||
Assertions.assertEquals(2, productsService.getAll().size());
|
||||
final ProductsEntity last = productsService.get(2L);
|
||||
Assertions.assertEquals(2L, last.getId());
|
||||
|
||||
final ProductsEntity newEntity = productsService.create(new ProductsEntity(category1, "Lenovo IDEA PAD 13", 15232.00));
|
||||
Assertions.assertEquals(3, productsService.getAll().size());
|
||||
Assertions.assertNotEquals(product.getId(), newEntity.getId());
|
||||
}
|
||||
}
|
||||
|
100
src/test/java/com/example/demo/UsersServiceTests.java
Normal file
100
src/test/java/com/example/demo/UsersServiceTests.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.example.demo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import com.example.demo.core.error.NotFoundException;
|
||||
import com.example.demo.itemCategories.model.CategoriesEntity;
|
||||
import com.example.demo.itemCategories.service.CategoriesService;
|
||||
import com.example.demo.itemOrders.model.OrdersEntity;
|
||||
import com.example.demo.itemOrders.service.OrdersService;
|
||||
import com.example.demo.itemProducts.model.ProductsEntity;
|
||||
import com.example.demo.itemProducts.service.ProductsService;
|
||||
import com.example.demo.itemUsers.service.UsersService;
|
||||
import com.example.demo.itemUsers.model.UsersEntity;
|
||||
|
||||
@SpringBootTest
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class UsersServiceTests {
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private ProductsService productsService;
|
||||
@Autowired
|
||||
private CategoriesService categoriesService;
|
||||
|
||||
private UsersEntity user;
|
||||
|
||||
private ProductsEntity product;
|
||||
private CategoriesEntity category;
|
||||
|
||||
@BeforeEach
|
||||
void createData() {
|
||||
removeData();
|
||||
|
||||
category = categoriesService.create(new CategoriesEntity("Телефон"));
|
||||
|
||||
product = productsService.create(new ProductsEntity(category, "Iphone 13", 150000.00));
|
||||
|
||||
user = usersService.create(new UsersEntity("Natalia", "1234"));
|
||||
usersService.create(new UsersEntity("Revengel", "4567"));
|
||||
|
||||
final var orders = List.of(
|
||||
new OrdersEntity(product, 3),
|
||||
new OrdersEntity(product, 2),
|
||||
new OrdersEntity(product, 1),
|
||||
new OrdersEntity(product, 4));
|
||||
orders.forEach(order -> ordersService.create(user.getId(), order));
|
||||
}
|
||||
@AfterEach
|
||||
void removeData() {
|
||||
usersService.getAll().forEach(item -> usersService.delete(item.getId()));
|
||||
productsService.getAll().forEach(item -> productsService.delete(item.getId()));
|
||||
categoriesService.getAll().forEach(item -> categoriesService.delete(item.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTest() {
|
||||
Assertions.assertThrows(NotFoundException.class, () -> usersService.get(0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTest() {
|
||||
Assertions.assertEquals(2, usersService.getAll().size());
|
||||
Assertions.assertEquals(user, usersService.get(user.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTest() {
|
||||
final String newPassword = "0000";
|
||||
final UsersEntity entity = usersService.get(user.getId());
|
||||
final String login = entity.getLogin();
|
||||
final String oldPassword = entity.getPassword();
|
||||
final UsersEntity newEntity = usersService.update(user.getId(), new UsersEntity(login, newPassword));
|
||||
Assertions.assertEquals(2, usersService.getAll().size());
|
||||
Assertions.assertEquals(newEntity, usersService.get(newEntity.getId()));
|
||||
Assertions.assertEquals(newPassword, newEntity.getPassword());
|
||||
Assertions.assertNotEquals(oldPassword, newEntity.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteTest() {
|
||||
usersService.delete(user.getId());
|
||||
Assertions.assertEquals(1, usersService.getAll().size());
|
||||
|
||||
final UsersEntity newEntity = usersService.create(new UsersEntity("Natalia", "1234"));
|
||||
Assertions.assertEquals(2, usersService.getAll().size());
|
||||
Assertions.assertNotEquals(user.getId(), newEntity.getId());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user