Code Snippet – How to get the count of rows from SQLite Database In Android?

Android comes with a utility class called DatabaseUtils which has a method queryNumEntries that can take your database object and table name as parameter and return the total number of records on that database. Quite a clean way. You don’t need to be writing ‘Select Count(*) from mytable‘ kind of stuffs.

public long count() {
    return DatabaseUtils.queryNumEntries(db,'myTablename');
}

Java EE Connector Architecture [JCA] – An overview

Overview:
Java EE Connector Architecture (JCA) is a Java-based technology solution for connecting application servers and enterprise information systems (EIS) as part of enterprise application integration (EAI) solutions. While JDBC is specifically used to connect Java EE applications to databases, JCA is a more generic architecture for connection to legacy systems (including databases). JCA was developed under the Java Community Process as JSR 16 (JCA 1.0) and JSR 112 (JCA 1.5). As of 2006[update], the current version of JCA is version 1.5.

JCA and J2EE:
J2EE Version 1.3 required application servers to support Version 1.0 of the J2EE Connector Architecture (JCA).

Contracts:
The J2EE Connector Architecture defines a standard for connecting a compliant application server to an EIS. It defines a standard set of system-level contracts between the J2EE application server and a resource adapter. The system contracts defined by Version 1.0 of the J2EE Connector Architecture are described by the specification as follows:

  • Connection management
    Connection management enables an application server to pool connections to the underlying EIS and enables application components to connect to an EIS. This leads to a scalable application environment that can support a large number of clients requiring access to an EIS.
  • Transaction management
    Transaction management enables an application server to use a transaction manager to manage transactions across multiple resource managers. This contract also supports transactions that are managed internal to an EIS resource manager without the necessity of involving an external transaction manager.
  • Security management
    Security management provides support for a secure application environment that reduces security threats to the EIS and protects valuable information resources managed by the EIS.

The additional system contracts defined by Version 1.5 of the J2EE Connector Architecture are described by the specification as follows:

  • Life cycle management
    Life cycle management enables an application server to manage the life cycle of a resource adapter. This contract provides a mechanism for the application server to bootstrap a resource adapter instance during its deployment or application server startup, and to notify the resource adapter instance during its undeployment or during an orderly shutdown of the application server.
  • Work management
    Work management enables a resource adapter to do work (monitor network endpoints, call application components, and so on) by submitting work instances to an application server for execution. The application server dispatches threads to execute submitted work instances. This allows a resource adapter to avoid creating or managing threads directly, and allows an application server to efficiently pool threads and have more control over its run time environment. The resource adapter can control the transaction context with which work instances are executed.
  • Transaction inflow management
    Transaction inflow management enables a resource adapter to propagate an imported transaction to an application server. This contract also allows a resource adapter to transmit transaction completion and crash recovery calls initiated by an EIS, and ensures that the Atomicity, Consistency, Isolation and Durability (ACID) properties of the imported transaction are preserved.
  • Message inflow management
    Message inflow management enables a resource adapter to asynchronously deliver messages to message endpoints residing in the application server independent of the specific messaging style, messaging semantics, and messaging infrastructure used to deliver messages. This contract also serves as the standard message provider pluggability contract that allows a wide range of message providers (Java Message Service (JMS), Java API for XML Messaging (JAXM), and so on) to be plugged into any J2EE compatible application server with a resource adapter.

The article is taken from Wikipedia. See the license terms.

Understanding the JUnit Annotations And Their Work

Annotations have made some of the programming stuffs easier because they do a lot of things in the background, which any programmer would otherwise needed to have coded by themselves. JUnit uses a bunch of annotations and represents various separate tasks they do behind the scene. Here are some of the most widely used annotations from Java based Unit Testing Framework – The JUnit. If you would like to see a comprehensive example of JUnit with all these annotations in action, see my previous article on JUnit Test Case

  1. @Test
    • Denotes a test method. Can be used with expected to assert expected results on the object under test.
  2. @Before
    • Run before each test method is run i.e. do a setup
  3. @After
    • Run after each test method is run i.e. do a teardown
  4. @BeforeClass
    • Run before all the tests in a class (Runs once for all of the tests)
  5. @AfterClass
    • Run after all the tests in a class (Runs once for all of the tests)
  6. @Parameters
    • Allows you to run the same test with different data by defining the data parameters. @Parameters have to return List[], and the parameter will pass into class constructor as argument.
  7. @RunWith
    • Exclusively tells the class that the Junit Test Case uses Parameterized runner
  8. @Ignore
    • This allows to skip a test. ¬†You might want to skip a test if you are still working on it or you are not convinced it’s a valid test case or maybe ignore cases which are long running.