Protobuf4j: A Facility Framework to Develop with Google Protobuf

A Facility Framework to Develop with Google Protobuf

License

License

Categories

Categories

Protobuf Data Data Structures
GroupId

GroupId

xyz.codemeans.protobuf4j
ArtifactId

ArtifactId

protobuf4j-core
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Protobuf4j: A Facility Framework to Develop with Google Protobuf
A Facility Framework to Develop with Google Protobuf
Project URL

Project URL

https://github.com/YuanWenqing/protobuf4j
Source Code Management

Source Code Management

https://github.com/YuanWenqing/protobuf4j

Download protobuf4j-core

How to add to project

<!-- https://jarcasting.com/artifacts/xyz.codemeans.protobuf4j/protobuf4j-core/ -->
<dependency>
    <groupId>xyz.codemeans.protobuf4j</groupId>
    <artifactId>protobuf4j-core</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/xyz.codemeans.protobuf4j/protobuf4j-core/
implementation 'xyz.codemeans.protobuf4j:protobuf4j-core:1.0.1'
// https://jarcasting.com/artifacts/xyz.codemeans.protobuf4j/protobuf4j-core/
implementation ("xyz.codemeans.protobuf4j:protobuf4j-core:1.0.1")
'xyz.codemeans.protobuf4j:protobuf4j-core:jar:1.0.1'
<dependency org="xyz.codemeans.protobuf4j" name="protobuf4j-core" rev="1.0.1">
  <artifact name="protobuf4j-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='xyz.codemeans.protobuf4j', module='protobuf4j-core', version='1.0.1')
)
libraryDependencies += "xyz.codemeans.protobuf4j" % "protobuf4j-core" % "1.0.1"
[xyz.codemeans.protobuf4j/protobuf4j-core "1.0.1"]

Dependencies

compile (4)

Group / Artifact Type Version
com.google.protobuf : protobuf-java jar 3.6.0
org.apache.commons : commons-lang3 jar 3.7
com.google.guava : guava jar 25.1-jre
com.hubspot.jackson : jackson-datatype-protobuf jar 0.9.9-jackson2.9-proto3

Project Modules

There are no modules declared in this project.

Protobuf4j

Introduction

A Facility framework to develop with Google Protobuf, including:

  • Utils to handle Protobuf messages and enums
  • ORM-based DAO for storing Protobuf Message in MySQL
  • Some supports with Spring and SpringBoot

Modules

  • protobuf4j-core: helper class for Protobuf Message and Enum, codec class for Message.
  • protobuf4j-sql: abstraction for SQL fragment and statement.
  • protobuf4j-orm: basic ORM-like DAO framework utilizing protobuf4j-sql
  • protobuf4j-orm-starter: springboot starter for protobuf4j-orm, including autoconfiguration and jdbc injection
  • protobuf4j-spring: some extensions for Protobuf to integrate with spring

ORM Usage

Gradle

implementation("xyz.codemeans.protobuf4j:protobuf4j-orm-starter:$protobuf4jVersion")

The latest version can be found in maven central repository.

Properties

protobuf4j.datasource.auto-enable=<if-auto-configuration-enalbed:default true>

Java

Example Code: example

interface

public interface ExampleDao extends IPrimaryKeyMessageDao<Long, Example> {
}

impl

@Repository
public class ExampleDaoImpl extends PrimaryKeyProtoMessageDao<Long, Example> implements ExampleDao {
  public ExampleDaoImpl() {
    super(Example.class, ExampleNaming.ID);
  }
}

CRUD

@Autowired
ExampleDao exampleDao;

public Example createExample(Example example) {
  long id = exampleDao.insertReturnKey(example).longValue();
  return exampleDao.selectOneByPrimaryKey(id);
}

public Example getExample(long id) {
  return exampleDao.selectOneByPrimaryKey(id);
  // or
  //return exampleDao.selectOneByCond(FieldAndValue.eq(ExampleNaming.ID, id));
}

public Example updateExample(Example newValue, Example oldValue) {
  exampleDao.updateMessageByPrimaryKey(newValue, oldValue);
  return exampleDao.selectOneByPrimaryKey(newValue.getId());
}

public void deleteExample(long id) {
  exampleDao.deleteByPrimaryKey(id);
}

// complex conditions and pagination
public List<Example> listExamples(WhereClause where) {
  return exampleDao.selectByWhere(where);
}

public Map<Long, Example> getExamples(Collection<Long> ids) {
  return exampleDao.selectMultiByPrimaryKey(ids);
}

SQL Usage

// condition
List<IExpression> conds = Lists.newArrayList();
conds.add(FieldAndValue.like(ExampleNaming.NAME, SqlUtil.likePrefix(prefix)));
conds.add(FieldAndValue.gte(ExampleNaming.ID, beg));
conds.add(FieldAndValue.lt(ExampleNaming.ID, end));
IExpression allAndCond = LogicalExpr.and(conds));

// pagination
PaginationClause.newBuilder(limit).buildByOffset(offset);
PaginationClause.newBuilder(limit).buildByPageNo(pn)

// select specified columns
SelectClause selectClause = new SelectClause();
selectClause.select(ExampleNaming.NAME);
FromClause fromClause = QueryCreator.fromType(Example.class);
SelectSql sql = new SelectSql(selectClause, fromClause);
exampleDao.doSelect(sql, new SingleColumnRowMapper<>(String.class));

// update whole message with different fields
exampleDao.updateMessageByPrimaryKey(newValue, oldValue);

Reference

Versions

Version
1.0.1
1.0.0
0.9.3.alpha
0.9.0.alpha