3 |
import java.io.ByteArrayOutputStream; |
import java.io.ByteArrayOutputStream; |
4 |
import java.io.IOException; |
import java.io.IOException; |
5 |
import java.sql.SQLException; |
import java.sql.SQLException; |
6 |
|
import java.util.List; |
7 |
import java.util.logging.Level; |
import java.util.logging.Level; |
8 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
9 |
|
|
10 |
|
import javax.jdo.PersistenceManager; |
11 |
|
import javax.jdo.Query; |
12 |
import javax.servlet.ServletException; |
import javax.servlet.ServletException; |
|
import javax.servlet.annotation.WebServlet; |
|
13 |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServlet; |
14 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletRequest; |
15 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
18 |
import org.simpleframework.xml.core.Persister; |
import org.simpleframework.xml.core.Persister; |
19 |
|
|
20 |
import dk.thoerup.android.traininfo.common.StationBean; |
import dk.thoerup.android.traininfo.common.StationBean; |
21 |
|
import dk.thoerup.traininfoservice.jdo.JdoStationBean; |
22 |
|
import dk.thoerup.traininfoservice.jdo.PMF; |
23 |
|
|
24 |
/** |
/** |
25 |
* Servlet implementation class LocateStations |
* Servlet implementation class LocateStations |
26 |
*/ |
*/ |
27 |
@WebServlet(urlPatterns={"/LocateStations"}) |
|
28 |
public class LocateStations extends HttpServlet { |
public class LocateStations extends HttpServlet { |
29 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
30 |
|
|
88 |
return out.toString(); |
return out.toString(); |
89 |
} |
} |
90 |
|
|
91 |
|
@SuppressWarnings("unchecked") |
92 |
@Override |
@Override |
93 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
94 |
|
|
95 |
|
if (true) { |
96 |
|
PersistenceManager pm = null; |
97 |
|
try { |
98 |
|
pm = PMF.get().getPersistenceManager(); |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
String query = "select from " + JdoStationBean.class.getName() + " where name.matches('Test.*')"; |
104 |
|
List<JdoStationBean> stations = (List<JdoStationBean>) pm.newQuery(query).execute(); |
105 |
|
|
106 |
|
logger.info("size=" + stations.size() ); |
107 |
|
for(JdoStationBean bean : stations) { |
108 |
|
logger.info("Station: " + bean.getId() + "/" + bean.getName()); |
109 |
|
} |
110 |
|
|
111 |
|
/*if (stations.size() == 0) { |
112 |
|
JdoStationBean b = new JdoStationBean(); |
113 |
|
b.setId(1000); |
114 |
|
b.setName("TestStation"); |
115 |
|
b.setMetro("12"); |
116 |
|
pm.makePersistent(b); |
117 |
|
|
118 |
|
JdoStationBean b2 = new JdoStationBean(); |
119 |
|
b2.setId(1001); |
120 |
|
b2.setName("teststation 2"); |
121 |
|
b2.setMetro("12"); |
122 |
|
pm.makePersistent(b2); |
123 |
|
}*/ |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
} finally { |
128 |
|
if (pm != null) |
129 |
|
pm.close(); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
return; |
134 |
|
} |
135 |
|
|
136 |
try { |
try { |
137 |
StationBean stations = getStations(request); |
StationBean stations = getStations(request); |