Modular Integration

Speedment is designed to play nicely with other frameworks and libraries. On this page we have gathered some links on how to integrate with other environments.

Table of Contents:

Spring Framework

Getting started with Speedment and Spring is very easy! The generated Speedment Application and Manager classes can be configured as Spring Beans, making it possible to autowire them into any controller or service you want!

Here is an example:

SpeedmentConfig.java
@Configuration
class SpeedmentConfig {

    private @Value("${dbms.username}") String username; // Database credentials
    private @Value("${dbms.password}") String password;

    @Bean
    YourApplication getApplication() {
        return new YourApplicationBuilder() // Generated by Speedment
            .withUsername(username)
            .withPassword(password)
            .build();
    }

    @Bean
    EmployeeManager getEmployeeManager(YourApplication app) { 
        return app.getOrThrow(EmployeeManager.class); // Generated manager for Employee table
    }
}

The EmployeeManager can now be autowired into any Spring component like this:

SpeedmentConfig.java
@Component
class MyCustomComponent {

    private @Autowired EmployeeManager employees;

    public int numberOfEmployeesNamedSteveOverThirty() {
        return employees.stream()
            .filter(Employee.NAME.equalIgnoreCase("Steve"))
            .filter(Employee.AGE.greaterOrEqual(30))
            .count(); // Converted into one single SQL statement.
    }
}

For even more examples of Speedment and Spring in action, take a look at the following articles:

Java EE

To integrate Speedment with Java EE, you need to specify how the Speedment instance is created by wrapping the builder pattern in a Java EE singleton bean:

@Startup
@Singleton
public class SpeedmentBean {

    private YourApplication app;
    private EmployeeManager employees;
    
    @PostConstruct
    void init() {
        app = new YourApplicationBuilder()
            .withUsername()
            .withPassword()
            .build();
            
        employees = app.getOrThrow(EmployeeManager.class);
    }
}

You now have an object with a default constructor that can be injected into your other Java EE components using dependency injection.

@Path("/employees")
public class MyAwesomeService {

    @Inject SpeedmentBean speedment;
    
    @GET
    @Path("/overThirty")
    public long getEmployeesOverThirty() {
        return speedment.employees.stream()
            .filter(Employee.NAME.equalIgnoreCase("Steve"))
            .filter(Employee.AGE.greaterOrEqual(30))
            .count(); // Converted into one single SQL statement.
        ;
            
    }
}

For a complete guide on using Speedment with Java EE, see this tutorial.

Sencha Ext JS

The easiest way to integrate Speedment with a front-end framework like Sencha Ext JS is to expand the code generator to also generate REST endpoints and then query them using an Ext JS Grid or Chart backed by a remote datastore.

For a one-end solution using this approach, see the Ext Speeder product.