| 1 | import org.odmg.Database;
|
|---|
| 2 | import org.odmg.ODMGException;
|
|---|
| 3 | import org.odmg.OQLQuery;
|
|---|
| 4 | import org.odmg.Transaction;
|
|---|
| 5 |
|
|---|
| 6 | import rasj.RasException;
|
|---|
| 7 | import rasj.RasImplementation;
|
|---|
| 8 | import rasj.RasMArrayShort;
|
|---|
| 9 | import rasj.RasMInterval;
|
|---|
| 10 |
|
|---|
| 11 | public class MemFill {
|
|---|
| 12 | private static String server = "localhost";
|
|---|
| 13 | private static String port = "7001";
|
|---|
| 14 | private static String base = "RASBASE";
|
|---|
| 15 | private static String user = "rasadmin";
|
|---|
| 16 | private static String password = "rasadmin";
|
|---|
| 17 |
|
|---|
| 18 | private static int getIndex(int cols, int row, int col) {
|
|---|
| 19 | return (row * cols) + col;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | public static void main(String[] args) {
|
|---|
| 23 | Database database = null;
|
|---|
| 24 | Transaction transaction = null;
|
|---|
| 25 | try {
|
|---|
| 26 | RasImplementation app = new RasImplementation("http://" + server + ":" + port);
|
|---|
| 27 | app.setUserIdentification(user, password);
|
|---|
| 28 |
|
|---|
| 29 | database = app.newDatabase();
|
|---|
| 30 | database.open(base, Database.OPEN_READ_WRITE);
|
|---|
| 31 |
|
|---|
| 32 | int minRow = 0;
|
|---|
| 33 | int maxRow = 900;
|
|---|
| 34 | int minCol = 0;
|
|---|
| 35 | int maxCol = 900;
|
|---|
| 36 | short value = 0;
|
|---|
| 37 | short[] rawData = new short[maxRow * maxCol];
|
|---|
| 38 | for (int row = minRow; row < maxRow; row++) {
|
|---|
| 39 | for (int col = minCol; col < maxCol; col++) {
|
|---|
| 40 | rawData[getIndex(maxCol, row, col)] = value;
|
|---|
| 41 | value = (short) (value + 1);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | for (int day = 1; day <= 31; day++) {
|
|---|
| 46 | for (int hour = 0; hour <= 23; hour++) {
|
|---|
| 47 | System.out.println("Update data for day=" + day + " hour=" + hour);
|
|---|
| 48 |
|
|---|
| 49 | transaction = app.newTransaction();
|
|---|
| 50 | transaction.begin();
|
|---|
| 51 |
|
|---|
| 52 | String interval = String.format("[%d:%d, %d:%d]", minRow, maxRow - 1, minCol, maxCol - 1);
|
|---|
| 53 | RasMArrayShort data = new RasMArrayShort(new RasMInterval(interval));
|
|---|
| 54 | data.setObjectTypeName("MemTest");
|
|---|
| 55 | data.setArray(rawData);
|
|---|
| 56 |
|
|---|
| 57 | OQLQuery updateQuery = app.newOQLQuery();
|
|---|
| 58 | updateQuery.create("update MemTestData as c set c[$1, $2, $3, $4, $5, *:*, *:*] assign $6");
|
|---|
| 59 | updateQuery.bind(2016);
|
|---|
| 60 | updateQuery.bind(12);
|
|---|
| 61 | updateQuery.bind(day);
|
|---|
| 62 | updateQuery.bind(hour);
|
|---|
| 63 | updateQuery.bind(0);
|
|---|
| 64 | updateQuery.bind(data);
|
|---|
| 65 | updateQuery.execute();
|
|---|
| 66 |
|
|---|
| 67 | transaction.commit();
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 | } catch (ODMGException e) {
|
|---|
| 71 | e.printStackTrace();
|
|---|
| 72 | if (transaction != null) {
|
|---|
| 73 | transaction.abort();
|
|---|
| 74 | }
|
|---|
| 75 | } catch (RasException e) {
|
|---|
| 76 | e.printStackTrace();
|
|---|
| 77 | } finally {
|
|---|
| 78 | if (database != null) {
|
|---|
| 79 | try {
|
|---|
| 80 | database.close();
|
|---|
| 81 | } catch (ODMGException e) {
|
|---|
| 82 | e.printStackTrace();
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|