On Github challendy / 1devday-slides
(at least thats what they say ;))
Chris Hallendy
technologist @ MadDog Technology
challendy@maddogtechnology.com
https://github.com/challendy
public static void main(String[] args) throws Exception {
new StoreApplication().run(args);
}
java -jar target/store-dropwizard-0.0.1-SNAPSHOT.jar server example.yml
@Override
public void initialize(Bootstrap bootstrap) {
bootstrap.addBundle migrationsBundle
bootstrap.addBundle hibernateBundle
}
@Override
public void run(StoreConfiguration configuration,
Environment environment) throws ClassNotFoundException {
final VisitDAO dao = new VisitDAO(hibernateBundle.getSessionFactory());
final Template template = configuration.buildTemplate();
environment.healthChecks().register("template", new TemplateHealthCheck(template));
environment.jersey().register(new VisitResource(dao));
}
@Path("/visits")
@Produces(MediaType.APPLICATION_JSON)
public class VisitResource {
private final VisitDAO visitDAO;
public VisitResource(VisitDAO visitDAO) {
this.visitDAO = visitDAO;
}
@Timed(name = "createVisit")
@POST
@UnitOfWork
public Visit createVist(Visit visit) {
return visitDAO.create(visit);
}
@GET
@UnitOfWork
public List<visit> listVisits() {
return visitDAO.findAll();
}
} </visit>
@Entity
@Table(name = "visits")
@NamedQueries({
@NamedQuery(
name = "com.mystore.core.Visit.findAll",
query = "SELECT v FROM Visit v"
)
})
public class Visit {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "user_id", nullable = false)
private long userId;
@Column(name = "beacon_id", nullable = false)
private String beaconId;
}
public class MySQLHealthCheck extends HealthCheck {
private final SessionFactory sessionFactory
public MySQLHealthCheck(SessionFactory sessionFactory) {
super("MySQL")
this.sessionFactory = sessionFactory
}
@Override
protected com.yammer.metrics.core.HealthCheck.Result check() {
if (!sessionFactory.closed) {
return healthy()
} else {
return unhealthy('Session Factory is Closed!')
}
}
}
Tracking iBeacon Visits from a device.