Skip to content

Commit

Permalink
Refactor API second step.
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Aug 27, 2015
1 parent a5a8253 commit d890286
Show file tree
Hide file tree
Showing 249 changed files with 2,003 additions and 3,248 deletions.
Expand Up @@ -14,9 +14,8 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.util.version;
package com.speedment;

import com.speedment.core.annotations.Api;
import static com.speedment.util.Util.instanceNotAllowed;

/**
Expand All @@ -27,7 +26,6 @@
* @author pemi
* @since 2.0
*/
@Api(version = "2.0")
public final class SpeedmentVersion {

private static final String IMPLEMENTATION_TITLE = "Speedment";
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/speedment/api/HasSpeedment.java
@@ -0,0 +1,9 @@
package com.speedment.api;

/**
*
* @author pemi
*/
public interface HasSpeedment {
Speedment getSpeedment();
}
Expand Up @@ -14,11 +14,11 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.core.manager;
package com.speedment.api;

import com.speedment.core.annotations.Api;
import com.speedment.core.config.model.Column;
import com.speedment.core.config.model.Table;
import com.speedment.api.annotation.Api;
import com.speedment.api.config.Column;
import com.speedment.api.config.Table;
import com.speedment.core.exception.SpeedmentException;
import com.speedment.core.lifecycle.Lifecyclable;
import com.speedment.core.manager.metaresult.MetaResult;
Expand All @@ -35,7 +35,7 @@
* @author pemi
* @param <ENTITY> Entity type for this Manager
*/
@Api(version = "2.0")
@Api(version = "2.1")
public interface Manager<ENTITY> extends Lifecyclable<Manager<ENTITY>> {

// Entity Inspection
Expand All @@ -50,38 +50,15 @@ public interface Manager<ENTITY> extends Lifecyclable<Manager<ENTITY>> {
// Data source metadata
Table getTable();

// Introspectors
// Class<? extends Manager<ENTITY>> getManagerClass();
ENTITY newInstance();

Class<ENTITY> getEntityClass();

// Class<BUILDER> getBuilderClass();
// Factories
//Stream<ENTITY> copies(ENTITY entity);
// BUILDER builder();
//
// BUILDER toBuilder(ENTITY entity);
String toJson(ENTITY entity);

default ENTITY toInternal(ENTITY entity) {
return entity;
}

// Queries
Stream<ENTITY> stream();

default long size() {
return stream().count();
}

// Reactor methods
void onInsert(Consumer<ENTITY> listener);

void onUpdate(Consumer<ENTITY> listener);

void onDelete(Consumer<ENTITY> listener);

// Persistence
/**
* Persists the provided entity to the underlying database and returns a
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/com/speedment/api/Speedment.java
@@ -0,0 +1,79 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.api;

import com.speedment.core.platform.component.Component;
import com.speedment.api.annotation.Api;
import com.speedment.core.exception.SpeedmentException;

/**
* The {@code Platform} class acts as a generic holder of different system
* {@link Component Components}. Using its pluggable architecture, one can
* replace existing default implementations of existing Components or plug in
* custom made implementation of any Interface.
* <p>
* Pluggable instances must implement the {@link Component} interface.
*
* <img src="{@docRoot}/doc-files/hare.png" alt="Hare">
*
* @author pemi
*/
@Api(version = "2.1")
public interface Speedment {

/**
* Gets a {@link Speedment} {@link Component} based on its interface class.
* <p>
* The supported standard interfaces are:
* <ul>
* <li>{@link com.speedment.core.platform.component.EntityManager}</li>
* <li>{@link com.speedment.core.platform.component.DbmsHandlerComponent}</li>
* <li>{@link com.speedment.core.platform.component.ManagerComponent}</li>
* <li>{@link com.speedment.core.platform.component.PrimaryKeyFactoryComponent}</li>
* <li>{@link com.speedment.core.platform.component.ProjectComponent}</li>
* <li>{@link com.speedment.core.platform.component.SqlTypeMapperComponent}</li>
* <li>{@link com.speedment.core.platform.component.LoggerFactoryComponent}</li>
* <li>{@link com.speedment.core.platform.component.JavaTypeMapperComponent}</li>
* </ul>
*
* @param <R> The intended return type
* @param iface The interface class of the intended return type
* @return The currently mapped instance
*/
<R extends Component> R get(Class<R> iface);

Component add(Component item);

/**
* 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;

}
Expand Up @@ -14,7 +14,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.core.annotations;
package com.speedment.api.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.core.config.model;
package com.speedment.api.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Expand Up @@ -14,16 +14,16 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.core.config.model;
package com.speedment.api.config;

import com.speedment.core.config.model.aspects.Ordinable;
import com.speedment.core.annotations.Api;
import com.speedment.core.config.model.aspects.Child;
import com.speedment.core.config.model.aspects.Enableable;
import com.speedment.core.config.model.aspects.Node;
import com.speedment.core.config.model.impl.ColumnImpl;
import com.speedment.core.config.model.parameters.ColumnCompressionTypeable;
import com.speedment.core.config.model.parameters.FieldStorageTypeable;
import com.speedment.api.config.aspects.Ordinable;
import com.speedment.api.annotation.Api;
import com.speedment.api.annotation.External;
import com.speedment.api.config.aspects.Child;
import com.speedment.api.config.aspects.Enableable;
import com.speedment.core.config.impl.ColumnImpl;
import com.speedment.api.config.aspects.ColumnCompressionTypeable;
import com.speedment.api.config.aspects.FieldStorageTypeable;
import java.util.Optional;
import java.util.function.Supplier;

Expand All @@ -32,7 +32,7 @@
*
* @author pemi
*/
@Api(version = "2.0")
@Api(version = "2.1")
public interface Column extends Node, Enableable, Ordinable, Child<Table>,
FieldStorageTypeable, ColumnCompressionTypeable {

Expand Down Expand Up @@ -169,4 +169,4 @@ default Class<Table> getParentInterfaceMainClass() {
*/
@External(type = Class.class)
void setMapping(Class<?> mappedClass);
}
}
Expand Up @@ -14,32 +14,34 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.core.config.model;

import com.speedment.core.annotations.Api;
import com.speedment.core.config.model.aspects.Parent;
import com.speedment.core.config.model.aspects.Child;
import com.speedment.core.config.model.aspects.Enableable;
import com.speedment.core.config.model.aspects.Node;
import com.speedment.core.config.model.impl.DbmsImpl;
import com.speedment.core.config.model.parameters.DbmsTypeable;
package com.speedment.api.config;

import com.speedment.api.Speedment;
import com.speedment.api.annotation.Api;
import com.speedment.core.config.impl.utils.ConfigUtil;
import com.speedment.api.annotation.External;
import com.speedment.api.config.aspects.Parent;
import com.speedment.api.config.aspects.Child;
import com.speedment.api.config.aspects.Enableable;
import com.speedment.api.config.aspects.DbmsTypeable;
import com.speedment.core.config.impl.DbmsImpl;
import groovy.lang.Closure;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.function.Function;

/**
*
* @author pemi
*/
@Api(version = "2.0")
@Api(version = "2.1")
public interface Dbms extends Node, Enableable, DbmsTypeable, Child<Project>, Parent<Schema> {

/**
* Factory holder.
*/
enum Holder {
HOLDER;
private Supplier<Dbms> provider = DbmsImpl::new;
private Function<Speedment, Dbms> provider = DbmsImpl::new;
}

/**
Expand All @@ -48,7 +50,7 @@ enum Holder {
*
* @param provider the new constructor
*/
static void setSupplier(Supplier<Dbms> provider) {
static void setSupplier(Function<Speedment, Dbms> provider) {
Holder.HOLDER.provider = provider;
}

Expand All @@ -57,10 +59,11 @@ static void setSupplier(Supplier<Dbms> provider) {
* supplied by the default factory. To change implementation, please use the
* {@link #setSupplier(java.util.function.Supplier) setSupplier} method.
*
* @return the new instance
* @param speedment the {@link Speedment} instance
* @return the new instance
*/
static Dbms newDbms() {
return Holder.HOLDER.provider.get();
static Dbms newDbms(Speedment speedment) {
return Holder.HOLDER.provider.apply(speedment);
}

/**
Expand All @@ -85,11 +88,7 @@ default Class<Project> getParentInterfaceMainClass() {
*
* @return the newly added child
*/
default Schema addNewSchema() {
final Schema e = Schema.newSchema();
add(e);
return e;
}
Schema addNewSchema();

/**
* Returns the address of the database host if it is specified. The address
Expand Down Expand Up @@ -190,8 +189,5 @@ default Schema addNewSchema() {
* @param c Closure
* @return the new Schema
*/
// DO NOT REMOVE, CALLED VIA REFLECTION
default Schema schema(Closure<?> c) {
return ConfigUtil.groovyDelegatorHelper(c, this::addNewSchema);
}
Schema schema(Closure<?> c);
}
Expand Up @@ -14,22 +14,22 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.core.config.model;
package com.speedment.api.config;

import com.speedment.core.annotations.Api;
import com.speedment.core.config.model.aspects.Parent;
import com.speedment.core.config.model.aspects.Child;
import com.speedment.core.config.model.aspects.Enableable;
import com.speedment.core.config.model.aspects.Node;
import com.speedment.core.config.model.impl.ForeignKeyImpl;
import com.speedment.api.annotation.Api;
import com.speedment.core.config.impl.utils.ConfigUtil;
import com.speedment.api.config.aspects.Parent;
import com.speedment.api.config.aspects.Child;
import com.speedment.api.config.aspects.Enableable;
import com.speedment.core.config.impl.ForeignKeyImpl;
import groovy.lang.Closure;
import java.util.function.Supplier;

/**
*
* @author pemi
*/
@Api(version = "2.0")
@Api(version = "2.1")
public interface ForeignKey extends Node, Enableable, Child<Table>, Parent<ForeignKeyColumn> {

/**
Expand Down Expand Up @@ -83,11 +83,7 @@ default Class<Table> getParentInterfaceMainClass() {
*
* @return the newly added child
*/
default ForeignKeyColumn addNewForeignKeyColumn() {
final ForeignKeyColumn e = ForeignKeyColumn.newForeignKeyColumn();
add(e);
return e;
}
ForeignKeyColumn addNewForeignKeyColumn();

/**
* Creates and returns a new ForeignKeyColumn.
Expand All @@ -97,9 +93,5 @@ default ForeignKeyColumn addNewForeignKeyColumn() {
* @param c Closure
* @return the new ForeignKeyColumn
*/
// DO NOT REMOVE, CALLED VIA REFLECTION
default ForeignKeyColumn foreignKeyColumn(Closure<?> c) {
return ConfigUtil.groovyDelegatorHelper(c, this::addNewForeignKeyColumn);
}

}
public ForeignKeyColumn foreignKeyColumn(Closure<?> c);
}

0 comments on commit d890286

Please sign in to comment.