Code Monkey home page Code Monkey logo

database-engine's Introduction

Database-Engine

Database Engine that supports some features like:

  • Creating a table
  • Inserting into a table
  • Updating a table
  • Deleting from a table
  • Selecting from a table
  • Creating an Index -using Octree-
  • Writing SQL queries
  • Supported data types: int (java.lang.Integer), double (java.lang.Double), date (java.util.Date), varchar (java.lang.String)

Java CI with Maven

Apache Maven badge Github Actions badge Junit 5 badge Git badge Github badge Dependabot badge Checkstyle badge Java badge ANTLR badge

Tools


How to run tests and checks:

  • Make sure to have Apache Maven installed on your pc.
  • To run checkStyle checks run the following command : mvn checkstyle:check
  • To run Junit5 tests run the following command : mvn test

Code examples

Normal Selection

SQLTerm[] sqlTerms = new SQLTerm[2];
sqlTerms[0] = new SQLTerm("Students", "gpa", "=", 4.0);
sqlTerms[1] = new SQLTerm("Students", "id", ">", 100);
String[] strArrOperator = new String[] { "AND" };
engine.selectFromTable(sqlTerms, strArrOperator);

Selection Using SQL

StringBuffer command = new StringBuffer("SELECT * FROM Students WHERE gpa = 4.0 AND id > 100");
engine.parseSQL(command);

Normal Insertion

Hashtable<String, Object> htblColNameValue = new Hashtable<>();
htblColNameValue.put("id", 1);
htblColNameValue.put("name", "student1");
htblColNameValue.put("gpa", 3.3);
engine.insertIntoTable("Students", htblColNameValue);

Insertion Using SQL

StringBuffer command = new StringBuffer("INSERT INTO Students(id, gpa, name) VALUES(1, 3.3, 'student1')");
		engine.parseSQL(command);

Normal Deletion

Hashtable<String, Object> htblColNameValue = new Hashtable<>();
htblColNameValue.put("gpa", 3.3);
engine.DeleteFromTable("Students", htblColNameValue);

Deletion Using SQL

StringBuffer command = new StringBuffer("DELETE FROM  Students WHERE gpa = 3.3");
		engine.parseSQL(command);

Project Structure

Expand
- project-name/
|- src/
   |- main/
      |- java/
         |- app/
            |- Action.java
            |- DBApp.java
            |- IDatabase.java
         |- constants/
            |- Constants.java
         |- datamanipulation/
            |- CsvReader.java
            |- CsvWriter.java
         |- exceptions/
            |- DBAppException.java
         |- sql/
            |- SQLTerm.java
            |- antlrfiles/
               |- SQLiteLexer.java
               |- SQLiteParser.java
               |- SQLiteParserBaseListener.java
               |- SQLiteParserBaseVisitor.java
               |- SQLiteParserListener.java
               |- SQLiteParserVisitor.java
               |- SQLiteLexer.interp
               |- SQLiteLexer.tokens
               |- SQLiteParser.interp
               |- SQLiteParser.tokens
            |- parser/
               |- MiniDBListener.java
               |- SQLParser.java
         |- storage/
            |- Cell.java
            |- Table.java
            |- Page.java
            |- Tuple.java
            |- TupleBuilder.java
            |- TupleDirector.java
            |- ITupleBuilder.java
            |- ITupleDirector.java
            |- index/
               |- DBAppNull.java
               |- Item.java
               |- Vector3.java
               |- OctreeIndex.java
               |- OctreeNode.java
               |- OctreeBounds.java
         |- util/
            |- Compare.java
            |- PagePrinter.java
            |- TypeParser.java
            |- filecontroller/
               |- ConfigReader.java
               |- FileCreator.java
               |- FileDeleter.java
               |- FileType.java
               |- Serializer.java
            |- search/
               |- PageSearch.java
               |- TupleSearch.java
               |- Selector.java
            |- validation/
               |- Validator.java
   |- test/
      |- java/
         |- app/
            |- DBAppTest.java

Run Locally

1- Clone the project

  git clone https://github.com/YehiaFarghaly/Database-Engine.git

2- Go to the project directory

3- Build the project using Maven

  mvn clean

4- Run Javafx project using Maven

  mvn javafx:run

Notes

  • There is a ready table called student with the following columns (ID: int, GPA: Double, Name: String)

Screenshots

Selection Example

Screenshot (130)

Insertion Example

Screenshot (131)

Deletion Example

Screenshot (132)

License

MIT License

Authors

database-engine's People

Contributors

abdulrhman500 avatar aelmeky avatar dependabot[bot] avatar malekelkssas avatar mohamed-khaled308 avatar yehiafarghaly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

database-engine's Issues

Unit tests

Unit tests need to be written for milestone 2

Validation methods are needed for insertion

I added 2 methods in the validator class :

  1. validTable(String tableName) -> this one should check if the name of the table exists in the database.

  2. validTuple(HashTable<String,Object> tuple) -> this one should make sure that the primary key does not exist already in the table, and that the input data is consistent with the datatypes defined for this table

Need someone to implement them @Aelmeky

Check if table name already exists

if table already exists
1> it adds data(colNameType + min + max) again to the metadata.csv file
2> min and max are allowed to be null

 public static void main(String args[]) throws DBAppException, IOException {

        DBApp app = new DBApp();
        app.init();
        String tableName = "Employee";
        String PK = "id";
        Hashtable<String, String> nameType = new Hashtable<>();
        nameType.put("id", Constants.INTEGER_DATA_TYPE_NAME);
        nameType.put("firstName", Constants.STRING_DATA_TYPE_NAME);
        nameType.put("lastName", Constants.STRING_DATA_TYPE_NAME);
        nameType.put("phone", Constants.STRING_DATA_TYPE_NAME);
        nameType.put("qqq", Constants.STRING_DATA_TYPE_NAME);  **//  it does not have min or max but still accepted with no exception** 


        Hashtable<String, String> nameMin = new Hashtable<>();

        nameMin.put("id", "0");
        nameMin.put("firstName", "a");
        nameMin.put("lastName", "a");
        nameMin.put("phone", "0000000000");


        Hashtable<String, String> nameMax = new Hashtable<>();

        nameMax.put("id", "10000");
        nameMax.put("firstName", "zzz");
        nameMax.put("lastName", "zb");
        nameMax.put("phone", "9999999999999");


        app.createTable(tableName, PK, nameType, nameMin, nameMax);

     System.out.println(app.getMyTables());
}

the compareTo method

the compareTo method cause in logical error because of trying to compare between different types that are not compatible.

Select Method

The select method needs to be implemented by who ever finishes his task first.

Code needs more formatting

After testing, code needs to be written in more readable way, Javadocs has to be added for the new methods and duplicates should be removed

handling nulls

you should handle the nulls in insertion (do not forget to use DBAppnull)

SQL Parcer

We need the SQL parser to handle all operations allowed in our database @abdulrhman500 by Wednesday at maximum

Logical error in inserting in a full page.

When inserting a record to a page which is full, the correct functionality is :

  1. Insert the record the current page
  2. Create a new page
  3. Shift the last record in the current page to the new page
    But what happens is that the current page gets one more record than its max size and a new record is inserted in the new page

Insert using Index

Need to handle the case when Index is created on the Clustering key column

User Interface

Need a simple UI terminal to write SQL queries and execute them

Update using Index

We need to edit the update method now to handle the case in which an index is implemented on the Clustering Key Column @Aelmeky by Wednesday at maximum

Missing validation case (1)

During test found the following case ( In both Update and Delete) :
The tuple which contains the data to be updated had more attributes than it should. In this case it should through a DBAppException but it didn't, So please add a check that the size of the input hashtable is less than or equal to the number of table's columns. and add another check that each key in the tuple corresponds to an existing attribute in the table @Aelmeky

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.