Package sk.iway.iwcm.stat
Class StatWriteBuffer
java.lang.Object
sk.iway.iwcm.stat.StatWriteBuffer
StatWriteBuffer.java
Acts as a synchronized buffer for Stat* inserts. Made this way in order to avoid
database congestion caused by every user's HTTP request filling the database.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Adds an SQL statement into a buffer queue.static void
addUpdateInsertPair
(String update, String insert, String table, Object... parameters) Serves as a facade for a re-occuring pattern in stat tables:int rowsTouched = executeUpdate(); //insert new values into database in case there are none if (rowsTouched == 0) executeInsert();
Acts in a same way as add method NOTE: insert and update must share the same number of parameters for this method to work correctlystatic void
Sweeps the buffer and flushes its contents into database.static int
size()
-
Constructor Details
-
StatWriteBuffer
public StatWriteBuffer()
-
-
Method Details
-
add
Adds an SQL statement into a buffer queue.- Parameters:
sql
- SQL statement pushed into prepareStatement allocationtable
- Base table name used for table creation if SQL fails. For inserting into stat_error_2010_07, pass "stat_error" as a parameterparameters
- Pushed into prepareStatement setObject calls
-
addUpdateInsertPair
public static void addUpdateInsertPair(String update, String insert, String table, Object... parameters) Serves as a facade for a re-occuring pattern in stat tables:int rowsTouched = executeUpdate(); //insert new values into database in case there are none if (rowsTouched == 0) executeInsert();
Acts in a same way as add method NOTE: insert and update must share the same number of parameters for this method to work correctly -
size
public static int size() -
main
Sweeps the buffer and flushes its contents into database. Launched by a background cron task.
-