Compare commits

...

2 Commits

Author SHA1 Message Date
revengel66
79bbcca648 problems with orderstest 2024-04-20 22:09:20 +04:00
revengel66
7526d3fd8b test 2024-04-20 15:04:34 +04:00
18 changed files with 614 additions and 248 deletions

Binary file not shown.

374
data.trace.db Normal file
View 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

View File

@ -1,6 +1,6 @@
package com.example.demo;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Objects;
import org.slf4j.Logger;
@ -27,7 +27,7 @@ public class DemoApplication implements CommandLineRunner {
private final ProductsService productsService;
private final OrdersService ordersService;
public DemoApplication(UsersService userService, CategoriesService categoriesService, ProductsService productsService, OrdersService ordersService) {
public DemoApplication(CategoriesService categoriesService, ProductsService productsService, UsersService userService, OrdersService ordersService) {
this.userService = userService;
this.categoriesService = categoriesService;
@ -44,23 +44,27 @@ public class DemoApplication implements CommandLineRunner {
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"));
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));
}
}
}

View File

@ -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() {

View File

@ -45,7 +45,7 @@ public class OrdersController {
@GetMapping
public List<OrdersDto> getAll(@PathVariable(name = "user") Long userId, @RequestParam(name = "productId", defaultValue = "0") ProductsEntity product) {
return ordersService.getAll(userId, product.getId()).stream().map(this::toDto).toList();
return ordersService.getAll(userId).stream().map(this::toDto).toList();
}
@GetMapping("/{id}")
public OrdersDto get(@PathVariable(name = "user") Long userId, @PathVariable(name = "id") Long id) {

View File

@ -1,32 +0,0 @@
package com.example.demo.itemOrders.api;
public class OrdersGroupedDto {
private Long userId;
private Long totalSum;
private Integer totalCount;
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getTotalSum() {
return totalSum;
}
public void setTotalSum(Long totalSum) {
this.totalSum = totalSum;
}
public Integer getTotalCount() {
return totalCount;
}
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}
}

View File

@ -1,5 +1,4 @@
package com.example.demo.itemOrders.model;
import java.text.SimpleDateFormat;
import java.util.Objects;
import com.example.demo.core.model.BaseEntity;
import com.example.demo.itemProducts.model.ProductsEntity;
@ -10,8 +9,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
@Entity
@Table(name = "orders")
@ -26,21 +23,16 @@ public class OrdersEntity extends BaseEntity {
@Column(nullable = false)
private Integer count;
@Temporal(TemporalType.DATE)
private SimpleDateFormat date;
@Column(nullable = false)
private Double sum;
//@Column(nullable = false)
//private Double sum = getSum();
public OrdersEntity() {
super();
}
public OrdersEntity(Long id, ProductsEntity product, Integer count, SimpleDateFormat date) {
super(id);
public OrdersEntity(ProductsEntity product, Integer count) {
this.product = product;
this.count = count;
this.date = date;
}
public ProductsEntity getProduct() {
return product;
@ -58,25 +50,20 @@ public class OrdersEntity extends BaseEntity {
user.getOrders().add(this);
}
}
public Double getSum() {
sum = count * product.getPrice();
return sum;
}
// public Double getSum() {
// sum = count * product.getPrice();
// return sum;
// }
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;
}
@Override
public int hashCode() {
return Objects.hash(id, product, count, date);
return Objects.hash(id, product, count);
}
@Override
@ -88,7 +75,7 @@ public class OrdersEntity extends BaseEntity {
final OrdersEntity other = (OrdersEntity) obj;
return Objects.equals(other.getId(), id)
&& Objects.equals(other.getProduct(), product)
&& Objects.equals(other.getCount(), count)
&& Objects.equals(other.getDate(), date);
&& Objects.equals(other.getUser().getId(), user.getId())
&& Objects.equals(other.getCount(), count);
}
}

View File

@ -1,11 +0,0 @@
package com.example.demo.itemOrders.model;
import com.example.demo.itemUsers.model.UsersEntity;
public interface OrdersGrouped {
UsersEntity getUser();
double getTotalSum();
int getTotalCount();
}

View File

@ -2,18 +2,15 @@ package com.example.demo.itemOrders.repository;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import com.example.demo.itemOrders.model.OrdersEntity;
import com.example.demo.itemOrders.model.OrdersGrouped;
//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);
List<OrdersEntity> findByUserIdAndProductId(long userId, long productId);
// select
// tpe.name,
// coalesce(sum(order.price), 0),
@ -21,11 +18,12 @@ public interface OrdersRepository extends CrudRepository<OrdersEntity, Long> {
// 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);
// @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);
}

View File

@ -7,7 +7,7 @@ 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.model.OrdersGrouped;
import com.example.demo.itemOrders.repository.OrdersRepository;
import com.example.demo.itemUsers.model.UsersEntity;
import com.example.demo.itemUsers.service.UsersService;
@ -23,48 +23,44 @@ public class OrdersService {
}
@Transactional(readOnly = true)
public List<OrdersEntity> getAll(long userId, Long productId) {
public List<OrdersEntity> getAll(long userId) {
userService.get(userId);
if (productId <= 0L) {
return repository.findByUserId(userId);
} else {
return repository.findByUserIdAndProductId(userId, productId);
}
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);
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());
existsEntity.setDate(entity.getDate());
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);
}
// @Transactional(readOnly = true)
// public List<OrdersGrouped> getTotal(long userId) {
// //userService.get(userId);
// return repository.getOrdersTotalByUser(userId);
// }
}

View File

@ -13,7 +13,7 @@ public class ProductsDto {
private String name;
@NotNull
@Min(1)
private Long typeId;
private Long categoryId;
@NotNull
@Min(1)
private Double price;
@ -27,11 +27,11 @@ public class ProductsDto {
}
public Long getTypeId() {
return typeId;
return categoryId;
}
public void setTypeId(Long typeId) {
this.typeId = typeId;
public void setTypeId(Long categoryId) {
this.categoryId = categoryId;
}
public Double getPrice() {

View File

@ -16,29 +16,27 @@ import jakarta.persistence.Table;
public class ProductsEntity extends BaseEntity{
@ManyToOne
@JoinColumn(name = "categoryId", nullable = false)
private CategoriesEntity type;
private CategoriesEntity category;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private Double price;
public ProductsEntity(Object object, String string) {
super();
public ProductsEntity() {
}
public ProductsEntity(Long id, CategoriesEntity type, String name, Double price) {
super(id);
this.type = type;
public ProductsEntity(CategoriesEntity category, String name, Double price) {
this.category = category;
this.name = name;
this.price = price;
}
public CategoriesEntity getType() {
return type;
return category;
}
public void setType(CategoriesEntity type) {
this.type = type;
public void setType(CategoriesEntity category) {
this.category = category;
}
public Double getPrice() {
return price;
@ -55,7 +53,7 @@ public class ProductsEntity extends BaseEntity{
@Override
public int hashCode() {
return Objects.hash(id, type, name, price);
return Objects.hash(id, category, name, price);
}
@Override
@ -66,7 +64,7 @@ public class ProductsEntity extends BaseEntity{
return false;
final ProductsEntity other = (ProductsEntity) obj;
return Objects.equals(other.getId(), id)
&& Objects.equals(other.getType(), type)
&& Objects.equals(other.getType(), category)
&& Objects.equals(other.getName(), name)
&& Objects.equals(other.getPrice(), price);
}

View File

@ -3,6 +3,7 @@ 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;
@ -26,11 +27,9 @@ public class UsersEntity extends BaseEntity {
private Set<OrdersEntity> orders = new HashSet<>();
public UsersEntity() {
super();
}
public UsersEntity(Long id, String login, String password) {
super(id);
public UsersEntity(String login, String password) {
this.login = login;
this.password = password;
}
@ -38,7 +37,7 @@ public class UsersEntity extends BaseEntity {
return orders;
}
public void addOrder(OrdersEntity order) {
public void setOrder(OrdersEntity order) {
if (order.getUser() != this) {
order.setUser(this);
}

View File

@ -37,7 +37,8 @@ public class UsersService {
final UsersEntity existsEntity = get(id);
existsEntity.setLogin(entity.getLogin());
existsEntity.setPassword(entity.getPassword());
return repository.save(existsEntity);
repository.save(existsEntity);
return existsEntity;
}
@Transactional
public UsersEntity delete(Long id) {

View File

@ -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());
}
}

View File

@ -1,8 +1,8 @@
package com.example.demo;
import java.text.SimpleDateFormat;
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;
@ -24,69 +24,60 @@ import com.example.demo.itemOrders.model.OrdersEntity;
@TestMethodOrder(OrderAnnotation.class)
class OrdersServiceTests {
@Autowired
private OrdersService ordersService;
@Autowired
private UsersService usersService;
private UsersEntity user1;
private UsersEntity user2;
@Autowired
private CategoriesService categoriesService;
private CategoriesEntity category1;
private CategoriesEntity category2;
@Autowired
private ProductsService productsService;
private ProductsEntity product1;
private ProductsEntity product2;
private ProductsEntity product3;
private OrdersService ordersService;
@Autowired
private UsersService usersService;
@Autowired
private CategoriesService categoriesService;
@Autowired
private ProductsService productsService;
@Test
void getTest() {
Assertions.assertThrows(NotFoundException.class, () -> ordersService.get(1,0L));
}
private OrdersEntity order;
private UsersEntity user;
private CategoriesEntity category;
private ProductsEntity product;
@Test
@Order(1)
void createTest() {
@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()));
}
user1 = usersService.create(new UsersEntity(null, "Natalia", "1234"));
user2 = usersService.create(new UsersEntity(null, "Revengel", "4567"));
// @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());
// }
category1 = categoriesService.create(new CategoriesEntity(null, "Телефон"));
category2 = categoriesService.create(new CategoriesEntity(null, "Игровая приставка"));
// @Test
// @Order(4)
// void deleteTest() {
// ordersService.delete(user.getId(),order.getId());
// Assertions.assertEquals(3, ordersService.getAll(user.getId()).size());
product1 = productsService.create(new ProductsEntity(null, category1, "Lenovo IDEA PAD 13", 15232.00));
product2 = productsService.create(new ProductsEntity(null, category1, "Acer", 20300.00));
product3 = productsService.create(new ProductsEntity(null, category2, "Iphone 13", 150000.00));
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")));
final OrdersEntity last = ordersService.create(user2.getId(), new OrdersEntity(null, product1, 4, new SimpleDateFormat("07/04/2024")));
Assertions.assertEquals(4, ordersService.getAll(1,0L).size());
Assertions.assertEquals(0, ordersService.getAll(1,-1L).size());
Assertions.assertEquals(last, ordersService.get(1,last.getId()));
}
@Test
@Order(2)
void updateTest() {
final Integer newCount = 5;
final OrdersEntity entity = ordersService.get(1,1L);
final Integer oldCount = entity.getCount();
final OrdersEntity newEntity = ordersService.update(1,1L,
new OrdersEntity(null, product1, newCount, new SimpleDateFormat("09/04/2024")));
Assertions.assertEquals(4, ordersService.getAll(1,0L).size());
Assertions.assertEquals(newEntity, ordersService.get(1,1L));
Assertions.assertEquals(newCount, newEntity.getCount());
Assertions.assertNotEquals(oldCount, newEntity.getCount());
}
@Test
@Order(3)
void deleteTest() {
ordersService.delete(2,3L);
Assertions.assertEquals(3, ordersService.getAll(1,0L).size());
final OrdersEntity last = ordersService.get(1,2L);
Assertions.assertEquals(2L, last.getId());
}
// 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());
// }
}

View File

@ -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());
}
}

View File

@ -1,14 +1,23 @@
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.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.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;
@ -17,6 +26,42 @@ import com.example.demo.itemUsers.model.UsersEntity;
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() {
@ -24,34 +69,32 @@ class UsersServiceTests {
}
@Test
@Order(1)
void createTest() {
usersService.create(new UsersEntity(null, "Natalia", "1234"));
final UsersEntity last = usersService.create(new UsersEntity(null, "Revengel", "4567"));
Assertions.assertEquals(2, usersService.getAll().size());
Assertions.assertEquals(last, usersService.get(2L));
Assertions.assertEquals(user, usersService.get(user.getId()));
}
@Test
@Order(2)
void updateTest() {
final String newPassword = "0000";
final UsersEntity entity = usersService.get(2L);
final UsersEntity entity = usersService.get(user.getId());
final String login = entity.getLogin();
final String oldPassword = entity.getPassword();
final UsersEntity newEntity = usersService.update(2L, new UsersEntity(1L, login, newPassword));
final UsersEntity newEntity = usersService.update(user.getId(), new UsersEntity(login, newPassword));
Assertions.assertEquals(2, usersService.getAll().size());
Assertions.assertEquals(newEntity, usersService.get(2L));
Assertions.assertEquals(newEntity, usersService.get(newEntity.getId()));
Assertions.assertEquals(newPassword, newEntity.getPassword());
Assertions.assertNotEquals(oldPassword, newEntity.getPassword());
}
@Test
@Order(3)
void deleteTest() {
usersService.delete(2L);
usersService.delete(user.getId());
Assertions.assertEquals(1, usersService.getAll().size());
final UsersEntity last = usersService.get(1L);
Assertions.assertEquals(1L, last.getId());
final UsersEntity newEntity = usersService.create(new UsersEntity("Natalia", "1234"));
Assertions.assertEquals(2, usersService.getAll().size());
Assertions.assertNotEquals(user.getId(), newEntity.getId());
}
}