use of org.apache.karaf.examples.jdbc.api.Booking in project karaf by apache.
the class AddCommand method execute.
@Override
public Object execute() throws Exception {
Booking booking = new Booking();
if (id == 0) {
Random random = new Random();
id = Long.valueOf(random.nextInt(9000000) + 1000000);
}
booking.setId(id);
booking.setCustomer(customer);
booking.setFlight(flight);
bookingService.add(booking);
return null;
}
use of org.apache.karaf.examples.jdbc.api.Booking in project karaf by apache.
the class ListCommand method execute.
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column("ID");
table.column("Flight");
table.column("Customer");
for (Booking booking : bookingService.list()) {
table.addRow().addContent(booking.getId(), booking.getFlight(), booking.getCustomer());
}
table.print(System.out);
return null;
}
use of org.apache.karaf.examples.jdbc.api.Booking in project karaf by apache.
the class BookingServiceJdbcImpl method list.
@Override
public Collection<Booking> list() {
Collection<Booking> bookings = new ArrayList<>();
try (Connection connection = dataSource.getConnection()) {
try (PreparedStatement selectStatement = connection.prepareStatement(selectBookingSql)) {
ResultSet rs = selectStatement.executeQuery();
while (rs.next()) {
Booking booking = new Booking();
booking.setId(rs.getLong("id"));
booking.setCustomer(rs.getString("customer"));
booking.setFlight(rs.getString("flight"));
bookings.add(booking);
}
} catch (SQLException exception) {
LOGGER.error("Can't retreive the bookings", exception);
}
} catch (Exception exception) {
LOGGER.error("Error getting connection ", exception);
}
return bookings;
}
use of org.apache.karaf.examples.jdbc.api.Booking in project karaf by apache.
the class GetCommand method execute.
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column("ID");
table.column("Flight");
table.column("Customer");
Booking booking = bookingService.get(id);
table.addRow().addContent(booking.getId(), booking.getFlight(), booking.getCustomer());
table.print(System.out);
return null;
}
use of org.apache.karaf.examples.jdbc.api.Booking in project karaf by apache.
the class BookingServiceJdbcImpl method get.
@Override
public Booking get(Long id) {
try (Connection connection = dataSource.getConnection()) {
String sqlQuery = selectBookingSql + " where id = ?";
try (PreparedStatement selectStatement = connection.prepareStatement(sqlQuery)) {
selectStatement.setLong(1, id);
ResultSet rs = selectStatement.executeQuery();
if (rs.next()) {
Booking booking = new Booking();
booking.setId(id);
booking.setCustomer(rs.getString("customer"));
booking.setFlight(rs.getString("flight"));
return booking;
}
} catch (SQLException exception) {
LOGGER.error("Can't find booking with id {}", id, exception);
}
} catch (Exception exception) {
LOGGER.error("Error getting connection ", exception);
}
return null;
}
Aggregations