Optimize DbSegmentPublisher.publishSegment

This commit is contained in:
Tugdual Saunier 2014-02-17 17:54:59 +00:00
parent 4dce007577
commit 4b67dbff5f
1 changed files with 15 additions and 15 deletions

View File

@ -41,6 +41,7 @@ public class DbSegmentPublisher implements SegmentPublisher
private final ObjectMapper jsonMapper; private final ObjectMapper jsonMapper;
private final DbTablesConfig config; private final DbTablesConfig config;
private final IDBI dbi; private final IDBI dbi;
private final String statement;
@Inject @Inject
public DbSegmentPublisher( public DbSegmentPublisher(
@ -52,6 +53,20 @@ public class DbSegmentPublisher implements SegmentPublisher
this.jsonMapper = jsonMapper; this.jsonMapper = jsonMapper;
this.config = config; this.config = config;
this.dbi = dbi; this.dbi = dbi;
if (DbConnector.isPostgreSQL(dbi)) {
this.statement = String.format(
"INSERT INTO %s (id, dataSource, created_date, start, \"end\", partitioned, version, used, payload) "
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
config.getSegmentsTable()
);
} else {
this.statement = String.format(
"INSERT INTO %s (id, dataSource, created_date, start, end, partitioned, version, used, payload) "
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
config.getSegmentsTable()
);
}
} }
public void publishSegment(final DataSegment segment) throws IOException public void publishSegment(final DataSegment segment) throws IOException
@ -83,21 +98,6 @@ public class DbSegmentPublisher implements SegmentPublisher
@Override @Override
public Void withHandle(Handle handle) throws Exception public Void withHandle(Handle handle) throws Exception
{ {
String statement;
if (DbConnector.isPostgreSQL(dbi)) {
statement = String.format(
"INSERT INTO %s (id, dataSource, created_date, start, \"end\", partitioned, version, used, payload) "
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
config.getSegmentsTable()
);
} else {
statement = String.format(
"INSERT INTO %s (id, dataSource, created_date, start, end, partitioned, version, used, payload) "
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
config.getSegmentsTable()
);
}
handle.createStatement(statement) handle.createStatement(statement)
.bind("id", segment.getIdentifier()) .bind("id", segment.getIdentifier())
.bind("dataSource", segment.getDataSource()) .bind("dataSource", segment.getDataSource())