org.smartparam.manager.audit.jdbc.JdbcEventLogRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smartparam-manager-audit-jdbc Show documentation
Show all versions of smartparam-manager-audit-jdbc Show documentation
SmartParam manager auditing JDBC repository.
The newest version!
/*
* Copyright 2014 Adam Dubiel, Przemek Hertel.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.smartparam.manager.audit.jdbc;
import java.util.Arrays;
import java.util.List;
import org.polyjdbc.core.query.QueryRunner;
import org.polyjdbc.core.query.TransactionRunner;
import org.polyjdbc.core.query.TransactionWrapper;
import org.polyjdbc.core.query.VoidTransactionWrapper;
import org.smartparam.engine.config.initialization.InitializableComponent;
import org.smartparam.manager.audit.EventLogFilters;
import org.smartparam.manager.audit.EventLogRepository;
import org.smartparam.manager.audit.EventLogEntry;
/**
*
* @author Adam Dubiel
*/
public class JdbcEventLogRepository implements EventLogRepository, InitializableComponent {
private final TransactionRunner transactionRunner;
private final JdbcEventLogEntryDAO jdbcEventLogEntryDAO;
private final SchemaCreator schemaCreator;
public JdbcEventLogRepository(TransactionRunner transactionRunner,
JdbcEventLogEntryDAO jdbcEventLogEntryDAO, SchemaCreator schemaCreator) {
this.transactionRunner = transactionRunner;
this.jdbcEventLogEntryDAO = jdbcEventLogEntryDAO;
this.schemaCreator = schemaCreator;
}
@Override
public boolean supports(Class extends EventLogEntry> entryClass) {
return true;
}
@Override
public void initialize() {
schemaCreator.createSchema();
}
@Override
public List list(final EventLogFilters filters) {
return transactionRunner.run(new TransactionWrapper>() {
@Override
public List perform(QueryRunner queryRunner) {
return jdbcEventLogEntryDAO.list(queryRunner, filters);
}
});
}
@Override
public void save(EventLogEntry eventLogEntry) {
save(Arrays.asList(eventLogEntry));
}
@Override
public void save(final List eventLogEntries) {
transactionRunner.run(new VoidTransactionWrapper() {
@Override
public void performVoid(QueryRunner queryRunner) {
for (EventLogEntry entry : eventLogEntries) {
jdbcEventLogEntryDAO.save(queryRunner, entry);
}
}
});
}
}