Skip to content

Commit

Permalink
runtime-core: Implement pluggable terminators etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Apr 15, 2017
1 parent 12649c1 commit d9fae26
Show file tree
Hide file tree
Showing 85 changed files with 3,176 additions and 471 deletions.
Expand Up @@ -732,7 +732,11 @@ enum LogType implements HasLogglerName {
/** /**
* Logging related to connection handling. * Logging related to connection handling.
*/ */
CONNECTION; CONNECTION,
/**
* Logging related to stream optimization handling.
*/
STREAM_OPTIMIZER;


private final String loggerName; private final String loggerName;


Expand Down
@@ -0,0 +1,44 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.speedment.runtime.core.component.sql;

import com.speedment.runtime.core.internal.component.sql.MetricsImpl;

/**
*
*/
public interface Metrics {

/**
* Returns the number of pipeline reductions an optimizer was able to do. If
* an optimizer cannot optimize the pipeline at all, then {@code 0} should
* be returned.
*
* @return The number of pipeline reductions an optimizer was able to do
*/
int getPipelineReductions();

/**
* Creates and returns a new Metrics.
*
* @param pipelineReductions number of pipeline reductions that were made
* @return a new Metrics
*/
static Metrics of(int pipelineReductions) {
return new MetricsImpl(pipelineReductions);
}

/**
* Returns an empty metrics. This can be used by optimizers that are unable
* to optimize the current stream.
*
* @return Returns an empty metrics
*/
static Metrics empty() {
return MetricsImpl.EMPTY;
}

}
Expand Up @@ -27,6 +27,7 @@
*/ */
public interface SqlStreamOptimizer<ENTITY> { public interface SqlStreamOptimizer<ENTITY> {



/** /**
* Returns a metric of how well this optimizer can optimize the given * Returns a metric of how well this optimizer can optimize the given
* pipeline. The best imaginable optimization metric is * pipeline. The best imaginable optimization metric is
Expand All @@ -41,7 +42,7 @@ public interface SqlStreamOptimizer<ENTITY> {
* @param dbmsType the type of the database * @param dbmsType the type of the database
* @return how well this optimizer can optimize the given pipeline * @return how well this optimizer can optimize the given pipeline
*/ */
<P extends Pipeline> int metrics(P initialPipeline, DbmsType dbmsType); <P extends Pipeline> Metrics metrics(P initialPipeline, DbmsType dbmsType);


/** /**
* Returns an optimized pipeline, potentially by modifying the query. * Returns an optimized pipeline, potentially by modifying the query.
Expand Down

This file was deleted.

@@ -0,0 +1,17 @@
package com.speedment.runtime.core.component.sql.override;

import com.speedment.runtime.core.component.sql.override.doubles.DoubleSqlStreamTerminatorOverride;
import com.speedment.runtime.core.component.sql.override.ints.IntSqlStreamTerminatorOverride;
import com.speedment.runtime.core.component.sql.override.longs.LongSqlStreamTerminatorOverride;
import com.speedment.runtime.core.component.sql.override.reference.ReferenceSqlStreamTerminatorOverride;

/**
*
* @author Per Minborg
*/
public interface SqlStreamTerminatorComponent extends
DoubleSqlStreamTerminatorOverride,
IntSqlStreamTerminatorOverride,
LongSqlStreamTerminatorOverride,
ReferenceSqlStreamTerminatorOverride {
}
@@ -0,0 +1,7 @@
package com.speedment.runtime.core.component.sql.override;

/**
*
* @author Per Minborg
*/
public interface Terminator {}
@@ -0,0 +1,27 @@
package com.speedment.runtime.core.component.sql.override.doubles;

import com.speedment.runtime.core.component.sql.SqlStreamOptimizerInfo;
import static com.speedment.runtime.core.internal.component.sql.override.def.doubles.DefaultDoubleCountTerminator.DEFAULT;
import com.speedment.runtime.core.internal.manager.sql.SqlStreamTerminator;
import com.speedment.runtime.core.internal.stream.builder.pipeline.DoublePipeline;

/**
*
* @author Per Minborg
* @param <ENTITY> the original stream entity source type
*/
@FunctionalInterface
public interface DoubleCountTerminator<ENTITY> extends DoubleTerminator {

<T> long apply(
SqlStreamOptimizerInfo<ENTITY> info,
SqlStreamTerminator<ENTITY> sqlStreamTerminator,
DoublePipeline pipeline
);

@SuppressWarnings("unchecked")
static <ENTITY> DoubleCountTerminator<ENTITY> defaultTerminator() {
return (DoubleCountTerminator<ENTITY>) DEFAULT;
}

}
@@ -0,0 +1,32 @@
/**
*
* Copyright (c) 2006-2017, 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.core.component.sql.override.doubles;

/**
*
* @author Per Minborg
*/
public interface DoubleSqlStreamTerminatorOverride {

// ForEachTerminator<ENTITY> getForEachHandler();
//
// void setForEachHandler(ForEachTerminator<ENTITY> forEach);
<ENTITY> DoubleCountTerminator<ENTITY> getDoubleCountTerminator();

<ENTITY> void setDoubleCountTerminator(DoubleCountTerminator<ENTITY> count);

}
@@ -0,0 +1,10 @@
package com.speedment.runtime.core.component.sql.override.doubles;

import com.speedment.runtime.core.component.sql.override.ints.*;
import com.speedment.runtime.core.component.sql.override.Terminator;

/**
*
* @author Per Minborg
*/
public interface DoubleTerminator extends Terminator {}
@@ -0,0 +1,27 @@
package com.speedment.runtime.core.component.sql.override.ints;

import com.speedment.runtime.core.component.sql.SqlStreamOptimizerInfo;
import static com.speedment.runtime.core.internal.component.sql.override.def.ints.DefaultIntCountTerminator.DEFAULT;
import com.speedment.runtime.core.internal.manager.sql.SqlStreamTerminator;
import com.speedment.runtime.core.internal.stream.builder.pipeline.IntPipeline;

/**
*
* @author Per Minborg
* @param <ENTITY> the original stream entity source type
*/
@FunctionalInterface
public interface IntCountTerminator<ENTITY> extends IntTerminator {

<T> long apply(
SqlStreamOptimizerInfo<ENTITY> info,
SqlStreamTerminator<ENTITY> sqlStreamTerminator,
IntPipeline pipeline
);

@SuppressWarnings("unchecked")
static <ENTITY> IntCountTerminator<ENTITY> defaultTerminator() {
return (IntCountTerminator<ENTITY>) DEFAULT;
}

}
@@ -0,0 +1,32 @@
/**
*
* Copyright (c) 2006-2017, 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.core.component.sql.override.ints;

/**
*
* @author Per Minborg
*/
public interface IntSqlStreamTerminatorOverride {

// ForEachTerminator<ENTITY> getForEachHandler();
//
// void setForEachHandler(ForEachTerminator<ENTITY> forEach);
<ENTITY> IntCountTerminator<ENTITY> getIntCountTerminator();

<ENTITY> void setIntCountTerminator(IntCountTerminator<ENTITY> count);

}
@@ -0,0 +1,9 @@
package com.speedment.runtime.core.component.sql.override.ints;

import com.speedment.runtime.core.component.sql.override.Terminator;

/**
*
* @author Per Minborg
*/
public interface IntTerminator extends Terminator {}
@@ -0,0 +1,27 @@
package com.speedment.runtime.core.component.sql.override.longs;

import com.speedment.runtime.core.component.sql.SqlStreamOptimizerInfo;
import static com.speedment.runtime.core.internal.component.sql.override.def.longs.DefaultLongCountTerminator.DEFAULT;
import com.speedment.runtime.core.internal.manager.sql.SqlStreamTerminator;
import com.speedment.runtime.core.internal.stream.builder.pipeline.LongPipeline;

/**
*
* @author Per Minborg
* @param <ENTITY> the original stream entity source type
*/
@FunctionalInterface
public interface LongCountTerminator<ENTITY> extends LongTerminator {

<T> long apply(
SqlStreamOptimizerInfo<ENTITY> info,
SqlStreamTerminator<ENTITY> sqlStreamTerminator,
LongPipeline pipeline
);

@SuppressWarnings("unchecked")
static <ENTITY> LongCountTerminator<ENTITY> defaultTerminator() {
return (LongCountTerminator<ENTITY>) DEFAULT;
}

}
@@ -0,0 +1,32 @@
/**
*
* Copyright (c) 2006-2017, 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.core.component.sql.override.longs;

/**
*
* @author Per Minborg
*/
public interface LongSqlStreamTerminatorOverride {

// ForEachTerminator<ENTITY> getForEachHandler();
//
// void setForEachHandler(ForEachTerminator<ENTITY> forEach);
<ENTITY> LongCountTerminator<ENTITY> getLongCountTerminator();

<ENTITY> void setLongCountTerminator(LongCountTerminator<ENTITY> count);

}
@@ -0,0 +1,9 @@
package com.speedment.runtime.core.component.sql.override.longs;

import com.speedment.runtime.core.component.sql.override.Terminator;

/**
*
* @author Per Minborg
*/
public interface LongTerminator extends Terminator {}

0 comments on commit d9fae26

Please sign in to comment.