sql >> データベース >  >> RDS >> PostgreSQL

パッケージ、バージョン、ライセンスをモデル化する方法は?

    あなたは解決策を見つけることにかなり近づいていました。

    次の設定が機能します:

    NpmPackage

    @Entity
    @Table(name = "npm_package")
    public class NpmPackage {
    
      public NpmPackage(String name, String description) {
        this.name = name;
        this.description = description;
      }
    
      public NpmPackage() {
      }
    
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
    
      private String name;
    
      private String description;
    
      @OneToMany(mappedBy = "npmPackage", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
      private List<NpmPackageVersion> versions = new ArrayList<>();
    
      ...//getters and setters
    
      public void addVersion(NpmPackageVersion version) {
        this.versions.add(version);
        version.setNpmPackage(this);
      }
    
      public void removeVersion(NpmPackageVersion version) {
        this.versions.remove(version);
      }
    }
    

    NpmPackageVersion

    @Entity
    @Table(name = "npm_package_version")
    public class NpmPackageVersion {
    
        public NpmPackageVersion(String version, License license) {
            setVersion(version);
            this.license = license;
        }
    
        public NpmPackageVersion() {
        }
    
        @EmbeddedId
        private NpmPackageIdVersion npmPackageIdVersion = new NpmPackageIdVersion();
    
        @MapsId("npmPackageId")
        @ManyToOne
        private NpmPackage npmPackage;
    
        @ManyToOne
        private License license;
    
        public String getVersion() {
            return npmPackageIdVersion.version;
        }
    
        public void setVersion(String version) {
            npmPackageIdVersion.version = version;
        }
    
        ...//getters and setters
    
        @Embeddable
        public static class NpmPackageIdVersion implements Serializable {
            private static final long serialVersionUID = 3357194191099820556L;
    
            private Long npmPackageId;
    
            private String version;
    
            ... //getters and setters etc.
        }
    }
    
    

    ライセンス

    @Entity
    @Table(name = "license")
    public class License {
    
        public License() {}
    
        public License(String name, String licenseId) {
            this.name = name;
            this.licenseId = licenseId;
        }
    
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Integer id;
    
        private String reference;
    
        @Column(name = "is_deprecated_license_id")
        private boolean deprecatedLicenseId;
    
        private Integer referenceNumber;
    
        private String name;
    
        private String licenseId;
    
        @Column(name = "is_osi_approved")
        private boolean osiApproved;
    
        ... //getters and setters
    }
    

    次のコードを使用してテストしました:

    @Transactional
    public NpmPackage createPackage() {
            License license = new License("General Public License", "GPL 2.0");
            em.persist(license);
            NpmPackage npmPackage = new NpmPackage("react", "React Framework");
            npmPackage.addVersion(new NpmPackageVersion("8.11.0", license));
            em.persist(npmPackage);
    }
    



    1. C#をPostgresに接続するにはどうすればよいですか?

    2. DockerへのMySQLのインストールが失敗し、エラーメッセージが表示されますソケットを介してローカルMySQLサーバーに接続できません

    3. PHP PDO複数のクエリリクエストを実行する方法は?

    4. GroovySQLOracle配列関数/プロシージャアウトパラメータの登録