|
25 | 25 |
|
26 | 26 | public abstract class AvroSchemaHelper
|
27 | 27 | {
|
28 |
| - private static final LRUMap<String, String> SCHEMA_NAME_CACHE = new LRUMap<>(16, 1024); |
29 |
| - |
30 | 28 | /**
|
31 | 29 | * Dedicated mapper for handling default values (String <-> JsonNode <-> Object)
|
32 | 30 | *
|
@@ -334,46 +332,47 @@ public static String getTypeId(Schema schema) {
|
334 | 332 | * </p>
|
335 | 333 | */
|
336 | 334 | public static String getFullName(Schema schema) {
|
337 |
| - switch (schema.getType()) { |
338 |
| - case RECORD: |
339 |
| - case ENUM: |
340 |
| - case FIXED: |
341 |
| - String namespace = schema.getNamespace(); |
342 |
| - String name = schema.getName(); |
343 |
| - String key = namespace + "." + name; |
344 |
| - String schemaName = SCHEMA_NAME_CACHE.get(key); |
345 |
| - |
346 |
| - if (schemaName == null) { |
347 |
| - schemaName = resolveFullName(schema); |
348 |
| - SCHEMA_NAME_CACHE.put(key, schemaName); |
349 |
| - } |
350 |
| - |
351 |
| - return schemaName; |
352 |
| - |
353 |
| - default: |
354 |
| - return schema.getType().getName(); |
355 |
| - } |
356 |
| - } |
| 335 | + final Schema.Type type = schema.getType(); |
| 336 | + switch (type) { |
| 337 | + case RECORD: |
| 338 | + case ENUM: |
| 339 | + case FIXED: |
| 340 | + final String namespace = schema.getNamespace(); |
| 341 | + final String name = schema.getName(); |
357 | 342 |
|
358 |
| - private static String resolveFullName(Schema schema) { |
359 |
| - String namespace = schema.getNamespace(); |
360 |
| - String name = schema.getName(); |
| 343 | + // Handle (presumed) common case |
| 344 | + if (namespace == null) { |
| 345 | + return name; |
| 346 | + } |
| 347 | + final int len = namespace.length(); |
| 348 | + if (namespace.charAt(len-1) == '$') { |
| 349 | + return namespace + name; |
| 350 | + } |
| 351 | + return _findFullName(namespace, name); |
361 | 352 |
|
362 |
| - if (namespace == null) { |
363 |
| - return schema.getName(); |
| 353 | + default: |
| 354 | + return type.getName(); |
364 | 355 | }
|
| 356 | + } |
365 | 357 |
|
366 |
| - if (namespace.endsWith("$")) { |
367 |
| - return namespace + name; |
368 |
| - } |
| 358 | + private static String _findFullName(final String namespace, final String name) { |
| 359 | + final String cacheKey = namespace + "." + name; |
| 360 | + String schemaName = SCHEMA_NAME_CACHE.get(cacheKey); |
369 | 361 |
|
| 362 | + if (schemaName == null) { |
| 363 | + schemaName = _resolveFullName(namespace, name); |
| 364 | + SCHEMA_NAME_CACHE.put(cacheKey, schemaName); |
| 365 | + } |
| 366 | + return schemaName; |
| 367 | + } |
| 368 | + |
| 369 | + private static String _resolveFullName(final String namespace, final String name) { |
370 | 370 | StringBuilder sb = new StringBuilder(1 + namespace.length() + name.length());
|
371 | 371 |
|
372 | 372 | // 28-Feb-2020: [dataformats-binary#195] somewhat complicated logic of trying
|
373 | 373 | // to support differences between avro-lib 1.8 and 1.9...
|
374 | 374 | // Check if this is a nested class
|
375 |
| - String nestedClassName = sb.append(namespace).append('$').append(name).toString(); |
376 |
| - |
| 375 | + final String nestedClassName = sb.append(namespace).append('$').append(name).toString(); |
377 | 376 | try {
|
378 | 377 | Class.forName(nestedClassName);
|
379 | 378 |
|
@@ -438,4 +437,7 @@ public static JsonNode parseDefaultValue(String defaultValue) throws JsonMapping
|
438 | 437 | throw new JsonMappingException(null, "Failed to parse default value", e);
|
439 | 438 | }
|
440 | 439 | }
|
| 440 | + |
| 441 | + // @since 2.11.3 |
| 442 | + private static final LRUMap<String, String> SCHEMA_NAME_CACHE = new LRUMap<>(80, 800); |
441 | 443 | }
|
0 commit comments