Guest User

Untitled

a guest
Dec 11th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. package dbms;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.Path;
  7. import java.nio.file.Paths;
  8. import java.util.ArrayList;
  9.  
  10. public class DBMS implements IDBMS{
  11.  
  12.  
  13. private DataBase db = new DataBase ();
  14. private String protocol;
  15. private String userName;
  16. private String password;
  17. /// 5ly constructor el dbms y5od protocol w username w password //?? w path ?
  18. public DBMS (String protocol,String userName,String password){
  19. this.protocol=protocol;
  20. this.userName=userName;
  21. this.password=password;
  22. try {
  23. if (!Files.exists(Constants.homeDir)){
  24. Files.createDirectory(Constants.homeDir);
  25. }
  26. } catch (IOException e) {
  27. e.printStackTrace();
  28. }
  29. }
  30.  
  31.  
  32. public void createDB(String dbName) {
  33. // TODO Auto-generated method stub
  34. Path dbPath = Paths.get(Constants.homeDir + File.separator + dbName);
  35. //if directory exists?
  36. if (!Files.exists(dbPath)) {
  37. try {
  38. Files.createDirectory(dbPath);
  39. Logs.printDBcreated();
  40. } catch (IOException e) {
  41. //fail to create directory
  42. e.printStackTrace();
  43. }
  44. }
  45. else{
  46. Logs.printDBDuplicate();
  47. }
  48. }
  49.  
  50. public void useDB (String dbName){
  51. db.setDataBase(dbName);
  52. }
  53.  
  54. public void dropDB(String dbName){
  55. Path dbPath = Paths.get(Constants.homeDir+File.separator
  56.  
  57. +dbName);
  58. try{
  59. if (Files.isDirectory(dbPath)){
  60. File[] dbTables = dbPath.toFile().listFiles();
  61. for (int i=0; i<dbTables.length;i++){
  62. File[] innerFiles = dbTables[i].listFiles();
  63. for (int j=0; j< innerFiles.length;j++){
  64. innerFiles[j].delete();
  65. }
  66. dbTables[i].delete();
  67. }
  68. Files.delete(dbPath);
  69. Logs.printDBdeleted(dbName);
  70. }
  71. else{
  72. Logs.printNoDB();
  73. }
  74. } catch (IOException e){
  75. Logs.printError();
  76. e.printStackTrace();
  77. }
  78. }
  79.  
  80. public void changeDBStructure(int mode, ArrayList<String> query){
  81. db.changeDBStructure(mode, query);
  82. }
  83.  
  84. public int excuteUpdateQuery(int mode, ArrayList<String> query){
  85.  
  86. return db.updateTables(mode, query);
  87.  
  88. }
  89.  
  90.  
  91. public ResultSet selectQuery(ArrayList<String> query){
  92. //
  93. return db.selectQuery(query);
  94. }
  95.  
  96. public int selectQueryLog (){
  97. return db.errorSelectQuery();
  98. }
  99. }
Add Comment
Please, Sign In to add comment