OmniSciDB  04ee39c94c
Worker Class Reference
+ Inheritance diagram for Worker:
+ Collaboration diagram for Worker:

Public Member Functions

void run ()
 

Package Functions

 Worker (int ti, int nt)
 

Package Attributes

Random r = new Random()
 
int threadId
 
int numOfTables
 

Static Package Attributes

static final Logger MAPDLOGGER = LoggerFactory.getLogger(Worker.class)
 
static final String JDBC_DRIVER = "com.omnisci.jdbc.OmniSciDriver"
 
static final String DB_URL = "jdbc:omnisci:localhost:6274:omnisci"
 
static final String USER = "admin"
 
static final String PASS = "HyperInteractive"
 

Private Member Functions

void doQuery (Connection conn, String sql, Statement stmt) throws SQLException
 
void doInsertQuery (Connection conn, Statement stmt, int tab) throws SQLException
 
void doSelectQuery (Connection conn, Statement stmt, int tab) throws SQLException
 

Private Attributes

Connection conn = null
 
Statement stmt = null
 

Detailed Description

Definition at line 28 of file Worker.java.

Constructor & Destructor Documentation

◆ Worker()

Worker.Worker ( int  ti,
int  nt 
)
inlinepackage

Definition at line 46 of file Worker.java.

References doQuery(), and numOfTables.

46  {
47  threadId = ti;
48  numOfTables = nt;
49 
50  try {
51  // STEP 2: Register JDBC driver
52  Class.forName(JDBC_DRIVER);
53 
54  // STEP 3: Open a connection
55  MAPDLOGGER.info(threadId + ": Connecting to database...");
56  conn = DriverManager.getConnection(DB_URL, USER, PASS);
57  stmt = conn.createStatement();
58 
59  for (int i = 0; i < numOfTables; i++) {
60  // doQuery(conn, "drop table t" + i, stmt);
61  doQuery(conn, "create table if not exists t" + i + " (newn int)", stmt);
62  }
63  } catch (SQLException se) {
64  // Handle errors for JDBC
65  se.printStackTrace();
66 
67  } catch (ClassNotFoundException ex) {
68  ex.printStackTrace();
69  } // end try
70  }
void doQuery(Connection conn, String sql, Statement stmt)
Definition: Worker.java:109
int threadId
Definition: Worker.java:43
static final Logger MAPDLOGGER
Definition: Worker.java:29
static final String JDBC_DRIVER
Definition: Worker.java:31
int numOfTables
Definition: Worker.java:44
Statement stmt
Definition: Worker.java:39
Connection conn
Definition: Worker.java:38
static final String PASS
Definition: Worker.java:36
static final String USER
Definition: Worker.java:35
static final String DB_URL
Definition: Worker.java:32
+ Here is the call graph for this function:

Member Function Documentation

◆ doInsertQuery()

void Worker.doInsertQuery ( Connection  conn,
Statement  stmt,
int  tab 
) throws SQLException
inlineprivate

Definition at line 129 of file Worker.java.

References doQuery().

Referenced by run().

130  {
131  doQuery(conn, "insert into t" + tab + " values (1)", stmt);
132  }
void doQuery(Connection conn, String sql, Statement stmt)
Definition: Worker.java:109
Statement stmt
Definition: Worker.java:39
Connection conn
Definition: Worker.java:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doQuery()

void Worker.doQuery ( Connection  conn,
String  sql,
Statement  stmt 
) throws SQLException
inlineprivate

Definition at line 109 of file Worker.java.

References sql().

Referenced by doInsertQuery(), doSelectQuery(), and Worker().

109  {
110  ResultSet rs = null;
111  try {
112  rs = stmt.executeQuery(sql);
113  } catch (SQLException se) {
114  if (se.getMessage().contains("does not exist")) {
115  MAPDLOGGER.info(threadId + ": table not present");
116  return;
117  } else {
118  throw se;
119  }
120  }
121  while (rs.next()) {
122  int sum = rs.getInt(1);
123 
124  MAPDLOGGER.info(threadId + ": result " + sum);
125  }
126  rs.close();
127  }
auto sql(const std::string &sql_stmts)
int threadId
Definition: Worker.java:43
static final Logger MAPDLOGGER
Definition: Worker.java:29
Statement stmt
Definition: Worker.java:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doSelectQuery()

void Worker.doSelectQuery ( Connection  conn,
Statement  stmt,
int  tab 
) throws SQLException
inlineprivate

Definition at line 134 of file Worker.java.

References doQuery().

Referenced by run().

135  {
136  doQuery(conn, ("select sum(newn) from t" + tab), stmt);
137  }
void doQuery(Connection conn, String sql, Statement stmt)
Definition: Worker.java:109
Statement stmt
Definition: Worker.java:39
Connection conn
Definition: Worker.java:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

void Worker.run ( )
inline

Definition at line 72 of file Worker.java.

References doInsertQuery(), doSelectQuery(), and threadId.

72  {
73  try {
74  int tab = this.threadId;
75  for (int i = 0; i < 100; i++) {
76  doInsertQuery(conn, stmt, tab);
77  doSelectQuery(conn, stmt, tab);
78  tab++;
79  if (tab >= this.numOfTables) {
80  tab = 0;
81  }
82  }
83 
84  conn.close();
85  } catch (SQLException se) {
86  // Handle errors for JDBC
87  se.printStackTrace();
88  } catch (Exception e) {
89  // Handle errors for Class.forName
90  e.printStackTrace();
91  } finally {
92  // finally block used to close resources
93  try {
94  if (stmt != null) {
95  stmt.close();
96  }
97  } catch (SQLException se2) {
98  } // nothing we can do
99  try {
100  if (conn != null) {
101  conn.close();
102  }
103  } catch (SQLException se) {
104  se.printStackTrace();
105  } // end finally try
106  } // end try
107  } // end main
int threadId
Definition: Worker.java:43
int numOfTables
Definition: Worker.java:44
Statement stmt
Definition: Worker.java:39
Connection conn
Definition: Worker.java:38
void doSelectQuery(Connection conn, Statement stmt, int tab)
Definition: Worker.java:134
void doInsertQuery(Connection conn, Statement stmt, int tab)
Definition: Worker.java:129
+ Here is the call graph for this function:

Member Data Documentation

◆ conn

Connection Worker.conn = null
private

Definition at line 38 of file Worker.java.

◆ DB_URL

final String Worker.DB_URL = "jdbc:omnisci:localhost:6274:omnisci"
staticpackage

Definition at line 32 of file Worker.java.

◆ JDBC_DRIVER

final String Worker.JDBC_DRIVER = "com.omnisci.jdbc.OmniSciDriver"
staticpackage

Definition at line 31 of file Worker.java.

◆ MAPDLOGGER

final Logger Worker.MAPDLOGGER = LoggerFactory.getLogger(Worker.class)
staticpackage

Definition at line 29 of file Worker.java.

◆ numOfTables

int Worker.numOfTables
package

Definition at line 44 of file Worker.java.

Referenced by Worker().

◆ PASS

final String Worker.PASS = "HyperInteractive"
staticpackage

Definition at line 36 of file Worker.java.

◆ r

Random Worker.r = new Random()
package

Definition at line 41 of file Worker.java.

◆ stmt

Statement Worker.stmt = null
private

Definition at line 39 of file Worker.java.

◆ threadId

int Worker.threadId
package

Definition at line 43 of file Worker.java.

Referenced by run().

◆ USER

final String Worker.USER = "admin"
staticpackage

Definition at line 35 of file Worker.java.


The documentation for this class was generated from the following file: