forked from Blazebit/blaze-persistence
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Blazebit#1905] Add some ISO temporal format functions to use in Basi…
…cUserTypes for multiset fetching
- Loading branch information
Showing
46 changed files
with
1,530 additions
and
62 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
56 changes: 56 additions & 0 deletions
56
core/impl/src/main/java/com/blazebit/persistence/impl/function/dateiso/DateIsoFunction.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,56 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.dateiso; | ||
|
||
import com.blazebit.persistence.spi.FunctionRenderContext; | ||
import com.blazebit.persistence.spi.JpqlFunction; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class DateIsoFunction implements JpqlFunction { | ||
public static final String FUNCTION_NAME = "date_iso"; | ||
|
||
@Override | ||
public boolean hasArguments() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hasParenthesesIfNoArguments() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<?> getReturnType(Class<?> firstArgumentType) { | ||
return String.class; | ||
} | ||
|
||
@Override | ||
public void render(FunctionRenderContext context) { | ||
if (context.getArgumentsSize() != 1) { | ||
throw new RuntimeException("The date_iso function needs exactly one argument <date>! args=" + context); | ||
} | ||
context.addChunk( getExpression( context.getArgument( 0))); | ||
} | ||
|
||
protected String getExpression(String timestampArgument) { | ||
return "to_char(" + timestampArgument + ", 'YYYY-MM-DD')"; | ||
} | ||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
...c/main/java/com/blazebit/persistence/impl/function/dateiso/PostgreSQLDateIsoFunction.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,28 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.dateiso; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class PostgreSQLDateIsoFunction extends DateIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "to_char(" + timestampArgument + ", 'YYYY-MM-DD')"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/com/blazebit/persistence/impl/function/dateiso/SQLServerDateIsoFunction.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,29 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.dateiso; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class SQLServerDateIsoFunction extends DateIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "format(" + timestampArgument + ", 'yyyy-MM-dd')"; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...pl/src/main/java/com/blazebit/persistence/impl/function/timeiso/MySQLTimeIsoFunction.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,29 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.timeiso; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class MySQLTimeIsoFunction extends TimeIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "date_format(" + timestampArgument + ", '%H:%i:%S.%f')"; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...c/main/java/com/blazebit/persistence/impl/function/timeiso/PostgreSQLTimeIsoFunction.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,28 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.timeiso; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class PostgreSQLTimeIsoFunction extends TimeIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "to_char(" + timestampArgument + ", 'HH24:MI:SS.US')"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/com/blazebit/persistence/impl/function/timeiso/SQLServerTimeIsoFunction.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,29 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.timeiso; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class SQLServerTimeIsoFunction extends TimeIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "format(" + timestampArgument + ", 'HH:mm:ss.nnnnnnn')"; | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
core/impl/src/main/java/com/blazebit/persistence/impl/function/timeiso/TimeIsoFunction.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,56 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.timeiso; | ||
|
||
import com.blazebit.persistence.spi.FunctionRenderContext; | ||
import com.blazebit.persistence.spi.JpqlFunction; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class TimeIsoFunction implements JpqlFunction { | ||
public static final String FUNCTION_NAME = "time_iso"; | ||
|
||
@Override | ||
public boolean hasArguments() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hasParenthesesIfNoArguments() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<?> getReturnType(Class<?> firstArgumentType) { | ||
return String.class; | ||
} | ||
|
||
@Override | ||
public void render(FunctionRenderContext context) { | ||
if (context.getArgumentsSize() != 1) { | ||
throw new RuntimeException("The time_iso function needs exactly one argument <time>! args=" + context); | ||
} | ||
context.addChunk( getExpression( context.getArgument( 0))); | ||
} | ||
|
||
protected String getExpression(String timestampArgument) { | ||
return "to_char(" + timestampArgument + ", 'HH24:MI:SS.FF9')"; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...n/java/com/blazebit/persistence/impl/function/timestampiso/MySQLTimestampIsoFunction.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,29 @@ | ||
/* | ||
* Copyright 2014 - 2024 Blazebit. | ||
* | ||
* 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.blazebit.persistence.impl.function.timestampiso; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class MySQLTimestampIsoFunction extends TimestampIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "date_format(" + timestampArgument + ", '%Y-%m-%dT%H:%i:%S.%f')"; | ||
} | ||
|
||
} |
Oops, something went wrong.