phoenix-data

Apache Phoenix Data for Spring Boot

License

License

Categories

Categories

Data
GroupId

GroupId

io.github.ufukhalis.phoenix
ArtifactId

ArtifactId

phoenix-data
Last Version

Last Version

0.0.5
Release Date

Release Date

Type

Type

jar
Description

Description

phoenix-data
Apache Phoenix Data for Spring Boot
Project URL

Project URL

https://github.com/ufukhalis/phoenix-data
Source Code Management

Source Code Management

https://github.com/ufukhalis/phoenix-data/tree/master

Download phoenix-data

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.ufukhalis.phoenix/phoenix-data/ -->
<dependency>
    <groupId>io.github.ufukhalis.phoenix</groupId>
    <artifactId>phoenix-data</artifactId>
    <version>0.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.ufukhalis.phoenix/phoenix-data/
implementation 'io.github.ufukhalis.phoenix:phoenix-data:0.0.5'
// https://jarcasting.com/artifacts/io.github.ufukhalis.phoenix/phoenix-data/
implementation ("io.github.ufukhalis.phoenix:phoenix-data:0.0.5")
'io.github.ufukhalis.phoenix:phoenix-data:jar:0.0.5'
<dependency org="io.github.ufukhalis.phoenix" name="phoenix-data" rev="0.0.5">
  <artifact name="phoenix-data" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.ufukhalis.phoenix', module='phoenix-data', version='0.0.5')
)
libraryDependencies += "io.github.ufukhalis.phoenix" % "phoenix-data" % "0.0.5"
[io.github.ufukhalis.phoenix/phoenix-data "0.0.5"]

Dependencies

compile (4)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter jar 2.1.2.RELEASE
org.apache.phoenix : phoenix-server-client jar 4.7.0-HBase-1.1
org.apache.phoenix : phoenix-core jar 5.0.0-alpha-HBase-2.0
io.vavr : vavr jar 0.9.3

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.1.2.RELEASE

Project Modules

There are no modules declared in this project.

Build Status Coverage Status

Phoenix Data

This project goal is to make more easily configuration and using Apache Phoenix with Spring Boot based applications.

There are not good enough example of usage the Apache Phoenix, especially with Spring Boot. So Phoenix Data was born via this idea. For now, with this library you can easily connect to Apache Phoenix and can execute the raw SQL queries. It has support for Async calls too.

This project uses the vavr library which is really good implement of functional Java.

Quick Start

First add dependency to your project.

<dependency>
    <groupId>io.github.ufukhalis.phoenix</groupId>
    <artifactId>phoenix-data</artifactId>
    <version>0.0.5</version>
</dependency>

Then create a class add @EnablePhoenixData annotation.

@EnablePhoenixData
@Configuration
public class PhoenixConfig {

}

After then you need to add below properties to your application.properties file.

phoenix.data.jdbcUrl = jdbc:phoenix:thin:url=http://localhost:8765;serialization=PROTOBUF
phoenix.data.maxConnection = 10 # optional
phoenix.data.minConnection = 5  # optional
phoenix.data.basePackage = {your.root.package} # com.test
phoenix.data.tableStrategy = CREATE # Other options are NONE and DROP_CREATE

After these configurations, let's create your repository class which is extends PhoenixCrudRepository.

@Repository
public class YourRepository extends PhoenixCrudRepository<TestEntity, Long> {

}

Then we can define our basic Entity class.

@Entity("tableName")
public class TestEntity {
    
    @Column(value = "id", isPrimaryKey = true)
    private Long id;
    
    @Column("name")
    private String name;
    
}    

Depends table creation strategy, when your application start to running related strategy will run.

Then you can autowire your repository.

@Autowired
YourRepository yourRepository; 

Save your entity

TestEntity entity = ...
yourRepository.save(entity);

Find your entity by using its primary key

Optional<TestEntity> entity = yourRepository.find(1L);

Delete your entity by using its primary key

yourRepository.delete(1L);

Create query by using PhoenixQuery class.

final PhoenixQuery phoenixQuery = new PhoenixQuery.Builder(YourEntity.class)
                .select()
                .build();

YourEntity entity = yourRepository.find(phoenixQuery);

Also you can execute raw queries via yourRepository

String rawSql = "drop table if exists javatest";
int rowAffected = yourRepository.executeUpdate(rawSql);
//...

Or async call

String rawSql = "drop table if exists javatest";
Future<Integer> rowAffected = yourRepository.executeUpdateAsync(rawSql);
//...

Run your query and get results

String rawSql = "select * from javatest";
ResultSet rs = yourRepository.executeQuery(rawSql);
while(rs.next()) {
    //..
}

Or async call

String rawSql = "select * from javatest";
Future<ResultSet> resultSetFuture = yourRepository.executeQueryAsync(rawSql);
resultSetFuture.mapTry(resultSet -> {
    //..
});

Note

This project is still under development. But you can use in your projects.

For more information about Apache Phoenix, check the site https://phoenix.apache.org/

For more information about vavr.io, check the site http://vavr-io.github.io

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENCE.

Versions

Version
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1