00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 package roboearth.wp5.conn;
00050
00051 import java.io.File;
00052 import java.sql.Connection;
00053 import java.sql.DriverManager;
00054 import java.sql.PreparedStatement;
00055 import java.sql.ResultSet;
00056 import java.sql.SQLException;
00057 import java.sql.Statement;
00058 import java.util.ArrayList;
00059
00060 import org.semanticweb.owlapi.model.OWLOntology;
00061
00062 import roboearth.wp5.owl.OWLIO;
00063
00064
00076 public class REConnectionMySQL implements REInterface {
00077
00078
00082 public final static String roboEarthMysqlHost = "atradig131.informatik.tu-muenchen.de";
00083
00087 public final static String roboEarthMysqlDB = "roboearth";
00088
00092 public final static String roboEarthMysqlUser = "roboearth";
00093
00097 public final static String roboEarthMysqlPassword = "RoboEarth2010";
00098
00099
00100 protected Connection conn = null;
00101
00102
00103 public REConnectionMySQL() {
00104
00105 try {
00106 Class.forName("com.mysql.jdbc.Driver").newInstance();
00107 conn = DriverManager.getConnection("jdbc:mysql://"+roboEarthMysqlHost+"/"+
00108 roboEarthMysqlDB+"?" +
00109 "user="+roboEarthMysqlUser+
00110 "&password="+roboEarthMysqlPassword);
00111
00112 } catch (SQLException ex) {
00113
00114 System.out.println("SQLException: " + ex.getMessage());
00115 System.out.println("SQLState: " + ex.getSQLState());
00116 System.out.println("VendorError: " + ex.getErrorCode());
00117
00118 } catch (Exception ex) {
00119 ex.printStackTrace();
00120 }
00121
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 @Override
00131 public String requestActionRecipe(String id) {
00132
00133 String recipe = null;
00134
00135 if (id != null && id.length()>0) {
00136
00137 String query = "SELECT title, tags, description, recipe from actionrecipes where title='"+id+"'";
00138 String owlDescription="";
00139
00140 Statement stmt = null;
00141 ResultSet rs = null;
00142
00143 try {
00144 stmt = conn.createStatement();
00145 rs = stmt.executeQuery(query);
00146
00147
00148 if (!rs.next()) {
00149 System.out.println("No recipe found.");
00150 } else {
00151
00152
00153 owlDescription = cleanOWLString(rs.getString(4));
00154 recipe = owlDescription;
00155 }
00156 }
00157 catch (SQLException ex){
00158
00159 System.out.println("SQLException: " + ex.getMessage());
00160 System.out.println("SQLState: " + ex.getSQLState());
00161 System.out.println("VendorError: " + ex.getErrorCode());
00162 }
00163 finally {
00164
00165 if (rs != null) {
00166 try {
00167 rs.close();
00168 } catch (SQLException sqlEx) { }
00169
00170 rs = null;
00171 }
00172
00173 if (stmt != null) {
00174 try {
00175 stmt.close();
00176 } catch (SQLException sqlEx) { }
00177
00178 stmt = null;
00179 }
00180 }
00181
00182
00183 }
00184
00185 return recipe;
00186
00187 }
00188
00189
00190
00191 public String requestEnvironment(String id) {
00192
00193 String map = null;
00194
00195 if (id != null && id.length()>0) {
00196
00197 String query = "SELECT title, tags, description, map from maps where title='"+id+"'";
00198 String owlDescription="";
00199
00200 Statement stmt = null;
00201 ResultSet rs = null;
00202
00203 try {
00204 stmt = conn.createStatement();
00205 rs = stmt.executeQuery(query);
00206
00207
00208 if (!rs.next()) {
00209 System.out.println("No environment found.");
00210 } else {
00211
00212
00213 owlDescription = cleanOWLString(rs.getString(4));
00214 map = owlDescription;
00215 }
00216 }
00217 catch (SQLException ex){
00218
00219 System.out.println("SQLException: " + ex.getMessage());
00220 System.out.println("SQLState: " + ex.getSQLState());
00221 System.out.println("VendorError: " + ex.getErrorCode());
00222 }
00223 finally {
00224
00225 if (rs != null) {
00226 try {
00227 rs.close();
00228 } catch (SQLException sqlEx) { }
00229
00230 rs = null;
00231 }
00232
00233 if (stmt != null) {
00234 try {
00235 stmt.close();
00236 } catch (SQLException sqlEx) { }
00237
00238 stmt = null;
00239 }
00240 }
00241
00242
00243 }
00244
00245 return map;
00246
00247 }
00248
00249
00250 @Override
00251 public boolean submitActionRecipe(OWLOntology actionRecipe, String id, String tags, String description) {
00252
00253 boolean ok = false;
00254
00255 if (actionRecipe != null && id != null && tags != null && description != null) {
00256
00257 try{
00258 PreparedStatement stmt = conn.prepareStatement("INSERT INTO actionrecipes(title, tags, description, recipe)" +
00259 " VALUES(?, ?, ?, ?)");
00260
00261 stmt.setString(1, id);
00262 stmt.setString(2, tags);
00263 stmt.setString(3, description);
00264
00265 String owlData = OWLIO.saveOntologyToString(actionRecipe, actionRecipe.getOWLOntologyManager().getOntologyFormat(actionRecipe));
00266 stmt.setString(4, owlData);
00267
00268 stmt.executeUpdate();
00269
00270 ok=true;
00271
00272 } catch (SQLException e) {
00273 e.printStackTrace();
00274 }
00275 }
00276
00277 return ok;
00278
00279 }
00280
00281 @Override
00282 public boolean submitEnvironment(OWLOntology map, String id, String tags, String description) {
00283
00284 boolean ok = false;
00285
00286 if (map != null && id != null && tags != null && description != null) {
00287
00288
00289 try{
00290 PreparedStatement stmt = conn.prepareStatement("INSERT INTO maps(title, tags, description, map)" +
00291 " VALUES(?, ?, ?, ?)");
00292
00293 stmt.setString(1, id);
00294 stmt.setString(2, tags);
00295 stmt.setString(3, description);
00296
00297 String owlData = OWLIO.saveOntologyToString(map, map.getOWLOntologyManager().getOntologyFormat(map));
00298 stmt.setString(4, owlData);
00299
00300 stmt.executeUpdate();
00301
00302 ok=true;
00303
00304 } catch (SQLException e) {
00305 e.printStackTrace();
00306 }
00307 }
00308
00309 return ok;
00310
00311 }
00312
00319 public static String cleanOWLString(String owlData) {
00320
00321 return owlData.replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", "\"").replaceAll("\t", "").trim();
00322
00323 }
00324
00328 public static void main(String[] args) {
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 }
00368
00369
00370
00371
00372 @Override
00373 public boolean deleteActionRecipe(String uid) {
00374
00375 return false;
00376 }
00377
00378
00379
00380
00381 @Override
00382 public boolean deleteEnvironment(String uid) {
00383
00384 return false;
00385 }
00386
00387
00388
00389
00390 @Override
00391 public boolean deleteEnvironmentBinaryFile(String uid, String filename) {
00392
00393 return false;
00394 }
00395
00396
00397
00398
00399 @Override
00400 public boolean deleteObject(String uid) {
00401
00402 return false;
00403 }
00404
00405
00406
00407
00408 @Override
00409 public boolean deleteObjectBinaryFile(String uid, String filename) {
00410
00411 return false;
00412 }
00413
00414
00415
00416
00417 @Override
00418 public String queryActionRecipeDB(String seRQLquery) {
00419
00420 return null;
00421 }
00422
00423
00424
00425
00426 @Override
00427 public String queryEnvironmentDB(String seRQLquery) {
00428
00429 return null;
00430 }
00431
00432
00433
00434
00435 @Override
00436 public String queryObjectDB(String seRQLquery) {
00437
00438 return null;
00439 }
00440
00441
00442
00443
00444 @Override
00445 public String requestEnvironment(String uid,
00446 ArrayList<String> outFilenames, ArrayList<String> outFileURLs) {
00447
00448 return null;
00449 }
00450
00451
00452
00453
00454 @Override
00455 public File requestEnvironmentBinaryFile(String objectUID, String filename,
00456 String targetPath) {
00457
00458 return null;
00459 }
00460
00461
00462
00463
00464 @Override
00465 public byte[] requestEnvironmentBinaryFile(String objectUID, String filename) {
00466
00467 return null;
00468 }
00469
00470
00471
00472
00473 @Override
00474 public String requestObject(String uid, ArrayList<String> outFilenames,
00475 ArrayList<String> outFileURLs) {
00476
00477 return null;
00478 }
00479
00480
00481
00482
00483 @Override
00484 public File requestObjectBinaryFile(String objectUID, String filename,
00485 String targetPath) {
00486
00487 return null;
00488 }
00489
00490
00491
00492
00493 @Override
00494 public byte[] requestObjectBinaryFile(String objectUID, String filename) {
00495
00496 return null;
00497 }
00498
00499
00500
00501
00502 @Override
00503 public String[] searchActionRecipes(String searchID,
00504 ArrayList<String> outUIDs) {
00505
00506 return null;
00507 }
00508
00509
00510
00511
00512 @Override
00513 public String[] searchEnvironments(String searchID,
00514 ArrayList<String> outUIDs,
00515 ArrayList<ArrayList<String>> outFilenames,
00516 ArrayList<ArrayList<String>> outFileURLs) {
00517
00518 return null;
00519 }
00520
00521
00522
00523
00524 @Override
00525 public String[] searchObjects(String searchID, ArrayList<String> outUIDs,
00526 ArrayList<ArrayList<String>> outFilenames,
00527 ArrayList<ArrayList<String>> outFileURLs) {
00528
00529 return null;
00530 }
00531
00532
00533
00534
00535 @Override
00536 public boolean submitEnvironment(OWLOntology env, String cls, String id,
00537 String description, ArrayList<File> binaryFiles) {
00538
00539 return false;
00540 }
00541
00542
00543
00544
00545 @Override
00546 public boolean submitEnvironment(OWLOntology env, String cls, String id,
00547 String description, ArrayList<byte[]> binaryData,
00548 ArrayList<String> filenames) {
00549
00550 return false;
00551 }
00552
00553
00554
00555
00556 @Override
00557 public boolean submitEnvironmentBinaryFile(String uid, File file) {
00558
00559 return false;
00560 }
00561
00562
00563
00564
00565 @Override
00566 public boolean submitEnvironmentBinaryFile(String uid, byte[] data,
00567 String filename) {
00568
00569 return false;
00570 }
00571
00572
00573
00574
00575 @Override
00576 public boolean submitObject(OWLOntology objectOwl, String cls, String id,
00577 String description) {
00578
00579 return false;
00580 }
00581
00582
00583
00584
00585 @Override
00586 public boolean submitObject(OWLOntology objectOwl, String cls, String id,
00587 String description, ArrayList<File> binaryFiles) {
00588
00589 return false;
00590 }
00591
00592
00593
00594
00595 @Override
00596 public boolean submitObject(OWLOntology objectOwl, String cls, String id,
00597 String description, ArrayList<byte[]> binaryData,
00598 ArrayList<String> filenames) {
00599
00600 return false;
00601 }
00602
00603
00604
00605
00606 @Override
00607 public boolean submitObjectBinaryFile(String uid, File file) {
00608
00609 return false;
00610 }
00611
00612
00613
00614
00615 @Override
00616 public boolean submitObjectBinaryFile(String uid, byte[] data,
00617 String filename) {
00618
00619 return false;
00620 }
00621
00622
00623
00624
00625 @Override
00626 public boolean updateActionRecipe(String uid, OWLOntology actionRecipe,
00627 String description) {
00628
00629 return false;
00630 }
00631
00632
00633
00634
00635 @Override
00636 public boolean updateEnvironment(String uid, OWLOntology env,
00637 String description) {
00638
00639 return false;
00640 }
00641
00642
00643
00644
00645 @Override
00646 public boolean updateEnvironmentBinaryFile(String uid, File file) {
00647
00648 return false;
00649 }
00650
00651
00652
00653
00654 @Override
00655 public boolean updateEnvironmentBinaryFile(String uid, byte[] data,
00656 String filename) {
00657
00658 return false;
00659 }
00660
00661
00662
00663
00664 @Override
00665 public boolean updateObject(String uid, OWLOntology objectOwl,
00666 String description) {
00667
00668 return false;
00669 }
00670
00671
00672
00673
00674 @Override
00675 public boolean updateObjectBinaryFile(String uid, File file) {
00676
00677 return false;
00678 }
00679
00680
00681
00682
00683 @Override
00684 public boolean updateObjectBinaryFile(String uid, byte[] data,
00685 String filename) {
00686
00687 return false;
00688 }
00689
00690
00691
00692
00693 @Override
00694 public ArrayList<byte[]> request2dMap(String envUid, OWLOntology srdl,
00695 String baseScannerLink, String simpleMapNameWithoutExt) {
00696
00697 return null;
00698 }
00699
00700
00701
00702
00703 @Override
00704 public ArrayList<byte[]> requestProjected2dMap(String envUid, double minZ,
00705 double maxZ, String simpleMapNameWithoutExt) {
00706
00707 return null;
00708 }
00709
00710
00711
00712
00713
00714
00715
00716 @Override
00717 public boolean updateObject(String uid, String objectOwl, String description) {
00718
00719 return false;
00720 }
00721
00722
00723
00724
00725
00726
00727
00728 @Override
00729 public String requestRobot(String uid) {
00730
00731 return null;
00732 }
00733
00734
00735
00736
00737
00738
00739
00740 @Override
00741 public boolean submitActionRecipe(String actionRecipe, String cls,
00742 String id, String description) {
00743
00744 return false;
00745 }
00746
00747
00748
00749
00750
00751
00752
00753 @Override
00754 public boolean submitEnvironment(String env, String cls, String id,
00755 String description) {
00756
00757 return false;
00758 }
00759
00760
00761
00762
00763
00764
00765
00766 @Override
00767 public boolean submitEnvironment(String env, String cls, String id,
00768 String description, ArrayList<File> binaryFiles) {
00769
00770 return false;
00771 }
00772
00773
00774
00775
00776
00777
00778
00779 @Override
00780 public boolean submitEnvironment(String env, String cls, String id,
00781 String description, ArrayList<byte[]> binaryData,
00782 ArrayList<String> filenames) {
00783
00784 return false;
00785 }
00786
00787
00788
00789
00790
00791
00792
00793 @Override
00794 public boolean submitObject(String objectOwl, String cls, String id,
00795 String description) {
00796
00797 return false;
00798 }
00799
00800
00801
00802
00803
00804
00805
00806 @Override
00807 public boolean submitObject(String objectOwl, String cls, String id,
00808 String description, ArrayList<File> binaryFiles) {
00809
00810 return false;
00811 }
00812
00813
00814
00815
00816
00817
00818
00819 @Override
00820 public boolean submitObject(String objectOwl, String cls, String id,
00821 String description, ArrayList<byte[]> binaryData,
00822 ArrayList<String> filenames) {
00823
00824 return false;
00825 }
00826
00827
00828
00829
00830
00831
00832
00833 @Override
00834 public boolean updateActionRecipe(String uid, String actionRecipe,
00835 String description) {
00836
00837 return false;
00838 }
00839
00840
00841
00842
00843
00844
00845
00846 @Override
00847 public boolean updateEnvironment(String uid, String env, String description) {
00848
00849 return false;
00850 }
00851
00852
00853 }