-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add runtime hints for spanner (#2123)
* fix: add runtime hints for spanner module
- Loading branch information
Showing
13 changed files
with
247 additions
and
22 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
41 changes: 41 additions & 0 deletions
41
...src/main/java/com/google/cloud/spring/data/spanner/aot/SpannerRepositoryRuntimeHints.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,41 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 com.google.cloud.spring.data.spanner.aot; | ||
|
||
import java.util.Arrays; | ||
import org.springframework.aot.hint.MemberCategory; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
import org.springframework.aot.hint.TypeReference; | ||
|
||
public class SpannerRepositoryRuntimeHints implements RuntimeHintsRegistrar { | ||
|
||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
hints | ||
.reflection() | ||
.registerTypes( | ||
Arrays.asList( | ||
TypeReference.of( | ||
com.google.cloud.spring.data.spanner.repository.support.SimpleSpannerRepository | ||
.class)), | ||
hint -> | ||
hint.withMembers( | ||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INVOKE_DECLARED_METHODS)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...rc/main/java/com/google/cloud/spring/data/spanner/aot/SpannerSchemaUtilsRuntimeHints.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,41 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 com.google.cloud.spring.data.spanner.aot; | ||
|
||
import java.util.Arrays; | ||
import org.springframework.aot.hint.MemberCategory; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
import org.springframework.aot.hint.TypeReference; | ||
|
||
public class SpannerSchemaUtilsRuntimeHints implements RuntimeHintsRegistrar { | ||
|
||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
// Called reflectively by org.springframework.expression.spel.support.ReflectiveMethodExecutor | ||
// which is invoked transitively by SpannerPersistentEntityImpl#tableName() from | ||
// SpannerSchemaUtils. | ||
hints | ||
.reflection() | ||
.registerTypes( | ||
Arrays.asList(TypeReference.of(java.lang.String.class)), | ||
hint -> | ||
hint.withMembers( | ||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INVOKE_DECLARED_METHODS)); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
.../src/test/java/com/google/cloud/spring/data/spanner/aot/CommitTimestampsRuntimeHints.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,41 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 com.google.cloud.spring.data.spanner.aot; | ||
|
||
import java.util.Arrays; | ||
import org.springframework.aot.hint.MemberCategory; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
import org.springframework.aot.hint.TypeReference; | ||
|
||
public class CommitTimestampsRuntimeHints implements RuntimeHintsRegistrar { | ||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
hints | ||
.reflection() | ||
.registerTypes( | ||
Arrays.asList( | ||
TypeReference.of( | ||
com.google.cloud.spring.data.spanner.test.domain.CommitTimestamps.class)), | ||
hint -> | ||
hint.withMembers( | ||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, | ||
MemberCategory.DECLARED_CLASSES, | ||
MemberCategory.DECLARED_FIELDS)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...test/java/com/google/cloud/spring/data/spanner/aot/CommitTimestampsRuntimeHintsTests.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,34 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 com.google.cloud.spring.data.spanner.aot; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection; | ||
|
||
import com.google.cloud.spring.data.spanner.test.domain.CommitTimestamps; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
|
||
class CommitTimestampsRuntimeHintsTests { | ||
@Test | ||
void registerCommitTimestamps() { | ||
RuntimeHints runtimeHints = new RuntimeHints(); | ||
CommitTimestampsRuntimeHints registrar = new CommitTimestampsRuntimeHints(); | ||
registrar.registerHints(runtimeHints, null); | ||
assertThat(runtimeHints).matches(reflection().onType(CommitTimestamps.class)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...est/java/com/google/cloud/spring/data/spanner/aot/SpannerRepositoryRuntimeHintsTests.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,35 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 com.google.cloud.spring.data.spanner.aot; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection; | ||
|
||
import com.google.cloud.spring.data.spanner.repository.support.SimpleSpannerRepository; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
|
||
class SpannerRepositoryRuntimeHintsTests { | ||
|
||
@Test | ||
void registerSimpleSpannerRepository() { | ||
RuntimeHints runtimeHints = new RuntimeHints(); | ||
SpannerRepositoryRuntimeHints registrar = new SpannerRepositoryRuntimeHints(); | ||
registrar.registerHints(runtimeHints, null); | ||
assertThat(runtimeHints).matches(reflection().onType(SimpleSpannerRepository.class)); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...st/java/com/google/cloud/spring/data/spanner/aot/SpannerSchemaUtilsRuntimeHintsTests.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,35 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* 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 com.google.cloud.spring.data.spanner.aot; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
|
||
class SpannerSchemaUtilsRuntimeHintsTests { | ||
@Test | ||
void registerString() { | ||
RuntimeHints runtimeHints = new RuntimeHints(); | ||
SpannerSchemaUtilsRuntimeHints registrar = new SpannerSchemaUtilsRuntimeHints(); | ||
registrar.registerHints(runtimeHints, null); | ||
assertThat(runtimeHints) | ||
.matches( | ||
reflection().onType(String.class)); | ||
} | ||
} |
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
Oops, something went wrong.