Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Java CI

on:
push:
paths:
- 'java/**'
branches: [ main, issue-14-b8e14d79 ]
pull_request:
paths:
- 'java/**'
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build with Maven
run: |
cd java
mvn clean compile

- name: Run tests
run: |
cd java
mvn test

- name: Package
run: |
cd java
mvn package -DskipTests

- name: Build examples
run: |
cd java/examples
mvn clean compile
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,37 @@ mutation {
}
}
```

## Java Implementation

This repository now includes a complete Java implementation with three packages:

1. **Platform.Data.Doublets.Client** - Abstract API for both GraphQL and native implementations
2. **Platform.Data.Doublets.Gql.Client** - GraphQL client that connects to the server
3. **Platform.Data.Doublets.Native** - Native library wrapper using JNI

### Quick Start (Java)

The Java implementation provides a clean, type-safe API that can swap between GraphQL and native backends:

```java
import platform.data.doublets.client.*;
import platform.data.doublets.gql.client.GraphQLLinksClient;

// Create GraphQL client
LinksClient client = new GraphQLLinksClient("http://localhost:60341/v1/graphql");

// Create a link
Link link = client.getOrCreate(1L, 2L);

// Search with query builder
LinkQuery query = LinkQuery.builder()
.fromId(1L)
.limit(10)
.sortBy(LinkQuery.SortField.ID, LinkQuery.SortOrder.ASC)
.build();

List<Link> results = client.searchLinks(query);
```

For detailed documentation and examples, see the [Java README](java/README.md).
197 changes: 197 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# Platform Data Doublets Java Implementation

This is a Java implementation of Platform Data Doublets that provides three packages for different use cases:

## Packages

### 1. Platform.Data.Doublets.Client (platform-data-doublets-client)
Abstract API that provides a standard interface for both GraphQL and native implementations.

**Maven Dependency:**
```xml
<dependency>
<groupId>platform.data.doublets</groupId>
<artifactId>platform-data-doublets-client</artifactId>
<version>1.0.0</version>
</dependency>
```

### 2. Platform.Data.Doublets.Gql.Client (platform-data-doublets-gql-client)
GraphQL client implementation that connects to a Platform Data Doublets GraphQL server.

**Maven Dependency:**
```xml
<dependency>
<groupId>platform.data.doublets</groupId>
<artifactId>platform-data-doublets-gql-client</artifactId>
<version>1.0.0</version>
</dependency>
```

### 3. Platform.Data.Doublets.Native (platform-data-doublets-native)
Native implementation that wraps the C++ library using JNI.

**Maven Dependency:**
```xml
<dependency>
<groupId>platform.data.doublets</groupId>
<artifactId>platform-data-doublets-native</artifactId>
<version>1.0.0</version>
</dependency>
```

## Usage Examples

### Using the GraphQL Client

```java
import platform.data.doublets.client.*;
import platform.data.doublets.gql.client.GraphQLLinksClient;

public class GraphQLExample {
public static void main(String[] args) throws DoubletsException {
// Create GraphQL client
LinksClient client = new GraphQLLinksClient("http://localhost:8080/v1/graphql");

// Create a new link
Link link = client.getOrCreate(2L, 3L);
System.out.println("Created link: " + link);

// Search for links
LinkQuery query = LinkQuery.builder()
.fromId(2L)
.limit(10)
.sortBy(LinkQuery.SortField.ID, LinkQuery.SortOrder.ASC)
.build();

List<Link> links = client.searchLinks(query);
System.out.println("Found " + links.size() + " links");

// Get total count
long count = client.getLinksCount();
System.out.println("Total links: " + count);
}
}
```

### Using the Native Client

```java
import platform.data.doublets.client.*;
import platform.data.doublets.native.NativeLinksClient;

public class NativeExample {
public static void main(String[] args) throws DoubletsException {
// Create native client
try (NativeLinksClient client = new NativeLinksClient("my-database.links")) {

// Create a new link
Link link = client.create(1L, 2L);
System.out.println("Created link: " + link);

// Update the link
Link updatedLink = client.update(link.getId(), 3L, 4L);
System.out.println("Updated link: " + updatedLink);

// Get all links
List<Link> allLinks = client.getAllLinks();
System.out.println("All links: " + allLinks);

// Delete the link
client.delete(link.getId());
System.out.println("Link deleted");

} // Client automatically closed here
}
}
```

### Using the Abstract Interface

```java
import platform.data.doublets.client.*;
import platform.data.doublets.gql.client.GraphQLLinksClient;
import platform.data.doublets.native.NativeLinksClient;

public class AbstractExample {
public static void demonstrateLinks(LinksClient client) throws DoubletsException {
// This method works with any implementation
Link link = client.getOrCreate(10L, 20L);

Optional<Link> retrieved = client.getLink(link.getId());
if (retrieved.isPresent()) {
System.out.println("Retrieved: " + retrieved.get());
}

List<Link> fromLinks = client.getLinksByFrom(10L);
System.out.println("Links from 10: " + fromLinks.size());
}

public static void main(String[] args) throws DoubletsException {
// Can switch implementations easily
LinksClient graphqlClient = new GraphQLLinksClient("http://localhost:8080/v1/graphql");
LinksClient nativeClient = new NativeLinksClient("db.links");

System.out.println("Using GraphQL client:");
demonstrateLinks(graphqlClient);

System.out.println("Using Native client:");
demonstrateLinks(nativeClient);
}
}
```

## Building

To build all packages:

```bash
cd java
mvn clean install
```

To build a specific package:

```bash
cd java/platform-data-doublets-client
mvn clean install
```

## Running Tests

```bash
cd java
mvn test
```

## Architecture

The architecture follows the dependency pattern described in the issue:

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ GraphQLLinksClient β”‚ β”‚ NativeLinksClient β”‚
β”‚ (GraphQL implementation)β”‚ β”‚ (JNI implementation) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LinksClient β”‚
β”‚ (Abstract API) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

This design allows:
- **Swappable implementations**: Easy to switch between GraphQL and native
- **Testability**: Mock implementations can be created for testing
- **Future extensibility**: New implementations can be added easily
- **Separation of concerns**: GraphQL logic separate from native library concerns

## Requirements

- Java 17 or higher
- Maven 3.6 or higher
- For GraphQL client: Access to a Platform Data Doublets GraphQL server
- For native client: Native library (platform-data-doublets-native.dll/so/dylib)
53 changes: 53 additions & 0 deletions java/examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>platform.data.doublets</groupId>
<artifactId>platform-data-doublets-examples</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Platform Data Doublets Examples</name>
<description>Usage examples for Platform Data Doublets Java packages</description>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>platform.data.doublets</groupId>
<artifactId>platform-data-doublets-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>platform.data.doublets</groupId>
<artifactId>platform-data-doublets-gql-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>platform.data.doublets</groupId>
<artifactId>platform-data-doublets-native</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading
Loading