From d916043e0767699b5e10a663a1267e981d43fdfc Mon Sep 17 00:00:00 2001 From: nova Date: Fri, 13 Dec 2019 21:04:36 +0530 Subject: [PATCH] added hibernate stats profile --- .../org/ros/chatto/ChattoApplication.java | 14 +++++----- .../java/org/ros/chatto/logged/BeanUtil.java | 6 +++-- .../repository/ChatMessageRepository.java | 27 +++++++------------ .../resources/application-stats.properties | 1 + .../src/main/resources/application.properties | 6 +++-- 5 files changed, 26 insertions(+), 28 deletions(-) create mode 100644 chatto/src/main/resources/application-stats.properties diff --git a/chatto/src/main/java/org/ros/chatto/ChattoApplication.java b/chatto/src/main/java/org/ros/chatto/ChattoApplication.java index 631743b..5a42691 100644 --- a/chatto/src/main/java/org/ros/chatto/ChattoApplication.java +++ b/chatto/src/main/java/org/ros/chatto/ChattoApplication.java @@ -4,8 +4,10 @@ import java.sql.SQLException; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; @SpringBootApplication public class ChattoApplication extends SpringBootServletInitializer { @@ -14,9 +16,9 @@ public class ChattoApplication extends SpringBootServletInitializer { SpringApplication.run(ChattoApplication.class, args); } - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(ChattoApplication.class); - } - + @Configuration + @Profile("development") + @ComponentScan(lazyInit = true) + static class LocalConfig { + } } \ No newline at end of file diff --git a/chatto/src/main/java/org/ros/chatto/logged/BeanUtil.java b/chatto/src/main/java/org/ros/chatto/logged/BeanUtil.java index 5e6b260..5f46fb8 100644 --- a/chatto/src/main/java/org/ros/chatto/logged/BeanUtil.java +++ b/chatto/src/main/java/org/ros/chatto/logged/BeanUtil.java @@ -5,8 +5,10 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Service; -@Service +import lombok.extern.slf4j.Slf4j; +@Service +@Slf4j public class BeanUtil implements ApplicationContextAware { private static ApplicationContext context; @@ -20,7 +22,7 @@ public class BeanUtil implements ApplicationContextAware { } public static T getBean(Class beanClass) { - + log.debug("Instantiating class {}", beanClass.getName()); return context.getBean(beanClass); } diff --git a/chatto/src/main/java/org/ros/chatto/repository/ChatMessageRepository.java b/chatto/src/main/java/org/ros/chatto/repository/ChatMessageRepository.java index b5e098a..1b4af53 100644 --- a/chatto/src/main/java/org/ros/chatto/repository/ChatMessageRepository.java +++ b/chatto/src/main/java/org/ros/chatto/repository/ChatMessageRepository.java @@ -11,27 +11,18 @@ import org.springframework.stereotype.Repository; @Repository public interface ChatMessageRepository extends JpaRepository { -// @Query("select r from RoleRepository where name = ?1") -// @Query("select ur from UserRole ur where ur.user.userID = ?1") -// @Query("select m from ChatMessage m where m.toUser.userID = ?1 or m.toUser.userID = ?2 and " -// + "m.fromUser.userID = ?1 or m.fromUser.userID = ?2 order by m.messageTime asc") @Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu " + "where (tu.userName = ?1 or tu.userName = ?2) and " + "(fu.userName = ?1 or fu.userName = ?2) order by m.messageTime asc") public List getAllMessages(String fromUser, String toUser); - - @Query("select m from ChatMessage m join fetch m.messageCipher where (m.toUser.userName = ?1 or m.toUser.userName = ?2) and " - + "(m.fromUser.userName = ?1 or m.fromUser.userName = ?2) and" - + "(m.messageTime > ?3) order by m.messageTime asc") + + @Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu " + + "where (tu.userName = ?1 or tu.userName = ?2) and " + + "(fu.userName = ?1 or fu.userName = ?2) and (m.messageTime > ?3) order by m.messageTime asc") public List getNewMessages(String fromUser, String toUser, Date lastMessageTime); - - @Query("select m from ChatMessage m join fetch m.messageCipher where (m.toUser.userName = ?1 or m.toUser.userName = ?2) and " - + "(m.fromUser.userName = ?1 or m.fromUser.userName = ?2) order by m.messageTime desc") + + @Query("select m from ChatMessage m join fetch m.messageCipher mc join fetch m.toUser tu join fetch m.fromUser fu " + + "where (tu.userName = ?1 or tu.userName = ?2) and " + + "(fu.userName = ?1 or fu.userName = ?2) order by m.messageTime desc") public List getAllMessages(String fromUser, String toUser, PageRequest pageRequest); - - -// DELETE FROM Country c WHERE c.population < :p -// @Query("delete from ChatMessage m where where (m.toUser.userName = ?1 or m.toUser.userName = ?2) and" -// + " (m.fromUser.userName = ?1 or m.fromUser.userName = ?2)") -// public void deleteConversation(String fromUser, String toUser); -} +} \ No newline at end of file diff --git a/chatto/src/main/resources/application-stats.properties b/chatto/src/main/resources/application-stats.properties new file mode 100644 index 0000000..e273072 --- /dev/null +++ b/chatto/src/main/resources/application-stats.properties @@ -0,0 +1 @@ +spring.jpa.properties.hibernate.generate_statistics=true \ No newline at end of file diff --git a/chatto/src/main/resources/application.properties b/chatto/src/main/resources/application.properties index 553ef96..7035df8 100644 --- a/chatto/src/main/resources/application.properties +++ b/chatto/src/main/resources/application.properties @@ -14,7 +14,7 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial spring.jpa.hibernate.ddl-auto = none spring.jpa.open-in-view=false -#spring.jpa.properties.hibernate.generate_statistics=true +# spring.jpa.properties.hibernate.generate_statistics=true logging.level.org.hibernate.stat=debug logging.level.org.springframework.web=DEBUG logging.level.web=DEBUG @@ -30,4 +30,6 @@ logging.level.org.springframework.cache = DEBUG #test.bindAddress=192.168.1.106 -chatto.token.timeout-duration=30 \ No newline at end of file +chatto.token.timeout-duration=30 + +# spring.devtools.add-properties=false \ No newline at end of file