Browse Source

added hibernate stats profile

master
nova 4 years ago
parent
commit
d916043e07
  1. 14
      chatto/src/main/java/org/ros/chatto/ChattoApplication.java
  2. 6
      chatto/src/main/java/org/ros/chatto/logged/BeanUtil.java
  3. 27
      chatto/src/main/java/org/ros/chatto/repository/ChatMessageRepository.java
  4. 1
      chatto/src/main/resources/application-stats.properties
  5. 6
      chatto/src/main/resources/application.properties

14
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 {
}
}

6
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> T getBean(Class<T> beanClass) {
log.debug("Instantiating class {}", beanClass.getName());
return context.getBean(beanClass);
}

27
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<ChatMessage, Long> {
// @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<ChatMessage> 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<ChatMessage> 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<ChatMessage> 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);
}
}

1
chatto/src/main/resources/application-stats.properties

@ -0,0 +1 @@
spring.jpa.properties.hibernate.generate_statistics=true

6
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
chatto.token.timeout-duration=30
# spring.devtools.add-properties=false
Loading…
Cancel
Save