forked from jsimone/play20ShardExample
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 73e81b2
Showing
20 changed files
with
436 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<classpath> | ||
<classpathentry output="target/scala-2.9.1/classes" path="app" kind="src"></classpathentry> | ||
<classpathentry output="target/scala-2.9.1/test-classes" path="test" kind="src"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/sbt/boot/scala-2.9.1/lib/scala-library.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/play/play_2.9.1/2.0/jars/play_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/play/templates_2.9.1/2.0/jars/templates_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/repository/local/com.github.scala-incubator.io/scala-io-file_2.9.1/0.2.0/jars/scala-io-file_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/repository/local/com.github.scala-incubator.io/scala-io-core_2.9.1/0.2.0/jars/scala-io-core_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/repository/local/com.github.jsuereth.scala-arm/scala-arm_2.9.1/0.3/jars/scala-arm_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/play/anorm_2.9.1/2.0/jars/anorm_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/io.netty/netty/3.3.0.Final/bundles/netty.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.slf4j/slf4j-api/1.6.4/jars/slf4j-api.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.slf4j/jul-to-slf4j/1.6.4/jars/jul-to-slf4j.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.slf4j/jcl-over-slf4j/1.6.4/jars/jcl-over-slf4j.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/ch.qos.logback/logback-core/1.0.0/jars/logback-core.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/ch.qos.logback/logback-classic/1.0.0/jars/logback-classic.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.typesafe.akka/akka-actor/2.0/jars/akka-actor.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.typesafe.akka/akka-slf4j/2.0/jars/akka-slf4j.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.google.guava/guava/10.0.1/jars/guava.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.google.code.findbugs/jsr305/1.3.9/jars/jsr305.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.avaje/ebean/2.7.3/jars/ebean.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.hibernate.javax.persistence/hibernate-jpa-2.0-api/1.0.1.Final/jars/hibernate-jpa-2.0-api.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.h2database/h2/1.3.158/jars/h2.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.scala-tools/scala-stm_2.9.1/0.4/jars/scala-stm_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.jolbox/bonecp/0.7.1.RELEASE/bundles/bonecp.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.yaml/snakeyaml/1.9/bundles/snakeyaml.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.hibernate/hibernate-validator/4.2.0.Final/jars/hibernate-validator.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/javax.validation/validation-api/1.0.0.GA/jars/validation-api.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.springframework/spring-context/3.0.7.RELEASE/jars/spring-context.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.springframework/spring-core/3.0.7.RELEASE/jars/spring-core.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.springframework/spring-beans/3.0.7.RELEASE/jars/spring-beans.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/joda-time/joda-time/2.0/jars/joda-time.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.joda/joda-convert/1.1/jars/joda-convert.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/javassist/javassist/3.12.1.GA/jars/javassist.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/commons-lang/commons-lang/2.6/jars/commons-lang.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.ning/async-http-client/1.7.0/jars/async-http-client.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/oauth.signpost/signpost-core/1.2.1.1/jars/signpost-core.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/commons-codec/commons-codec/1.3/jars/commons-codec.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.codahale/jerkson_2.9.1/0.5.0/jars/jerkson_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.codehaus.jackson/jackson-core-asl/1.9.5/jars/jackson-core-asl.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.codehaus.jackson/jackson-mapper-asl/1.9.5/jars/jackson-mapper-asl.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.reflections/reflections/0.9.6/jars/reflections.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/javax.servlet/javax.servlet-api/3.0.1/jars/javax.servlet-api.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/javax.transaction/jta/1.1/jars/jta.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/tyrex/tyrex/1.0.1/jars/tyrex.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/jaxen/jaxen/1.1.3/jars/jaxen.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/net.sf.ehcache/ehcache-core/2.5.0/jars/ehcache-core.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/play/play-test_2.9.1/2.0/jars/play-test_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.specs2/specs2_2.9.1/1.7.1/jars/specs2_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.specs2/specs2-scalaz-core_2.9.1/6.0.1/jars/specs2-scalaz-core_2.9.1.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/com.novocode/junit-interface/0.8/jars/junit-interface.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/junit/junit/4.8.2/jars/junit.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.scala-tools.testing/test-interface/0.5/jars/test-interface.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.fluentlenium/fluentlenium-festassert/0.5.6/jars/fluentlenium-festassert.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.fluentlenium/fluentlenium-core/0.5.6/jars/fluentlenium-core.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-java/2.16.1/jars/selenium-java.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-android-driver/2.16.1/jars/selenium-android-driver.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-remote-driver/2.16.1/jars/selenium-remote-driver.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/cglib/cglib-nodep/2.1_3/jars/cglib-nodep.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.json/json/20080701/jars/json.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-api/2.16.1/jars/selenium-api.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.apache.httpcomponents/httpclient/4.1.2/jars/httpclient.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.apache.httpcomponents/httpcore/4.1.3/jars/httpcore.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/commons-logging/commons-logging/1.1.1/jars/commons-logging.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/commons-codec/commons-codec/1.4/jars/commons-codec.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.apache.commons/commons-exec/1.1/jars/commons-exec.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/net.java.dev.jna/jna/3.4.0/jars/jna.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/net.java.dev.jna/platform/3.4.0/jars/platform.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-chrome-driver/2.16.1/jars/selenium-chrome-driver.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-htmlunit-driver/2.16.1/jars/selenium-htmlunit-driver.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/net.sourceforge.htmlunit/htmlunit/2.9/jars/htmlunit.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/xalan/xalan/2.7.1/jars/xalan.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/xalan/serializer/2.7.1/jars/serializer.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/xml-apis/xml-apis/1.3.04/jars/xml-apis.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/commons-collections/commons-collections/3.2.1/jars/commons-collections.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.apache.httpcomponents/httpmime/4.1.2/jars/httpmime.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/net.sourceforge.htmlunit/htmlunit-core-js/2.9/jars/htmlunit-core-js.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/xerces/xercesImpl/2.9.1/jars/xercesImpl.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/net.sourceforge.nekohtml/nekohtml/1.9.15/jars/nekohtml.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/net.sourceforge.cssparser/cssparser/0.9.5/jars/cssparser.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.w3c.css/sac/1.3/jars/sac.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/commons-io/commons-io/2.0.1/jars/commons-io.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-firefox-driver/2.16.1/jars/selenium-firefox-driver.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-ie-driver/2.16.1/jars/selenium-ie-driver.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-iphone-driver/2.16.1/jars/selenium-iphone-driver.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.seleniumhq.selenium/selenium-support/2.16.1/jars/selenium-support.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.easytesting/fest-assert/1.4/jars/fest-assert.jar" kind="lib"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/play-2.0/framework/../repository/local/org.easytesting/fest-util/1.1.6/jars/fest-util.jar" kind="lib"></classpathentry> | ||
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"></classpathentry> | ||
<classpathentry path="bin" kind="output"></classpathentry> | ||
<classpathentry path="/Users/johnsimone/dev/supportApps/att/shardExample/target/scala-2.9.1/classes_managed" kind="lib"></classpathentry> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
logs | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
.history | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<projectDescription> | ||
<name>shardExample</name> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.scala-ide.sdt.core.scalabuilder</name> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.scala-ide.sdt.core.scalanature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#Generated by sbteclipse | ||
#Wed May 23 09:24:10 PDT 2012 | ||
Xcheckinit=true | ||
deprecation=true | ||
encoding=utf8 | ||
unchecked=true | ||
scala.compiler.useProjectSettings=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This is your new Play 2.0 application | ||
===================================== | ||
|
||
This file will be packaged with your application, when using `play dist`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package controllers; | ||
|
||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import models.Contact; | ||
import play.mvc.Controller; | ||
import play.mvc.Result; | ||
import play.mvc.Http.RequestBody; | ||
import service.ContactService; | ||
import views.html.index; | ||
|
||
public class Application extends Controller { | ||
|
||
public static Result index() { | ||
try { | ||
List<Contact> contacts = ContactService.listContacts(); | ||
} catch(SQLException e) { | ||
e.printStackTrace(); | ||
return internalServerError(); | ||
} | ||
return ok(index.render("Your new application is ready.")); | ||
} | ||
|
||
public static Result insert() { | ||
Contact contact = new Contact(); | ||
RequestBody body = request().body(); | ||
Map<String, String[]> postData = body.asFormUrlEncoded(); | ||
contact.setFirstName(postData.get("firstName")[0]); | ||
contact.setFirstName(postData.get("lastName")[0]); | ||
contact.setFirstName(postData.get("phone")[0]); | ||
contact.setFirstName(postData.get("address")[0]); | ||
contact.setFirstName(postData.get("zip")[0]); | ||
try { | ||
ContactService.createContact(contact); | ||
} catch(SQLException e) { | ||
e.printStackTrace(); | ||
return internalServerError(); | ||
} | ||
return redirect("/"); | ||
} | ||
|
||
public static Result update(Long contactId) { | ||
return ok(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package models; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class Contact { | ||
|
||
private Long id; | ||
private String firstName; | ||
private String lastName; | ||
private String phone; | ||
private String address; | ||
private String zip; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
public String getFirstName() { | ||
return firstName; | ||
} | ||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
public String getLastName() { | ||
return lastName; | ||
} | ||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
public String getPhone() { | ||
return phone; | ||
} | ||
public void setPhone(String phone) { | ||
this.phone = phone; | ||
} | ||
public String getAddress() { | ||
return address; | ||
} | ||
public void setAddress(String address) { | ||
this.address = address; | ||
} | ||
public String getZip() { | ||
return zip; | ||
} | ||
public void setZip(String zip) { | ||
this.zip = zip; | ||
} | ||
|
||
public static Contact createFromResultSet(ResultSet rs) throws SQLException { | ||
Contact contact = new Contact(); | ||
contact.setId(rs.getLong("id")); | ||
contact.setFirstName(rs.getString("firstName")); | ||
contact.setLastName(rs.getString("lastName")); | ||
contact.setPhone(rs.getString("phone")); | ||
contact.setAddress(rs.getString("address")); | ||
return contact; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package service; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import models.Contact; | ||
import play.db.DB; | ||
|
||
public class ContactService { | ||
|
||
public static Connection getConnection() { | ||
return DB.getConnection("db1"); | ||
} | ||
|
||
public static List<Contact> listContacts() throws SQLException { | ||
List<Contact> contacts = new ArrayList<Contact>(); | ||
Connection conn = null; | ||
try { | ||
getConnection(); | ||
String query = "select id, firstName, lastName, phone, address, zip from contacts"; | ||
PreparedStatement stmt = conn.prepareStatement(query); | ||
ResultSet rs = stmt.executeQuery(); | ||
while(rs.next()) { | ||
contacts.add(Contact.createFromResultSet(rs)); | ||
} | ||
} finally { | ||
conn.close(); | ||
} | ||
|
||
return contacts; | ||
} | ||
|
||
public static void createContact(Contact contact) throws SQLException { | ||
Connection conn = null; | ||
try { | ||
conn = getConnection(); | ||
String query = "insert into contacts (firstName, lastName, phone, address, zip) values (?,?,?,?,?)"; | ||
PreparedStatement stmt = conn.prepareStatement(query); | ||
stmt.setString(1, contact.getFirstName()); | ||
stmt.setString(2, contact.getLastName()); | ||
stmt.setString(3, contact.getPhone()); | ||
stmt.setString(4, contact.getAddress()); | ||
stmt.setString(5, contact.getZip()); | ||
stmt.executeUpdate(); | ||
} finally { | ||
conn.close(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.