Apache Phoenix JDBC Driver and spring JdbcTemplate integration

Source: Internet
Author: User


Description: The Phoenix query engine translates SQL queries into one or more hbase scan and orchestrates execution to produce a standard JDBC result set. Directly using the HBase API, the co-processor and the custom filter, the performance magnitude is milliseconds for simple queries, and the performance magnitude is seconds for millions. More Reference website: http://phoenix.apache.org/

Phoenix is a JDBC driver that uses the Phoenix JDBC, like the normal database (Mysql) JDBC, to modularize the operation of the database, and to manage the data sources and things in a spring jdbctemplate way.
The implementation steps are as follows:
(1) for the integration of Phoenix and HBase, please refer to:
Writing Pom.xml
  <dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-core</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>

(2) If it is the Windows development environment, configure the C:\Windows\System32\drivers\etc\hosts file, addconfiguration of the DEVELOP5
192.168.199.242   DEVELOP5

(3) Configuring the Spring configuration file
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
<bean id="phoenixJdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="phoenixDataSource"/>
<qualifier value="phoenixJdbcTemplate"></qualifier>
</bean>
<bean id="baseInterfacePonenixImpl" class="com.eric.monitor.dao.impl.HBaseBaseDAOImpl">
<property name="jdbcTemplate" ref="phoenixJdbcTemplate"/>
</bean>
<context:component-scan base-package="com.eric.monitor.dao.impl"/>
<context:component-scan base-package="com.eric.monitor.service.impl"/>
<bean id="phoenixDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.apache.phoenix.jdbc.PhoenixDriver"/>
<property name="url" value="jdbc:phoenix:develop5"/>
<property name="username" value=""/>
<property name="password" value=""/>
<property name="initialSize" value="20"/>
<property name="maxActive" value="0"/>
<! -- because Phoenix will not automatically commit when making data changes, the defaultautocommit property must be added, otherwise the data cannot be submitted -- >
<property name="defaultAutoCommit" value="true"/>
</bean>
</beans>



(3) Writing Java programs
import com.eric.common.framework.dao.HBaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
* *
Class description
*
* @author aihua.sun
* @date 2015/3/9
* @since V1.0
* /
@Repository
public class HBaseBaseDAOImpl implements HBaseDao {
private JdbcTemplate jdbcTemplate;
public HBaseBaseDAOImpl(JdbcTemplate template) {
this.jdbcTemplate = template;
}
public HBaseBaseDAOImpl() {
Super ();
}
public List query(String querySql) {
return jdbcTemplate.query(querySql);
}
@Override
public void update(String querySql) {
System.out.println(querySql);
jdbcTemplate.update(querySql);
}
@Override
public void batchUpdate(String updateSQL) {
System.out.println("##########BATCH UPDATE:"+updateSQL);
jdbcTemplate.batchUpdate(updateSQL);
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
@Autowired
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
} 



Apache Phoenix JDBC Driver and spring JdbcTemplate integration



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.