-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeAdapter for UUID, OffsetDateTime and URI
- Loading branch information
Showing
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...ain/java/com/blazebit/expression/declarative/impl/OffsetDateTimeTimestampTypeAdapter.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,55 @@ | ||
/* | ||
* Copyright 2019 - 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.expression.declarative.impl; | ||
|
||
import java.io.Serializable; | ||
import java.time.Instant; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
|
||
import com.blazebit.domain.runtime.model.DomainType; | ||
import com.blazebit.expression.ExpressionInterpreter; | ||
import com.blazebit.expression.spi.TypeAdapter; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.0.0 | ||
*/ | ||
public class OffsetDateTimeTimestampTypeAdapter implements TypeAdapter<OffsetDateTime, Instant>, Serializable { | ||
|
||
public static final OffsetDateTimeTimestampTypeAdapter INSTANCE = new OffsetDateTimeTimestampTypeAdapter(); | ||
|
||
private OffsetDateTimeTimestampTypeAdapter() { | ||
} | ||
|
||
@Override | ||
public Instant toInternalType(ExpressionInterpreter.Context context, OffsetDateTime value, DomainType domainType) { | ||
if (value == null) { | ||
return null; | ||
} | ||
return value.toInstant(); | ||
} | ||
|
||
@Override | ||
public OffsetDateTime toModelType(ExpressionInterpreter.Context context, Instant value, DomainType domainType) { | ||
if (value == null) { | ||
return null; | ||
} | ||
return OffsetDateTime.ofInstant(value, ZoneOffset.UTC); | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
declarative/impl/src/main/java/com/blazebit/expression/declarative/impl/URITypeAdapter.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,46 @@ | ||
/* | ||
* Copyright 2019 - 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.expression.declarative.impl; | ||
|
||
import java.io.Serializable; | ||
import java.net.URI; | ||
|
||
import com.blazebit.domain.runtime.model.DomainType; | ||
import com.blazebit.expression.ExpressionInterpreter; | ||
import com.blazebit.expression.spi.TypeAdapter; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.0.0 | ||
*/ | ||
public class URITypeAdapter implements TypeAdapter<URI, String>, Serializable { | ||
|
||
public static final URITypeAdapter INSTANCE = new URITypeAdapter(); | ||
|
||
private URITypeAdapter() { | ||
} | ||
|
||
@Override | ||
public String toInternalType(ExpressionInterpreter.Context context, URI value, DomainType domainType) { | ||
return value.toString(); | ||
} | ||
|
||
@Override | ||
public URI toModelType(ExpressionInterpreter.Context context, String value, DomainType domainType) { | ||
return URI.create(value); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
declarative/impl/src/main/java/com/blazebit/expression/declarative/impl/UUIDTypeAdapter.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,46 @@ | ||
/* | ||
* Copyright 2019 - 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.expression.declarative.impl; | ||
|
||
import java.io.Serializable; | ||
import java.util.UUID; | ||
|
||
import com.blazebit.domain.runtime.model.DomainType; | ||
import com.blazebit.expression.ExpressionInterpreter; | ||
import com.blazebit.expression.spi.TypeAdapter; | ||
|
||
/** | ||
* @author Christian Beikov | ||
* @since 1.0.0 | ||
*/ | ||
public class UUIDTypeAdapter implements TypeAdapter<UUID, String>, Serializable { | ||
|
||
public static final UUIDTypeAdapter INSTANCE = new UUIDTypeAdapter(); | ||
|
||
private UUIDTypeAdapter() { | ||
} | ||
|
||
@Override | ||
public String toInternalType(ExpressionInterpreter.Context context, UUID value, DomainType domainType) { | ||
return value.toString(); | ||
} | ||
|
||
@Override | ||
public UUID toModelType(ExpressionInterpreter.Context context, String value, DomainType domainType) { | ||
return UUID.fromString(value); | ||
} | ||
} |