-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #865 from jeffgbutler/renderer-factory
Implement Renderer Factory
- Loading branch information
Showing
11 changed files
with
171 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/org/mybatis/dynamic/sql/render/Renderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2016-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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 org.mybatis.dynamic.sql.render; | ||
|
||
@FunctionalInterface | ||
public interface Renderer<T, R> { | ||
R render(T t); | ||
} |
124 changes: 124 additions & 0 deletions
124
src/main/java/org/mybatis/dynamic/sql/render/RendererFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright 2016-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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 org.mybatis.dynamic.sql.render; | ||
|
||
import org.mybatis.dynamic.sql.configuration.StatementConfiguration; | ||
import org.mybatis.dynamic.sql.delete.DeleteModel; | ||
import org.mybatis.dynamic.sql.delete.render.DeleteRenderer; | ||
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider; | ||
import org.mybatis.dynamic.sql.insert.BatchInsertModel; | ||
import org.mybatis.dynamic.sql.insert.GeneralInsertModel; | ||
import org.mybatis.dynamic.sql.insert.InsertModel; | ||
import org.mybatis.dynamic.sql.insert.InsertSelectModel; | ||
import org.mybatis.dynamic.sql.insert.MultiRowInsertModel; | ||
import org.mybatis.dynamic.sql.insert.render.BatchInsert; | ||
import org.mybatis.dynamic.sql.insert.render.BatchInsertRenderer; | ||
import org.mybatis.dynamic.sql.insert.render.GeneralInsertRenderer; | ||
import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider; | ||
import org.mybatis.dynamic.sql.insert.render.InsertRenderer; | ||
import org.mybatis.dynamic.sql.insert.render.InsertSelectRenderer; | ||
import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider; | ||
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider; | ||
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertRenderer; | ||
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider; | ||
import org.mybatis.dynamic.sql.select.MultiSelectModel; | ||
import org.mybatis.dynamic.sql.select.SelectModel; | ||
import org.mybatis.dynamic.sql.select.render.MultiSelectRenderer; | ||
import org.mybatis.dynamic.sql.select.render.SelectRenderer; | ||
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; | ||
import org.mybatis.dynamic.sql.update.UpdateModel; | ||
import org.mybatis.dynamic.sql.update.render.UpdateRenderer; | ||
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider; | ||
|
||
public interface RendererFactory { | ||
static Renderer<RenderingStrategy, DeleteStatementProvider> createDeleteRenderer(DeleteModel deleteModel, | ||
StatementConfiguration statementConfiguration) { | ||
return renderingStrategy -> DeleteRenderer.withDeleteModel(deleteModel) | ||
.withStatementConfiguration(statementConfiguration) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static <T> Renderer<RenderingStrategy, BatchInsert<T>> createBatchInsertRenderer( | ||
BatchInsertModel<T> batchInsertModel) { | ||
return renderingStrategy -> BatchInsertRenderer.withBatchInsertModel(batchInsertModel) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static Renderer<RenderingStrategy, GeneralInsertStatementProvider> createGeneralInsertRenderer( | ||
GeneralInsertModel generalInsertModel, StatementConfiguration statementConfiguration) { | ||
return renderingStrategy -> GeneralInsertRenderer.withInsertModel(generalInsertModel) | ||
.withStatementConfiguration(statementConfiguration) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static <T> Renderer<RenderingStrategy, InsertStatementProvider<T>> createInsertRenderer( | ||
InsertModel<T> insertModel) { | ||
return renderingStrategy -> InsertRenderer.withInsertModel(insertModel) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static Renderer<RenderingStrategy, InsertSelectStatementProvider> createInsertSelectRenderer( | ||
InsertSelectModel insertSelectModel, StatementConfiguration statementConfiguration) { | ||
return renderingStrategy -> InsertSelectRenderer.withInsertSelectModel(insertSelectModel) | ||
.withStatementConfiguration(statementConfiguration) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static <T> Renderer<RenderingStrategy, MultiRowInsertStatementProvider<T>> createMultiRowInsertRenderer( | ||
MultiRowInsertModel<T> multiRowInsertModel) { | ||
return renderingStrategy -> MultiRowInsertRenderer.withMultiRowInsertModel(multiRowInsertModel) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static Renderer<RenderingStrategy, SelectStatementProvider> createMultiSelectRenderer( | ||
MultiSelectModel multiSelectModel, StatementConfiguration statementConfiguration) { | ||
return renderingStrategy -> new MultiSelectRenderer.Builder() | ||
.withMultiSelectModel(multiSelectModel) | ||
.withStatementConfiguration(statementConfiguration) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static Renderer<RenderingContext, SelectStatementProvider> createSelectRenderer( | ||
SelectModel selectModel) { | ||
return renderingContext -> SelectRenderer.withSelectModel(selectModel) | ||
.withRenderingContext(renderingContext) | ||
.build() | ||
.render(); | ||
} | ||
|
||
static Renderer<RenderingStrategy, UpdateStatementProvider> createUpdateRenderer( | ||
UpdateModel updateModel, StatementConfiguration statementConfiguration) { | ||
return renderingStrategy -> UpdateRenderer.withUpdateModel(updateModel) | ||
.withStatementConfiguration(statementConfiguration) | ||
.withRenderingStrategy(renderingStrategy) | ||
.build() | ||
.render(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters