Skip to content

refactor: update entity type references for consistency across importer formats#2245

Merged
robfrank merged 2 commits intomainfrom
chore/clean-importer
Jun 5, 2025
Merged

refactor: update entity type references for consistency across importer formats#2245
robfrank merged 2 commits intomainfrom
chore/clean-importer

Conversation

@robfrank
Copy link
Collaborator

@robfrank robfrank commented Jun 5, 2025

This pull request includes several changes aimed at improving code readability, modernizing syntax, and enhancing maintainability across multiple files. The most significant updates involve replacing legacy constructs with modern Java features, simplifying imports, and updating enum naming conventions.

Syntax Modernization

  • Replaced if-else type checks with switch expressions for better readability in Type.java.

Enum Naming and Usage

  • Renamed ENTITY_TYPE to EntityType in AnalyzedEntity.java and updated all references across the codebase to use the new naming convention. This improves adherence to Java naming standards. [1] [2] [3] [4] [5] [6] [7] [8]

Import Optimization

  • Reorganized imports in several files to remove unused imports and group related ones together. This cleanup reduces clutter and improves maintainability. [1] [2] [3] [4] [5]

Code Simplification

  • Simplified the getOrCreateEntity method in AnalyzedSchema.java by replacing manual checks with computeIfAbsent, reducing boilerplate code.
  • Replaced a traditional for loop with an enhanced for-each loop in AnalyzedEntity.java for better readability.

Enum Refactoring

  • Renamed PHASE to Phase in OrientDBImporter.java and updated all references to align with Java naming conventions. [1] [2] [3] [4] [5] [6]

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @robfrank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

I, gemini-code-assist, have summarized this pull request. This PR focuses on improving code quality and consistency across the importer formats. Key changes include modernizing Java syntax by replacing if-else chains with switch expressions and traditional for loops with enhanced for-each loops, updating enum naming conventions (ENTITY_TYPE to EntityType, PHASE to Phase) for better adherence to Java standards, optimizing imports to remove unused ones and improve organization, and simplifying code logic, such as using computeIfAbsent in AnalyzedSchema.java.

Highlights

  • Enum Renaming: The ENTITY_TYPE enum in AnalyzedEntity.java has been renamed to EntityType, and the PHASE enum in OrientDBImporter.java has been renamed to Phase to align with standard Java naming conventions. All references across affected files have been updated.
  • Syntax Modernization: Replaced if-else statements with modern switch expressions in Type.java for handling different date/time types. Replaced a traditional for loop with an enhanced for-each loop in AnalyzedEntity.java.
  • Import Optimization: Imports have been cleaned up and reorganized in several files (JsonlExporterFormat.java, AnalyzedEntity.java, AnalyzedProperty.java, Neo4jImporter.java, OrientDBImporter.java, Source.java, SourceDiscovery.java, SourceSchema.java, CreateEdgeFromImportTask.java, LinkEdgeFromImportTask.java, RemoteDatabase.java, RemoteImmutableDocument.java) to remove unused imports and improve readability.
  • Code Simplification: The getOrCreateEntity method in AnalyzedSchema.java was simplified by using computeIfAbsent instead of a manual check and put operation.
  • Consistent Entity Type Usage: Updated method signatures and usages across various importer format files (GraphMLImporterFormat.java, GraphSONImporterFormat.java, Importer.java, SourceDiscovery.java, CSVImporterFormat.java, FormatImporter.java, GloVeImporterFormat.java, JSONImporterFormat.java, JsonlImporterFormat.java, Neo4jImporterFormat.java, OrientDBImporterFormat.java, RDFImporterFormat.java, Word2VecImporterFormat.java, XMLImporterFormat.java) to use the new AnalyzedEntity.EntityType enum.

Changelog

Click here to see the changelog
  • engine/src/main/java/com/arcadedb/schema/Type.java
    • Replaced if-else if chain with a switch expression (lines 558-573) for handling type conversions to Instant.class.
  • gremlin/src/main/java/com/arcadedb/gremlin/integration/importer/format/GraphMLImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 39).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 52).
  • gremlin/src/main/java/com/arcadedb/gremlin/integration/importer/format/GraphSONImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 39).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 52).
  • integration/src/main/java/com/arcadedb/integration/exporter/format/JsonlExporterFormat.java
    • Reorganized and specified individual imports from java.io.*, java.util.*, java.util.logging.*, and java.util.zip.* (lines 40-48).
    • Reordered class members (lines 53-54).
  • integration/src/main/java/com/arcadedb/integration/importer/AnalyzedEntity.java
    • Reorganized and specified individual imports from java.util.* (lines 23-26).
    • Renamed ENTITY_TYPE enum to EntityType (line 29).
    • Changed type of type field from ENTITY_TYPE to EntityType (line 32).
    • Reordered class members (lines 34-36).
    • Replaced traditional for loop with enhanced for-each loop in setRowSize method (lines 68-70).
    • Changed return type of getType() method from ENTITY_TYPE to EntityType (line 83).
  • integration/src/main/java/com/arcadedb/integration/importer/AnalyzedProperty.java
    • Reorganized and specified individual imports from java.util.* (lines 23-24).
    • Reordered class members (lines 31-32).
  • integration/src/main/java/com/arcadedb/integration/importer/AnalyzedSchema.java
    • Changed parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in getOrCreateEntity method signature (line 31).
    • Replaced if-else check with computeIfAbsent logic in getOrCreateEntity method (line 32).
  • integration/src/main/java/com/arcadedb/integration/importer/Importer.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in calls to loadFromSource (lines 53-56).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in loadFromSource method signature (line 80).
  • integration/src/main/java/com/arcadedb/integration/importer/Neo4jImporter.java
    • Reorganized and specified individual imports from java.io.*, java.math.*, java.text.*, java.util.*, java.util.concurrent.atomic.*, java.util.stream.*, and java.util.zip.* (lines 41-58).
    • Removed unused PHASE enum declaration (lines 82-83).
  • integration/src/main/java/com/arcadedb/integration/importer/OrientDBImporter.java
    • Reorganized and specified individual imports from java.io.*, java.util.*, java.util.concurrent.atomic.*, and java.util.zip.* (lines 47-62).
    • Changed type of phase field from PHASE to Phase and updated initialization (line 102).
    • Renamed PHASE enum to Phase (line 112).
    • Updated usage of PHASE.ANALYZE to Phase.ANALYZE (line 211).
    • Updated usage of PHASE.CREATE_SCHEMA to Phase.CREATE_SCHEMA (line 228).
    • Updated usage of PHASE.CREATE_EDGES to Phase.CREATE_EDGES (line 235).
    • Updated usage of PHASE.CREATE_SCHEMA, PHASE.CREATE_RECORDS, PHASE.CREATE_EDGES, and PHASE.ANALYZE to use Phase enum (lines 449-453).
    • Updated usage of PHASE.CREATE_SCHEMA and PHASE.CREATE_RECORDS to use Phase enum (lines 582-584).
  • integration/src/main/java/com/arcadedb/integration/importer/Source.java
    • Reorganized and specified individual imports from java.io.*, java.util.concurrent.*, and java.util.logging.* (lines 23-26).
  • integration/src/main/java/com/arcadedb/integration/importer/SourceDiscovery.java
    • Reorganized and specified individual imports from java.io.*, java.lang.reflect.*, java.net.*, java.util.*, java.util.concurrent.*, java.util.concurrent.atomic.*, java.util.logging.*, and java.util.zip.* (lines 34-52).
    • Improved formatting for getSchema method signature (lines 66-69).
    • Removed unnecessary if (formatImporter == null) check (lines 81-89).
    • Improved formatting for getSourceFromURL method return statement (lines 116-140).
    • Improved formatting for analyzeSourceContent method signature (lines 186-188).
    • Improved formatting for Class.forName calls and catch blocks (lines 231-235, 242-246).
    • Improved formatting for log message in analyzeSourceContent (lines 251-252).
    • Improved formatting for log message in analyzeSourceContent (lines 326-327).
  • integration/src/main/java/com/arcadedb/integration/importer/SourceSchema.java
    • Reorganized and specified individual imports from java.util.* (lines 23-24).
    • Reordered class members (lines 27-28).
  • integration/src/main/java/com/arcadedb/integration/importer/format/CSVImporterFormat.java
    • Improved formatting for load method signature (lines 61-65).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 434).
    • Updated usage of AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType (lines 476-478).
  • integration/src/main/java/com/arcadedb/integration/importer/format/FormatImporter.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 34).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 37).
  • integration/src/main/java/com/arcadedb/integration/importer/format/GloVeImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 44).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 59).
  • integration/src/main/java/com/arcadedb/integration/importer/format/JSONImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 69).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 113).
  • integration/src/main/java/com/arcadedb/integration/importer/format/JsonlImporterFormat.java
    • Changed import from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType (line 13).
    • Updated parameter type from ENTITY_TYPE to EntityType in load method signature (line 44).
    • Updated parameter type from ENTITY_TYPE to EntityType in analyze method signature (line 243).
  • integration/src/main/java/com/arcadedb/integration/importer/format/Neo4jImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 35).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 55).
  • integration/src/main/java/com/arcadedb/integration/importer/format/OrientDBImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 36).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 56).
  • integration/src/main/java/com/arcadedb/integration/importer/format/RDFImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 37).
  • integration/src/main/java/com/arcadedb/integration/importer/format/Word2VecImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 44).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 60).
  • integration/src/main/java/com/arcadedb/integration/importer/format/XMLImporterFormat.java
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in load method signature (line 43).
    • Updated parameter type from AnalyzedEntity.ENTITY_TYPE to AnalyzedEntity.EntityType in analyze method signature (line 140).
  • integration/src/main/java/com/arcadedb/integration/importer/graph/CreateEdgeFromImportTask.java
    • Reorganized and specified individual imports from java.util.* and java.util.logging.* (lines 41-43).
    • Improved formatting for constructor signature (lines 57-63).
    • Added @Override annotation to execute method (line 73).
    • Improved formatting for log message in execute (lines 108-113).
    • Improved formatting for CompressedRID2RIDsIndex instantiation (lines 120-122).
    • Improved formatting for createEdgesInBatch method signature (lines 143-145).
    • Improved formatting for createIncomingEdgesInBatch method signature (lines 163-164).
    • Improved formatting for log message in createIncomingEdgesInBatch (lines 168-172).
    • Improved formatting for log message in createIncomingEdgesInBatch (lines 205-207).
    • Improved formatting for log message in createIncomingEdgesInBatch (lines 215-217).
  • integration/src/main/java/com/arcadedb/integration/importer/graph/GraphImporter.java
    • Reorganized and specified individual imports from java.util.* and java.util.logging.* (lines 37-40).
    • Renamed STATUS enum to Status (line 47).
    • Changed type of status field from STATUS to Status and updated initialization (line 49).
    • Reordered class members in GraphImporterThreadContext (lines 52-53).
    • Improved formatting for constructor signature (lines 64-65).
    • Added check for active transaction before commit in close method (lines 84-85).
    • Replaced traditional for loop with enhanced for-each loop in close method (lines 89-90).
    • Replaced traditional for loop with Arrays.fill in close method (line 96).
    • Updated usage of STATUS.CLOSED to Status.CLOSED (line 98).
    • Replaced final DatabaseInternal db = database; with direct usage of database in createVertex (lines 121-122).
    • Improved formatting for createEdge method signature (lines 130-135).
    • Improved formatting for async.scheduleTask call (lines 139-141).
    • Updated usage of STATUS.IMPORTING_VERTEX to Status.IMPORTING_VERTEX (line 145).
    • Updated usage of STATUS.IMPORTING_EDGE to Status.IMPORTING_EDGE (line 148).
    • Replaced traditional for loop with enhanced for-each loop in createIncomingEdges (lines 177-178).
    • Improved formatting for log message in createIncomingEdges (lines 195-197).
  • integration/src/main/java/com/arcadedb/integration/importer/graph/LinkEdgeFromImportTask.java
    • Reorganized and specified individual imports from java.util.* (line 31).
    • Improved formatting for constructor signature (lines 41-43).
    • Added @Override annotation to execute method (line 49).
  • network/src/main/java/com/arcadedb/remote/RemoteDatabase.java
    • Reorganized and specified individual imports from java.io.* and java.net.* (lines 45-49).
    • Added static import for CAT_PROPERTY (line 51).
    • Used CAT_PROPERTY constant instead of literal string "@cat" (line 539).
    • Replaced if-else if chain with a switch expression (lines 541-545) for handling record categories.
  • network/src/main/java/com/arcadedb/remote/RemoteImmutableDocument.java
    • Reorganized and specified individual imports from java.util.* (lines 30-33).
    • Added static imports for CAT_PROPERTY and TYPE_PROPERTY (lines 35, 37).
    • Added a blank line in the get method (line 83).
    • Used CAT_PROPERTY constant instead of literal string "@cat" (line 96).
    • Used TYPE_PROPERTY constant instead of literal string "@type" (line 97).
    • Used CAT_PROPERTY constant instead of literal string "@cat" (line 108).
    • Used TYPE_PROPERTY constant instead of literal string "@type" (line 109).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Enums uppercase,
A style now past its grace.
Lowercase the name,
Consistency's the aim,
Refactor finds its place.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a good set of refactorings that enhance code readability, modernize syntax, and improve maintainability. The changes, particularly the consistent renaming of enums to follow Java conventions (e.g., EntityType, Phase) and the adoption of modern Java features like switch expressions and computeIfAbsent, are well-executed and beneficial.

The import optimizations and simplifications like using enhanced for-each loops also contribute positively to the codebase's clarity.

I've noted a few minor points for consideration, but overall, the changes are solid.

Summary of Findings

  • Enum Naming Conventions: Successfully updated enums like ENTITY_TYPE to EntityType and PHASE to Phase, adhering to Java naming standards.
  • Syntax Modernization: Effectively replaced if-else chains with switch expressions in several places, enhancing readability.
  • Code Simplification: Utilized modern Java features like computeIfAbsent and enhanced for-each loops to simplify code and reduce boilerplate.
  • Import Optimization: Cleaned up imports across multiple files, improving maintainability.
  • Use of Constants: Replaced magic strings like "@cat" with defined constants (e.g., Property.CAT_PROPERTY) in network communication classes, which is a good practice.
  • Potential NullPointerException: In SourceDiscovery.java, a removed null check for formatImporter might lead to an NPE if analyzeSourceContent can return null. This needs verification.
  • Switch Default Case Handling: In Type.java, the new switch expression has an empty default case. Consider if explicit error handling for unexpected types would be more robust.

Merge Readiness

The pull request is in good shape and introduces valuable refactorings. The identified points are mostly minor or for clarification. Once these are considered or addressed, the PR should be ready for merging. As an AI, I cannot approve pull requests, so please ensure it's reviewed and approved by other team members.

Comment on lines +558 to +573
switch (value) {
case Instant instant -> {
if (property != null)
return instant.truncatedTo(DateUtils.getPrecisionFromType(property.getType()));
} else if (value instanceof Date date)
}
case Date date -> {
return DateUtils.dateTime(database, date.getTime(), ChronoUnit.MILLIS, LocalDateTime.class,
property != null ? DateUtils.getPrecisionFromType(property.getType()) : ChronoUnit.MILLIS);
else if (value instanceof Calendar calendar)
}
case Calendar calendar -> {
return DateUtils.dateTime(database, calendar.getTimeInMillis(), ChronoUnit.MILLIS, Instant.class,
property != null ? DateUtils.getPrecisionFromType(property.getType()) : ChronoUnit.MILLIS);
}
default -> {
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new switch expression is a good improvement for readability over the if-else if chain. However, the default case (lines 571-572) is currently empty. If the intention is that no action should be taken for other types, this is fine. But if this switch is expected to be exhaustive for Instant.class conversions or if other value types might lead to unexpected fall-through, consider if an explicit throw new IllegalArgumentException("Unsupported type for Instant conversion: " + value.getClass().getName()); or similar handling in the default case would be more robust. This would make unexpected types fail fast. What are your thoughts on this?

default -> {
          throw new IllegalArgumentException("Unsupported type for Instant conversion: " + value.getClass().getName());
        }

Comment on lines +84 to +85
if (database.isTransactionActive())
database.commit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check if (database.isTransactionActive()) before committing is a good addition for robustness. It prevents attempting to commit if no transaction is active, which could lead to errors or unexpected behavior.

@codacy-production
Copy link

codacy-production bot commented Jun 5, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.05% 26.61%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (3ce825e) 72354 46148 63.78%
Head commit (dfee0a7) 72361 (+7) 46114 (-34) 63.73% (-0.05%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2245) 109 29 26.61%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@robfrank robfrank merged commit f7cbb74 into main Jun 5, 2025
17 of 19 checks passed
robfrank added a commit that referenced this pull request Jun 17, 2025
…er formats (#2245) [skip ci]

(cherry picked from commit f7cbb74)
@robfrank robfrank deleted the chore/clean-importer branch June 20, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant