Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding Db/DbOom performance tests #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@
<artifactId>spring-jdbc</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<scope>test</scope>
<groupId>org.jodd</groupId>
<artifactId>jodd-db</artifactId>
<!-- 3.8.0+ java 8 is required -->
<version>3.7.1</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
Expand Down
79 changes: 79 additions & 0 deletions core/src/test/java/org/sql2o/performance/PojoPerformanceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.sql2o.performance;

import jodd.db.DbSession;
import jodd.db.connection.DataSourceConnectionProvider;
import jodd.db.oom.DbOomQuery;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.ibatis.annotations.Result;
Expand Down Expand Up @@ -144,6 +147,8 @@ public void select()
tests.add(new ApacheDbUtilsTypicalSelect());
tests.add(new MyBatisSelect());
tests.add(new SpringJdbcTemplateSelect());
tests.add(new DbOomOptimalSelect());
tests.add(new DbOomTypicalSelect());

System.out.println("Warming up...");
tests.run(ITERATIONS);
Expand Down Expand Up @@ -550,4 +555,78 @@ public void run(int input)
public void close()
{}
}

abstract class DbOomSelect extends PerformanceTestBase
{
private DbSession session;
private DbOomQuery query;

abstract String getSQL();

@Override
public void init()
{
// session = new DbSession(new ConnectionProvider() {
// @Override
// public void init() {
//
// }
//
// @Override
// public Connection getConnection() {
// try {
// return sql2o.getConnectionSource().getConnection();
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// @Override
// public void closeConnection(Connection connection) {
// try {
// connection.close();
// } catch (SQLException e) {
// throw new RuntimeException(e);
// }
// }
//
// @Override
// public void close() {
// // no-op
// }
// });
session = new DbSession(new DataSourceConnectionProvider(sql2o.getDataSource()));
query = new DbOomQuery(session, getSQL() + " WHERE id = ?");
}

@Override
public void run(int input)
{
query.setInteger(1, input);
query.find(Post.class);
}

@Override
public void close()
{
session.closeSession();
}
}

class DbOomTypicalSelect extends DbOomSelect
{
@Override
String getSQL() {
return SELECT_TYPICAL;
}
}

class DbOomOptimalSelect extends DbOomSelect
{
@Override
String getSQL() {
return SELECT_OPTIMAL;
}
}

}