Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbms;
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- public class DBMS implements IDBMS{
- private DataBase db = new DataBase ();
- private String protocol;
- private String userName;
- private String password;
- /// 5ly constructor el dbms y5od protocol w username w password //?? w path ?
- public DBMS (String protocol,String userName,String password){
- this.protocol=protocol;
- this.userName=userName;
- this.password=password;
- try {
- if (!Files.exists(Constants.homeDir)){
- Files.createDirectory(Constants.homeDir);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void createDB(String dbName) {
- // TODO Auto-generated method stub
- Path dbPath = Paths.get(Constants.homeDir + File.separator + dbName);
- //if directory exists?
- if (!Files.exists(dbPath)) {
- try {
- Files.createDirectory(dbPath);
- Logs.printDBcreated();
- } catch (IOException e) {
- //fail to create directory
- e.printStackTrace();
- }
- }
- else{
- Logs.printDBDuplicate();
- }
- }
- public void useDB (String dbName){
- db.setDataBase(dbName);
- }
- public void dropDB(String dbName){
- Path dbPath = Paths.get(Constants.homeDir+File.separator
- +dbName);
- try{
- if (Files.isDirectory(dbPath)){
- File[] dbTables = dbPath.toFile().listFiles();
- for (int i=0; i<dbTables.length;i++){
- File[] innerFiles = dbTables[i].listFiles();
- for (int j=0; j< innerFiles.length;j++){
- innerFiles[j].delete();
- }
- dbTables[i].delete();
- }
- Files.delete(dbPath);
- Logs.printDBdeleted(dbName);
- }
- else{
- Logs.printNoDB();
- }
- } catch (IOException e){
- Logs.printError();
- e.printStackTrace();
- }
- }
- public void changeDBStructure(int mode, ArrayList<String> query){
- db.changeDBStructure(mode, query);
- }
- public int excuteUpdateQuery(int mode, ArrayList<String> query){
- return db.updateTables(mode, query);
- }
- public ResultSet selectQuery(ArrayList<String> query){
- //
- return db.selectQuery(query);
- }
- public int selectQueryLog (){
- return db.errorSelectQuery();
- }
- }
Add Comment
Please, Sign In to add comment