An open API service indexing awesome lists of open source software.

https://github.com/y1j2x34/spring-influxdb-orm

Spring InfluxDB ORM
https://github.com/y1j2x34/spring-influxdb-orm

influxdb orm-framework orm-library spring spring-boot

Last synced: 8 days ago
JSON representation

Spring InfluxDB ORM

Awesome Lists containing this project

README

        

# spring-influxdb-orm

[![Build Status](https://travis-ci.org/y1j2x34/spring-influxdb-orm.svg?branch=master)](https://travis-ci.org/y1j2x34/spring-influxdb-orm)
[![codecov.io](https://codecov.io/github/y1j2x34/spring-influxdb-orm/coverage.svg?branch=master)](https://codecov.io/github/y1j2x34/spring-influxdb-orm)

## Usages

### Basic Usages

ApplicationContext.xml

```xml



```

CensusMeasurement.java

```java
package com.yourcompany.influxdb.entity;

@InfluxDBMeasurement('census')
public class CensusMeasurement implements Serializable {
private static final long serialVersionUID = 8260424450884444916L;

private Date time;

@TagColumn("location")
private String location;
@TagColumn("scientist")
private String scientist;

@FieldColumn("butterflies")
private Integer butterflies;
@FieldColumn("honeybees")
private Integer honeybees;

// getters and setters
// hashCode and equals

public String toString(){
return "[time: " + time.getTime() + ", location: " + location
+ ", scientist: " + scientist + ", butterflies: " + butterflies + ", honeybees: " + honeybees + "]";
}
}
```

CensusDao.java

```java
package com.yourcompany.influxdb.dao;

public interface CensusDao extends InfluxDBDao {

@InfluxDBSelect("select * from census where scientist = #{scientist}")
public List selectByScientist(@InfluxDBParam("scientist") String scientist);

@InfluxDBExecute("DROP SERIES FROM census where scientist=#{scientist} and location=#{location}")
public void dropSeries( //
@InfluxDBParam("scientist") String scientist, //
@InfluxDBParam("location") Integer location //
);
@InfluxDBSelect("select scientist,location,butterflies from census where scientist = #{scientist}")
public List> selectButterflies( //
@InfluxDBParam("scientist") String scientist, //
@InfluxDBParam("location") Integer location //
);

public void hello();
}
```

Main.java

```java
package com.yourcompany.influxdb;
public class Main {
public static void main(String[] args) {
try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml")) {
context.refresh();
CensusDao dao = context.getBean(CensusDao.class);
List measurements = dao.selectByScientist("lanstroth");
System.out.println(measurements);

dao.dropSeries("lastroth", 12);

List> result = dao.selectButterflies("lanstroth", 10);
System.out.println(result);
}
}
}
```

## Advanced Usages

### Sharding

```java
// TODO
```

### Specify executor

```java
// CensusDao.java
public interface CensusDao{
@SpecifiedExecutor(HelloWorldExecutor.class)
public void execute(String scientist, Integer location);
}
// HelloWorldExecutor.java
public class HelloWorldExecutor extends Executor {
public HelloWorldExecutor(InfluxDBRepository repository) {
super(repository);
}

@Override
public ResultContext execute(MapperMethod method, Map parameters) {
System.out.println("hello world");
return ResultContext.VOID;
}
}

```

### Custom annotation

Select.java

```java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@AnnotateExecutor(SelectExecutor.class)
public @interface Select{
String value();
}
```

SelectExecutor.java

```java
public class SelectExecutor extends AnnotationExecutor {
public SelectExecutor(InfluxDBRepository repository, Select selectAnnotation) {
super(repository, selectAnnotation);
}

@Override
public ResultContext execute(MapperMethod method, Map parameters) {
String command = super.annotation.value();
String parsedCommand = CommandUtils.parseCommand(command, parameters);
return repository.query(parsedCommand);
}
}
```

### Gzip support

https://github.com/influxdata/influxdb-java#gzips-support-version-25-required

## License

This project is released under MIT License