Small DB fix
This commit is contained in:
@@ -40,33 +40,33 @@ import org.sql2o.Sql2o;
|
|||||||
public class AnimationEndpoint
|
public class AnimationEndpoint
|
||||||
{
|
{
|
||||||
private static final String CREATE_SQL = "CREATE TABLE IF NOT EXISTS `animation` (\n"
|
private static final String CREATE_SQL = "CREATE TABLE IF NOT EXISTS `animation` (\n"
|
||||||
+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
|
+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
|
||||||
+ " `region` int(11) NOT NULL,\n"
|
+ " `npcid` int(11) NOT NULL,\n"
|
||||||
+ " `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n"
|
+ " `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n"
|
||||||
+ " `rev` int(11) NOT NULL,\n"
|
+ " `rev` int(11) NOT NULL,\n"
|
||||||
+ " `anim1` int(11),\n"
|
+ " `anim1` int(11),\n"
|
||||||
+ " `anim2` int(11),\n"
|
+ " `anim2` int(11),\n"
|
||||||
+ " `anim3` int(11),\n"
|
+ " `anim3` int(11),\n"
|
||||||
+ " `anim4` int(11),\n"
|
+ " `anim4` int(11),\n"
|
||||||
+ " `anim5` int(11),\n"
|
+ " `anim5` int(11),\n"
|
||||||
+ " `anim6` int(11),\n"
|
+ " `anim6` int(11),\n"
|
||||||
+ " `anim7` int(11),\n"
|
+ " `anim7` int(11),\n"
|
||||||
+ " `anim8` int(11),\n"
|
+ " `anim8` int(11),\n"
|
||||||
+ " `anim9` int(11),\n"
|
+ " `anim9` int(11),\n"
|
||||||
+ " `anim10` int(11),\n"
|
+ " `anim10` int(11),\n"
|
||||||
+ " PRIMARY KEY (`id`),\n"
|
+ " PRIMARY KEY (`id`),\n"
|
||||||
+ " KEY `npcid` (`npcid`,`time`)\n"
|
+ " KEY `npcid` (`npcid`,`time`)\n"
|
||||||
+ ") ENGINE=InnoDB";
|
+ ") ENGINE=InnoDB";
|
||||||
|
|
||||||
private final Sql2o sql2o;
|
private final Sql2o sql2o;
|
||||||
|
|
||||||
private final Cache<Integer, AnimationCache> keyCache = CacheBuilder.newBuilder()
|
private final Cache<Integer, AnimationCache> keyCache = CacheBuilder.newBuilder()
|
||||||
.maximumSize(1024)
|
.maximumSize(1024)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public AnimationEndpoint(
|
public AnimationEndpoint(
|
||||||
@Qualifier("Runelite SQL2O") Sql2o sql2o
|
@Qualifier("Runelite SQL2O") Sql2o sql2o
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.sql2o = sql2o;
|
this.sql2o = sql2o;
|
||||||
@@ -74,18 +74,18 @@ public class AnimationEndpoint
|
|||||||
try (Connection con = sql2o.beginTransaction())
|
try (Connection con = sql2o.beginTransaction())
|
||||||
{
|
{
|
||||||
con.createQuery(CREATE_SQL)
|
con.createQuery(CREATE_SQL)
|
||||||
.executeUpdate();
|
.executeUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnimationEntry findLatestAnimations(Connection con, int npcid)
|
private AnimationEntry findLatestAnimations(Connection con, int npcid)
|
||||||
{
|
{
|
||||||
return con.createQuery("select npcid, time, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10 from animation "
|
return con.createQuery("select npcid, time, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10 from animation "
|
||||||
+ "where npcid = :npcid "
|
+ "where npcid = :npcid "
|
||||||
+ "order by time desc "
|
+ "order by time desc "
|
||||||
+ "limit 1")
|
+ "limit 1")
|
||||||
.addParameter("npcid", npcid)
|
.addParameter("npcid", npcid)
|
||||||
.executeAndFetchFirst(AnimationEntry.class);
|
.executeAndFetchFirst(AnimationEntry.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void submit(AnimationRequest animationRequest)
|
public void submit(AnimationRequest animationRequest)
|
||||||
@@ -98,7 +98,7 @@ public class AnimationEndpoint
|
|||||||
|
|
||||||
AnimationCache animationCache = keyCache.getIfPresent(npcid);
|
AnimationCache animationCache = keyCache.getIfPresent(npcid);
|
||||||
if (animationCache == null
|
if (animationCache == null
|
||||||
|| animationCache.getAnim1() != animations[0]
|
|| animationCache.getAnim1() != animations[0]
|
||||||
|| animationCache.getAnim2() != animations[1]
|
|| animationCache.getAnim2() != animations[1]
|
||||||
|| animationCache.getAnim3() != animations[2]
|
|| animationCache.getAnim3() != animations[2]
|
||||||
|| animationCache.getAnim4() != animations[3]
|
|| animationCache.getAnim4() != animations[3]
|
||||||
@@ -137,7 +137,7 @@ public class AnimationEndpoint
|
|||||||
|
|
||||||
// already have these?
|
// already have these?
|
||||||
if (animationEntry != null
|
if (animationEntry != null
|
||||||
&& animationEntry.getAnimations()[0] == animations[0]
|
&& animationEntry.getAnimations()[0] == animations[0]
|
||||||
&& animationEntry.getAnimations()[1] == animations[1]
|
&& animationEntry.getAnimations()[1] == animations[1]
|
||||||
&& animationEntry.getAnimations()[2] == animations[2]
|
&& animationEntry.getAnimations()[2] == animations[2]
|
||||||
&& animationEntry.getAnimations()[3] == animations[3]
|
&& animationEntry.getAnimations()[3] == animations[3]
|
||||||
@@ -155,22 +155,22 @@ public class AnimationEndpoint
|
|||||||
if (query == null)
|
if (query == null)
|
||||||
{
|
{
|
||||||
query = con.createQuery("insert into animation (npcid, rev, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10) "
|
query = con.createQuery("insert into animation (npcid, rev, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10) "
|
||||||
+ "values (:npcid, :rev, :anim1, :anim2, :anim3, :anim4, anim5, anim6, anim7, anim8, anim9, anim10)");
|
+ "values (:npcid, :rev, :anim1, :anim2, :anim3, :anim4, anim5, anim6, anim7, anim8, anim9, anim10)");
|
||||||
}
|
}
|
||||||
|
|
||||||
query.addParameter("npcid", npcid)
|
query.addParameter("npcid", npcid)
|
||||||
.addParameter("rev", animationRequest.getRevision())
|
.addParameter("rev", animationRequest.getRevision())
|
||||||
.addParameter("anim1", animations[0])
|
.addParameter("anim1", animations[0])
|
||||||
.addParameter("anim2", animations[1])
|
.addParameter("anim2", animations[1])
|
||||||
.addParameter("anim3", animations[2])
|
.addParameter("anim3", animations[2])
|
||||||
.addParameter("anim4", animations[3])
|
.addParameter("anim4", animations[3])
|
||||||
.addParameter("anim5", animations[4])
|
.addParameter("anim5", animations[4])
|
||||||
.addParameter("anim6", animations[5])
|
.addParameter("anim6", animations[5])
|
||||||
.addParameter("anim7", animations[6])
|
.addParameter("anim7", animations[6])
|
||||||
.addParameter("anim8", animations[7])
|
.addParameter("anim8", animations[7])
|
||||||
.addParameter("anim9", animations[8])
|
.addParameter("anim9", animations[8])
|
||||||
.addParameter("anim10", animations[9])
|
.addParameter("anim10", animations[9])
|
||||||
.addToBatch();
|
.addToBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query != null)
|
if (query != null)
|
||||||
@@ -186,10 +186,10 @@ public class AnimationEndpoint
|
|||||||
try (Connection con = sql2o.open())
|
try (Connection con = sql2o.open())
|
||||||
{
|
{
|
||||||
return con.createQuery(
|
return con.createQuery(
|
||||||
"select t1.npcid, t2.time, t2.rev, t2.anim1, t2.anim2, t2.anim3, t2.anim4, t2.anim5, t2.anim6, t2.anim7, t2.anim8, t2.anim9, t2.anim10 from " +
|
"select t1.npcid, t2.time, t2.rev, t2.anim1, t2.anim2, t2.anim3, t2.anim4, t2.anim5, t2.anim6, t2.anim7, t2.anim8, t2.anim9, t2.anim10 from " +
|
||||||
"(select npcid,max(id) as id from animation group by npcid) t1 " +
|
"(select npcid,max(id) as id from animation group by npcid) t1 " +
|
||||||
"join animation t2 on t1.id = t2.id")
|
"join animation t2 on t1.id = t2.id")
|
||||||
.executeAndFetch(AnimationEntry.class);
|
.executeAndFetch(AnimationEntry.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,9 +198,9 @@ public class AnimationEndpoint
|
|||||||
try (Connection con = sql2o.open())
|
try (Connection con = sql2o.open())
|
||||||
{
|
{
|
||||||
return con.createQuery("select npcid, time, rev, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10 from animation "
|
return con.createQuery("select npcid, time, rev, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10 from animation "
|
||||||
+ "where npcid = :npcid order by time desc limit 1")
|
+ "where npcid = :npcid order by time desc limit 1")
|
||||||
.addParameter("npcid", npcid)
|
.addParameter("npcid", npcid)
|
||||||
.executeAndFetchFirst(AnimationEntry.class);
|
.executeAndFetchFirst(AnimationEntry.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user