I Will post the code, hopefully it doesnt look to bad on here.
HibernateApplication.java
package com.example;
import com.example.Testing;
import com.example.TestingDAO;
import com.example.TestingResource;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.auth.AuthDynamicFeature;
import io.dropwizard.auth.AuthValueFactoryProvider;
import io.dropwizard.auth.basic.BasicCredentialAuthFilter;
import io.dropwizard.configuration.EnvironmentVariableSubstitutor;
import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.hibernate.HibernateBundle;
import io.dropwizard.migrations.MigrationsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.views.ViewBundle;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import java.util.Map;
public class HibernateApplication extends
Application<HibernateConfiguration> {
public static void main(String[] args) throws Exception {
System.out.println("GKLOJGAOKFOKAGK");
new HibernateApplication().run(args);
}
private final HibernateBundle<HibernateConfiguration> hibernate = new
HibernateBundle<HibernateConfiguration>(Testing.class){
@Override
public DataSourceFactory
getDataSourceFactory(HibernateConfiguration configuration){
return configuration.getDataSourceFactory();
}
};
@Override
public String getName() {
return "hello-world";
}
@Override
public void initialize(Bootstrap<HibernateConfiguration>
bootstrap){bootstrap.addBundle(hibernate);}
// public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap)
{
// // Enable variable substitution with environment variables
// bootstrap.setConfigurationSourceProvider(
// new SubstitutingSourceProvider(
// bootstrap.getConfigurationSourceProvider(),
// new EnvironmentVariableSubstitutor(false)
// )
// );
//
// bootstrap.addCommand(new RenderCommand());
// bootstrap.addBundle(new AssetsBundle());
// bootstrap.addBundle(new
MigrationsBundle<HelloWorldConfiguration>() {
// @Override
// public DataSourceFactory
getDataSourceFactory(HelloWorldConfiguration configuration) {
// return configuration.getDataSourceFactory();
// }
// });
// bootstrap.addBundle(hibernateBundle);
// bootstrap.addBundle(new ViewBundle<HelloWorldConfiguration>() {
// @Override
// public Map<String, Map<String, String>>
getViewConfiguration(HelloWorldConfiguration configuration) {
// return configuration.getViewRendererConfiguration();
// }
// });
// }
@Override
public void run(HibernateConfiguration config, Environment environment){
System.out.println("qwtwerwerqwer");
final TestingDAO dao = new
TestingDAO(hibernate.getSessionFactory());
environment.jersey().register(new TestingResource(dao));
}
}
Testing.java
package com.example;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.util.Objects;
@Entity
@Table(name = "testing")
public class Testing {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "tick", nullable = false)
private String timeTick;
public Testing() {
}
public String getTimeTick(){
return timeTick;
}
@Column(name = "tick", nullable = false)
public void setTimeTick(String timeTick){
this.timeTick = timeTick;
}
public void insert(){
System.out.println("hi");
}
}
TestingDAO.java
package com.example;
import com.example.Testing;
import io.dropwizard.hibernate.AbstractDAO;
import org.hibernate.SessionFactory;
import java.util.List;
import java.util.Optional;
public class TestingDAO extends AbstractDAO<Testing> {
public TestingDAO(SessionFactory factory) {
super(factory);
}
public Testing create(Testing timeTick) {
return persist(timeTick);
}
}
TestingResource.java
package com.example;
import com.example.Testing;
import com.example.TestingDAO;
import io.dropwizard.hibernate.UnitOfWork;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;
@Path("/insert")
@Produces(MediaType.APPLICATION_JSON)
public class TestingResource {
private final TestingDAO testingDAO;
public TestingResource(TestingDAO testingDAO) {
this.testingDAO = testingDAO;
}
@POST
@UnitOfWork
public Testing createTesting(Testing TimeTick) {
return testingDAO.create(TimeTick);
}
}
--
You received this message because you are subscribed to the Google Groups
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.