Jump to content

Apache Empire-db: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
mNo edit summary
 
(19 intermediate revisions by 15 users not shown)
Line 1: Line 1:
{{Short description|Open-source Java library}}
{{Unreferenced|date=May 2011}}
{{Notability|Products|date=March 2022}}

{{ Infobox Software
{{Infobox software
| name = Apache Empire-db
| name = Apache Empire-db
| logo = Apache_Empire-db_Logo.svg
| logo = [[File:Empire-db.png|250px]]
| logo size = 300px
| screenshot =
| screenshot =
| caption =
| caption =
| developer = [[Apache Software Foundation]]
| developer = [[Apache Software Foundation]]
| status = incubation
| latest release version = 2.4.3
| latest release version = 3.0.0
| latest release date = {{release date|2014|08|20}}
| latest release date = {{Start date and age|2022|03|11}}
| latest preview version =
| latest preview version =
| latest preview date =
| latest preview date =
| operating system = [[Cross-platform]]
| operating system = [[Cross-platform]]
| repo = {{URL|https://gitbox.apache.org/repos/asf?p{{=}}empire-db.git|EmpireDB Repository}}
| programming language = [[Java (programming language)|Java]]
| programming language = [[Java (programming language)|Java]]
| genre = [[Persistence Framework]]
| genre = [[Persistence Framework]]
| license = [[Apache License]] 2.0
| license = [[Apache License 2.0]]
| website = {{url|http://empire-db.apache.org/}}
| website = {{URL|//empire-db.apache.org/}}
}}
}}
'''Apache Empire-db''' is a Java library that provides a high level object-oriented API for accessing [[relational database management system]]s (RDBMS) through [[JDBC]]. Apache Empire-db is open source and provided under the [[Apache License 2.0]] from the [[Apache Software Foundation]].

'''Apache Empire-db''' is a Java library that provides a high level object-oriented API for accessing [[relational database management system]]s (RDBMS) through [[JDBC]]. Apache Empire-db is open source and provided under the Apache 2.0 license from the [[Apache Software Foundation]].


Compared to [[Object-relational mapping]] (ORM) or other data persistence solutions such as [[Hibernate (Java)|Hibernate]], [[iBATIS]] or [[TopLink]] Empire-db does not use XML files or Java annotations to provide a mapping of plain (old) Java object ([[POJO]]'s) to database tables, views and columns. Instead Empire-db uses a Java object model to describe the underlying data model and an API that works almost solely with object references rather than [[string literal]]s.
Compared to [[Object-relational mapping]] (ORM) or other data persistence solutions such as [[Hibernate (Java)|Hibernate]], [[iBATIS]] or [[TopLink]] Empire-db does not use XML files or Java annotations to provide a mapping of plain (old) Java object ([[POJO]]'s) to database tables, views and columns. Instead Empire-db uses a Java object model to describe the underlying data model and an API that works almost solely with object references rather than [[string literal]]s.


Empire-db's aim is to provide better software quality and improved maintainability through increased compile-time safety and reduced redundancy of metadata. Additionally applications may benefit from better performance due to full control over [[SQL]] statements and their execution by the developer compared to most OR-mapping solutions.
Empire-db's aim is to provide better software quality and improved maintainability through increased compile-time safety and reduced redundancy of metadata. Additionally applications may benefit from better performance due to full control over [[SQL]] statements and their execution by the developer compared to most OR-mapping solutions.<ref>{{Cite web |title=Apache Empire-db |url=https://empire-db.apache.org/pages/home.html |access-date=2022-03-21 |website=empire-db.apache.org}}</ref>


== Major benefits ==
== Major benefits ==

Empire-db's key strength is its API for dynamic SQL generation for arbitrary select, update, insert or delete statements, purely by using Java methods which reference the model objects. This provides type-safety and almost entirely eliminates the use of string literals for names or expressions in code. Additionally DBMS independence is achieved through a pluggable driver model.
Empire-db's key strength is its API for dynamic SQL generation for arbitrary select, update, insert or delete statements, purely by using Java methods which reference the model objects. This provides type-safety and almost entirely eliminates the use of string literals for names or expressions in code. Additionally DBMS independence is achieved through a pluggable driver model.


Using references to table and column objects significantly improves compile-time safety and thus reduces the amount of testing. As a positive side effect the IDE's code completion can be used to browse the data model, increases productivity and eliminates the need for other external tools or IDE-plugins.
Using references to table and column objects significantly improves compile-time safety and thus reduces the amount of testing. As a positive side effect the IDE's code completion can be used to browse the data model, increases productivity and eliminates the need for other external tools or IDE-plugins.


Further the object model also provides safe and easy access to meta-information of the data model such as field data type, maximum field length, whether a field is mandatory and a finite choice of options for a field’s values. Metadata is user-extensible and not limited to DBMS related metadata. Availability of meta-information encourages more generic code and eliminates redundancies throughout application layers.
Further the object model also provides safe and easy access to meta-information of the data model such as field data type, maximum field length, whether a field is mandatory and a finite choice of options for a field's values. Metadata is user-extensible and not limited to DBMS related metadata. Availability of meta-information encourages more generic code and eliminates redundancies throughout application layers.


== Features at a glance ==
== Features at a glance ==

* Data model definition through a Java object model omits the need to learn XML schemas or annotations and easily allows user interceptions and extensions.
* Data model definition through a Java object model omits the need to learn XML schemas or annotations and easily allows user interceptions and extensions.
* Portable RDBMS independent record handling and command definition with support for a variety of relational databases such as [[Oracle Database|Oracle]], [[Microsoft SQL Server]], [[MySQL]], [[Apache Derby|Derby]], [[H2 (DBMS)|H2]] and [[HSQLDB]] (as of version 2.0.5)
* Portable RDBMS independent record handling and command definition with support for a variety of relational databases such as [[Oracle Database|Oracle]], [[Microsoft SQL Server]], [[MySQL]], [[Apache Derby|Derby]], [[H2 (DBMS)|H2]] and [[HSQLDB]] (as of version 2.0.5)
Line 42: Line 40:
* Automatic tracking of record state and field modification (aka "dirty checking") to only insert/ update modified fields.
* Automatic tracking of record state and field modification (aka "dirty checking") to only insert/ update modified fields.
* Support for optimistic locking through timestamp column.
* Support for optimistic locking through timestamp column.
* No need to always work with full database entities. Build queries to provide you with the data exactly as you need it, and obtain the result for example as a list of any type of POJO with matching property setters or constructor.
* No need to always work with full database entities. Build queries to provide the data exactly as needed, and obtain the result for example as a list of any type of POJO with matching property setters or constructor.
* Lightweight and passive library with zero configuration footprint that allows simple integration with any architecture or framework.
* Lightweight and passive library with zero configuration footprint that allows simple integration with any architecture or framework.


== Example ==
== Example ==

As an example consider a database with two tables called ''Employees'' and ''Departments'' for which a list of employees in a particular format, with certain constraints and a given order should be retrieved.
As an example consider a database with two tables called ''Employees'' and ''Departments'' for which a list of employees in a particular format, with certain constraints and a given order should be retrieved.


The corresponding Oracle syntax SQL statement is assumed to be as follows:
The corresponding Oracle syntax SQL statement is assumed to be as follows:


<source lang="sql">
<syntaxhighlight lang="sql">
SELECT t1.EMPLOYEE_ID,
SELECT t1.EMPLOYEE_ID,
t1.LASTNAME || ', ' || t1.FIRSTNAME AS NAME,
t1.LASTNAME || ', ' || t1.FIRSTNAME AS NAME,
Line 60: Line 57:
AND t1.RETIRED=0
AND t1.RETIRED=0
ORDER BY t1.LASTNAME, t1.FIRSTNAME
ORDER BY t1.LASTNAME, t1.FIRSTNAME
</syntaxhighlight>
</source>


This SQL statement can be created using Empire-db's command API using object model references like this:
This SQL statement can be created using Empire-db's command API using object model references like this:


<source lang="java">
<syntaxhighlight lang="java">
SampleDB db = getDatabase();
SampleDB db = getDatabase();
// Declare shortcuts (not necessary but convenient)
// Declare shortcuts (not necessary but convenient)
Line 83: Line 80:
cmd.orderBy(EMP.LASTNAME);
cmd.orderBy(EMP.LASTNAME);
cmd.orderBy(EMP.FIRSTNAME);
cmd.orderBy(EMP.FIRSTNAME);
</syntaxhighlight>
</source>


In order to execute the query and retrieve a list of POJO's holding the query result the following code may be used:
In order to execute the query and retrieve a list of POJO's holding the query result the following code may be used:


<source lang="java">
<syntaxhighlight lang="java">
// Class definition for target objects
// Class definition for target objects
public class EmployeeInfo {
public class EmployeeInfo {
Line 107: Line 104:
reader.close()
reader.close()
}
}
</syntaxhighlight>
</source>


Empire-db also supports field access through object references or obtaining query results as XML.
Empire-db also supports field access through object references or obtaining query results as XML.


== History ==
== History ==

Empire-db was originally developed at ESTEAM Software a German software development company which used Empire-db to develop various applications for a variety of different branches.
Empire-db was originally developed at ESTEAM Software a German software development company which used Empire-db to develop various applications for a variety of different branches.


In January 2008 Empire-db was made officially open dource and first published though SourceForge.net.
In January 2008 Empire-db was made officially open source and first published though SourceForge.net.


In June 2008 a proposal was submitted to the Apache Software Foundation for Empire-db to become an Apache Incubator project. In July 2008 Empire-db got accepted for incubation and all rights over the Software were transferred to the Apache Foundation.
In June 2008 a proposal was submitted to the Apache Software Foundation for Empire-db to become an Apache Incubator project. In July 2008 Empire-db got accepted for incubation and all rights over the Software were transferred to the Apache Foundation.
Line 122: Line 118:


== See also ==
== See also ==
{{Portal|Java}}
{{Portal|Computer programming}}
* [[Java Database Connectivity]] (JDBC)
* [[Java Database Connectivity]] (JDBC)
* [[Object-relational mapping]]
* [[Object-relational mapping]]
Line 129: Line 125:
* [[TopLink]]
* [[TopLink]]
* [[Apache Struts]]
* [[Apache Struts]]

==References==
{{reflist}}


== External links ==
== External links ==
* {{official website|//empire-db.apache.org/}}
* [http://incubator.apache.org/empire-db Empire-db project page at the Apache Foundation]

{{apache}}
{{Apache Software Foundation}}


[[Category:Apache Software Foundation|Empire-db]]
[[Category:Apache Software Foundation projects|Empire-db]]
[[Category:Java (programming language)]]
[[Category:Java (programming language) libraries]]

Latest revision as of 17:44, 30 December 2023

Apache Empire-db
Developer(s)Apache Software Foundation
Stable release
3.0.0 / March 11, 2022; 2 years ago (2022-03-11)
RepositoryEmpireDB Repository
Written inJava
Operating systemCross-platform
TypePersistence Framework
LicenseApache License 2.0
Websiteempire-db.apache.org

Apache Empire-db is a Java library that provides a high level object-oriented API for accessing relational database management systems (RDBMS) through JDBC. Apache Empire-db is open source and provided under the Apache License 2.0 from the Apache Software Foundation.

Compared to Object-relational mapping (ORM) or other data persistence solutions such as Hibernate, iBATIS or TopLink Empire-db does not use XML files or Java annotations to provide a mapping of plain (old) Java object (POJO's) to database tables, views and columns. Instead Empire-db uses a Java object model to describe the underlying data model and an API that works almost solely with object references rather than string literals.

Empire-db's aim is to provide better software quality and improved maintainability through increased compile-time safety and reduced redundancy of metadata. Additionally applications may benefit from better performance due to full control over SQL statements and their execution by the developer compared to most OR-mapping solutions.[1]

Major benefits

[edit]

Empire-db's key strength is its API for dynamic SQL generation for arbitrary select, update, insert or delete statements, purely by using Java methods which reference the model objects. This provides type-safety and almost entirely eliminates the use of string literals for names or expressions in code. Additionally DBMS independence is achieved through a pluggable driver model.

Using references to table and column objects significantly improves compile-time safety and thus reduces the amount of testing. As a positive side effect the IDE's code completion can be used to browse the data model, increases productivity and eliminates the need for other external tools or IDE-plugins.

Further the object model also provides safe and easy access to meta-information of the data model such as field data type, maximum field length, whether a field is mandatory and a finite choice of options for a field's values. Metadata is user-extensible and not limited to DBMS related metadata. Availability of meta-information encourages more generic code and eliminates redundancies throughout application layers.

Features at a glance

[edit]
  • Data model definition through a Java object model omits the need to learn XML schemas or annotations and easily allows user interceptions and extensions.
  • Portable RDBMS independent record handling and command definition with support for a variety of relational databases such as Oracle, Microsoft SQL Server, MySQL, Derby, H2 and HSQLDB (as of version 2.0.5)
  • DDL generation for target DBMS from object definition, either for the entire database or for individual objects such as tables, views, columns and relations.
  • Type-safe API for dynamic SQL command generation allows dynamic building of SQL statements using API methods and object references only instead of string literals. This provides a high degree of type-safety which simplifies testing and maintenance.
  • Reduced amount of Java code and powerful interception of field and metadata access through dynamic beans as an alternative to POJOs. This even allows data model changes (DDL) at runtime.
  • Automatic tracking of record state and field modification (aka "dirty checking") to only insert/ update modified fields.
  • Support for optimistic locking through timestamp column.
  • No need to always work with full database entities. Build queries to provide the data exactly as needed, and obtain the result for example as a list of any type of POJO with matching property setters or constructor.
  • Lightweight and passive library with zero configuration footprint that allows simple integration with any architecture or framework.

Example

[edit]

As an example consider a database with two tables called Employees and Departments for which a list of employees in a particular format, with certain constraints and a given order should be retrieved.

The corresponding Oracle syntax SQL statement is assumed to be as follows:

    SELECT t1.EMPLOYEE_ID, 
           t1.LASTNAME || ', ' || t1.FIRSTNAME AS NAME, 
           t2.DEPARTMENT
    FROM (EMPLOYEES t1 
          INNER JOIN DEPARTMENTS t2 ON t1.DEPARTMENT_ID = t2.DEPARTMENT_ID)
    WHERE upper(t1.LASTNAME) LIKE upper('Foo%') 
      AND t1.RETIRED=0
    ORDER BY t1.LASTNAME, t1.FIRSTNAME

This SQL statement can be created using Empire-db's command API using object model references like this:

    SampleDB db = getDatabase();
    // Declare shortcuts (not necessary but convenient)
    SampleDB.Employees EMP = db.EMPLOYEES;
    SampleDB.Departments DEP = db.DEPARTMENTS;
    // Create a command object
    DBCommand cmd = db.createCommand();
    // Select columns
    cmd.select(EMP.EMPLOYEE_ID);
    cmd.select(EMP.LASTNAME.append(", ").append(EMP.FIRSTNAME).as("NAME"));
    cmd.select(DEP.DEPARTMENT);
    // Join tables
    cmd.join  (EMP.DEPARTMENT_ID, DEP.DEPARTMENT_ID);
    // Set constraints
    cmd.where(EMP.LASTNAME.likeUpper("Foo%"));
    cmd.where(EMP.RETIRED.is(false));
    // Set order
    cmd.orderBy(EMP.LASTNAME);
    cmd.orderBy(EMP.FIRSTNAME);

In order to execute the query and retrieve a list of POJO's holding the query result the following code may be used:

    // Class definition for target objects
    public class EmployeeInfo {
        private int employeeId;
        private String name;
        private String department;
        // Getter's and Setters for all properties
        // or a public Constructor using fields
        public get...
        public set...
    }

    // Retrieve employee list using the cmd object created above
    DBReader reader = new DBReader();
    try {
        reader.open(cmd, getConnection());
        List<EmployeeInfo> empList = reader.getBeanList(EmployeeInfo.class);
    } finally {
        reader.close()
    }

Empire-db also supports field access through object references or obtaining query results as XML.

History

[edit]

Empire-db was originally developed at ESTEAM Software a German software development company which used Empire-db to develop various applications for a variety of different branches.

In January 2008 Empire-db was made officially open source and first published though SourceForge.net.

In June 2008 a proposal was submitted to the Apache Software Foundation for Empire-db to become an Apache Incubator project. In July 2008 Empire-db got accepted for incubation and all rights over the Software were transferred to the Apache Foundation.

In October 2008 Empire-db 2.0.4 was the first official Apache incubator release with all package names changed to begin with org.apache.empire.

See also

[edit]

References

[edit]
  1. ^ "Apache Empire-db". empire-db.apache.org. Retrieved 2022-03-21.
[edit]