Fixed sync db calls for pets.

Make sure to add/remove pets in mysql.
This commit is contained in:
Jonathan Williams 2015-08-14 00:37:43 -05:00
parent bc8aff31cb
commit f5d934fe53

View File

@ -26,14 +26,34 @@ public class PetRepository extends RepositoryBase
_webAddress = webAddress;
}
public void AddPet(PetChangeToken token)
public void AddPet(final PetChangeToken token)
{
new AsyncJsonWebCall(_webAddress + "Pets/AddPet").Execute(token);
Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable()
{
public void run()
{
executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName)
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
}
});
}
public void RemovePet(PetChangeToken token)
public void RemovePet(final PetChangeToken token)
{
new AsyncJsonWebCall(_webAddress + "Pets/RemovePet").Execute(token);
Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable()
{
public void run()
{
executeUpdate("DELETE FROM accountPets WHERE petId = ? AND accountId = ?;"
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
}
});
}
public List<PetExtraToken> GetPetExtras(List<PetExtraToken> petExtraTokens)
@ -41,20 +61,26 @@ public class PetRepository extends RepositoryBase
return new JsonWebCall(_webAddress + "Pets/GetPetExtras").Execute(new TypeToken<List<PetExtraToken>>(){}.getType(), petExtraTokens);
}
public void UpdatePet(PetChangeToken token)
public void UpdatePet(final PetChangeToken token)
{
new AsyncJsonWebCall(_webAddress + "Pets/UpdatePet").Execute(token);
int rowsChanged = executeUpdate("UPDATE accountPets SET petName = ? WHERE petId = ? AND accountId = ?;", new ColumnVarChar("petName", 32, token.PetName)
Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable()
{
public void run()
{
int rowsChanged = executeUpdate("UPDATE accountPets SET petName = ? WHERE petId = ? AND accountId = ?;", new ColumnVarChar("petName", 32, token.PetName)
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
if (rowsChanged < 1)
{
executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName)
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
if (rowsChanged < 1)
{
executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName)
, new ColumnInt("petId", token.PetId)
, new ColumnInt("accountId", token.AccountId));
}
}
}
});
}
@Override