@@ -0,0 +1,2880 @@
+package glossary.engine;%0A%0Aimport glossary.engine.dao.*;%0Aimport glossary.engine.facade.WritingTestFacade;%0Aimport glossary.engine.facade.WritingTestFacadeImpl;%0Aimport glossary.engine.facade.WritingTestFacadeMock;%0Aimport glossary.engine.model.CardList;%0Aimport glossary.global.exception.DatabaseException;%0A%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.sql.Connection;%0Aimport java.sql.DriverManager;%0Aimport java.sql.SQLException;%0Aimport java.sql.Statement;%0A%0A/**%0A * Created by Pavel M%C3%A1ca %3Cmaca.pavel@gmail.com%3E on 04.07.2017.%0A */%0Apublic class GlossaryEngine %7B%0A    static private String DB_FILE_NAME = %22glossary.db%22;%0A%0A    private Connection connection;%0A%0A%0A    public GlossaryEngine() throws DatabaseException %7B%0A        createDatabaseConnection();%0A    %7D%0A%0A    public CardListDao getCardListDao() %7B%0A        return new CardListDaoMock();%0A    %7D%0A%0A    public CardDao getCardDao() %7B%0A        return new CardDaoMock();%0A    %7D%0A%0A%0A    public WritingTestFacade startWritingTest(int wordCount) %7B%0A        return new WritingTestFacadeMock();%0A    %7D%0A%0A    protected void createDatabaseConnection() throws DatabaseException %7B%0A        Path filepath = Paths.get(DB_FILE_NAME);%0A        boolean createDb = true;%0A        if (Files.exists(filepath)) %7B%0A            createDb = false;%0A        %7D%0A%0A        try %7B%0A            // db parameters%0A            String url = %22jdbc:sqlite:%22 + DB_FILE_NAME;%0A%0A            // create a connection to the database%0A            connection = DriverManager.getConnection(url);%0A%0A            if (createDb) %7B%0A                createDatabase();%0A            %7D%0A        %7D catch (SQLException e) %7B%0A            System.out.println(e.getMessage());%0A            throw new DatabaseException(%22Nelze se p%C5%99ipojit k datab%C3%A1zi.%22);%0A        %7D%0A    %7D%0A%0A    private void createDatabase() throws DatabaseException %7B%0A        try %7B%0A            Statement statement = connection.createStatement();%0A            statement.executeUpdate(%22CREATE TABLE 'card' (%22 +%0A                    %22  'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,%22 +%0A                    %22  'id_list' INTEGER NOT NULL,%22 +%0A                    %22  'word_1' TEXT NOT NULL,%22 +%0A                    %22  'word_2' TEXT NOT NULL, 'priority' INTEGER NOT NULL DEFAULT '1',%22 +%0A                    %22  FOREIGN KEY ('id_list') REFERENCES 'list' ('id') ON DELETE CASCADE%22 +%0A                    %22);%22);%0A%0A            statement.executeUpdate(%22CREATE TABLE 'list' (%22 +%0A                    %22  'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,%22 +%0A                    %22  'name' TEXT NOT NULL%22 +%0A                    %22);%22);%0A        %7D catch (SQLException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A    %7D%0A%0A    public void close() %7B%0A        if (connection != null) %7B%0A            try %7B%0A                connection.close();%0A            %7D catch (SQLException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

add GlossaryEngine