aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/PushQueriesServiceImpl.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-14 12:22:53 +0300
committerGravatar Vitaly Takmazov2023-01-14 13:59:24 +0300
commit834fef2a7794d769144c7c087a8b1fa0a2a9bb21 (patch)
treef44d2139be62ed7382c83ff234a557be66a9bde5 /src/main/java/com/juick/service/PushQueriesServiceImpl.java
parent456f2a28efc72809c4ac7dd7ee838e0e5b0a061f (diff)
DB: merge ios, android, winphone tables to user_services
Diffstat (limited to 'src/main/java/com/juick/service/PushQueriesServiceImpl.java')
-rw-r--r--src/main/java/com/juick/service/PushQueriesServiceImpl.java124
1 files changed, 35 insertions, 89 deletions
diff --git a/src/main/java/com/juick/service/PushQueriesServiceImpl.java b/src/main/java/com/juick/service/PushQueriesServiceImpl.java
index 0b83465a..18a14bd6 100644
--- a/src/main/java/com/juick/service/PushQueriesServiceImpl.java
+++ b/src/main/java/com/juick/service/PushQueriesServiceImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -17,15 +17,18 @@
package com.juick.service;
+import com.juick.model.ExternalToken;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
/**
* Created by aalexeev on 11/13/16.
@@ -33,113 +36,56 @@ import java.util.List;
@Repository
public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueriesService {
- @Transactional(readOnly = true)
- @Override
- public List<String> getGCMRegID(final int uid) {
- return getJdbcTemplate().queryForList(
- "SELECT regid FROM android WHERE user_id=?",
- String.class,
- uid);
- }
-
- @Transactional(readOnly = true)
- @Override
- public List<String> getGCMTokens(final Collection<Integer> uids) {
- if (CollectionUtils.isEmpty(uids))
- return Collections.emptyList();
-
- return getNamedParameterJdbcTemplate().queryForList(
- "SELECT regid FROM android INNER JOIN users ON (users.id = android.user_id) WHERE users.id IN (:ids)",
- new MapSqlParameterSource("ids", uids),
- String.class);
- }
+ private class TokenMapper implements RowMapper<ExternalToken> {
- @Transactional
- @Override
- public boolean addGCMToken(Integer uid, String token) {
- try {
- return getJdbcTemplate().update("INSERT INTO android(user_id,regid) VALUES (?, ?)",
- uid, token) > 0;
- } catch (DataIntegrityViolationException e) {
- return false;
+ @Override
+ public ExternalToken mapRow(ResultSet rs, int rowNum) throws SQLException {
+ return new ExternalToken(
+ null,
+ rs.getString("service_type"),
+ rs.getString("regid"),
+ null
+ );
}
}
- @Transactional
- @Override
- public boolean deleteGCMToken(String token) {
- return getJdbcTemplate().update("DELETE FROM android WHERE regid=?", token) > 0;
- }
-
@Transactional(readOnly = true)
@Override
- public List<String> getMPNSURL(final int uid) {
- return getJdbcTemplate().queryForList(
- "SELECT url FROM winphone WHERE user_id=?",
- String.class,
- uid);
+ public Collection<ExternalToken> getToken(final int uid, final String serviceType) {
+ return getJdbcTemplate().query(
+ "SELECT regid, service_type FROM user_services WHERE user_id=? AND service_type=?",
+ new TokenMapper(),
+ uid, serviceType);
}
@Transactional(readOnly = true)
@Override
- public List<String> getMPNSTokens(final Collection<Integer> uids) {
+ public Collection<ExternalToken> getTokens(final Collection<Integer> uids) {
if (CollectionUtils.isEmpty(uids))
return Collections.emptyList();
-
- return getNamedParameterJdbcTemplate().queryForList(
- "SELECT url FROM winphone INNER JOIN users ON (users.id=winphone.user_id) WHERE users.id IN (:ids)",
+ return getNamedParameterJdbcTemplate().query(
+ """
+ SELECT regid, service_type FROM user_services INNER JOIN users
+ ON (users.id = user_services.user_id) WHERE users.id IN (:ids)""",
new MapSqlParameterSource("ids", uids),
- String.class);
- }
-
- @Transactional
- @Override
- public boolean addMPNSToken(Integer uid, String token) {
- return getJdbcTemplate().update("INSERT IGNORE INTO winphone(user_id,url) VALUES (?, ?)",
- uid, token) > 0;
- }
-
- @Transactional
- @Override
- public boolean deleteMPNSToken(String token) {
- return getJdbcTemplate().update("DELETE FROM winphone WHERE url=?", token) > 0;
- }
-
- @Transactional(readOnly = true)
- @Override
- public List<String> getAPNSToken(final int uid) {
- return getJdbcTemplate().queryForList(
- "SELECT token from ios WHERE user_id=?",
- String.class,
- uid);
+ new TokenMapper());
}
@Transactional
@Override
- public boolean deleteAPNSToken(String token) {
- return getJdbcTemplate().update("DELETE FROM ios WHERE token=?", token) > 0;
- }
-
- @Transactional(readOnly = true)
- @Override
- public List<String> getAPNSTokens(final Collection<Integer> uids) {
- if (CollectionUtils.isEmpty(uids))
- return Collections.emptyList();
-
- return getNamedParameterJdbcTemplate().queryForList(
- "SELECT token FROM ios INNER JOIN users ON (users.id = ios.user_id) WHERE users.id IN (:ids)",
- new MapSqlParameterSource("ids", uids),
- String.class);
+ public boolean addToken(final Integer uid, final String serviceType, final String token) {
+ try {
+ return getJdbcTemplate().update(
+ "INSERT INTO user_services(user_id, regid, service_type) VALUES (?, ?, ?)",
+ uid, token, serviceType) > 0;
+ } catch (DataIntegrityViolationException e) {
+ return false;
+ }
}
@Transactional
@Override
- public boolean addAPNSToken(Integer uid, String token) {
- try {
- return getJdbcTemplate().update("INSERT INTO ios(user_id,token) VALUES (?, ?)",
- uid, token) > 0;
- } catch (DataIntegrityViolationException e) {
- return true;
- }
+ public boolean deleteToken(final String serviceType, final String token) {
+ return getJdbcTemplate().update("DELETE FROM user_services WHERE regid=? AND service_type=?", token, serviceType) > 0;
}
}