-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
767 additions
and
93 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
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,52 @@ | ||
/* | ||
* Copyright (C) 2024 Nameless Production Committee | ||
* | ||
* Licensed under the MIT License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/mit-license.php | ||
*/ | ||
package typewriter.query; | ||
|
||
import java.util.List; | ||
|
||
import ch.epfl.labos.iu.orm.queryll2.path.PathAnalysisMethodChecker; | ||
import ch.epfl.labos.iu.orm.queryll2.symbolic.BasicSymbolicInterpreter.OperationSideEffect; | ||
import ch.epfl.labos.iu.orm.queryll2.symbolic.MethodSignature; | ||
import ch.epfl.labos.iu.orm.queryll2.symbolic.TypedValue; | ||
|
||
public class MethodChecker implements PathAnalysisMethodChecker { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean isFluentChaining(MethodSignature m) { | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public boolean isPutFieldAllowed() { | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public OperationSideEffect isStaticMethodSafe(MethodSignature m) { | ||
return null; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public OperationSideEffect isMethodSafe(MethodSignature m, TypedValue base, List<TypedValue> args) { | ||
return null; | ||
} | ||
} |
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,90 @@ | ||
/* | ||
* Copyright (C) 2024 Nameless Production Committee | ||
* | ||
* Licensed under the MIT License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/mit-license.php | ||
*/ | ||
package typewriter.query; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import typewriter.api.Identifiable; | ||
import typewriter.api.Specifier; | ||
import typewriter.rdb.Dialect; | ||
|
||
public class QueryWriter<M extends Identifiable> { | ||
|
||
private final Dialect dialect; | ||
|
||
private final List<String> selects = new ArrayList(); | ||
|
||
/** | ||
* @param dialect | ||
*/ | ||
public QueryWriter(Dialect dialect) { | ||
this.dialect = dialect; | ||
} | ||
|
||
/** | ||
* Select column by name. | ||
* | ||
* @param column | ||
* @return | ||
*/ | ||
public QueryWriter<M> select(String column) { | ||
return selectAs(null, column); | ||
} | ||
|
||
/** | ||
* Select column by name with alias. | ||
* | ||
* @param alias An alias of column. | ||
* @param column A column name. | ||
* @return | ||
*/ | ||
public QueryWriter<M> selectAs(String alias, String column) { | ||
if (alias == null || alias.isEmpty()) { | ||
selects.add(column); | ||
} else { | ||
selects.add(column + " AS " + alias); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Select column by {@link Specifier}. | ||
* | ||
* @param specifier A column specifier. | ||
* @return | ||
*/ | ||
public QueryWriter<M> select(Specifier<M, ?> specifier) { | ||
return select(specifier.propertyName(dialect)); | ||
} | ||
|
||
/** | ||
* Select column by {@link Specifier} with alias. | ||
* | ||
* @param alias An alias of column. | ||
* @param specifier A column specifier. | ||
* @return | ||
*/ | ||
public QueryWriter<M> selectAs(String alias, Specifier<M, ?> specifier) { | ||
return selectAs(alias, specifier.propertyName(dialect)); | ||
} | ||
|
||
/** | ||
* @param dialect | ||
*/ | ||
public String build(Dialect dialect) { | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
builder.append(selects.stream().collect(Collectors.joining(", ", "SELECT ", ""))); | ||
|
||
return builder.toString(); | ||
} | ||
} |
Oops, something went wrong.