https://github.com/ufukhalis/phoenix-data
Apache Phoenix Client for Spring Boot
https://github.com/ufukhalis/phoenix-data
apache-phoenix hbase-client phoenix-client spring-boot
Last synced: 5 months ago
JSON representation
Apache Phoenix Client for Spring Boot
- Host: GitHub
- URL: https://github.com/ufukhalis/phoenix-data
- Owner: ufukhalis
- License: apache-2.0
- Created: 2019-01-18T10:39:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-18T20:57:11.000Z (about 7 years ago)
- Last Synced: 2025-08-01T09:54:56.898Z (11 months ago)
- Topics: apache-phoenix, hbase-client, phoenix-client, spring-boot
- Language: Java
- Size: 93.8 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://travis-ci.com/ufukhalis/phoenix-data) [](https://coveralls.io/github/ufukhalis/phoenix-data)
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.
io.github.ufukhalis.phoenix
phoenix-data
0.0.5
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 {
}
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 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 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 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](./LICENSE).