Skip to content

Commit

Permalink
Runtime: Fix bugs and increase testability
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Jun 10, 2016
1 parent f86829c commit 0e15457
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 42 deletions.
29 changes: 5 additions & 24 deletions runtime/src/main/java/com/speedment/runtime/Speedment.java
Expand Up @@ -20,7 +20,6 @@
import com.speedment.runtime.component.Component;
import com.speedment.runtime.config.Project;
import com.speedment.runtime.exception.SpeedmentException;
import com.speedment.runtime.manager.Manager;

/**
* The {@code Platform} class acts as a generic holder of different system
Expand All @@ -36,36 +35,18 @@
*/
@Api(version = "2.4")
public interface Speedment {

/**
* Obtains and returns the currently associated {@link Manager}
* implementation for the given Entity interface Class. If no Manager exists
* for the given entityClass, a SpeedmentException will be thrown.
* <p>
* N.B.This conveniency method is a pure delegator to the ManagerComponent
* and is exactly equivalent to the code:
* <p>
* {@code get(ManagerComponent.class).managerOf(entityClass) }
*
* @param <ENTITY> the Entity interface type
* @param entityClass the Entity interface {@code Class}
* @return the currently associated {@link Manager} implementation for the
* given Entity interface Class
* @throws SpeedmentException if no Manager exists for the given entityClass
*/
<ENTITY> Manager<ENTITY> managerOf(Class<ENTITY> entityClass) throws SpeedmentException;


/**
* Returns the specified component from the platform, or if it does not
* exist, throws a {@code SpeedmentException}.
*
* @param <C> the component interface type
* @param componentClass the component interface class
* @return the component
* @param <T> the component interface type
* @param type the component interface class
* @return the component
*
* @throws SpeedmentException if it was not installed
*/
<C extends Component> C getOrThrow(Class<C> componentClass) throws SpeedmentException;
<T> T getOrThrow(Class<T> type) throws SpeedmentException;

/**
* Returns the project node.
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.speedment.runtime.internal.runtime;

import com.speedment.common.injector.Injector;
import com.speedment.common.injector.exception.CyclicReferenceException;
import com.speedment.runtime.Speedment;
import com.speedment.runtime.SpeedmentVersion;
import static com.speedment.runtime.SpeedmentVersion.getImplementationVendor;
Expand Down Expand Up @@ -79,8 +80,7 @@ public abstract class AbstractApplicationBuilder<
private boolean validateRuntimeConfig;

protected AbstractApplicationBuilder(Class<? extends APP> applicationImplClass) {
this.injector = Injector.builder()
.canInject(applicationImplClass);
this.injector = Injector.builder().canInject(applicationImplClass);

withsNamed = new ArrayList<>();
withsAll = new ArrayList<>();
Expand Down Expand Up @@ -230,7 +230,7 @@ public final APP build() {

try {
inj = injector.build();
} catch (final InstantiationException ex) {
} catch (final InstantiationException | CyclicReferenceException ex) {
throw new SpeedmentException("Error in dependency injection.", ex);
}

Expand Down
Expand Up @@ -20,7 +20,6 @@
import com.speedment.common.injector.annotation.Inject;
import com.speedment.common.injector.annotation.RequiresInjectable;
import com.speedment.runtime.Speedment;
import com.speedment.runtime.component.Component;
import com.speedment.runtime.component.ManagerComponent;
import com.speedment.runtime.component.ProjectComponent;
import com.speedment.runtime.config.Project;
Expand All @@ -38,8 +37,6 @@
import com.speedment.runtime.internal.component.ResultSetMapperComponentImpl;
import com.speedment.runtime.internal.component.TypeMapperComponentImpl;
import com.speedment.runtime.internal.config.dbms.StandardDbmsTypes;
import com.speedment.runtime.manager.Manager;
import static java.util.Objects.requireNonNull;

/**
* An abstract base implementation of the {@link Speedment} interface.
Expand All @@ -64,23 +61,13 @@
})
public abstract class AbstractSpeedment implements Speedment {

private @Inject ManagerComponent managerComponent;
private @Inject ProjectComponent projectComponent;
private Injector injector;
private @Inject Injector injector;

protected AbstractSpeedment() {}

void setInjector(Injector injector) {
this.injector = requireNonNull(injector);
}

@Override
public <ENTITY> Manager<ENTITY> managerOf(Class<ENTITY> entityClass) throws SpeedmentException {
return managerComponent.managerOf(entityClass);
}

@Override
public <C extends Component> C getOrThrow(Class<C> componentClass) throws SpeedmentException {
public <T> T getOrThrow(Class<T> componentClass) throws SpeedmentException {
try {
return injector.get(componentClass);
} catch (final IllegalArgumentException ex) {
Expand Down

0 comments on commit 0e15457

Please sign in to comment.