Java BreweryDB Connector – Version 0.0.3

On August 13, 2013, in JavaBreweryDBConnector, by terencejackson

Hi Guys,

today I published the version 0.0.3-SNAPSHOT of the Java BreweryDB Connector. It is a connector written it Java to get data of http://www.brewerydb.com/. You can find the Java BreweryDB Connector on Github: https://github.com/terencejackson/JavaBreweryDbConnector

With this version the following new functionality is introduced:

  • Asynchronous beer service
  • Asynchronous guice module
  • Synchronous guice module

To use it in your application you have to put the following in you pom.xml:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<repositories>
    <repository>
        <id>JavaBreweryDbConnector</id>
        <url>https://raw.github.com/terencejackson/JavaBreweryDbConnector/mvn-repo/</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>
 
<dependency>
    <groupId>com.tj.brewerydb</groupId>
    <artifactId>connector</artifactId>
    <version>0.0.3-SNAPSHOT</version>
</dependency>
<repositories>
    <repository>
        <id>JavaBreweryDbConnector</id>
        <url>https://raw.github.com/terencejackson/JavaBreweryDbConnector/mvn-repo/</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>

<dependency>
    <groupId>com.tj.brewerydb</groupId>
    <artifactId>connector</artifactId>
    <version>0.0.3-SNAPSHOT</version>
</dependency>

If you are using Google Guice you can use the connector as followed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
System.out.println("start");
 
// Create the injector, the async module creates the sync and async object
Injector injector = Guice.createInjector(new BreweryDBAsyncModule());
 
// Get the sync service
final IBreweryDBService syncService = injector
        .getInstance(IBreweryDBService.class);
// Do some sync calls
Beer result = syncService.getBeerById("cBLTUw");
System.out.println("Sync: " + result);
//Get beers by name
List<Beer> salvator = syncService.getAllBeers(BeersFilter.createNameFilter("Salvator"));
System.out.println("Sync: " + salvator);
 
// Get the async service
final IBreweryDBServiceAsync asyncService = injector
        .getInstance(IBreweryDBServiceAsync.class);
 
// Do some async calls
asyncService.getAllBeers(new IResultCallback<List<Beer>>() {
 
    public void onSuccess(List<Beer> result) {
        System.out.println(result);
    }
 
    public void onError(Throwable throwable) {
        throwable.printStackTrace();
    }
});
 
asyncService.getBeerById("cBLTUw", new IResultCallback<Beer>() {
 
    public void onSuccess(Beer result) {
        System.out.println("Async:" + result);
    }
 
    public void onError(Throwable throwable) {
        throwable.printStackTrace();
    }
});
 
System.out.println("Done");
System.out.println("start");

// Create the injector, the async module creates the sync and async object
Injector injector = Guice.createInjector(new BreweryDBAsyncModule());

// Get the sync service
final IBreweryDBService syncService = injector
        .getInstance(IBreweryDBService.class);
// Do some sync calls
Beer result = syncService.getBeerById("cBLTUw");
System.out.println("Sync: " + result);
//Get beers by name
List<Beer> salvator = syncService.getAllBeers(BeersFilter.createNameFilter("Salvator"));
System.out.println("Sync: " + salvator);

// Get the async service
final IBreweryDBServiceAsync asyncService = injector
        .getInstance(IBreweryDBServiceAsync.class);

// Do some async calls
asyncService.getAllBeers(new IResultCallback<List<Beer>>() {

    public void onSuccess(List<Beer> result) {
        System.out.println(result);
    }

    public void onError(Throwable throwable) {
        throwable.printStackTrace();
    }
});

asyncService.getBeerById("cBLTUw", new IResultCallback<Beer>() {

    public void onSuccess(Beer result) {
        System.out.println("Async:" + result);
    }

    public void onError(Throwable throwable) {
        throwable.printStackTrace();
    }
});

System.out.println("Done");

By default you have to provide a configuration.properties in your classpath with the following entry:

apiKey=YOURAPIKEY

Hope this post gets you started with the connector.

Tagged with:  

Leave a Reply

Your email address will not be published. Required fields are marked *