@@ -90,9 +90,13 @@ public void createDataSource() {
9090 ThreadUtil .sleep (5000 );
9191 }
9292 Properties props = new Properties ();
93- props .setProperty ("dataSourceClassName" , "com.yugabyte.ysql.YBClusterAwareDataSource" );
94- //props.setProperty("dataSource.serverNames", ip);
95- props .setProperty ("dataSource.serverName" , ip );
93+ if (workConf .getDBType ().equals ("yugabyte" )){
94+ props .setProperty ("dataSourceClassName" , "com.yugabyte.ysql.YBClusterAwareDataSource" );
95+ } else {
96+ props .setProperty ("dataSourceClassName" , "org.postgresql.ds.PGSimpleDataSource" );
97+ }
98+ //props.setProperty("dataSource.serverNames", ip);
99+ props .setProperty ("dataSource.serverName" , ip );
96100 props .setProperty ("dataSource.portNumber" , Integer .toString (workConf .getPort ()));
97101 props .setProperty ("dataSource.user" , workConf .getDBUsername ());
98102 props .setProperty ("dataSource.password" , workConf .getDBPassword ());
@@ -119,30 +123,57 @@ public void createDataSource() {
119123 }
120124
121125 public final Connection makeConnection () throws SQLException {
122- YBClusterAwareDataSource ds = new YBClusterAwareDataSource ();
123- ds .setProperty ("user" , workConf .getDBUsername ());
124- ds .setProperty ("password" , workConf .getDBPassword ());
125- ds .setProperty ("reWriteBatchedInserts" , "true" );
126-
127- if (workConf .getSslCert () != null && workConf .getSslCert ().length () > 0 ) {
128- assert (workConf .getSslKey ().length () > 0 ) : "The SSL key is empty." ;
129- ds .setProperty ("sslmode" , "require" );
130- ds .setProperty ("sslcert" , workConf .getSslCert ());
131- ds .setProperty ("sslkey" , workConf .getSslKey ());
126+ Connection conn = null ;
127+ if (workConf .getDBType ().equals ("yugabyte" )) {
128+ YBClusterAwareDataSource ds = new YBClusterAwareDataSource ();
129+ ds .setProperty ("user" , workConf .getDBUsername ());
130+ ds .setProperty ("password" , workConf .getDBPassword ());
131+ ds .setProperty ("reWriteBatchedInserts" , "true" );
132+
133+ if (workConf .getSslCert () != null && workConf .getSslCert ().length () > 0 ) {
134+ assert (workConf .getSslKey ().length () > 0 ) : "The SSL key is empty." ;
135+ ds .setProperty ("sslmode" , "require" );
136+ ds .setProperty ("sslcert" , workConf .getSslCert ());
137+ ds .setProperty ("sslkey" , workConf .getSslKey ());
138+ }
139+ int r = dataSourceCounter .getAndIncrement () % workConf .getNodes ().size ();
140+ String connectStr ;
141+ if (workConf .getJdbcURL () != null && workConf .getJdbcURL ().length () > 0 ) {
142+ connectStr = workConf .getJdbcURL ();
143+ } else {
144+ connectStr = String .format ("jdbc:yugabytedb://%s:%d/%s" ,
145+ workConf .getNodes ().get (r ),
146+ workConf .getPort (),
147+ workConf .getDBName ());
148+ }
149+ ds .setUrl (connectStr );
150+ conn = ds .getConnection ();
132151 }
152+ else {
153+ java .util .Properties props = new java .util .Properties ();
154+ props .put ("user" , workConf .getDBUsername ());
155+ props .put ("password" , workConf .getDBPassword ());
156+ props .put ("reWriteBatchedInserts" , "true" );
133157
134- int r = dataSourceCounter .getAndIncrement () % workConf .getNodes ().size ();
135- String connectStr ;
136- if (workConf .getJdbcURL () != null && workConf .getJdbcURL ().length ()>0 ) {
137- connectStr =workConf .getJdbcURL ();
138- } else {
139- connectStr = String .format ("jdbc:yugabytedb://%s:%d/%s" ,
140- workConf .getNodes ().get (r ),
141- workConf .getPort (),
142- workConf .getDBName ());
158+ if (workConf .getSslCert () != null && workConf .getSslCert ().length () > 0 ) {
159+ assert (workConf .getSslKey ().length () > 0 ) : "The SSL key is empty." ;
160+ props .put ("sslmode" , "require" );
161+ props .put ("sslcert" , workConf .getSslCert ());
162+ props .put ("sslkey" , workConf .getSslKey ());
163+ }
164+ int r = dataSourceCounter .getAndIncrement () % workConf .getNodes ().size ();
165+ String connectStr ;
166+ if (workConf .getJdbcURL () != null && workConf .getJdbcURL ().length () > 0 ) {
167+ connectStr = workConf .getJdbcURL ();
168+ } else {
169+ connectStr = String .format ("jdbc:postgresql://%s:%d/%s" ,
170+ workConf .getNodes ().get (r ),
171+ workConf .getPort (),
172+ workConf .getDBName ());
173+ }
174+ conn = DriverManager .getConnection (connectStr , props );
143175 }
144- ds .setUrl (connectStr );
145- return ds .getConnection ();
176+ return conn ;
146177 }
147178
148179 private static final AtomicInteger dataSourceCounter = new AtomicInteger (0 );
@@ -199,7 +230,7 @@ public final void createDatabase() {
199230 try {
200231 Connection conn = makeConnection ();
201232 SchemaManager schemaManager = SchemaManagerFactory .getSchemaManager (workConf , conn );
202- schemaManager .create ();
233+ schemaManager .create (workConf . getDBType () );
203234 conn .close ();
204235 } catch (SQLException ex ) {
205236 throw new RuntimeException (String .format ("Unexpected error when trying to create the %s database" , this .benchmarkName ), ex );
0 commit comments