this was alot simpler than with c++
This commit is contained in:
@@ -15,6 +15,7 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -34,10 +35,8 @@ public class DataMapper {
|
||||
public static DataMapper instance = new DataMapper();
|
||||
private volatile boolean called;
|
||||
private final ConcurrentMap<Integer, StringObject> soEventContentCache;
|
||||
private final Stopwatch stopwatch;
|
||||
|
||||
public DataMapper() {
|
||||
this.stopwatch = Stopwatch.createStarted();
|
||||
this.soEventContentCache = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
}
|
||||
|
||||
@@ -46,6 +45,47 @@ public class DataMapper {
|
||||
return MapColoumns;
|
||||
}
|
||||
|
||||
public void insertIntoDBEventContent(ConcurrentMap<Integer, String> EventContentMap) {
|
||||
String SQL_Delete = "delete from Maps";
|
||||
String l_sSQL = "INSERT INTO `EventContent` (`title`,`Rewards`,`Leaders`,`datum`,`hours`) VALUES (?, ?, ?, ?, ?)";
|
||||
String l_SQLMaps = "INSERT INTO `Maps` (`MapNames`) VALUES (?)";
|
||||
List<String> maps = new ArrayList();
|
||||
try (Connection l_cCon = DBCPDataSource.getConnection()) {
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(SQL_Delete)) {
|
||||
s.executeUpdate();
|
||||
}
|
||||
SQL_Delete = "delete from EventContent";
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(SQL_Delete)) {
|
||||
s.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(l_sSQL)) {
|
||||
int i = 1;
|
||||
for (String str : EventContentMap.values()) {
|
||||
if (i < 6) {
|
||||
System.out.println("str: " + str + "\n");
|
||||
s.setString(i, str);
|
||||
i++;
|
||||
} else {
|
||||
maps.add(str);
|
||||
}
|
||||
}
|
||||
s.executeUpdate();
|
||||
}
|
||||
try (PreparedStatement s = l_cCon.prepareStatement(l_SQLMaps)) {
|
||||
for (String strMap : maps) {
|
||||
if (!maps.isEmpty()) {
|
||||
s.setString(1, strMap);
|
||||
s.addBatch();
|
||||
}
|
||||
}
|
||||
s.executeBatch();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
called = false;
|
||||
}
|
||||
|
||||
private Map<Integer, StringObject> getCache() throws SQLException, IOException, CustomError {
|
||||
List<StringObject> stro;
|
||||
stro = GetEventContentFromDBTable();
|
||||
@@ -66,21 +106,6 @@ public class DataMapper {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkUpdateTime() {
|
||||
new Thread(() -> {
|
||||
if (stopwatch.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS) {
|
||||
try {
|
||||
soEventContentCache.clear();
|
||||
called = false;
|
||||
initialization();
|
||||
stopwatch.reset();
|
||||
} catch (SQLException | IOException | CustomError ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static String modifyEventContent(String str, int i) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (i) {
|
||||
|
||||
Reference in New Issue
Block a user