Fix two syntax errors

This commit is contained in:
Dan Mulloy 2018-02-10 19:53:54 -05:00 committed by Alexander Meech
parent 0234cf0f74
commit ea276c5120
3 changed files with 89 additions and 166 deletions

View File

@ -141,7 +141,10 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
_loadedCommunities = new ConcurrentHashMap<>(); _loadedCommunities = new ConcurrentHashMap<>();
runAsync(() -> _repo.loadBrowserCommunities(_browserIds)); runAsync(() -> {
_repo.loadBrowserCommunities(_browserIds);
log("Loaded " + _browserIds.size() + " communities to show in browser");
});
_clientManager = require(CoreClientManager.class); _clientManager = require(CoreClientManager.class);
_clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor() _clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor()

View File

@ -37,12 +37,7 @@ public class CommunityRepository extends RepositoryBase
private static final String GET_COMMUNITY_MEMBERS = "SELECT cm.communityId, cm.accountId, cm.communityRole, ac.name, ac.uuid, ac.lastLogin, cm.readingChat FROM communityMembers cm INNER JOIN accounts ac ON ac.id=cm.accountId"; private static final String GET_COMMUNITY_MEMBERS = "SELECT cm.communityId, cm.accountId, cm.communityRole, ac.name, ac.uuid, ac.lastLogin, cm.readingChat FROM communityMembers cm INNER JOIN accounts ac ON ac.id=cm.accountId";
private static final String GET_COMMUNITY_JOIN_REQUESTS = "SELECT cjr.communityId, cjr.accountId, ac.name, ac.uuid FROM communityJoinRequests cjr INNER JOIN accounts ac ON ac.id=cjr.accountId WHERE cjr.accountId=?;"; private static final String GET_COMMUNITY_JOIN_REQUESTS = "SELECT cjr.communityId, cjr.accountId, ac.name, ac.uuid FROM communityJoinRequests cjr INNER JOIN accounts ac ON ac.id=cjr.accountId WHERE cjr.accountId=?;";
private static final String GET_COMMUNITY_SETTINGS = "SELECT communityId, settingId, settingValue FROM communitySettings"; private static final String GET_COMMUNITY_SETTINGS = "SELECT communityId, settingId, settingValue FROM communitySettings";
private static final String GET_PUBLIC_COMMUNITIES = "SELECT communityId FROM communities WHERE settingId=8 AND settingValue='true';"; private static final String GET_PUBLIC_COMMUNITIES = "SELECT communityId FROM communitySettings WHERE settingId=8 AND settingValue='true';";
// Old queries
private static final String GET_ALL_COMMUNITIES = "SELECT * FROM communities WHERE region=?;";
private static final String GET_COMMUNITY_BY_ID = "SELECT * FROM communities WHERE id=?;";
private static final String GET_COMMUNITY_BY_NAME = "SELECT * FROM communities WHERE name=? AND region=?;";
private static final String REMOVE_FROM_COMMUNITY = "DELETE FROM communityMembers WHERE accountId=? AND communityId=?;"; private static final String REMOVE_FROM_COMMUNITY = "DELETE FROM communityMembers WHERE accountId=? AND communityId=?;";
private static final String UPDATE_COMMUNITY_ROLE = "UPDATE communityMembers SET communityRole=? WHERE accountId=? AND communityId=?;"; private static final String UPDATE_COMMUNITY_ROLE = "UPDATE communityMembers SET communityRole=? WHERE accountId=? AND communityId=?;";
@ -112,16 +107,6 @@ public class CommunityRepository extends RepositoryBase
public void handlePlayerJoin(final Map<Integer, Community> store, final List<Integer> load, final int accountId) public void handlePlayerJoin(final Map<Integer, Community> store, final List<Integer> load, final int accountId)
{ {
loadInternal(store, load, accountId); loadInternal(store, load, accountId);
for (int id : load)
{
Community com = store.get(id);
if (com != null && !com.isBrowserFlagSet())
{
updateBrowserStatus(com, com.getPrivacySetting() != Community.PrivacySetting.PRIVATE
&& com.getMembers().size() >= 5);
}
}
} }
public void updateBrowserStatus(Community community, boolean flag) public void updateBrowserStatus(Community community, boolean flag)
@ -138,57 +123,94 @@ public class CommunityRepository extends RepositoryBase
{ {
try (Connection connection = getConnection()) try (Connection connection = getConnection())
{ {
// Only load the info for communities with the given IDs if (!load.isEmpty())
StringBuilder builder = new StringBuilder();
builder.append(" WHERE %col IN (");
for (int index = 0; index < load.size(); index++)
{ {
if (index != 0) // Only load the info for communities with the given IDs
builder.append(", "); StringBuilder builder = new StringBuilder();
builder.append("?"); builder.append(" WHERE %col IN (");
}
builder.append(");"); for (int index = 0; index < load.size(); index++)
String inClause = builder.toString();
ColumnInt[] idColumns = genIdColumns("id", load);
executeQuery(connection, GET_COMMUNITIES_BY_ID + inClause.replace("%col", "id"), resultSet ->
{
while (resultSet.next())
{ {
final int id = resultSet.getInt("id"); if (index != 0)
final String cName = resultSet.getString("name"); builder.append(", ");
final Community community = new Community(id, cName); builder.append("?");
store.put(id, community);
} }
}, idColumns);
idColumns = genIdColumns("cm.communityId", load); builder.append(");");
executeQuery(connection, GET_COMMUNITY_MEMBERS + inClause.replace("%col", "cm.communityId"), memberSet ->
{ String inClause = builder.toString();
while (memberSet.next()) ColumnInt[] idColumns = genIdColumns("id", load);
executeQuery(connection, GET_COMMUNITIES_BY_ID + inClause.replace("%col", "id"), resultSet ->
{ {
final int communityId = memberSet.getInt("communityId"); while (resultSet.next())
final int accountId1 = memberSet.getInt("accountId");
final String name = memberSet.getString("name");
final UUID uuid = UUID.fromString(memberSet.getString("uuid"));
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
final long lastLogin = memberSet.getTimestamp("lastLogin").getTime();
boolean readingChat = memberSet.getBoolean("readingChat");
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId1, role, lastLogin);
info.ReadingChat = readingChat;
Community community = store.get(communityId);
if (community != null)
{ {
community.getMembers().put(info.UUID, info); final int id = resultSet.getInt("id");
final String cName = resultSet.getString("name");
final Community community = new Community(id, cName);
store.put(id, community);
}
}, idColumns);
idColumns = genIdColumns("cm.communityId", load);
executeQuery(connection, GET_COMMUNITY_MEMBERS + inClause.replace("%col", "cm.communityId"), memberSet ->
{
while (memberSet.next())
{
final int communityId = memberSet.getInt("communityId");
final int accountId1 = memberSet.getInt("accountId");
final String name = memberSet.getString("name");
final UUID uuid = UUID.fromString(memberSet.getString("uuid"));
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
final long lastLogin = memberSet.getTimestamp("lastLogin").getTime();
boolean readingChat = memberSet.getBoolean("readingChat");
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId1, role, lastLogin);
info.ReadingChat = readingChat;
Community community = store.get(communityId);
if (community != null)
{
community.getMembers().put(info.UUID, info);
}
}
}, idColumns);
idColumns = genIdColumns("communityId", load);
executeQuery(connection, GET_COMMUNITY_SETTINGS + inClause.replace("%col", "communityId"), settingSet ->
{
while (settingSet.next())
{
final int communityId = settingSet.getInt("communityId");
final int settingId = settingSet.getInt("settingId");
final String value = settingSet.getString("settingValue");
Community community = store.get(communityId);
CommunitySetting setting = CommunitySetting.getSetting(settingId);
if (community != null && setting != null)
{
setting.parseValueInto(value, community);
}
}
}, idColumns);
// Ensure the browser flag is set
for (int id : load)
{
Community com = store.get(id);
if (com == null)
{
continue;
}
if (!com.isBrowserFlagSet())
{
updateBrowserStatus(com, com.getPrivacySetting() != Community.PrivacySetting.PRIVATE &&
com.getMembers().size() >= 5);
} }
} }
}, idColumns); }
if (accountId != -1) if (accountId != -1)
{ {
@ -209,24 +231,6 @@ public class CommunityRepository extends RepositoryBase
} }
}, new ColumnInt("cjr.accountId", accountId)); }, new ColumnInt("cjr.accountId", accountId));
} }
idColumns = genIdColumns("communityId", load);
executeQuery(connection, GET_COMMUNITY_SETTINGS + inClause.replace("%col", "communityId"), settingSet ->
{
while (settingSet.next())
{
final int communityId = settingSet.getInt("communityId");
final int settingId = settingSet.getInt("settingId");
final String value = settingSet.getString("settingValue");
Community community = store.get(communityId);
CommunitySetting setting = CommunitySetting.getSetting(settingId);
if (community != null && setting != null)
{
setting.parseValueInto(value, community);
}
}
}, idColumns);
} catch (SQLException ex) } catch (SQLException ex)
{ {
System.err.println("Encountered an SQL exception loading communities " + load); System.err.println("Encountered an SQL exception loading communities " + load);
@ -234,89 +238,6 @@ public class CommunityRepository extends RepositoryBase
} }
} }
/* public void loadCommunities(final Map<Integer, Community> communityMap)
{
try (Connection connection = getConnection())
{
executeQuery(connection, GET_ALL_COMMUNITIES, resultSet ->
{
Map<Integer, Community> resultant = new HashMap<>();
while (resultSet.next())
{
final int id = resultSet.getInt("id");
final String cName = resultSet.getString("name");
final Community community = new Community(id, cName);
resultant.put(community.getId(), community);
}
communityMap.clear();
communityMap.putAll(resultant);
}, new ColumnVarChar("region", 5, _us ? "US" : "EU"));
executeQuery(connection, GET_COMMUNITY_MEMBERS, memberSet ->
{
while (memberSet.next())
{
final int communityId = memberSet.getInt("communityId");
final int accountId = memberSet.getInt("accountId");
final String name = memberSet.getString("name");
final UUID uuid = UUID.fromString(memberSet.getString("uuid"));
final CommunityRole role = CommunityRole.parseRole(memberSet.getString("communityRole"));
final long lastLogin = memberSet.getTimestamp("lastLogin").getTime();
boolean readingChat = memberSet.getBoolean("readingChat");
CommunityMemberInfo info = new CommunityMemberInfo(name, uuid, accountId, role, lastLogin);
info.ReadingChat = readingChat;
Community community = communityMap.get(communityId);
if (community != null)
{
community.getMembers().put(info.UUID, info);
}
}
});
executeQuery(connection, GET_COMMUNITY_JOIN_REQUESTS, requestSet ->
{
while (requestSet.next())
{
final int communityId = requestSet.getInt("communityId");
final int accountId = requestSet.getInt("accountId");
final UUID uuid = UUID.fromString(requestSet.getString("uuid"));
final String name = requestSet.getString("name");
Community community = communityMap.get(communityId);
if (community != null)
{
community.getJoinRequests().put(uuid, new CommunityJoinRequestInfo(name, uuid, accountId));
}
}
});
executeQuery(connection, GET_COMMUNITY_SETTINGS, settingSet ->
{
while (settingSet.next())
{
final int communityId = settingSet.getInt("communityId");
final int settingId = settingSet.getInt("settingId");
final String value = settingSet.getString("settingValue");
Community community = communityMap.get(communityId);
CommunitySetting setting = CommunitySetting.getSetting(settingId);
if (community != null && setting != null)
{
setting.parseValueInto(value, community);
}
}
});
}
catch (SQLException e)
{
e.printStackTrace();
}
} */
public void updateMembersAndJoinRequests(List<Community> communities) public void updateMembersAndJoinRequests(List<Community> communities)
{ {
if (communities.isEmpty()) if (communities.isEmpty())

View File

@ -8,6 +8,8 @@ import java.sql.Statement;
import javax.sql.DataSource; import javax.sql.DataSource;
import com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
import org.jooq.impl.DSL; import org.jooq.impl.DSL;
@ -176,10 +178,6 @@ public abstract class RepositoryBase
{ {
affectedRows = executeInsert(connection, query, callable, null, columns); affectedRows = executeInsert(connection, query, callable, null, columns);
} }
catch (SQLException exception)
{
exception.printStackTrace();
}
catch (Exception exception) catch (Exception exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
@ -256,9 +254,10 @@ public abstract class RepositoryBase
{ {
executeQuery(preparedStatement, callable, columns); executeQuery(preparedStatement, callable, columns);
} }
catch (SQLException exception) catch (MySQLSyntaxErrorException syntaxException)
{ {
exception.printStackTrace(); System.err.println("Query \"" + query + "\" contained a syntax error:");
syntaxException.printStackTrace();
} }
catch (Exception exception) catch (Exception exception)
{ {