Tuesday, October 8, 2013

PHP-In-Java : Execute PHP code from within Java


Introduction :
Years ago an enterprising company named Caucho decided to write the "most reliable application server in the Open Source market." Their core product is a Java EE compliant Web server they call Resin, and at its heart is Quercus: a fast PHP interpreter written in cross-platform Java.

What is Quercus :
Quercus is pioneering a new mixed Java/PHP approach to web applications and services. On Quercus, Java and PHP is tightly integrated with each other - PHP applications can choose to use Java libraries and technologies like JMS, EJB, SOA frameworks, Hibernate, and Spring. This revolutionary capability is made possible because 1) PHP code is interpreted/compiled into Java and 2) Quercus and its libraries are written entirely in Java. This lets PHP applications and Java libraries to talk directly with one another at the program level. To facilitate this new Java/PHP architecture, Quercus provides an API and interface to expose Java libraries to PHP.

Benefits of Quercus :
Quercus and Quercus' PHP libraries are written entirely in Java, thereby taking the advantages of Java applications and infusing them into PHP. PHP applications running on Quercus are simply faster, easier to develop, more capable, more secure, and more scalable than any other PHP solution.
Quercus gives both Java and PHP developers a fast, safe, and powerful alternative to the standard PHP intepreter. Developers ambitious enough to use PHP in combination with Java will benefit the most from what Quercus has to offer.

Share:

Friday, September 20, 2013

Snaq DBPool Connection Pool : Java Connection Pooling Part - 2


What is Connection Pooling? 

One of the most expensive database-related tasks is the initial creation of the connection. Once the connection has been made the transaction often takes place very quickly. A connection pool maintains a pool of opened connections so the application can simply grab one when it needs to, use it, and then hand it back, eliminating much of the long wait for the creation of connections.

There are so many Connection Pooling library available in Java, Some of them are as follows ;
  • Tomcat JDBC Connection Pool
  • Snaq DBPool
  • C3P0
  • BoneCP
We have already gone through with Tomcat JDBC Connection Pool example, today we will check Snaq DBPool connection pooling. 

What is DBPool?

A Java-based database connection pooling utility, supporting time-based expiry, statement caching, connection validation, and easy configuration using a pool manager.

How do I use it?

To use DBPool you need to have the JAR file in a location where it's available for use by the host system you are using. For standalone applications this usually means in the CLASSPATH, and for application servers there is usually a specific directory is recommended for JAR libraries (for example, when used with Apache Tomcat it can be placed in the /WEB-INF/lib directory).
Usually DBPool is used in two different ways:

1. Direct use of individual connection pools.
2. Using the ConnectionPoolManager to manage one or more connection pools.

If you have never used DBPool before it's recommended that you start by simply integrating asingle connection pool into your application/applet to see how it works and performs. This provides the simplest direct support for pooled database connections and will get you up and running quickly. Once you learn exactly how it behaves and the benefits it can give you can try the pool manager approach to manage multiple pools if necessary.

Share:

Thursday, August 29, 2013

Tomcat JDBC Connection Pool : Java Connection Pooling Part - 1


What is Connection Pooling? 

One of the most expensive database-related tasks is the initial creation of the connection. Once the connection has been made the transaction often takes place very quickly. A connection pool maintains a pool of opened connections so the application can simply grab one when it needs to, use it, and then hand it back, eliminating much of the long wait for the creation of connections.

There are so many Connection Pooling library available in Java, Some of them are as follows ;
  • Tomcat JDBC Connection Pool
  • Snaq DBPool
  • C3P0
  • BoneCP
Today we will go through with Tomcat JDBC Connection Pool. I'll give a brief introduction with basic example (not in-depth).

Introduction :

JDBC connection pooling is conceptually similar to any other form of object pooling. Database connections are often expensive to create because of the overhead of establishing a network connection and initializing a database connection session in the back end database. In turn, connection session initialization often requires time consuming processing to perform user authentication, establish transactional contexts and establish other aspects of the session that are required for subsequent database usage.

Additionally, the database's ongoing management of all of its connection sessions can impose a major limiting factor on the scalability of your application. Valuable database resources such as locks, memory, cursors, transaction logs, statement handles and temporary tables all tend to increase based on the number of concurrent connection sessions.

All in all, JDBC database connections are both expensive to initially create and then maintain over time. Therefore, as we shall see, they are an ideal resource to pool.

you can checkout the detail description and features of JDBC Connection Pool here and here.

Share:

Thursday, August 22, 2013

Export or Backup MySQL Database in separate file using Shell Script


Live projects database are always critical for Clients and Companies and if the development phase is still in progress than you need to take backup of database on daily basis for safety concerns. i came across with the same situation and for that i've created a simple script which will take backup of your database.

it will export table wise separate sql file rather than one big SQL file. you can also make zip file for all the tables with gzipped option (dbname.gz).

This script is created for MySQL database only and it;s been tested on Mac OS X and Ubuntu OS.
You need to set path for MySQLDump and MySQL in script file.

Share:

Monday, August 19, 2013

Push Notification for iOS and Android with RESTlet Framework


Introduction :

Push notifications let your application notify a user of new messages or events even when the user is not actively using your application. On Android devices, when a device receives a push notification, your application's icon and a message appear in the status bar. When the user taps the notification, they are sent to your application. At iOS devices, it will appear as an alert box with buttons and header text and custom message.

Below are some prerequisites for Google Cloud Messaging (GCM) and Apple Push Notification Service (APNS).

1. GCM :
- Google Account.
- Register your application on GCM from Google APIs Console.
- Android API Key
- Android Device Push String (Android 2.2+)

2. iOS :
- iOS developer account
- Register your application on iOS developer account
- Download Push Notification P12 Certificate
- Add Device Profile on iOS developer account
- iOS device

Share:

Friday, August 2, 2013

Import MySQL .sql script from Java

Sometimes it is nice to programmatically run .sql scripts on a MySQL database using Java. This is easily achieved by using a simple ScriptRunner Class from the iBatis apache project. iBatis project is having it's own dependencies and if you want to check that class you need to add all the dependency. To overcome this issue i came across with a Slightly modified version of the com.ibatis.common.jdbc.ScriptRunner class from the iBATIS Apache project. it only removed dependency on Resource class and a constructor.

I made a simple java project which will execute the .sql script in local MySQL database.

Below are the steps to create new project and execute the .sql script in Java project.

Share:

Tuesday, June 4, 2013

Configure Apache Cassandra (Mac OS X)




Apache Cassandra Configuration Steps for Mac OS X:

1. Download And Install Apache Cassandra :
  • Download Apache Cassandra : http://cassandra.apache.org/download/
  • Now check weather JAVA_HOME and PATH environment variables has been set or not, if not then put this command in terminal 
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"
export PATH="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin:$PATH"
  • You also need to create three folders under /var/lib/cassandra/ folder for data, commit logs and saved caches, as follows.
/var/lib/cassandra/data
/var/lib/cassandra/commitlog
/var/lib/cassandra/saved_caches
  • Now start up Cassandra by invoking {cassandrafolderpath}$ bin/cassandra -f  from the command line.
  • Assuming you don't see messages with scary words like "error", or "fatal", or anything that looks like a Java stack trace, then everything should be working.
  • Press "Control-C" to stop Cassandra.
Share: