com.speedment.runtime.join.internal.component.stream.SqlJoinStreamSupplierComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of runtime-deploy Show documentation
Show all versions of runtime-deploy Show documentation
A Speedment bundle that shades all dependencies into one jar. This is
useful when deploying an application on a server.
/**
*
* Copyright (c) 2006-2019, 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.runtime.join.internal.component.stream;
import com.speedment.common.function.*;
import com.speedment.common.injector.Injector;
import com.speedment.common.injector.annotation.Config;
import com.speedment.common.injector.annotation.Execute;
import com.speedment.runtime.config.Project;
import com.speedment.runtime.config.identifier.TableIdentifier;
import com.speedment.runtime.core.component.DbmsHandlerComponent;
import com.speedment.runtime.core.component.ProjectComponent;
import com.speedment.runtime.core.component.SqlAdapter;
import com.speedment.runtime.join.Join;
import com.speedment.runtime.join.JoinStreamSupplierComponent;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin10;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin2;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin3;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin4;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin5;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin6;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin7;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin8;
import com.speedment.runtime.join.internal.component.stream.sql.SqlHasCreateJoin9;
import com.speedment.runtime.join.stage.Stage;
import com.speedment.runtime.join.trait.*;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;
/**
*
* @author Per Minborg
*/
public class SqlJoinStreamSupplierComponent
implements JoinStreamSupplierComponent {
private Map, SqlAdapter> sqlAdapterMap;
private HasCreateJoin2 join2Creator;
private HasCreateJoin3 join3Creator;
private HasCreateJoin4 join4Creator;
private HasCreateJoin5 join5Creator;
private HasCreateJoin6 join6Creator;
private HasCreateJoin7 join7Creator;
private HasCreateJoin8 join8Creator;
private HasCreateJoin9 join9Creator;
private HasCreateJoin10 join10Creator;
@Config(name = "allowStreamIteratorAndSpliterator", value = "false")
private boolean allowStreamIteratorAndSpliterator;
@Execute
void init(
final Injector injector,
final ProjectComponent projectComponent,
final DbmsHandlerComponent dbmsHandlerComponent
) {
final Project project = projectComponent.getProject();
sqlAdapterMap = injector.stream(SqlAdapter.class)
.map(sa -> (SqlAdapter) sa)
.collect(
toMap(
sa -> sa.identifier(),
sa -> sa
)
);
join2Creator = new SqlHasCreateJoin2(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join3Creator = new SqlHasCreateJoin3(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join4Creator = new SqlHasCreateJoin4(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join5Creator = new SqlHasCreateJoin5(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join6Creator = new SqlHasCreateJoin6(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join7Creator = new SqlHasCreateJoin7(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join8Creator = new SqlHasCreateJoin8(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join9Creator = new SqlHasCreateJoin9(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
join10Creator = new SqlHasCreateJoin10(dbmsHandlerComponent, project, this::sqlAdapterMapper, allowStreamIteratorAndSpliterator);
}
@Override
public Join createJoin(
final List> stages,
final BiFunction constructor,
final TableIdentifier t0,
final TableIdentifier t1
) {
return join2Creator.createJoin(stages, constructor, t0, t1);
}
@Override
@SuppressWarnings("unchecked")
public Join createJoin(
final List> stages,
final TriFunction constructor,
final TableIdentifier t0,
final TableIdentifier t1,
final TableIdentifier t2
) {
return join3Creator.createJoin(stages, constructor, t0, t1, t2);
}
@Override
@SuppressWarnings("unchecked")
public Join createJoin(
final List> stages,
final QuadFunction constructor,
final TableIdentifier t0,
final TableIdentifier t1,
final TableIdentifier t2,
final TableIdentifier t3
) {
return join4Creator.createJoin(stages, constructor, t0, t1, t2, t3);
}
@Override
@SuppressWarnings("unchecked")
public Join createJoin(
final List> stages,
final Function5 constructor,
final TableIdentifier t0,
final TableIdentifier t1,
final TableIdentifier t2,
final TableIdentifier t3,
final TableIdentifier t4
) {
return join5Creator.createJoin(stages, constructor, t0, t1, t2, t3, t4);
}
@Override
@SuppressWarnings("unchecked")
public Join createJoin(
final List> stages,
final Function6 constructor,
final TableIdentifier t0,
final TableIdentifier t1,
final TableIdentifier t2,
final TableIdentifier t3,
final TableIdentifier t4,
final TableIdentifier t5
) {
return join6Creator.createJoin(stages, constructor, t0, t1, t2, t3, t4, t5);
}
@Override
public Join createJoin(
List> stages,
Function7 constructor,
TableIdentifier t0,
TableIdentifier t1,
TableIdentifier t2,
TableIdentifier t3,
TableIdentifier t4,
TableIdentifier t5,
TableIdentifier t6
) {
return join7Creator.createJoin(stages, constructor, t0, t1, t2, t3, t4, t5, t6);
}
@Override
public Join createJoin(
List> stages,
Function8 constructor,
TableIdentifier t0,
TableIdentifier t1,
TableIdentifier t2,
TableIdentifier t3,
TableIdentifier t4,
TableIdentifier t5,
TableIdentifier t6,
TableIdentifier t7
) {
return join8Creator.createJoin(stages, constructor, t0, t1, t2, t3, t4, t5, t6, t7);
}
@Override
public Join createJoin(
List> stages,
Function9 constructor,
TableIdentifier t0,
TableIdentifier t1,
TableIdentifier t2,
TableIdentifier t3,
TableIdentifier t4,
TableIdentifier t5,
TableIdentifier t6,
TableIdentifier t7,
TableIdentifier t8
) {
return join9Creator.createJoin(stages, constructor, t0, t1, t2, t3, t4, t5, t6, t7, t8);
}
@Override
public Join createJoin(
List> stages,
Function10 constructor,
TableIdentifier t0,
TableIdentifier t1,
TableIdentifier t2,
TableIdentifier t3,
TableIdentifier t4,
TableIdentifier t5,
TableIdentifier t6,
TableIdentifier t7,
TableIdentifier t8,
TableIdentifier t9
) {
return join10Creator.createJoin(stages, constructor, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
}
private SqlAdapter sqlAdapterMapper(TableIdentifier identifier) {
@SuppressWarnings("unchecked")
final SqlAdapter result = (SqlAdapter) sqlAdapterMap.get(identifier);
if (result == null) {
throw new IllegalArgumentException(
"There is no mapping for " + identifier + " "
+ "The following " + sqlAdapterMap.size() + " mappings are available: "
+ sqlAdapterMap.keySet().stream().map(Object::toString).collect(joining(", "))
);
}
return result;
}
}