Using JDA

This commit is contained in:
Norbi Peti 2016-07-18 14:36:33 +02:00
parent 686e3a3eae
commit 2d2cc3c924
5 changed files with 41 additions and 10 deletions

View file

@ -28,6 +28,12 @@
<artifactId>derbyclient</artifactId>
<version>10.12.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.1.Final</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>

View file

@ -8,7 +8,7 @@ public class IndexPage extends Page {
@Override
public void handle(HttpExchange exchange) throws IOException {
IOHelper.SendResponse(200, "<h1>Index</h1>", exchange);
}
}

View file

@ -11,6 +11,8 @@ import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import io.github.norbipeti.chat.server.db.DataProvider;
public class Main {
// public static final HashMap<String, Page> Pages = new HashMap<String,
// Page>();
@ -20,15 +22,9 @@ public class Main {
// https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/
// https://docs.oracle.com/javase/8/docs/api/
System.out.println("Loading database...");
Connection conn = DriverManager.getConnection("jdbc:derby:memory:chatserver;create=true");
Statement statement = conn.createStatement();
if (statement.execute("CREATE TABLE users ( username varchar(255), password varchar(255), id int )"))
System.out.println("Created users table");
else
System.out.println("Failed to create users table!");
ResultSet results = statement.executeQuery("SELECT * FROM users");
while (results.next())
results.getString(0);
try (DataProvider provider = new DataProvider()) {
}
System.out.println("Starting webserver...");
HttpServer server = HttpServer.create(new InetSocketAddress(InetAddress.getLocalHost(), 8080), 10);
server.createContext("/").setHandler(new IndexPage());

View file

@ -0,0 +1,18 @@
package io.github.norbipeti.chat.server.db;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class DataProvider implements AutoCloseable {
private EntityManagerFactory emf;
public DataProvider() {
Persistence.createEntityManagerFactory("ChatServerPU");
}
@Override
public void close() {
if (emf != null)
emf.close();
}
}

View file

@ -0,0 +1,11 @@
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="ChatServerPU">
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:chatserver;create=true" />
</properties>
</persistence-unit>
</persistence>