Improve Your Data Model


DBRow's structure is designed to help you

Create and Improve Your Data Model

DBRow captures the concept of a row in a database table, and the properties of the table

You use DBRow by creating a subclass that contains annotations and fields that capture the names, type, and relationships of the table.

This architecture allows Query By Example and dynamic query creation

Infinitely many queries are available to you automatically. There is never a need to pre-define any SQL queries and you never write SQL

DBvolution is designed so DBRow subclasses are easy to write but you can use DBTableClassGenerator to generate the classes automatically

To start querying create a blank DBRow subclass using the default constructor

CompanyLogo logoExample = new CompanyLogo();

The classes of the field allow you set the permitted values of the fields to constrain your query. DBInteger, DBString, and DBByteArray are examples of QueryableDatatype which is key to defining query criteria

logoExample.carCompany.permittedValues(ford.uidCarCompany);

Finally get the list of relevant rows using DBDatabase's get(DBRow) method

List<CompanyLogo> foundLogos = database.get(logoExample);

Now you have a collection of all the database objects that you need available to reference, copy, update, and delete them as required. DBDatabase provides a convenient print method to view the results

database.print(foundLogos);
logoID:2, carCompany:2, imageBytes:/*BINARY DATA*/, imageFilename:ford_logo.jpg

Here's what all that code looks like in the IDE:
CompanyLogo logoExample = new CompanyLogo();
								 logoExample.carCompany.permittedValues(ford.uidCarCompany);
								 List<CompanyLogo> foundLogos = database.get(logoExample);
								 database.print(foundLogos);

Simple Solution to Complex Foreign Keys

Sometimes a DBRow will connect to another DBRow with 2 or more foreign key fields. For instance an Employee record might reference a manager and a mentor (also a manager) both of which are in the same table. This can have strange results but DBvolution allows you to subclass the referenced class to create a specialized foreign key using public class Mentor extends Manager{} and @DBForeignKey(Mentor.class)that will only be linked when you add the Mentor class to the query

Predefined Subsets Of Tables

Some tables are usually divided into a small number of subsets, lookup tables are a good example. You can build these subsets into your data model using a subclass and an initialization clause:
public class Employee extends DBRow
{
  DBString department = new DBString();
...
}

public class Accountants extends Employee
{
  {
    department.permittedValues("ACCOUNTS");
  }
}

When you want DB to be easier and faster...

Get DBvolution from GitHub or Maven

DBvolution is the gateway to your database and high-speed querying
  Contact us now for details
  +64 27 444 5201
  FaceBook
Twitter
Support us on Patreon