added hibernate stats profile

This commit is contained in:
nova 2019-12-13 21:04:36 +05:30
parent df8e735a9b
commit d916043e07
5 changed files with 26 additions and 28 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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
@ -31,3 +31,5 @@ logging.level.org.springframework.cache = DEBUG
#test.bindAddress=192.168.1.106
chatto.token.timeout-duration=30
# spring.devtools.add-properties=false