mirror of https://github.com/hykilpikonna/AquaDX
[ongeki] Fix event ranking query incompatibility with MySQL/MariaDB
parent
35f0c000bf
commit
447ddd99b0
|
@ -23,6 +23,7 @@ public interface UserEventPointRepository extends JpaRepository<UserEventPoint,
|
|||
@Transactional
|
||||
void deleteByUser(UserData user);
|
||||
|
||||
@Query(value = "SELECT rank from (SELECT user_id , DENSE_RANK() OVER (ORDER BY point DESC) as rank from ongeki_user_event_point where event_id = :eventId) where user_id == :userId limit 1", nativeQuery = true)
|
||||
//@Query(value = "SELECT rank from (SELECT user_id , DENSE_RANK() OVER (ORDER BY point DESC) as rank from ongeki_user_event_point where event_id = :eventId) where user_id == :userId limit 1", nativeQuery = true)
|
||||
@Query("SELECT COUNT(u)+1 FROM OngekiUserEventPoint u WHERE u.eventId = :eventId AND u.point > (SELECT u2.point FROM OngekiUserEventPoint u2 WHERE u2.user.id = :userId AND u2.eventId = :eventId)")
|
||||
int calculateRankByUserAndEventId(long userId, int eventId);
|
||||
}
|
||||
|
|
|
@ -181,19 +181,28 @@ class OngekiRepositoryTest {
|
|||
var u1 = getNewRandomValidUser();
|
||||
var u2 = getNewRandomValidUser();
|
||||
var u3 = getNewRandomValidUser();
|
||||
var u4 = getNewRandomValidUser();
|
||||
|
||||
final var eventId = 2857;
|
||||
final var eventId2 = 2858;
|
||||
|
||||
userEventPointRepository.saveAll(List.of(
|
||||
getEventPoint(u1, eventId, 500),
|
||||
getEventPoint(u3, eventId, 2857),
|
||||
getEventPoint(u2, eventId, 600),
|
||||
getEventPoint(u3, eventId, 2857)
|
||||
getEventPoint(u4, eventId, 600),
|
||||
getEventPoint(u1, eventId, 500),
|
||||
|
||||
getEventPoint(u3, eventId2, 2857),
|
||||
getEventPoint(u4, eventId2, 600),
|
||||
getEventPoint(u2, eventId2, 25)
|
||||
));
|
||||
|
||||
var eventPointData = userEventPointRepository.findByUser_Card_ExtId(u1.getCard().getExtId()).get(0);
|
||||
assertThat(calculateEventPointRank(u1, eventId)).isEqualTo(4);
|
||||
assertThat(calculateEventPointRank(u4, eventId)).isEqualTo(2);
|
||||
assertThat(calculateEventPointRank(u3, eventId)).isEqualTo(1);
|
||||
|
||||
var rank = userEventPointRepository.calculateRankByUserAndEventId(eventPointData.getUser().getId(), eventPointData.getEventId());
|
||||
assertThat(rank).isEqualTo(3);
|
||||
assertThat(calculateEventPointRank(u4, eventId2)).isEqualTo(2);
|
||||
assertThat(calculateEventPointRank(u2, eventId2)).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -418,6 +427,12 @@ class OngekiRepositoryTest {
|
|||
return new UserCharacter(-1, u, characterId, 0, 0, 10, 1, 1, 1, "2020", false);
|
||||
}
|
||||
|
||||
private int calculateEventPointRank(UserData user, int eventId) {
|
||||
var eventPointData = userEventPointRepository.findByUserAndEventId(user, eventId).get();
|
||||
var rank = userEventPointRepository.calculateRankByUserAndEventId(eventPointData.getUser().getId(), eventPointData.getEventId());
|
||||
return rank;
|
||||
}
|
||||
|
||||
private UserDeck getDeck(UserData u, Integer deckId) {
|
||||
return new UserDeck(-1, u, deckId, 1, 1, 1);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# For testing
|
||||
## AimeDb server setting
|
||||
aimedb.server.enable=true
|
||||
aimedb.server.port=22345
|
||||
allnet.server.host=localhost
|
||||
allnet.server.port=80
|
||||
aimedb.server.address=127.0.0.1
|
||||
billing.server.enable=true
|
||||
billing.server.port=8443
|
||||
## Http Server Port
|
||||
server.port=80
|
||||
spring.flyway.locations=classpath:db/migration/mariadb
|
||||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
||||
spring.datasource.username=aqua_test
|
||||
spring.datasource.password=aqua_test
|
||||
spring.datasource.url=jdbc:mariadb://localhost:3306/aqua_test?useSSL=false
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB10Dialect
|
||||
|
||||
# if you got any exception like while application booting:
|
||||
# "org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [id] in table [chusan_avatar]; found [int (Types#INTEGER)], but expecting [bigint (Types#BIGINT)]"
|
||||
# just comment this property and try again.
|
||||
# spring.jpa.hibernate.ddl-auto=validate
|
|
@ -10,9 +10,8 @@ billing.server.port=8443
|
|||
## Http Server Port
|
||||
server.port=80
|
||||
spring.flyway.locations=classpath:db/migration/mysql
|
||||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.username=aqua_test
|
||||
spring.datasource.password=aqua_test
|
||||
spring.datasource.url=jdbc:mariadb://localhost:3306/aqua_test?useSSL=false
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB10Dialect
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
spring.datasource.url=jdbc:mysql://localhost:13306/aqua_test?useSSL=false&allowPublicKeyRetrieval=true
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
|
||||
|
|
Loading…
Reference in New Issue