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 timestampiso function to abstract timestamp forma…
…tting
- Loading branch information
Showing
6 changed files
with
156 additions
and
1 deletion.
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
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-%d %H:%i:%S.%f')"; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...a/com/blazebit/persistence/impl/function/timestampiso/PostgreSQLTimestampIsoFunction.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.timestampiso; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class PostgreSQLTimestampIsoFunction extends TimestampIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "to_char(" + timestampArgument + ", 'YYYY-MM-DD HH24:MI:SS.US')"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...va/com/blazebit/persistence/impl/function/timestampiso/SQLServerTimestampIsoFunction.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 SQLServerTimestampIsoFunction extends TimestampIsoFunction { | ||
@Override | ||
protected String getExpression(String timestampArgument) { | ||
return "format(" + timestampArgument + ", 'yyyy-MM-dd HH:mm:ss.nnnnnnn')"; | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...c/main/java/com/blazebit/persistence/impl/function/timestampiso/TimestampIsoFunction.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.timestampiso; | ||
|
||
import com.blazebit.persistence.spi.FunctionRenderContext; | ||
import com.blazebit.persistence.spi.JpqlFunction; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.6.12 | ||
*/ | ||
public class TimestampIsoFunction implements JpqlFunction { | ||
public static final String FUNCTION_NAME = "timestamp_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 timestamp_iso function needs exactly one argument <timestamp>! args=" + context); | ||
} | ||
context.addChunk( getExpression( context.getArgument( 0))); | ||
} | ||
|
||
protected String getExpression(String timestampArgument) { | ||
return "to_char(" + timestampArgument + ", 'YYYY-MM-DD HH24:MI:SS.FF9')"; | ||
} | ||
|
||
} |
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