├── .gitignore ├── LICENSE-2.0.txt ├── README.md ├── changelog.txt ├── pom.xml └── src ├── main ├── config │ └── musicbrainz-data.properties.example ├── java │ └── fm │ │ └── last │ │ └── musicbrainz │ │ └── data │ │ ├── dao │ │ ├── ArtistDao.java │ │ ├── MusicBrainzDao.java │ │ ├── RecordingDao.java │ │ ├── ReleaseDao.java │ │ ├── TrackDao.java │ │ └── impl │ │ │ ├── AbstractMusicBrainzHibernateDao.java │ │ │ ├── ArtistDaoImpl.java │ │ │ ├── RecordingDaoImpl.java │ │ │ ├── ReleaseDaoImpl.java │ │ │ └── TrackDaoImpl.java │ │ ├── hibernate │ │ ├── AbstractEnumUserType.java │ │ ├── AreaTypeUserType.java │ │ ├── ArtistTypeUserType.java │ │ ├── GenderUserType.java │ │ ├── ReleaseGroupPrimaryTypeUserType.java │ │ ├── ReleaseGroupSecondaryTypeUserType.java │ │ └── ReleaseStatusUserType.java │ │ └── model │ │ ├── AbstractCoreEntity.java │ │ ├── AbstractName.java │ │ ├── Area.java │ │ ├── AreaType.java │ │ ├── Artist.java │ │ ├── ArtistCredit.java │ │ ├── ArtistCreditName.java │ │ ├── ArtistCreditNameCompositeKey.java │ │ ├── ArtistType.java │ │ ├── Gender.java │ │ ├── Medium.java │ │ ├── PartialDate.java │ │ ├── Recording.java │ │ ├── Release.java │ │ ├── ReleaseCountry.java │ │ ├── ReleaseCountryCompositeKey.java │ │ ├── ReleaseGroup.java │ │ ├── ReleaseGroupPrimaryType.java │ │ ├── ReleaseStatus.java │ │ ├── ReleaseUnknownCountry.java │ │ └── Track.java └── resources │ └── spring │ └── musicbrainz-data.xml └── test ├── config └── musicbrainz-data.properties ├── java └── fm │ └── last │ └── musicbrainz │ └── data │ ├── AbstractHibernateModelIT.java │ ├── dao │ └── impl │ │ ├── ArtistDaoImplIT.java │ │ ├── RecordingDaoIT.java │ │ ├── ReleaseDaoImplIT.java │ │ └── TrackDaoImplIT.java │ └── model │ ├── AreaIT.java │ ├── AreaTypeTest.java │ ├── ArtistCreditIT.java │ ├── ArtistIT.java │ ├── ArtistTypeTest.java │ ├── GenderTest.java │ ├── MediumIT.java │ ├── PartialDateTest.java │ ├── RecordingIT.java │ ├── ReleaseGroupIT.java │ ├── ReleaseGroupPrimaryTypeTest.java │ ├── ReleaseIT.java │ ├── ReleaseStatusTest.java │ └── TrackIT.java ├── resources ├── log4j.xml └── spring │ └── musicbrainz-data-test.xml └── sql └── musicbrainz-unittest.sql /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings/ 4 | target/ 5 | .idea 6 | *.iml 7 | -------------------------------------------------------------------------------- /LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # musicbrainz-data 2 | 3 | Java data bindings for the [MusicBrainz Database](http://musicbrainz.org/doc/MusicBrainz_Database) using Hibernate. 4 | 5 | ## Things to know 6 | 7 | * As of now, `musicbrainz-data` is meant for read-only access to the MusicBrainz Database. Nothing, however, prevents a user from changing entites; any change might be written to the database and might leave it in an inconsistent state afterwards. 8 | * Only a subset of the [database schema](http://musicbrainz.org/doc/MusicBrainz_Database/Schema) is implemented. Access is provided to artists, releases, tracks and recordings (and related tables). 9 | 10 | ## Configuration 11 | 12 | ### Set some properties for your context 13 | 14 | db.musicbrainz.driver.class=org.postgresql.Driver 15 | db.musicbrainz.url=jdbc:postgresql://localhost:5432/musicbrainz_db 16 | db.musicbrainz.user=musicbrainz 17 | db.musicbrainz.password=musicbrainz 18 | 19 | (see `src/main/config/musicbrainz-data.properties.example` for all available options) 20 | 21 | ### Import the musicbrainz-data Spring context: 22 | 23 | 24 | 25 | ### Add the musicbrainz-data dependency: 26 | 27 | 28 | fm.last 29 | musicbrainz-data 30 | 3.0.0 31 | 32 | 33 | ## Usage examples 34 | 35 | See the included tests for more examples. The Javadoc can be generated by running `mvn javadoc:javadoc`. 36 | 37 | ### General pattern 38 | 39 | @Component 40 | public class ArtistHandler { 41 | 42 | private final ArtistDao artistDao; 43 | 44 | @Autowired 45 | public ArtistHandler(ArtistDao artistDao) { 46 | this.artistDao = artistDao; 47 | } 48 | 49 | @Transactional 50 | public void process(int id) { 51 | Artist artist = artistDao.getById(id); 52 | // ... 53 | } 54 | } 55 | 56 | ### Query for all artists named 'MONO' (casing will be ignored) 57 | 58 | List artists = artistDao.getByName("mono"); 59 | 60 | ### Get release with GID 'c69b70bc-049e-3e3f-a5e4-5a1b4d62105f' 61 | 62 | UUID musicBrainzId = UUID.fromString("c69b70bc-049e-3e3f-a5e4-5a1b4d62105f"); 63 | Release release = releaseDao.getByGid(musicBrainzId); 64 | 65 | ## Running the tests 66 | 67 | * Create an empty database `musicbrainz_musicbrainzdata_unittest` (as described in the [MusicBrainz documentation](https://github.com/metabrainz/musicbrainz-server)). 68 | * Run `mvn clean verify` 69 | 70 | ## Contributing 71 | 72 | All contributions are welcome. Please use the [Last.fm codeformatting profile](https://github.com/lastfm/lastfm-oss-config/blob/master/src/main/resources/fm/last/last.fm.eclipse-codeformatter-profile.xml) found in the `lastfm-oss-config` project for formatting your changes. 73 | 74 | ### Contributors 75 | 76 | * [Stefan Sperber](https://github.com/stefansperber) (Last.fm) 77 | * [Oliver Charles](https://github.com/ocharles) (MusicBrainz) 78 | * [Aurélien Mino](https://github.com/murdos) 79 | 80 | ## License 81 | 82 | Copyright 2013 [Last.fm](http://www.last.fm/) 83 | 84 | 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 85 | 86 | [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 87 | 88 | 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. 89 | 90 | ## Kthxbye 91 | 92 | Last.fm <3 MusicBrainz 93 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | TBA 2 | - Schema-related update. Removed X_name table joins, using 'name' columns instead. 3 | 4 | 3.1.0 (2013-05-29) 5 | - Changed visibility of AbstractCoreEntity to public to allow mocking of entities (e.g., Artist, Track) 6 | (Mockito has problems when the parent of the mocked class is not public). 7 | 8 | 3.0.0 (2013-05-25) 9 | - Implemented changes from 2013-05-15 schema upgrade (API changes in TrackDao, Artist, Release, and Track). 10 | - Migrated project to lastfm-oss-parent. 11 | - Upgraded dependencies (Spring to 3.2.2.RELEASE, Guava to 14.0.1, slf4j to 1.7.5, joda-time to 2.2). 12 | 13 | 2.0.0 (2012-10-29) 14 | - Added support for artist gender, artist type, and artist begin and end dates (Thanks @murdos). 15 | - Improved representation of partial dates (Thanks @murdos). 16 | - Simplified implementation of ArtistCredit#getFullName() as artist_credit_name.join_phrase cannot be null 17 | after 2012-10-15 schema change. 18 | 19 | 1.3 (2012-08-06) 20 | - Replaced Spring dependency with latest release version 3.1.2.RELEASE. 21 | 22 | 1.2 (2012-07-26) 23 | - Initial release. DAOs and model objects to access artists, releases, tracks and recordings and their related entities. 24 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | fm.last 6 | lastfm-oss-parent 7 | 1.1.0 8 | 9 | 10 | musicbrainz-data 11 | jar 12 | 3.1.1-SNAPSHOT 13 | ${project.artifactId} 14 | ${project.scm.url} 15 | Java data bindings for the MusicBrainz Database using Hibernate 16 | 17 | 18 | scm:git:git@github.com:lastfm/${project.artifactId}.git 19 | scm:git:git@github.com:lastfm/${project.artifactId}.git 20 | https://github.com/lastfm/${project.artifactId} 21 | 22 | 23 | 24 | 25 | Stefan Sperber 26 | stefan.sperber@gmail.com 27 | http://www.stefansperber.com 28 | 29 | Java Developer 30 | 31 | Last.fm 32 | http://www.last.fm/ 33 | 34 | 35 | Oliver Charles 36 | ollie@ocharles.org.uk 37 | http://www.ocharles.org.uk 38 | 39 | Java Developer 40 | 41 | MusicBrainz 42 | http://www.musicbrainz.org/ 43 | 44 | 45 | Aurélien Mino 46 | aurelien.mino@gmail.com 47 | http://github.com/murdos 48 | 49 | Java Developer 50 | 51 | 52 | 53 | 54 | 55 | 3.6.9.Final 56 | 3.2.2.RELEASE 57 | 1.7.5 58 | 59 | 60 | 61 | 62 | org.hibernate 63 | hibernate-core 64 | ${hibernateVersion} 65 | 66 | 67 | joda-time 68 | joda-time 69 | 2.2 70 | 71 | 72 | joda-time 73 | joda-time-hibernate 74 | 1.3 75 | 76 | 77 | com.google.guava 78 | guava 79 | 14.0.1 80 | 81 | 82 | org.slf4j 83 | slf4j-api 84 | ${slf4jVersion} 85 | 86 | 87 | org.apache.commons 88 | commons-lang3 89 | 3.1 90 | 91 | 92 | 93 | 94 | org.springframework 95 | spring-core 96 | ${springVersion} 97 | 98 | 99 | org.springframework 100 | spring-expression 101 | ${springVersion} 102 | 103 | 104 | org.springframework 105 | spring-aop 106 | ${springVersion} 107 | 108 | 109 | org.springframework 110 | spring-beans 111 | ${springVersion} 112 | 113 | 114 | org.springframework 115 | spring-context 116 | ${springVersion} 117 | 118 | 119 | org.springframework 120 | spring-jdbc 121 | ${springVersion} 122 | 123 | 124 | org.springframework 125 | spring-orm 126 | ${springVersion} 127 | 128 | 129 | 130 | 131 | org.hamcrest 132 | hamcrest-library 133 | 1.3 134 | test 135 | 136 | 137 | junit 138 | junit 139 | 4.13.1 140 | test 141 | 142 | 143 | org.springframework 144 | spring-test 145 | ${springVersion} 146 | test 147 | 148 | 149 | org.slf4j 150 | slf4j-log4j12 151 | ${slf4jVersion} 152 | test 153 | 154 | 155 | 156 | 157 | c3p0 158 | c3p0 159 | 0.9.1.2 160 | runtime 161 | 162 | 163 | postgresql 164 | postgresql 165 | 9.1-901-1.jdbc4 166 | runtime 167 | 168 | 169 | org.javassist 170 | javassist 171 | 3.14.0-GA 172 | runtime 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /src/main/config/musicbrainz-data.properties.example: -------------------------------------------------------------------------------- 1 | db.musicbrainz.driver.class=org.postgresql.Driver 2 | db.musicbrainz.url=jdbc:postgresql://:/ 3 | db.musicbrainz.user= 4 | db.musicbrainz.password= 5 | db.musicbrainz.initial.pool.size= 6 | db.musicbrainz.max.pool.size= 7 | db.musicbrainz.acquire.increment= 8 | db.musicbrainz.max.idle.time= 9 | db.musicbrainz.idle.connection.test.period= -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/ArtistDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao; 17 | 18 | import java.util.List; 19 | 20 | import fm.last.musicbrainz.data.model.Artist; 21 | 22 | /** 23 | * Provides access to {@link Artist}s. 24 | */ 25 | public interface ArtistDao extends MusicBrainzDao { 26 | 27 | /** 28 | * Ignores the casing of {@code name}. 29 | * 30 | * @return Empty list when no {@link Artist}s are found 31 | */ 32 | public List getByName(String name); 33 | 34 | } -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/MusicBrainzDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao; 17 | 18 | import java.util.UUID; 19 | 20 | interface MusicBrainzDao { 21 | 22 | /** 23 | * @return Null if no entity with {@code id} exists 24 | */ 25 | T getById(int id); 26 | 27 | /** 28 | * Finds an entity by canonical GID or redirected GID. 29 | * 30 | * @return Null if no entity with associated {@code gid} exists 31 | */ 32 | T getByGid(UUID gid); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/RecordingDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao; 17 | 18 | import java.util.List; 19 | 20 | import fm.last.musicbrainz.data.model.Artist; 21 | import fm.last.musicbrainz.data.model.Recording; 22 | 23 | /** 24 | * Provides access to {@link Recording}s. 25 | */ 26 | public interface RecordingDao extends MusicBrainzDao { 27 | 28 | /** 29 | * Ignores the casing of {@code trackName}. 30 | * 31 | * @return Empty list if no {@link Recording}s are found 32 | */ 33 | List getByArtistAndName(Artist artist, String trackName); 34 | 35 | /** 36 | * @return Empty list if {@link Artist} has no {@link Recording}s 37 | */ 38 | List getByArtist(Artist artist); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/ReleaseDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao; 17 | 18 | import java.util.List; 19 | 20 | import fm.last.musicbrainz.data.model.Artist; 21 | import fm.last.musicbrainz.data.model.Release; 22 | 23 | /** 24 | * Provides access to {@link Release}s. 25 | */ 26 | public interface ReleaseDao extends MusicBrainzDao { 27 | 28 | /** 29 | * Also returns {@link Release}s where the {@link Artist} collaborated with other {@link Artist}s. 30 | * 31 | * @return Empty list if {@link Artist} has no {@link Release}s 32 | */ 33 | List getByArtist(Artist artist); 34 | 35 | /** 36 | * Ignores the casing of {@code releaseName}. 37 | * 38 | * @return Empty list if no {@link Release}s are found 39 | */ 40 | List getByArtistAndName(Artist artist, String releaseName); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/TrackDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao; 17 | 18 | import java.util.List; 19 | 20 | import fm.last.musicbrainz.data.model.Artist; 21 | import fm.last.musicbrainz.data.model.Track; 22 | 23 | /** 24 | * Provides access to {@link Track}s. 25 | */ 26 | public interface TrackDao extends MusicBrainzDao { 27 | 28 | /** 29 | * Ignores the casing of {@code trackName}. 30 | * 31 | * @return Empty list if no {@link Track}s are found 32 | */ 33 | List getByArtistAndName(Artist artist, String trackName); 34 | 35 | /** 36 | * Also returns {@link Track}s where the {@link Artist} collaborated with other {@link Artist}s. 37 | * 38 | * @return Empty list if {@link Artist} has no {@link Track}s 39 | */ 40 | List getByArtist(Artist artist); 41 | 42 | } -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/impl/AbstractMusicBrainzHibernateDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import java.io.Serializable; 19 | import java.util.List; 20 | 21 | import org.hibernate.Query; 22 | import org.hibernate.Session; 23 | import org.hibernate.SessionFactory; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.beans.factory.annotation.Qualifier; 28 | 29 | abstract class AbstractMusicBrainzHibernateDao { 30 | 31 | private static final Logger log = LoggerFactory.getLogger(AbstractMusicBrainzHibernateDao.class); 32 | 33 | private final Class entityClass; 34 | 35 | @Autowired 36 | @Qualifier("musicBrainzSessionFactory") 37 | private SessionFactory sessionFactory; 38 | 39 | protected AbstractMusicBrainzHibernateDao(Class entityClass) { 40 | this.entityClass = entityClass; 41 | log.debug("Instantiated DAO '{}' for entity type '{}'", getClass().getName(), entityClass.getName()); 42 | } 43 | 44 | protected Query query(String hql) { 45 | return currentSession().createQuery(hql); 46 | } 47 | 48 | protected Session currentSession() { 49 | return sessionFactory.getCurrentSession(); 50 | } 51 | 52 | @SuppressWarnings("unchecked") 53 | protected List list(Query query) { 54 | return query.list(); 55 | } 56 | 57 | @SuppressWarnings("unchecked") 58 | protected INTERFACE uniqueResult(Query query) { 59 | return (INTERFACE) query.uniqueResult(); 60 | } 61 | 62 | @SuppressWarnings("unchecked") 63 | protected INTERFACE get(Serializable id) { 64 | return (INTERFACE) currentSession().get(entityClass, id); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/impl/ArtistDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import java.util.List; 19 | import java.util.UUID; 20 | 21 | import org.hibernate.type.PostgresUUIDType; 22 | import org.springframework.stereotype.Repository; 23 | import org.springframework.transaction.annotation.Transactional; 24 | 25 | import fm.last.musicbrainz.data.dao.ArtistDao; 26 | import fm.last.musicbrainz.data.model.Artist; 27 | 28 | @Repository("musicBrainzArtistDaoImpl") 29 | @Transactional("musicBrainzTransactionManager") 30 | public class ArtistDaoImpl extends AbstractMusicBrainzHibernateDao implements ArtistDao { 31 | 32 | public ArtistDaoImpl() { 33 | super(Artist.class); 34 | } 35 | 36 | @Override 37 | public Artist getById(int id) { 38 | return get(id); 39 | } 40 | 41 | @Override 42 | public List getByName(String name) { 43 | return list(query("from " + Artist.class.getSimpleName() + " where upper(name) = upper(:name)").setString( 44 | "name", name)); 45 | } 46 | 47 | @Override 48 | public Artist getByGid(UUID gid) { 49 | return uniqueResult(query( 50 | "from " + Artist.class.getSimpleName() + " artist left outer join artist.redirectedGids gids " 51 | + "where artist.gid = :gid or :gid in (gids)").setParameter("gid", gid, PostgresUUIDType.INSTANCE)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/impl/RecordingDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import java.util.List; 19 | import java.util.UUID; 20 | 21 | import org.hibernate.type.PostgresUUIDType; 22 | import org.springframework.stereotype.Repository; 23 | import org.springframework.transaction.annotation.Transactional; 24 | 25 | import fm.last.musicbrainz.data.dao.RecordingDao; 26 | import fm.last.musicbrainz.data.model.Artist; 27 | import fm.last.musicbrainz.data.model.Recording; 28 | 29 | @Repository("musicBrainzRecordingDaoImpl") 30 | @Transactional("musicBrainzTransactionManager") 31 | public class RecordingDaoImpl extends AbstractMusicBrainzHibernateDao implements RecordingDao { 32 | 33 | public RecordingDaoImpl() { 34 | super(Recording.class); 35 | } 36 | 37 | @Override 38 | public Recording getById(int id) { 39 | return get(id); 40 | } 41 | 42 | @Override 43 | public Recording getByGid(UUID gid) { 44 | return uniqueResult(query( 45 | "from " + Recording.class.getSimpleName() + " recording left outer join recording.redirectedGids gids" 46 | + " where recording.gid = :gid or :gid in (gids)").setParameter("gid", gid, PostgresUUIDType.INSTANCE)); 47 | } 48 | 49 | @Override 50 | public List getByArtistAndName(Artist artist, String trackName) { 51 | return list(query( 52 | "select recording from " + Recording.class.getName() 53 | + " recording join recording.artistCredit.artistCreditNames artistCreditNames" 54 | + " where artistCreditNames.artist.id = :artistId and upper(recording.name) = upper(:name)") 55 | .setInteger("artistId", artist.getId()).setString("name", trackName)); 56 | } 57 | 58 | @Override 59 | public List getByArtist(Artist artist) { 60 | return list(query( 61 | "select recording from " + Recording.class.getName() 62 | + " recording join recording.artistCredit.artistCreditNames artistCreditNames" 63 | + " where artistCreditNames.artist.id = :artistId").setInteger("artistId", artist.getId())); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/impl/ReleaseDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import java.util.List; 19 | import java.util.UUID; 20 | 21 | import org.hibernate.type.PostgresUUIDType; 22 | import org.springframework.stereotype.Repository; 23 | import org.springframework.transaction.annotation.Transactional; 24 | 25 | import fm.last.musicbrainz.data.dao.ReleaseDao; 26 | import fm.last.musicbrainz.data.model.Artist; 27 | import fm.last.musicbrainz.data.model.Release; 28 | 29 | @Repository("musicBrainzReleaseDaoImpl") 30 | @Transactional("musicBrainzTransactionManager") 31 | public class ReleaseDaoImpl extends AbstractMusicBrainzHibernateDao implements ReleaseDao { 32 | 33 | public ReleaseDaoImpl() { 34 | super(Release.class); 35 | } 36 | 37 | @Override 38 | public Release getById(int id) { 39 | return get(id); 40 | } 41 | 42 | @Override 43 | public Release getByGid(UUID gid) { 44 | return uniqueResult(query( 45 | "from " + Release.class.getSimpleName() + " release left outer join release.redirectedGids gids" 46 | + " where release.gid = :gid or :gid in (gids)").setParameter("gid", gid, PostgresUUIDType.INSTANCE)); 47 | } 48 | 49 | @Override 50 | public List getByArtist(Artist artist) { 51 | return list(query( 52 | "select release from " + Release.class.getSimpleName() 53 | + " release join release.artistCredit.artistCreditNames artistCreditNames" 54 | + " where artistCreditNames.artist.id = :artistId").setInteger("artistId", artist.getId())); 55 | } 56 | 57 | @Override 58 | public List getByArtistAndName(Artist artist, String releaseName) { 59 | return list(query( 60 | "select release from " + Release.class.getName() 61 | + " release join release.artistCredit.artistCreditNames artistCreditNames" 62 | + " where artistCreditNames.artist.id = :artistId and upper(release.name) = upper(:name)").setInteger( 63 | "artistId", artist.getId()).setString("name", releaseName)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/dao/impl/TrackDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import java.util.List; 19 | import java.util.UUID; 20 | 21 | import org.hibernate.type.PostgresUUIDType; 22 | import org.springframework.stereotype.Repository; 23 | import org.springframework.transaction.annotation.Transactional; 24 | 25 | import fm.last.musicbrainz.data.dao.TrackDao; 26 | import fm.last.musicbrainz.data.model.Artist; 27 | import fm.last.musicbrainz.data.model.Track; 28 | 29 | @Repository("musicBrainzTrackDaoImpl") 30 | @Transactional("musicBrainzTransactionManager") 31 | public class TrackDaoImpl extends AbstractMusicBrainzHibernateDao implements TrackDao { 32 | 33 | public TrackDaoImpl() { 34 | super(Track.class); 35 | } 36 | 37 | @Override 38 | public Track getById(int id) { 39 | return get(id); 40 | } 41 | 42 | @Override 43 | public Track getByGid(UUID gid) { 44 | return uniqueResult(query( 45 | "from " + Track.class.getSimpleName() + " track left outer join track.redirectedGids gids" 46 | + " where track.gid = :gid or :gid in (gids)").setParameter("gid", gid, PostgresUUIDType.INSTANCE)); 47 | } 48 | 49 | @Override 50 | public List getByArtist(Artist musicBrainzArtist) { 51 | return list(query( 52 | "select track from " + Track.class.getSimpleName() 53 | + " track join track.artistCredit.artistCreditNames artistCreditNames" 54 | + " where artistCreditNames.artist.id = :artist").setInteger("artist", musicBrainzArtist.getId())); 55 | } 56 | 57 | @Override 58 | public List getByArtistAndName(Artist artist, String trackName) { 59 | return list(query( 60 | "select track from " + Track.class.getName() 61 | + " track join track.artistCredit.artistCreditNames artistCreditNames" 62 | + " where artistCreditNames.artist.id = :artistId and upper(track.name) = upper(:name)").setInteger( 63 | "artistId", artist.getId()).setString("name", trackName)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/hibernate/AbstractEnumUserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Types; 23 | 24 | import org.hibernate.HibernateException; 25 | import org.hibernate.usertype.UserType; 26 | 27 | abstract class AbstractEnumUserType> implements UserType { 28 | 29 | private final Class clazz; 30 | private static final int[] SQL_TYPES = { Types.INTEGER }; 31 | 32 | protected AbstractEnumUserType(Class clazz) { 33 | this.clazz = clazz; 34 | } 35 | 36 | @Override 37 | public int[] sqlTypes() { 38 | return SQL_TYPES; 39 | } 40 | 41 | @Override 42 | public Class returnedClass() { 43 | return clazz; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object x, Object y) throws HibernateException { 48 | if (x == y) { 49 | return true; 50 | } 51 | if (null == x || null == y) { 52 | return false; 53 | } 54 | Class javaClass = returnedClass(); 55 | if (!javaClass.equals(x.getClass()) || !javaClass.equals(y.getClass())) { 56 | return false; 57 | } 58 | return x.equals(y); 59 | } 60 | 61 | @Override 62 | public int hashCode(Object x) throws HibernateException { 63 | return x.hashCode(); 64 | } 65 | 66 | @Override 67 | public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException { 68 | Integer name = resultSet.getInt(names[0]); 69 | if (resultSet.wasNull()) { 70 | name = null; 71 | } 72 | return getEnumConstant(name); 73 | } 74 | 75 | protected abstract E getEnumConstant(Integer value); 76 | 77 | @SuppressWarnings("unchecked") 78 | @Override 79 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, 80 | SQLException { 81 | if (null == value) { 82 | preparedStatement.setNull(index, Types.INTEGER); 83 | } else { 84 | Integer enumValue = getIntegerValue((E) value); 85 | preparedStatement.setInt(index, enumValue); 86 | } 87 | } 88 | 89 | protected abstract Integer getIntegerValue(E value); 90 | 91 | @Override 92 | public Object deepCopy(Object value) throws HibernateException { 93 | return value; 94 | } 95 | 96 | @Override 97 | public boolean isMutable() { 98 | return false; 99 | } 100 | 101 | @Override 102 | public Serializable disassemble(Object value) throws HibernateException { 103 | return (Serializable) value; 104 | } 105 | 106 | @Override 107 | public Object assemble(Serializable cached, Object owner) throws HibernateException { 108 | return cached; 109 | } 110 | 111 | @Override 112 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 113 | return original; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/hibernate/AreaTypeUserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.hibernate; 17 | 18 | import fm.last.musicbrainz.data.model.AreaType; 19 | 20 | public class AreaTypeUserType extends AbstractEnumUserType { 21 | 22 | public AreaTypeUserType() { 23 | super(AreaType.class); 24 | } 25 | 26 | @Override 27 | public Integer getIntegerValue(AreaType type) { 28 | return type.getId(); 29 | } 30 | 31 | @Override 32 | public AreaType getEnumConstant(Integer id) { 33 | return AreaType.valueOf(id); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/hibernate/ArtistTypeUserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.hibernate; 17 | 18 | import fm.last.musicbrainz.data.model.ArtistType; 19 | 20 | public class ArtistTypeUserType extends AbstractEnumUserType { 21 | 22 | public ArtistTypeUserType() { 23 | super(ArtistType.class); 24 | } 25 | 26 | @Override 27 | public Integer getIntegerValue(ArtistType type) { 28 | return type.getId(); 29 | } 30 | 31 | @Override 32 | public ArtistType getEnumConstant(Integer id) { 33 | return ArtistType.valueOf(id); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/hibernate/GenderUserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.hibernate; 17 | 18 | import fm.last.musicbrainz.data.model.Gender; 19 | 20 | public class GenderUserType extends AbstractEnumUserType { 21 | 22 | public GenderUserType() { 23 | super(Gender.class); 24 | } 25 | 26 | @Override 27 | public Integer getIntegerValue(Gender type) { 28 | return type.getId(); 29 | } 30 | 31 | @Override 32 | public Gender getEnumConstant(Integer id) { 33 | return Gender.valueOf(id); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/hibernate/ReleaseGroupPrimaryTypeUserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.hibernate; 17 | 18 | import fm.last.musicbrainz.data.model.ReleaseGroupPrimaryType; 19 | 20 | public class ReleaseGroupPrimaryTypeUserType extends AbstractEnumUserType { 21 | 22 | public ReleaseGroupPrimaryTypeUserType() { 23 | super(ReleaseGroupPrimaryType.class); 24 | } 25 | 26 | @Override 27 | public Integer getIntegerValue(ReleaseGroupPrimaryType type) { 28 | return type.getId(); 29 | } 30 | 31 | @Override 32 | public ReleaseGroupPrimaryType getEnumConstant(Integer id) { 33 | return ReleaseGroupPrimaryType.valueOf(id); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/hibernate/ReleaseGroupSecondaryTypeUserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package fm.last.musicbrainz.data.hibernate; 15 | 16 | import fm.last.musicbrainz.data.model.ReleaseGroupSecondaryType; 17 | 18 | public class ReleaseGroupSecondaryTypeUserType extends 19 | AbstractEnumUserType { 20 | 21 | public ReleaseGroupSecondaryTypeUserType() { 22 | super(ReleaseGroupSecondaryType.class); 23 | } 24 | 25 | @Override 26 | public Integer getIntegerValue(ReleaseGroupSecondaryType type) { 27 | return type.getId(); 28 | } 29 | 30 | @Override 31 | public ReleaseGroupSecondaryType getEnumConstant(Integer id) { 32 | return ReleaseGroupSecondaryType.valueOf(id); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/hibernate/ReleaseStatusUserType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.hibernate; 17 | 18 | import fm.last.musicbrainz.data.model.ReleaseStatus; 19 | 20 | public class ReleaseStatusUserType extends AbstractEnumUserType { 21 | 22 | public ReleaseStatusUserType() { 23 | super(ReleaseStatus.class); 24 | } 25 | 26 | @Override 27 | public Integer getIntegerValue(ReleaseStatus status) { 28 | return status.getId(); 29 | } 30 | 31 | @Override 32 | public ReleaseStatus getEnumConstant(Integer id) { 33 | return ReleaseStatus.valueOf(id); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/AbstractCoreEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.UUID; 19 | 20 | import javax.persistence.Column; 21 | import javax.persistence.Id; 22 | import javax.persistence.MappedSuperclass; 23 | 24 | import org.hibernate.annotations.Type; 25 | import org.joda.time.DateTime; 26 | 27 | @MappedSuperclass 28 | public abstract class AbstractCoreEntity { 29 | 30 | @Id 31 | @Column(name = "id") 32 | protected int id; 33 | 34 | @Column(name = "gid", nullable = false, unique = true) 35 | @Type(type = "pg-uuid") 36 | protected UUID gid; 37 | 38 | @Column(name = "comment") 39 | protected String comment; 40 | 41 | @Column(name = "last_updated") 42 | @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime") 43 | protected DateTime lastUpdated; 44 | 45 | public int getId() { 46 | return id; 47 | } 48 | 49 | public String getComment() { 50 | return comment; 51 | } 52 | 53 | public DateTime getLastUpdated() { 54 | return lastUpdated; 55 | } 56 | 57 | public abstract String getName(); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/AbstractName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import javax.persistence.Column; 19 | import javax.persistence.Id; 20 | import javax.persistence.MappedSuperclass; 21 | 22 | @MappedSuperclass 23 | abstract class AbstractName { 24 | 25 | @Id 26 | @Column(name = "id") 27 | private int id; 28 | 29 | @Column(name = "name") 30 | private String name; 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/Area.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Set; 19 | import java.util.UUID; 20 | 21 | import javax.persistence.Access; 22 | import javax.persistence.AccessType; 23 | import javax.persistence.AttributeOverride; 24 | import javax.persistence.AttributeOverrides; 25 | import javax.persistence.CollectionTable; 26 | import javax.persistence.Column; 27 | import javax.persistence.ElementCollection; 28 | import javax.persistence.Embedded; 29 | import javax.persistence.Entity; 30 | import javax.persistence.FetchType; 31 | import javax.persistence.Id; 32 | import javax.persistence.JoinColumn; 33 | import javax.persistence.Table; 34 | 35 | import org.hibernate.annotations.Cache; 36 | import org.hibernate.annotations.CacheConcurrencyStrategy; 37 | import org.hibernate.annotations.Type; 38 | import org.joda.time.DateTime; 39 | 40 | import com.google.common.collect.ImmutableSet; 41 | import com.google.common.collect.Sets; 42 | 43 | @Access(AccessType.FIELD) 44 | @Entity 45 | @Table(name = "area", schema = "musicbrainz") 46 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 47 | public class Area { 48 | 49 | @Id 50 | @Column(name = "id") 51 | private int id; 52 | 53 | @Column(name = "gid", nullable = false, unique = true) 54 | @Type(type = "pg-uuid") 55 | private UUID gid; 56 | 57 | @ElementCollection(fetch = FetchType.LAZY) 58 | @CollectionTable(name = "area_gid_redirect", schema = "musicbrainz", joinColumns = @JoinColumn(name = "new_id")) 59 | @Column(name = "gid") 60 | @Type(type = "pg-uuid") 61 | private final Set redirectedGids = Sets.newHashSet(); 62 | 63 | @JoinColumn(name = "name") 64 | private String name; 65 | 66 | @Column(name = "type") 67 | @Type(type = "fm.last.musicbrainz.data.hibernate.AreaTypeUserType") 68 | private AreaType type; 69 | 70 | @Column(name = "last_updated") 71 | @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime") 72 | private DateTime lastUpdated; 73 | 74 | @Embedded 75 | @AttributeOverrides({ @AttributeOverride(name = "year", column = @Column(name = "begin_date_year")), 76 | @AttributeOverride(name = "month", column = @Column(name = "begin_date_month")), 77 | @AttributeOverride(name = "day", column = @Column(name = "begin_date_day")) }) 78 | private PartialDate beginDate; 79 | 80 | @Embedded 81 | @AttributeOverrides({ @AttributeOverride(name = "year", column = @Column(name = "end_date_year")), 82 | @AttributeOverride(name = "month", column = @Column(name = "end_date_month")), 83 | @AttributeOverride(name = "day", column = @Column(name = "end_date_day")) }) 84 | private PartialDate endDate; 85 | 86 | @Column(name = "ended") 87 | private boolean ended; 88 | 89 | public int getId() { 90 | return id; 91 | } 92 | 93 | public String getName() { 94 | return name; 95 | } 96 | 97 | public AreaType getType() { 98 | return type; 99 | } 100 | 101 | public DateTime getLastUpdated() { 102 | return lastUpdated; 103 | } 104 | 105 | /** 106 | * Returns an immutable set of all associated GIDs (canonical and redirected). 107 | */ 108 | public Set getGids() { 109 | return new ImmutableSet.Builder().addAll(redirectedGids).add(gid).build(); 110 | } 111 | 112 | public PartialDate getBeginDate() { 113 | return beginDate; 114 | } 115 | 116 | public PartialDate getEndDate() { 117 | return endDate; 118 | } 119 | 120 | public boolean hasEnded() { 121 | return ended; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/AreaType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Map; 19 | 20 | import com.google.common.collect.Maps; 21 | 22 | public enum AreaType { 23 | /* */ 24 | COUNTRY(1, "Country"), 25 | /* */ 26 | SUBDIVISION(2, "Subdivision"), 27 | /* */ 28 | CITY(3, "City"), 29 | /* */ 30 | MUNICIPALITY(4, "Municipality"), 31 | /* */ 32 | DISTRICT(5, "District"), 33 | /* */ 34 | ISLAND(6, "Island"), 35 | /* */ 36 | COUNTY(7, "County"), 37 | /* */ 38 | UNDEFINED(null, null); 39 | 40 | private static final Map idToType; 41 | 42 | static { 43 | idToType = Maps.newHashMap(); 44 | for (AreaType value : values()) { 45 | idToType.put(value.getId(), value); 46 | } 47 | } 48 | 49 | private Integer id; 50 | private String name; 51 | 52 | private AreaType(Integer id, String name) { 53 | this.id = id; 54 | this.name = name; 55 | } 56 | 57 | public static AreaType valueOf(Integer id) { 58 | AreaType type = idToType.get(id); 59 | if (type == null) { 60 | throw new IllegalArgumentException("Unrecognized area type: " + id); 61 | } 62 | return type; 63 | } 64 | 65 | public Integer getId() { 66 | return id; 67 | } 68 | 69 | public String getName() { 70 | return name; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/Artist.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Set; 19 | import java.util.UUID; 20 | 21 | import javax.persistence.Access; 22 | import javax.persistence.AccessType; 23 | import javax.persistence.AttributeOverride; 24 | import javax.persistence.AttributeOverrides; 25 | import javax.persistence.CollectionTable; 26 | import javax.persistence.Column; 27 | import javax.persistence.ElementCollection; 28 | import javax.persistence.Embedded; 29 | import javax.persistence.Entity; 30 | import javax.persistence.FetchType; 31 | import javax.persistence.JoinColumn; 32 | import javax.persistence.ManyToOne; 33 | import javax.persistence.Table; 34 | 35 | import org.hibernate.annotations.Cache; 36 | import org.hibernate.annotations.CacheConcurrencyStrategy; 37 | import org.hibernate.annotations.Type; 38 | 39 | import com.google.common.collect.ImmutableSet; 40 | import com.google.common.collect.Sets; 41 | 42 | @Access(AccessType.FIELD) 43 | @Entity 44 | @Table(name = "artist", schema = "musicbrainz") 45 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 46 | public class Artist extends AbstractCoreEntity { 47 | 48 | @ElementCollection(fetch = FetchType.LAZY) 49 | @CollectionTable(name = "artist_gid_redirect", schema = "musicbrainz", joinColumns = @JoinColumn(name = "new_id")) 50 | @Column(name = "gid") 51 | @Type(type = "pg-uuid") 52 | private final Set redirectedGids = Sets.newHashSet(); 53 | 54 | @Column(name = "name") 55 | private String name; 56 | 57 | @Column(name = "type") 58 | @Type(type = "fm.last.musicbrainz.data.hibernate.ArtistTypeUserType") 59 | private ArtistType type; 60 | 61 | @ManyToOne(optional = true, fetch = FetchType.LAZY) 62 | @JoinColumn(name = "area", nullable = false) 63 | private Area area; 64 | 65 | @Column(name = "gender") 66 | @Type(type = "fm.last.musicbrainz.data.hibernate.GenderUserType") 67 | private Gender gender; 68 | 69 | @Embedded 70 | @AttributeOverrides({ @AttributeOverride(name = "year", column = @Column(name = "begin_date_year")), 71 | @AttributeOverride(name = "month", column = @Column(name = "begin_date_month")), 72 | @AttributeOverride(name = "day", column = @Column(name = "begin_date_day")) }) 73 | private PartialDate beginDate; 74 | 75 | @Embedded 76 | @AttributeOverrides({ @AttributeOverride(name = "year", column = @Column(name = "end_date_year")), 77 | @AttributeOverride(name = "month", column = @Column(name = "end_date_month")), 78 | @AttributeOverride(name = "day", column = @Column(name = "end_date_day")) }) 79 | private PartialDate endDate; 80 | 81 | @Column(name = "ended") 82 | private boolean ended; 83 | 84 | @ManyToOne(optional = true, fetch = FetchType.LAZY) 85 | @JoinColumn(name = "begin_area", nullable = false) 86 | private Area beginArea; 87 | 88 | @ManyToOne(optional = true, fetch = FetchType.LAZY) 89 | @JoinColumn(name = "end_area", nullable = false) 90 | private Area endArea; 91 | 92 | public ArtistType getType() { 93 | return type; 94 | } 95 | 96 | public Area getArea() { 97 | return area; 98 | } 99 | 100 | public Area getBeginArea() { 101 | return beginArea; 102 | } 103 | 104 | public Area getEndArea() { 105 | return endArea; 106 | } 107 | 108 | public Gender getGender() { 109 | return gender; 110 | } 111 | 112 | public boolean hasEnded() { 113 | return ended; 114 | } 115 | 116 | public String getName() { 117 | return name; 118 | } 119 | 120 | /** 121 | * Returns an immutable set of all associated GIDs (canonical and redirected). 122 | */ 123 | public Set getGids() { 124 | return new ImmutableSet.Builder().addAll(redirectedGids).add(gid).build(); 125 | } 126 | 127 | public PartialDate getBeginDate() { 128 | return beginDate; 129 | } 130 | 131 | public PartialDate getEndDate() { 132 | return endDate; 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ArtistCredit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Collections; 19 | import java.util.List; 20 | 21 | import javax.persistence.Access; 22 | import javax.persistence.AccessType; 23 | import javax.persistence.Column; 24 | import javax.persistence.Entity; 25 | import javax.persistence.FetchType; 26 | import javax.persistence.Id; 27 | import javax.persistence.OneToMany; 28 | import javax.persistence.OrderBy; 29 | import javax.persistence.Table; 30 | 31 | import org.hibernate.annotations.Cache; 32 | import org.hibernate.annotations.CacheConcurrencyStrategy; 33 | 34 | import com.google.common.collect.Lists; 35 | 36 | @Access(AccessType.FIELD) 37 | @Entity 38 | @Table(name = "artist_credit", schema = "musicbrainz") 39 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 40 | public class ArtistCredit { 41 | 42 | @Id 43 | @Column(name = "id") 44 | private int id; 45 | 46 | @OneToMany(targetEntity = ArtistCreditName.class, fetch = FetchType.LAZY, mappedBy = "artistCredit", orphanRemoval = true) 47 | @OrderBy("position") 48 | private final List artistCreditNames = Lists.newArrayList(); 49 | 50 | public int getId() { 51 | return id; 52 | } 53 | 54 | /** 55 | * Returns an immutable list of {@link ArtistCreditName}s. 56 | */ 57 | public List getArtistCreditNames() { 58 | return Collections.unmodifiableList(artistCreditNames); 59 | } 60 | 61 | /** 62 | * Builds a full name by joining the {@code ArtistCreditName}s and their join phrases. 63 | */ 64 | public String getFullName() { 65 | StringBuilder builder = new StringBuilder(); 66 | for (ArtistCreditName artistCreditName : getArtistCreditNames()) { 67 | builder.append(artistCreditName.getName()); 68 | builder.append(artistCreditName.getJoinPhrase()); 69 | } 70 | return builder.toString(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ArtistCreditName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import javax.persistence.Access; 19 | import javax.persistence.AccessType; 20 | import javax.persistence.Column; 21 | import javax.persistence.Entity; 22 | import javax.persistence.FetchType; 23 | import javax.persistence.Id; 24 | import javax.persistence.IdClass; 25 | import javax.persistence.JoinColumn; 26 | import javax.persistence.ManyToOne; 27 | import javax.persistence.Table; 28 | 29 | import org.hibernate.annotations.Cache; 30 | import org.hibernate.annotations.CacheConcurrencyStrategy; 31 | 32 | @Access(AccessType.FIELD) 33 | @Entity 34 | @IdClass(ArtistCreditNameCompositeKey.class) 35 | @Table(name = "artist_credit_name", schema = "musicbrainz") 36 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 37 | public class ArtistCreditName { 38 | 39 | @Id 40 | @Column(name = "artist_credit") 41 | private int artistCredit; 42 | 43 | @Id 44 | @Column(name = "position") 45 | private short position; 46 | 47 | @ManyToOne(targetEntity = Artist.class, fetch = FetchType.LAZY) 48 | @JoinColumn(name = "artist") 49 | private Artist artist; 50 | 51 | @Column(name = "join_phrase") 52 | private String joinPhrase; 53 | 54 | public int getArtistCreditId() { 55 | return artistCredit; 56 | } 57 | 58 | public short getPosition() { 59 | return position; 60 | } 61 | 62 | public Artist getArtist() { 63 | return artist; 64 | } 65 | 66 | public String getName() { 67 | return artist.getName(); 68 | } 69 | 70 | public String getJoinPhrase() { 71 | return joinPhrase; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ArtistCreditNameCompositeKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.apache.commons.lang3.builder.EqualsBuilder; 21 | import org.apache.commons.lang3.builder.HashCodeBuilder; 22 | 23 | class ArtistCreditNameCompositeKey implements Serializable { 24 | 25 | private static final long serialVersionUID = 21062012L; 26 | 27 | int artistCredit; 28 | short position; 29 | 30 | @Override 31 | public int hashCode() { 32 | return new HashCodeBuilder(2105, 2011).append(artistCredit).append(position).toHashCode(); 33 | } 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | if (object == null) { 38 | return false; 39 | } 40 | if (object == this) { 41 | return true; 42 | } 43 | if (object.getClass() != getClass()) { 44 | return false; 45 | } 46 | ArtistCreditNameCompositeKey rhs = (ArtistCreditNameCompositeKey) object; 47 | return new EqualsBuilder().append(artistCredit, rhs.artistCredit).append(position, rhs.position).isEquals(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ArtistType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Map; 19 | 20 | import com.google.common.collect.Maps; 21 | 22 | public enum ArtistType { 23 | /* */ 24 | PERSON(1, "Person"), 25 | /* */ 26 | GROUP(2, "Group"), 27 | /* */ 28 | OTHER(3, "Other"), 29 | /* */ 30 | CHARACTER(4, "Character"), 31 | /* */ 32 | ORCHESTRA(5, "Orchestra"), 33 | /* */ 34 | CHOIR(6, "Choir"), 35 | /* */ 36 | UNDEFINED(null, null); 37 | 38 | 39 | private static final Map idToType; 40 | 41 | static { 42 | idToType = Maps.newHashMap(); 43 | for (ArtistType value : values()) { 44 | idToType.put(value.getId(), value); 45 | } 46 | } 47 | 48 | private final Integer id; 49 | private final String name; 50 | 51 | private ArtistType(Integer id, String name) { 52 | this.id = id; 53 | this.name = name; 54 | } 55 | 56 | public static ArtistType valueOf(Integer id) { 57 | ArtistType type = idToType.get(id); 58 | if (type == null) { 59 | throw new IllegalArgumentException("Unrecognized artist type: " + id); 60 | } 61 | return type; 62 | } 63 | 64 | public Integer getId() { 65 | return id; 66 | } 67 | 68 | public String getName() { 69 | return name; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/Gender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Map; 19 | 20 | import com.google.common.collect.Maps; 21 | 22 | public enum Gender { 23 | /* */ 24 | MALE(1, "Male"), 25 | /* */ 26 | FEMALE(2, "Female"), 27 | /* */ 28 | OTHER(3, "Other"), 29 | /* */ 30 | UNDEFINED(null, null); 31 | 32 | private static final Map idToType; 33 | 34 | static { 35 | idToType = Maps.newHashMap(); 36 | for (Gender value : values()) { 37 | idToType.put(value.getId(), value); 38 | } 39 | } 40 | 41 | private final Integer id; 42 | private final String name; 43 | 44 | private Gender(Integer id, String name) { 45 | this.id = id; 46 | this.name = name; 47 | } 48 | 49 | public static Gender valueOf(Integer id) { 50 | Gender type = idToType.get(id); 51 | if (type == null) { 52 | throw new IllegalArgumentException("Unrecognized artist gender: " + id); 53 | } 54 | return type; 55 | } 56 | 57 | public Integer getId() { 58 | return id; 59 | } 60 | 61 | public String getName() { 62 | return name; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/Medium.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Collections; 19 | import java.util.List; 20 | 21 | import javax.persistence.Access; 22 | import javax.persistence.AccessType; 23 | import javax.persistence.Column; 24 | import javax.persistence.Entity; 25 | import javax.persistence.FetchType; 26 | import javax.persistence.Id; 27 | import javax.persistence.JoinColumn; 28 | import javax.persistence.OneToMany; 29 | import javax.persistence.OneToOne; 30 | import javax.persistence.OrderBy; 31 | import javax.persistence.Table; 32 | 33 | import org.hibernate.annotations.Cache; 34 | import org.hibernate.annotations.CacheConcurrencyStrategy; 35 | import org.hibernate.annotations.Type; 36 | import org.joda.time.DateTime; 37 | 38 | import com.google.common.collect.Lists; 39 | 40 | @Access(AccessType.FIELD) 41 | @Entity 42 | @Table(name = "medium", schema = "musicbrainz") 43 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 44 | public class Medium { 45 | 46 | @Id 47 | @Column(name = "id") 48 | private int id; 49 | 50 | @OneToOne(targetEntity = Release.class, optional = false, fetch = FetchType.LAZY) 51 | @JoinColumn(name = "release") 52 | private Release release; 53 | 54 | @Column(name = "position") 55 | private int position; 56 | 57 | @Column(name = "name") 58 | private String name; 59 | 60 | @Column(name = "last_updated") 61 | @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime") 62 | private DateTime lastUpdated; 63 | 64 | @OneToMany(targetEntity = Track.class, fetch = FetchType.LAZY) 65 | @JoinColumn(name = "medium") 66 | @OrderBy("position") 67 | private final List tracks = Lists.newArrayList(); 68 | 69 | public int getId() { 70 | return id; 71 | } 72 | 73 | public Release getRelease() { 74 | return release; 75 | } 76 | 77 | public int getPosition() { 78 | return position; 79 | } 80 | 81 | public String getName() { 82 | return name; 83 | } 84 | 85 | public DateTime getLastUpdated() { 86 | return lastUpdated; 87 | } 88 | 89 | /** 90 | * Returns an immutable list of {@link Track}s ordered by position. 91 | * 92 | * @return Empty list if medium has no {@link Track}s 93 | */ 94 | public List getTracks() { 95 | return Collections.unmodifiableList(tracks); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/PartialDate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Comparator; 19 | 20 | import javax.persistence.Access; 21 | import javax.persistence.AccessType; 22 | import javax.persistence.Embeddable; 23 | 24 | import org.joda.time.LocalDate; 25 | 26 | import com.google.common.base.Objects; 27 | import com.google.common.collect.ComparisonChain; 28 | import com.google.common.collect.Ordering; 29 | 30 | @Embeddable 31 | @Access(AccessType.PROPERTY) 32 | public class PartialDate implements Comparable { 33 | 34 | private static final String DATE_FIELD_SEPARATOR = "-"; 35 | 36 | private Short year; 37 | private Short month; 38 | private Short day; 39 | 40 | public PartialDate() { 41 | } 42 | 43 | /** ONLY FOR TESTING **/ 44 | PartialDate(Short year, Short month, Short day) { 45 | this.year = year; 46 | this.month = month; 47 | this.day = day; 48 | } 49 | 50 | public Short getYear() { 51 | return year; 52 | } 53 | 54 | public Short getMonth() { 55 | return month; 56 | } 57 | 58 | public Short getDay() { 59 | return day; 60 | } 61 | 62 | public void setYear(Short year) { 63 | this.year = year; 64 | } 65 | 66 | public void setMonth(Short month) { 67 | this.month = month; 68 | } 69 | 70 | public void setDay(Short day) { 71 | this.day = day; 72 | } 73 | 74 | public LocalDate toLocalDate() { 75 | if (year == null) { 76 | return null; 77 | } 78 | return LocalDate.parse(toString()); 79 | } 80 | 81 | @Override 82 | public boolean equals(Object obj) { 83 | if (obj instanceof PartialDate) { 84 | PartialDate other = (PartialDate) obj; 85 | return Objects.equal(year, other.getYear()) && Objects.equal(month, other.getMonth()) 86 | && Objects.equal(day, other.getDay()); 87 | } 88 | return false; 89 | } 90 | 91 | @Override 92 | public int hashCode() { 93 | return Objects.hashCode(year, month, day); 94 | } 95 | 96 | @Override 97 | public String toString() { 98 | if (year == null) { 99 | return ""; 100 | } 101 | StringBuilder sb = new StringBuilder(year); 102 | sb.append(String.format("%04d", year)); 103 | if (month != null) { 104 | sb.append(DATE_FIELD_SEPARATOR).append(String.format("%02d", month)); 105 | if (day != null) { 106 | sb.append(DATE_FIELD_SEPARATOR).append(String.format("%02d", day)); 107 | } 108 | } 109 | return sb.toString(); 110 | } 111 | 112 | @Override 113 | public int compareTo(PartialDate other) { 114 | Comparator comparator = Ordering.natural().nullsFirst(); 115 | return ComparisonChain.start().compare(year, other.getYear(), comparator) 116 | .compare(month, other.getMonth(), comparator).compare(day, other.getDay(), comparator).result(); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/Recording.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Set; 19 | import java.util.UUID; 20 | 21 | import javax.persistence.Access; 22 | import javax.persistence.AccessType; 23 | import javax.persistence.CollectionTable; 24 | import javax.persistence.Column; 25 | import javax.persistence.ElementCollection; 26 | import javax.persistence.Entity; 27 | import javax.persistence.FetchType; 28 | import javax.persistence.JoinColumn; 29 | import javax.persistence.ManyToOne; 30 | import javax.persistence.Table; 31 | 32 | import org.hibernate.annotations.Cache; 33 | import org.hibernate.annotations.CacheConcurrencyStrategy; 34 | import org.hibernate.annotations.Type; 35 | 36 | import com.google.common.collect.ImmutableSet; 37 | import com.google.common.collect.Sets; 38 | 39 | @Access(AccessType.FIELD) 40 | @Entity 41 | @Table(name = "recording", schema = "musicbrainz") 42 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 43 | public class Recording extends AbstractCoreEntity { 44 | 45 | @ElementCollection(fetch = FetchType.LAZY) 46 | @CollectionTable(name = "recording_gid_redirect", schema = "musicbrainz", joinColumns = @JoinColumn(name = "new_id")) 47 | @Column(name = "gid") 48 | @Type(type = "pg-uuid") 49 | private final Set redirectedGids = Sets.newHashSet(); 50 | 51 | @ManyToOne(optional = false, fetch = FetchType.LAZY) 52 | @JoinColumn(name = "artist_credit", nullable = true) 53 | private ArtistCredit artistCredit; 54 | 55 | @Column(name = "length") 56 | private Integer length; 57 | 58 | @Column(name = "name") 59 | private String name; 60 | 61 | public ArtistCredit getArtistCredit() { 62 | return artistCredit; 63 | } 64 | 65 | /** 66 | * Length in milliseconds. 67 | */ 68 | public Integer getLength() { 69 | return length; 70 | } 71 | 72 | /** 73 | * Returns an immutable set of all associated GIDs (canonical and redirected). 74 | */ 75 | public Set getGids() { 76 | return new ImmutableSet.Builder().addAll(redirectedGids).add(gid).build(); 77 | } 78 | 79 | @Override 80 | public String getName() { 81 | return name; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/Release.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Collections; 19 | import java.util.List; 20 | import java.util.Set; 21 | import java.util.UUID; 22 | 23 | import javax.persistence.Access; 24 | import javax.persistence.AccessType; 25 | import javax.persistence.CollectionTable; 26 | import javax.persistence.Column; 27 | import javax.persistence.ElementCollection; 28 | import javax.persistence.Entity; 29 | import javax.persistence.FetchType; 30 | import javax.persistence.JoinColumn; 31 | import javax.persistence.ManyToOne; 32 | import javax.persistence.OneToMany; 33 | import javax.persistence.OrderBy; 34 | import javax.persistence.Table; 35 | 36 | import org.hibernate.annotations.Cache; 37 | import org.hibernate.annotations.CacheConcurrencyStrategy; 38 | import org.hibernate.annotations.Type; 39 | 40 | import com.google.common.collect.ImmutableSet; 41 | import com.google.common.collect.Lists; 42 | import com.google.common.collect.Sets; 43 | 44 | @Access(AccessType.FIELD) 45 | @Entity 46 | @Table(name = "release", schema = "musicbrainz") 47 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 48 | public class Release extends AbstractCoreEntity { 49 | 50 | @ManyToOne(optional = false, fetch = FetchType.LAZY) 51 | @JoinColumn(name = "release_group", nullable = false) 52 | private ReleaseGroup releaseGroup; 53 | 54 | @ElementCollection(fetch = FetchType.LAZY) 55 | @CollectionTable(name = "release_gid_redirect", schema = "musicbrainz", joinColumns = @JoinColumn(name = "new_id")) 56 | @Column(name = "gid") 57 | @Type(type = "pg-uuid") 58 | private final Set redirectedGids = Sets.newHashSet(); 59 | 60 | @ManyToOne(targetEntity = ArtistCredit.class, fetch = FetchType.LAZY) 61 | @JoinColumn(name = "artist_credit", nullable = true) 62 | private ArtistCredit artistCredit; 63 | 64 | @OneToMany(targetEntity = Medium.class, fetch = FetchType.LAZY, mappedBy = "release", orphanRemoval = true) 65 | @OrderBy("position") 66 | private final List mediums = Lists.newArrayList(); 67 | 68 | @Column(name = "status") 69 | @Type(type = "fm.last.musicbrainz.data.hibernate.ReleaseStatusUserType") 70 | private ReleaseStatus status; 71 | 72 | @Column(name = "name") 73 | private String name; 74 | 75 | /** 76 | * Mapped as OneToMany to allow lazy loading. The primary key of musicbrainz.release_unknown_country will make sure 77 | * there exists one row at most per release. 78 | */ 79 | @OneToMany(targetEntity = ReleaseUnknownCountry.class, fetch = FetchType.LAZY, mappedBy = "release", orphanRemoval = true) 80 | private final Set releaseUnknownCountries = Sets.newHashSet(); 81 | 82 | @OneToMany(targetEntity = ReleaseCountry.class, fetch = FetchType.LAZY, mappedBy = "release", orphanRemoval = true) 83 | private final Set releaseCountries = Sets.newHashSet(); 84 | 85 | public ArtistCredit getArtistCredit() { 86 | return artistCredit; 87 | } 88 | 89 | /** 90 | * Returns and immutable list of {@link Medium}s ordered by position. 91 | */ 92 | public List getMediums() { 93 | return Collections.unmodifiableList(mediums); 94 | } 95 | 96 | /** 97 | * Returns an immutable set of all associated GIDs (canonical and redirected). 98 | */ 99 | public Set getGids() { 100 | return new ImmutableSet.Builder().addAll(redirectedGids).add(gid).build(); 101 | } 102 | 103 | public ReleaseStatus getStatus() { 104 | return status; 105 | } 106 | 107 | public ReleaseGroup getReleaseGroup() { 108 | return releaseGroup; 109 | } 110 | 111 | public PartialDate getReleaseDateForUnknownCountry() { 112 | if (releaseUnknownCountries.isEmpty()) { 113 | return null; 114 | } 115 | ReleaseUnknownCountry releaseUnknownCountry = releaseUnknownCountries.iterator().next(); 116 | return releaseUnknownCountry.getReleaseDate(); 117 | } 118 | 119 | /** 120 | * Returns and immutable set of {@link ReleaseCountry}. 121 | */ 122 | public Set getReleaseCountries() { 123 | return Collections.unmodifiableSet(releaseCountries); 124 | } 125 | 126 | @Override 127 | public String getName() { 128 | return name; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ReleaseCountry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import javax.persistence.Access; 19 | import javax.persistence.AccessType; 20 | import javax.persistence.AttributeOverride; 21 | import javax.persistence.AttributeOverrides; 22 | import javax.persistence.Column; 23 | import javax.persistence.Embedded; 24 | import javax.persistence.Entity; 25 | import javax.persistence.FetchType; 26 | import javax.persistence.Id; 27 | import javax.persistence.IdClass; 28 | import javax.persistence.JoinColumn; 29 | import javax.persistence.ManyToOne; 30 | import javax.persistence.Table; 31 | 32 | import org.hibernate.annotations.Cache; 33 | import org.hibernate.annotations.CacheConcurrencyStrategy; 34 | 35 | @Access(AccessType.FIELD) 36 | @Entity 37 | @IdClass(ReleaseCountryCompositeKey.class) 38 | @Table(name = "release_country", schema = "musicbrainz") 39 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 40 | public class ReleaseCountry { 41 | 42 | @Id 43 | @Column(name = "release") 44 | private int release; 45 | 46 | @Id 47 | @Column(name = "country", insertable = false, updatable = false) 48 | private int countryId; 49 | 50 | @ManyToOne(optional = false, fetch = FetchType.LAZY) 51 | @JoinColumn(name = "country", nullable = false) 52 | private Area country; 53 | 54 | @Embedded 55 | @AttributeOverrides({ @AttributeOverride(name = "year", column = @Column(name = "date_year")), 56 | @AttributeOverride(name = "month", column = @Column(name = "date_month")), 57 | @AttributeOverride(name = "day", column = @Column(name = "date_day")) }) 58 | private PartialDate releaseDate; 59 | 60 | public ReleaseCountry() { 61 | } 62 | 63 | /** ONLY FOR TESTING **/ 64 | ReleaseCountry(int releaseId, int countryId, PartialDate releaseDate) { 65 | release = releaseId; 66 | this.countryId = countryId; 67 | this.releaseDate = releaseDate; 68 | } 69 | 70 | public Area getCountry() { 71 | return country; 72 | } 73 | 74 | public PartialDate getReleaseDate() { 75 | return releaseDate; 76 | } 77 | 78 | @Override 79 | public int hashCode() { 80 | final int prime = 31; 81 | int result = 1; 82 | result = prime * result + countryId; 83 | result = prime * result + release; 84 | result = prime * result + (releaseDate == null ? 0 : releaseDate.hashCode()); 85 | return result; 86 | } 87 | 88 | @Override 89 | public boolean equals(Object obj) { 90 | if (this == obj) { 91 | return true; 92 | } 93 | if (obj == null) { 94 | return false; 95 | } 96 | if (getClass() != obj.getClass()) { 97 | return false; 98 | } 99 | ReleaseCountry other = (ReleaseCountry) obj; 100 | if (countryId != other.countryId) { 101 | return false; 102 | } 103 | if (release != other.release) { 104 | return false; 105 | } 106 | if (releaseDate == null) { 107 | if (other.releaseDate != null) { 108 | return false; 109 | } 110 | } else if (!releaseDate.equals(other.releaseDate)) { 111 | return false; 112 | } 113 | return true; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ReleaseCountryCompositeKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.io.Serializable; 19 | 20 | import org.apache.commons.lang3.builder.EqualsBuilder; 21 | import org.apache.commons.lang3.builder.HashCodeBuilder; 22 | 23 | class ReleaseCountryCompositeKey implements Serializable { 24 | 25 | private static final long serialVersionUID = 23052013L; 26 | 27 | int release; 28 | int country; 29 | 30 | @Override 31 | public int hashCode() { 32 | return new HashCodeBuilder(2305, 2013).append(release).append(country).toHashCode(); 33 | } 34 | 35 | @Override 36 | public boolean equals(Object object) { 37 | if (object == null) { 38 | return false; 39 | } 40 | if (object == this) { 41 | return true; 42 | } 43 | if (object.getClass() != getClass()) { 44 | return false; 45 | } 46 | ReleaseCountryCompositeKey rhs = (ReleaseCountryCompositeKey) object; 47 | return new EqualsBuilder().append(release, rhs.release).append(country, rhs.country).isEquals(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ReleaseGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Set; 19 | import java.util.UUID; 20 | 21 | import javax.persistence.Access; 22 | import javax.persistence.AccessType; 23 | import javax.persistence.CollectionTable; 24 | import javax.persistence.Column; 25 | import javax.persistence.ElementCollection; 26 | import javax.persistence.Entity; 27 | import javax.persistence.FetchType; 28 | import javax.persistence.JoinColumn; 29 | import javax.persistence.ManyToOne; 30 | import javax.persistence.Table; 31 | 32 | import org.hibernate.annotations.Cache; 33 | import org.hibernate.annotations.CacheConcurrencyStrategy; 34 | import org.hibernate.annotations.Type; 35 | 36 | import com.google.common.collect.ImmutableSet; 37 | import com.google.common.collect.Sets; 38 | 39 | @Access(AccessType.FIELD) 40 | @Entity 41 | @Table(name = "release_group", schema = "musicbrainz") 42 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 43 | public class ReleaseGroup extends AbstractCoreEntity { 44 | 45 | @ElementCollection(fetch = FetchType.LAZY) 46 | @CollectionTable(name = "release_group_gid_redirect", schema = "musicbrainz", joinColumns = @JoinColumn(name = "new_id")) 47 | @Column(name = "gid") 48 | @Type(type = "pg-uuid") 49 | private final Set redirectedGids = Sets.newHashSet(); 50 | 51 | @ManyToOne(targetEntity = ArtistCredit.class, fetch = FetchType.LAZY) 52 | @JoinColumn(name = "artist_credit", nullable = true) 53 | private ArtistCredit artistCredit; 54 | 55 | @Column(name = "type") 56 | @Type(type = "fm.last.musicbrainz.data.hibernate.ReleaseGroupPrimaryTypeUserType") 57 | private ReleaseGroupPrimaryType type; 58 | 59 | @Column(name = "name") 60 | private String name; 61 | 62 | public ArtistCredit getArtistCredit() { 63 | return artistCredit; 64 | } 65 | 66 | public ReleaseGroupPrimaryType getType() { 67 | return type; 68 | } 69 | 70 | /** 71 | * Returns an immutable set of all associated GIDs (canonical and redirected). 72 | */ 73 | public Set getGids() { 74 | return new ImmutableSet.Builder().addAll(redirectedGids).add(gid).build(); 75 | } 76 | 77 | @Override 78 | public String getName() { 79 | return name; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ReleaseGroupPrimaryType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Map; 19 | 20 | import com.google.common.collect.Maps; 21 | 22 | public enum ReleaseGroupPrimaryType { 23 | /* */ 24 | ALBUM(1, "Album"), 25 | /* */ 26 | SINGLE(2, "Single"), 27 | /* */ 28 | EP(3, "EP"), 29 | /* */ 30 | OTHER(11, "Other"), 31 | /* */ 32 | BROADCAST(12, "Broadcast"), 33 | /* */ 34 | UNDEFINED(null, null); 35 | 36 | private static final Map idToType; 37 | 38 | static { 39 | idToType = Maps.newHashMap(); 40 | for (ReleaseGroupPrimaryType value : values()) { 41 | idToType.put(value.getId(), value); 42 | } 43 | } 44 | 45 | private final Integer id; 46 | private final String name; 47 | 48 | private ReleaseGroupPrimaryType(Integer id, String name) { 49 | this.id = id; 50 | this.name = name; 51 | } 52 | 53 | public static ReleaseGroupPrimaryType valueOf(Integer id) { 54 | ReleaseGroupPrimaryType type = idToType.get(id); 55 | if (type == null) { 56 | throw new IllegalArgumentException("Unrecognized release group primary type: " + id); 57 | } 58 | return type; 59 | } 60 | 61 | public Integer getId() { 62 | return id; 63 | } 64 | 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ReleaseStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Map; 19 | 20 | import com.google.common.collect.Maps; 21 | 22 | public enum ReleaseStatus { 23 | /* */ 24 | OFFICIAL(1, "Official"), 25 | /* */ 26 | PROMOTION(2, "Promotion"), 27 | /* */ 28 | BOOTLEG(3, "Bootleg"), 29 | /* */ 30 | PSEUDO_RELEASE(4, "Pseudo-Release"), 31 | /* */ 32 | UNDEFINED(null, null); 33 | 34 | private static final Map idToType; 35 | 36 | static { 37 | idToType = Maps.newHashMap(); 38 | for (ReleaseStatus value : values()) { 39 | idToType.put(value.getId(), value); 40 | } 41 | } 42 | 43 | private final Integer id; 44 | private final String name; 45 | 46 | private ReleaseStatus(Integer id, String name) { 47 | this.id = id; 48 | this.name = name; 49 | } 50 | 51 | public static ReleaseStatus valueOf(Integer id) { 52 | ReleaseStatus status = idToType.get(id); 53 | if (status == null) { 54 | throw new IllegalArgumentException("Unrecognized release status: " + id); 55 | } 56 | return status; 57 | } 58 | 59 | public Integer getId() { 60 | return id; 61 | } 62 | 63 | public String getName() { 64 | return name; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/ReleaseUnknownCountry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import javax.persistence.Access; 19 | import javax.persistence.AccessType; 20 | import javax.persistence.AttributeOverride; 21 | import javax.persistence.AttributeOverrides; 22 | import javax.persistence.Column; 23 | import javax.persistence.Embedded; 24 | import javax.persistence.Entity; 25 | import javax.persistence.Id; 26 | import javax.persistence.Table; 27 | 28 | import org.hibernate.annotations.Cache; 29 | import org.hibernate.annotations.CacheConcurrencyStrategy; 30 | 31 | @Access(AccessType.FIELD) 32 | @Entity 33 | @Table(name = "release_unknown_country", schema = "musicbrainz") 34 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 35 | class ReleaseUnknownCountry { 36 | 37 | @Id 38 | @Column(name = "release") 39 | private int release; 40 | 41 | @Embedded 42 | @AttributeOverrides({ @AttributeOverride(name = "year", column = @Column(name = "date_year")), 43 | @AttributeOverride(name = "month", column = @Column(name = "date_month")), 44 | @AttributeOverride(name = "day", column = @Column(name = "date_day")) }) 45 | private PartialDate releaseDate; 46 | 47 | PartialDate getReleaseDate() { 48 | return releaseDate; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/fm/last/musicbrainz/data/model/Track.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import java.util.Set; 19 | import java.util.UUID; 20 | 21 | import javax.persistence.Access; 22 | import javax.persistence.AccessType; 23 | import javax.persistence.CollectionTable; 24 | import javax.persistence.Column; 25 | import javax.persistence.ElementCollection; 26 | import javax.persistence.Entity; 27 | import javax.persistence.FetchType; 28 | import javax.persistence.Id; 29 | import javax.persistence.JoinColumn; 30 | import javax.persistence.ManyToOne; 31 | import javax.persistence.Table; 32 | 33 | import org.hibernate.annotations.Cache; 34 | import org.hibernate.annotations.CacheConcurrencyStrategy; 35 | import org.hibernate.annotations.Type; 36 | import org.joda.time.DateTime; 37 | 38 | import com.google.common.collect.ImmutableSet; 39 | import com.google.common.collect.Sets; 40 | 41 | @Access(AccessType.FIELD) 42 | @Entity 43 | @Table(name = "track", schema = "musicbrainz") 44 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 45 | public class Track { 46 | 47 | @Id 48 | @Column(name = "id") 49 | private int id; 50 | 51 | @Column(name = "gid", nullable = false, unique = true) 52 | @Type(type = "pg-uuid") 53 | private UUID gid; 54 | 55 | @ElementCollection(fetch = FetchType.LAZY) 56 | @CollectionTable(name = "track_gid_redirect", schema = "musicbrainz", joinColumns = @JoinColumn(name = "new_id")) 57 | @Column(name = "gid") 58 | @Type(type = "pg-uuid") 59 | private final Set redirectedGids = Sets.newHashSet(); 60 | 61 | @ManyToOne(targetEntity = ArtistCredit.class, fetch = FetchType.LAZY) 62 | @JoinColumn(name = "artist_credit", nullable = true) 63 | private ArtistCredit artistCredit; 64 | 65 | @Column(name = "position") 66 | private int position; 67 | 68 | @Column(name = "number") 69 | private String number; 70 | 71 | @Column(name = "name") 72 | private String name; 73 | 74 | @ManyToOne(targetEntity = Recording.class, fetch = FetchType.LAZY) 75 | @JoinColumn(name = "recording") 76 | private Recording recording; 77 | 78 | @Column(name = "length") 79 | private Integer length; 80 | 81 | @Column(name = "last_updated") 82 | @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime") 83 | private DateTime lastUpdated; 84 | 85 | public int getId() { 86 | return id; 87 | } 88 | 89 | public int getPosition() { 90 | return position; 91 | } 92 | 93 | public String getNumber() { 94 | return number; 95 | } 96 | 97 | public String getName() { 98 | return name; 99 | } 100 | 101 | public ArtistCredit getArtistCredit() { 102 | return artistCredit; 103 | } 104 | 105 | public Recording getRecording() { 106 | return recording; 107 | } 108 | 109 | /** 110 | * Length in milliseconds. 111 | */ 112 | public Integer getLength() { 113 | return length; 114 | } 115 | 116 | public DateTime getLastUpdated() { 117 | return lastUpdated; 118 | } 119 | 120 | /** 121 | * Returns an immutable set of all associated GIDs (canonical and redirected). 122 | */ 123 | public Set getGids() { 124 | return new ImmutableSet.Builder().addAll(redirectedGids).add(gid).build(); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/resources/spring/musicbrainz-data.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.hibernate.dialect.PostgreSQLDialect 33 | validate 34 | ${hibernate.show_sql:false} 35 | false 36 | false 37 | 38 | 39 | 40 | 41 | fm.last.musicbrainz.data.model 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/test/config/musicbrainz-data.properties: -------------------------------------------------------------------------------- 1 | db.musicbrainz.driver.class=org.postgresql.Driver 2 | db.musicbrainz.url=jdbc:postgresql://localhost:5432/musicbrainz_musicbrainzdata_unittest 3 | db.musicbrainz.user=musicbrainz 4 | db.musicbrainz.password=musicbrainz 5 | 6 | hibernate.show_sql=true -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/AbstractHibernateModelIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.util.List; 21 | 22 | import javax.sql.DataSource; 23 | 24 | import org.hibernate.Session; 25 | import org.hibernate.SessionFactory; 26 | import org.hibernate.stat.Statistics; 27 | import org.junit.After; 28 | import org.junit.Before; 29 | import org.junit.Ignore; 30 | import org.junit.runner.RunWith; 31 | import org.springframework.beans.factory.annotation.Autowired; 32 | import org.springframework.jdbc.core.JdbcTemplate; 33 | import org.springframework.test.context.ContextConfiguration; 34 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 35 | 36 | import com.google.common.base.Charsets; 37 | import com.google.common.io.Files; 38 | 39 | @RunWith(SpringJUnit4ClassRunner.class) 40 | @ContextConfiguration(locations = { "/spring/musicbrainz-data-test.xml" }) 41 | @Ignore("This is abstract") 42 | public abstract class AbstractHibernateModelIT { 43 | 44 | private static final String TEST_SQL_PATH = "src/test/sql"; 45 | 46 | private final JdbcTemplate jdbcTemplate = new JdbcTemplate(); 47 | 48 | @Autowired 49 | private DataSource dataSource; 50 | 51 | @Autowired 52 | private SessionFactory sessionFactory; 53 | 54 | protected Session session; 55 | 56 | private Statistics statistics; 57 | 58 | private long fetches; 59 | 60 | @Before 61 | public void setupDatabases() throws Exception { 62 | jdbcTemplate.setDataSource(dataSource); 63 | insertTestData(jdbcTemplate, new File(TEST_SQL_PATH, "musicbrainz-unittest.sql")); 64 | } 65 | 66 | @Before 67 | public void initialise() { 68 | statistics = sessionFactory.getStatistics(); 69 | session = sessionFactory.openSession(); 70 | 71 | statistics.setStatisticsEnabled(true); 72 | markFetchCount(); 73 | } 74 | 75 | @After 76 | public void tearDown() { 77 | if (session != null) { 78 | session.close(); 79 | } 80 | if (statistics != null) { 81 | statistics.setStatisticsEnabled(false); 82 | } 83 | } 84 | 85 | private void markFetchCount() { 86 | fetches = statistics.getEntityFetchCount(); 87 | } 88 | 89 | protected long fetchCount() { 90 | return statistics.getEntityFetchCount() - fetches; 91 | } 92 | 93 | private void insertTestData(JdbcTemplate jdbcTemplate, File sqlFile) throws IOException { 94 | List lines = Files.readLines(sqlFile, Charsets.UTF_8); 95 | jdbcTemplate.batchUpdate(lines.toArray(new String[] {})); 96 | } 97 | } -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/dao/impl/ArtistDaoImplIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.CoreMatchers.nullValue; 20 | import static org.hamcrest.Matchers.equalToIgnoringCase; 21 | import static org.hamcrest.Matchers.hasSize; 22 | import static org.junit.Assert.assertThat; 23 | 24 | import java.util.List; 25 | import java.util.UUID; 26 | 27 | import org.junit.Test; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | 30 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 31 | import fm.last.musicbrainz.data.dao.ArtistDao; 32 | import fm.last.musicbrainz.data.model.Artist; 33 | 34 | public class ArtistDaoImplIT extends AbstractHibernateModelIT { 35 | 36 | @Autowired 37 | private ArtistDao dao; 38 | 39 | @Test 40 | public void getByExistingIdReturnsOneArtist() { 41 | Artist artist = dao.getById(1); 42 | assertThat(artist.getName(), is("Q and Not U")); 43 | } 44 | 45 | @Test 46 | public void getByNotExistingIdReturnsNull() { 47 | Artist artist = dao.getById(9001); 48 | assertThat(artist, is(nullValue())); 49 | } 50 | 51 | @Test 52 | public void getByExistingGidReturnsOneArtist() { 53 | UUID gid = UUID.fromString("994fcd41-2831-4318-9825-66bacbcf2cfe"); 54 | Artist artist = dao.getByGid(gid); 55 | assertThat(artist.getName(), is("Q and Not U")); 56 | } 57 | 58 | @Test 59 | public void getByNotExistingGidReturnsNull() { 60 | UUID gid = UUID.fromString("b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d"); 61 | Artist artist = dao.getByGid(gid); 62 | assertThat(artist, is(nullValue())); 63 | } 64 | 65 | @Test 66 | public void getByExistingRedirectedGidReturnsOneArtist() { 67 | UUID gid = UUID.fromString("a934e33f-b3cb-47dd-9638-f7f1f25fe162"); 68 | Artist artist = dao.getByGid(gid); 69 | assertThat(artist.getName(), is("Q and Not U")); 70 | } 71 | 72 | @Test 73 | public void getByExistingGidReturnsOneArtistThatHasNoRedirectedGids() { 74 | UUID gid = UUID.fromString("194fcd41-2831-4318-9825-66bacbcf2cfe"); 75 | Artist artist = dao.getByGid(gid); 76 | assertThat(artist.getName(), is("Mono")); 77 | } 78 | 79 | @Test 80 | public void getByExistingNameReturnsTwoArtists() { 81 | String artistName = "Mono"; 82 | List artists = dao.getByName(artistName); 83 | assertThat(artists, hasSize(2)); 84 | for (Artist artist : artists) { 85 | assertThat(artist.getName(), is(equalToIgnoringCase(artistName))); 86 | } 87 | } 88 | 89 | @Test 90 | public void getByExistingUppercaseNameReturnsTwoArtists() { 91 | List artists = dao.getByName("MONO"); 92 | assertThat(artists, hasSize(2)); 93 | } 94 | 95 | @Test 96 | public void getByExistingLowercaseNameReturnsTwoArtists() { 97 | List artists = dao.getByName("mono"); 98 | assertThat(artists, hasSize(2)); 99 | } 100 | 101 | @Test 102 | public void getByNotExistingNameReturnsEmptyList() { 103 | List artists = dao.getByName("does not exist"); 104 | assertThat(artists, hasSize(0)); 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/dao/impl/RecordingDaoIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.CoreMatchers.nullValue; 20 | import static org.hamcrest.Matchers.hasSize; 21 | import static org.junit.Assert.assertThat; 22 | 23 | import java.util.List; 24 | import java.util.UUID; 25 | 26 | import org.junit.Test; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | 29 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 30 | import fm.last.musicbrainz.data.dao.RecordingDao; 31 | import fm.last.musicbrainz.data.model.Artist; 32 | import fm.last.musicbrainz.data.model.Recording; 33 | 34 | public class RecordingDaoIT extends AbstractHibernateModelIT { 35 | 36 | @Autowired 37 | private RecordingDao dao; 38 | 39 | @Test 40 | public void getByExistingIdReturnsOneRecording() { 41 | Recording recording = dao.getById(1); 42 | assertThat(recording.getName(), is("The Saint")); 43 | } 44 | 45 | @Test 46 | public void getByNotExistingIdReturnsNull() { 47 | Recording recording = dao.getById(9001); 48 | assertThat(recording, is(nullValue())); 49 | } 50 | 51 | @Test 52 | public void getByExistingGidReturnsOneRecording() { 53 | UUID gid = UUID.fromString("4ea1383f-aca7-4a39-9839-576cf3af438b"); 54 | Recording recording = dao.getByGid(gid); 55 | assertThat(recording.getName(), is("The Saint")); 56 | } 57 | 58 | @Test 59 | public void getByNotExistingGidReturnsNull() { 60 | UUID gid = UUID.fromString("b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d"); 61 | Recording recording = dao.getByGid(gid); 62 | assertThat(recording, is(nullValue())); 63 | } 64 | 65 | @Test 66 | public void getByExistingGidReturnsOneRecordingThatHasNoRedirectedGids() { 67 | UUID gid = UUID.fromString("2ea1383f-aca7-4a39-9839-576cf3af438b"); 68 | Recording recording = dao.getByGid(gid); 69 | assertThat(recording.getName(), is("The Sinner")); 70 | } 71 | 72 | @Test 73 | public void getByArtistAndNameReturnsTwoRecordings() { 74 | Artist artist = (Artist) session.load(Artist.class, 5); 75 | String trackName = "Never Gonna Give You Up"; 76 | List recordings = dao.getByArtistAndName(artist, trackName); 77 | assertThat(recordings, hasSize(2)); 78 | for (Recording recording : recordings) { 79 | assertThat(recording.getName(), is(trackName)); 80 | } 81 | } 82 | 83 | @Test 84 | public void getByArtistAndUppercaseNameReturnsTwoRecordings() { 85 | Artist artist = (Artist) session.load(Artist.class, 5); 86 | List recordings = dao.getByArtistAndName(artist, "NEVER GONNA GIVE YOU UP"); 87 | assertThat(recordings, hasSize(2)); 88 | } 89 | 90 | @Test 91 | public void getByArtistAndLowercaseNameReturnsTwoRecordings() { 92 | Artist artist = (Artist) session.load(Artist.class, 5); 93 | List recordings = dao.getByArtistAndName(artist, "never gonna give you up"); 94 | assertThat(recordings, hasSize(2)); 95 | } 96 | 97 | @Test 98 | public void getByArtistAndNotExistingNameReturnsEmptyList() { 99 | Artist artist = (Artist) session.load(Artist.class, 4); 100 | List recordings = dao.getByArtistAndName(artist, "does not exists"); 101 | assertThat(recordings, hasSize(0)); 102 | } 103 | 104 | @Test 105 | public void getByArtistReturnsAllRecordings() { 106 | Artist artist = (Artist) session.load(Artist.class, 5); 107 | List recordings = dao.getByArtist(artist); 108 | assertThat(recordings, hasSize(4)); 109 | } 110 | 111 | @Test 112 | public void getByArtistReturnsNoRecordingsForEmptyArtist() { 113 | Artist artist = (Artist) session.load(Artist.class, 1); 114 | List recordings = dao.getByArtist(artist); 115 | assertThat(recordings, hasSize(0)); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/dao/impl/ReleaseDaoImplIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.CoreMatchers.nullValue; 20 | import static org.hamcrest.Matchers.hasSize; 21 | import static org.junit.Assert.assertThat; 22 | 23 | import java.util.List; 24 | import java.util.Set; 25 | import java.util.UUID; 26 | 27 | import org.junit.Test; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | 30 | import com.google.common.collect.Sets; 31 | 32 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 33 | import fm.last.musicbrainz.data.dao.ReleaseDao; 34 | import fm.last.musicbrainz.data.model.Artist; 35 | import fm.last.musicbrainz.data.model.Release; 36 | 37 | public class ReleaseDaoImplIT extends AbstractHibernateModelIT { 38 | 39 | @Autowired 40 | private ReleaseDao dao; 41 | 42 | @Test 43 | public void getByExistingIdReturnsOneRelese() { 44 | Release release = dao.getById(1); 45 | assertThat(release.getName(), is("The Best of Rick Astley")); 46 | } 47 | 48 | @Test 49 | public void getByNotExistingIdReturnsNull() { 50 | Release release = dao.getById(9001); 51 | assertThat(release, is(nullValue())); 52 | } 53 | 54 | @Test 55 | public void getByExistingGidReturnsOneRelease() { 56 | UUID gid = UUID.fromString("e1f5f807-3851-48fb-838b-fb8a069f53e7"); 57 | Release release = dao.getByGid(gid); 58 | assertThat(release.getName(), is("The Best of Rick Astley")); 59 | } 60 | 61 | @Test 62 | public void getByNotExistingGidReturnsNull() { 63 | UUID gid = UUID.fromString("b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d"); 64 | Release release = dao.getByGid(gid); 65 | assertThat(release, is(nullValue())); 66 | } 67 | 68 | @Test 69 | public void getByExistingRedirectedGidReturnsOneRelease() { 70 | UUID gid = UUID.fromString("5d32bacc-d62a-4e77-9f0e-d934e53d5359"); 71 | Release release = dao.getByGid(gid); 72 | assertThat(release.getName(), is("Multi-Disc Extravaganza")); 73 | } 74 | 75 | @Test 76 | public void getByExistingGidReturnsOneReleaseThatHasNoRedirectedGids() { 77 | UUID gid = UUID.fromString("f80addb0-1f8c-3c37-a4a9-6f8867be35fe"); 78 | Release release = dao.getByGid(gid); 79 | assertThat(release.getName(), is("The Warning")); 80 | } 81 | 82 | @Test 83 | public void getByExistingArtistReturnsThreeReleases() { 84 | Set expectedReleaseNames = Sets.newHashSet("The Warning", "One Life Stand", "Multi-Disc Extravaganza"); 85 | Set actualReleaseNames = Sets.newHashSet(); 86 | Artist artist = (Artist) session.load(Artist.class, 4); 87 | for (Release release : dao.getByArtist(artist)) { 88 | actualReleaseNames.add(release.getName()); 89 | } 90 | assertThat(actualReleaseNames, is(expectedReleaseNames)); 91 | } 92 | 93 | @Test 94 | public void getByArtistThatHasNoReleasesReturnsEmptyList() { 95 | Artist artist = (Artist) session.load(Artist.class, 1); 96 | List releases = dao.getByArtist(artist); 97 | assertThat(releases, hasSize(0)); 98 | } 99 | 100 | @Test 101 | public void getByArtistAndNameReturnsTwoReleases() { 102 | Artist artist = (Artist) session.load(Artist.class, 4); 103 | String releaseName = "The Warning"; 104 | List releases = dao.getByArtistAndName(artist, releaseName); 105 | assertThat(releases, hasSize(2)); 106 | for (Release release : releases) { 107 | assertThat(release.getName(), is(releaseName)); 108 | } 109 | } 110 | 111 | @Test 112 | public void getByArtistAndUppercaseNameReturnsTwoReleases() { 113 | Artist artist = (Artist) session.load(Artist.class, 4); 114 | List releases = dao.getByArtistAndName(artist, "THE WARNING"); 115 | assertThat(releases, hasSize(2)); 116 | } 117 | 118 | @Test 119 | public void getByArtistAndLowercaseNameReturnsTwoReleases() { 120 | Artist artist = (Artist) session.load(Artist.class, 4); 121 | List releases = dao.getByArtistAndName(artist, "the warning"); 122 | assertThat(releases, hasSize(2)); 123 | } 124 | 125 | @Test 126 | public void getByArtistAndNotExistingNameReturnsEmptyList() { 127 | Artist artist = (Artist) session.load(Artist.class, 3); 128 | List releases = dao.getByArtistAndName(artist, "does not exist"); 129 | assertThat(releases, hasSize(0)); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/dao/impl/TrackDaoImplIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.dao.impl; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.CoreMatchers.nullValue; 20 | import static org.hamcrest.Matchers.hasSize; 21 | import static org.junit.Assert.assertThat; 22 | 23 | import java.util.List; 24 | import java.util.Set; 25 | import java.util.UUID; 26 | 27 | import org.junit.Test; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | 30 | import com.google.common.collect.Sets; 31 | 32 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 33 | import fm.last.musicbrainz.data.dao.TrackDao; 34 | import fm.last.musicbrainz.data.model.Artist; 35 | import fm.last.musicbrainz.data.model.Track; 36 | 37 | public class TrackDaoImplIT extends AbstractHibernateModelIT { 38 | 39 | @Autowired 40 | private TrackDao dao; 41 | 42 | @Test 43 | public void getByExistingIdReturnsOneTrack() { 44 | Track track = dao.getById(1); 45 | assertThat(track.getName(), is("The Saint")); 46 | } 47 | 48 | @Test 49 | public void getByNotExistingIdReturnsNull() { 50 | Track track = dao.getById(9001); 51 | assertThat(track, is(nullValue())); 52 | } 53 | 54 | @Test 55 | public void getByExistingGidReturnsOneTrack() { 56 | UUID gid = UUID.fromString("70c4bd53-f3ef-354f-97a9-7ed76915087a"); 57 | Track track = dao.getByGid(gid); 58 | assertThat(track.getName(), is("The Saint")); 59 | } 60 | 61 | @Test 62 | public void getByNotExistingGidReturnsNull() { 63 | UUID gid = UUID.fromString("b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d"); 64 | Track track = dao.getByGid(gid); 65 | assertThat(track, is(nullValue())); 66 | } 67 | 68 | @Test 69 | public void getByExistingGidReturnsOneTrackThatHasNoRedirectedGids() { 70 | UUID gid = UUID.fromString("8f64df73-562c-4145-a9db-9736a3f04c27"); 71 | Track track = dao.getByGid(gid); 72 | assertThat(track.getName(), is("The Saint")); 73 | } 74 | 75 | @Test 76 | public void getByArtistAndNameReturnsOneTrack() { 77 | Artist artist = (Artist) session.load(Artist.class, 5); 78 | String trackName = "The Saint"; 79 | List tracks = dao.getByArtistAndName(artist, trackName); 80 | assertThat(tracks, hasSize(2)); 81 | for (Track track : tracks) { 82 | assertThat(track.getName(), is(trackName)); 83 | } 84 | } 85 | 86 | @Test 87 | public void getByArtistAndUppercaseNameReturnsOneTrack() { 88 | Artist artist = (Artist) session.load(Artist.class, 5); 89 | String trackName = "THE SAINT"; 90 | List tracks = dao.getByArtistAndName(artist, trackName); 91 | assertThat(tracks, hasSize(2)); 92 | } 93 | 94 | @Test 95 | public void getByArtistAndLowercaseNameReturnsOneTrack() { 96 | Artist artist = (Artist) session.load(Artist.class, 5); 97 | String trackName = "the saint"; 98 | List tracks = dao.getByArtistAndName(artist, trackName); 99 | assertThat(tracks, hasSize(2)); 100 | } 101 | 102 | @Test 103 | public void getByArtistAndNotExistingNameReturnsEmptyList() { 104 | Artist artist = (Artist) session.load(Artist.class, 4); 105 | List tracks = dao.getByArtistAndName(artist, "does not exists"); 106 | assertThat(tracks, hasSize(0)); 107 | } 108 | 109 | @Test 110 | public void getByExistingArtistReturnsThreeTracks() { 111 | Artist artist = (Artist) session.load(Artist.class, 5); 112 | List tracks = dao.getByArtist(artist); 113 | Set expectedTrackIds = Sets.newHashSet(1, 2, 3); 114 | Set actualTrackIds = Sets.newHashSet(); 115 | for (Track track : tracks) { 116 | actualTrackIds.add(track.getId()); 117 | } 118 | assertThat(actualTrackIds, is(expectedTrackIds)); 119 | } 120 | 121 | @Test 122 | public void getByArtistThatHasNoTracksReturnsEmptyList() { 123 | Artist artist = (Artist) session.load(Artist.class, 1); 124 | List tracks = dao.getByArtist(artist); 125 | assertThat(tracks, hasSize(0)); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/AreaIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.Matchers.hasSize; 20 | import static org.hamcrest.Matchers.nullValue; 21 | import static org.junit.Assert.assertThat; 22 | 23 | import java.util.Set; 24 | import java.util.UUID; 25 | 26 | import org.joda.time.DateTime; 27 | import org.joda.time.LocalDate; 28 | import org.junit.Test; 29 | 30 | import com.google.common.collect.Sets; 31 | 32 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 33 | 34 | public class AreaIT extends AbstractHibernateModelIT { 35 | 36 | @Test 37 | public void allFieldsArePopulated() { 38 | Set expectedGids = Sets.newHashSet(UUID.fromString("c741c28e-cbec-3977-88c8-583a8af62522"), 39 | UUID.fromString("6b43e5f2-49e8-46ce-94cb-a9b23e5bb4e8")); 40 | 41 | Area area = (Area) session.load(Area.class, 151); 42 | assertThat(area.getId(), is(151)); 43 | assertThat(area.getName(), is("Netherlands Antilles")); 44 | assertThat(area.getType(), is(AreaType.COUNTRY)); 45 | assertThat(area.getLastUpdated(), is(DateTime.parse("2013-05-15T16:49:41"))); 46 | assertThat(area.getGids(), is(expectedGids)); 47 | assertThat(area.getBeginDate().toLocalDate(), is(LocalDate.parse("1954-09-12"))); 48 | assertThat(area.getEndDate().toLocalDate(), is(LocalDate.parse("2010-12-09"))); 49 | assertThat(area.hasEnded(), is(true)); 50 | } 51 | 52 | @Test 53 | public void areaTypeIsUndefinedWhenNotSpecified() { 54 | Area area = (Area) session.load(Area.class, 1178); 55 | assertThat(area.getType(), is(AreaType.UNDEFINED)); 56 | } 57 | 58 | @Test 59 | public void beginAndEndDateAreNullWhenNotSpecified() { 60 | Area area = (Area) session.load(Area.class, 1178); 61 | assertThat(area.getBeginDate(), is(nullValue())); 62 | assertThat(area.getEndDate(), is(nullValue())); 63 | } 64 | 65 | @Test 66 | public void areaWithoutRedirectedGidsHasOneGid() { 67 | Area area = (Area) session.load(Area.class, 1178); 68 | assertThat(area.getGids(), hasSize(1)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/AreaTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.junit.Assert.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | public class AreaTypeTest { 24 | 25 | @Test 26 | public void idReturnsAreaTypeCountry() { 27 | assertThat(AreaType.valueOf(1), is(AreaType.COUNTRY)); 28 | } 29 | 30 | @Test 31 | public void idReturnsAreaTypeSubdivision() { 32 | assertThat(AreaType.valueOf(2), is(AreaType.SUBDIVISION)); 33 | } 34 | 35 | @Test 36 | public void idReturnsAreaTypeCity() { 37 | assertThat(AreaType.valueOf(3), is(AreaType.CITY)); 38 | } 39 | 40 | @Test 41 | public void nullReturnsAreaTypeUndefined() { 42 | Integer id = null; 43 | assertThat(AreaType.valueOf(id), is(AreaType.UNDEFINED)); 44 | } 45 | 46 | @Test(expected = IllegalArgumentException.class) 47 | public void unrecognisedIdThrowsException() { 48 | AreaType.valueOf(Integer.MAX_VALUE); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/ArtistCreditIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.junit.Assert.assertThat; 20 | 21 | import java.util.List; 22 | 23 | import org.junit.Test; 24 | 25 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 26 | 27 | public class ArtistCreditIT extends AbstractHibernateModelIT { 28 | 29 | @Test 30 | public void fullNameIsOrderedByPosition() { 31 | String expected = "Mono and Rick Astley feat. Hot Chip"; 32 | ArtistCredit artistCredit = (ArtistCredit) session.load(ArtistCredit.class, 3); 33 | assertThat(artistCredit.getFullName(), is(expected)); 34 | } 35 | 36 | @Test 37 | public void singleArtistArtistCreditHasSameFullNameAsArtist() { 38 | ArtistCredit artistCredit = (ArtistCredit) session.load(ArtistCredit.class, 1); 39 | Artist artist = artistCredit.getArtistCreditNames().iterator().next().getArtist(); 40 | assertThat(artistCredit.getFullName(), is(artist.getName())); 41 | } 42 | 43 | @Test 44 | public void artistCreditNameReferenceDoesNotHitDatabase() { 45 | ArtistCredit artistCredit = (ArtistCredit) session.load(ArtistCredit.class, 1); 46 | List artistCreditNames = artistCredit.getArtistCreditNames(); 47 | assertThat(fetchCount(), is(1L)); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/ArtistIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.CoreMatchers.nullValue; 20 | import static org.hamcrest.Matchers.hasSize; 21 | import static org.junit.Assert.assertThat; 22 | 23 | import java.util.Set; 24 | import java.util.UUID; 25 | 26 | import org.joda.time.DateTime; 27 | import org.joda.time.LocalDate; 28 | import org.junit.Test; 29 | 30 | import com.google.common.collect.Sets; 31 | 32 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 33 | 34 | public class ArtistIT extends AbstractHibernateModelIT { 35 | 36 | @Test 37 | public void allFieldsArePopulated() { 38 | Set expectedGids = Sets.newHashSet(UUID.fromString("a934e33f-b3cb-47dd-9638-f7f1f25fe162"), 39 | UUID.fromString("994fcd41-2831-4318-9825-66bacbcf2cfe")); 40 | 41 | Artist artist = (Artist) session.load(Artist.class, 1); 42 | assertThat(artist.getId(), is(1)); 43 | assertThat(artist.getName(), is("Q and Not U")); 44 | assertThat(artist.getComment(), is("Soft Pyramids")); 45 | assertThat(artist.getGids(), is(expectedGids)); 46 | assertThat(artist.getLastUpdated(), is(DateTime.parse("2012-04-10T14:00:00"))); 47 | assertThat(artist.getType(), is(ArtistType.UNDEFINED)); 48 | assertThat(artist.getGender(), is(Gender.UNDEFINED)); 49 | assertThat(artist.getBeginDate().toLocalDate(), is(LocalDate.parse("1950-02-03"))); 50 | assertThat(artist.getEndDate().toLocalDate(), is(LocalDate.parse("2001-04-05"))); 51 | assertThat(artist.getArea().getName(), is("Tokyo")); 52 | assertThat(artist.getBeginArea().getName(), is("South Korea")); 53 | assertThat(artist.getEndArea().getName(), is("Netherlands Antilles")); 54 | } 55 | 56 | @Test 57 | public void areasAreNullWhenNotSpecified() { 58 | Artist artist = (Artist) session.load(Artist.class, 5); 59 | assertThat(artist.getArea(), is(nullValue())); 60 | assertThat(artist.getBeginArea(), is(nullValue())); 61 | assertThat(artist.getEndArea(), is(nullValue())); 62 | } 63 | 64 | @Test 65 | public void beginAndEndDateAreNullWhenNotSpecified() { 66 | Artist artist = (Artist) session.load(Artist.class, 5); 67 | assertThat(artist.getBeginDate(), is(nullValue())); 68 | assertThat(artist.getEndDate(), is(nullValue())); 69 | } 70 | 71 | @Test 72 | public void artistWithoutRedirectedGidsHasOneGid() { 73 | Artist artist = (Artist) session.load(Artist.class, 3); 74 | assertThat(artist.getGids(), hasSize(1)); 75 | } 76 | 77 | @Test 78 | public void genderIsNotUndefinedWhenSpecified() { 79 | Artist artist = (Artist) session.load(Artist.class, 5); 80 | assertThat(artist.getGender(), is(Gender.MALE)); 81 | } 82 | 83 | @Test 84 | public void artistTypeIsNotUndefinedWhenSpecified() { 85 | Artist artist = (Artist) session.load(Artist.class, 5); 86 | assertThat(artist.getType(), is(ArtistType.PERSON)); 87 | } 88 | 89 | @Test 90 | public void areaReferenceDoesNotHitDatabase() { 91 | Artist artist = (Artist) session.load(Artist.class, 1); 92 | Area area = artist.getArea(); 93 | assertThat(fetchCount(), is(1L)); 94 | } 95 | 96 | @Test 97 | public void beginAreaReferenceDoesNotHitDatabase() { 98 | Artist artist = (Artist) session.load(Artist.class, 1); 99 | Area beginArea = artist.getBeginArea(); 100 | assertThat(fetchCount(), is(1L)); 101 | } 102 | 103 | @Test 104 | public void endAreaReferenceDoesNotHitDatabase() { 105 | Artist artist = (Artist) session.load(Artist.class, 1); 106 | Area endArea = artist.getEndArea(); 107 | assertThat(fetchCount(), is(1L)); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/ArtistTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.junit.Assert.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | public class ArtistTypeTest { 24 | 25 | @Test 26 | public void typeReturnsAreaTypePerson() { 27 | assertThat(ArtistType.valueOf(1), is(ArtistType.PERSON)); 28 | } 29 | 30 | @Test 31 | public void typeReturnsAreaTypeGroup() { 32 | assertThat(ArtistType.valueOf(2), is(ArtistType.GROUP)); 33 | } 34 | 35 | @Test 36 | public void typeReturnsAreaTypeOther() { 37 | assertThat(ArtistType.valueOf(3), is(ArtistType.OTHER)); 38 | } 39 | 40 | @Test 41 | public void typeReturnsAreaTypeUndefined() { 42 | Integer id = null; 43 | assertThat(ArtistType.valueOf(id), is(ArtistType.UNDEFINED)); 44 | } 45 | 46 | @Test(expected = IllegalArgumentException.class) 47 | public void unrecognisedTypeThrowsException() { 48 | ArtistType.valueOf(Integer.MAX_VALUE); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/GenderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.junit.Assert.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | public class GenderTest { 24 | 25 | @Test 26 | public void typeReturnsGenderMale() { 27 | assertThat(Gender.valueOf(1), is(Gender.MALE)); 28 | } 29 | 30 | @Test 31 | public void typeReturnsGenderFemale() { 32 | assertThat(Gender.valueOf(2), is(Gender.FEMALE)); 33 | } 34 | 35 | @Test 36 | public void typeReturnsGenderOther() { 37 | assertThat(Gender.valueOf(3), is(Gender.OTHER)); 38 | } 39 | 40 | @Test 41 | public void typeReturnsGenderUndefined() { 42 | Integer id = null; 43 | assertThat(Gender.valueOf(id), is(Gender.UNDEFINED)); 44 | } 45 | 46 | @Test(expected = IllegalArgumentException.class) 47 | public void unrecognisedTypeThrowsException() { 48 | Gender.valueOf(5); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/MediumIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.Matchers.lessThan; 20 | import static org.junit.Assert.assertThat; 21 | 22 | import java.util.List; 23 | import java.util.Set; 24 | 25 | import org.joda.time.DateTime; 26 | import org.junit.Test; 27 | 28 | import com.google.common.collect.Sets; 29 | 30 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 31 | 32 | public class MediumIT extends AbstractHibernateModelIT { 33 | 34 | @Test 35 | public void allFieldsArePopulated() { 36 | Medium medium = (Medium) session.load(Medium.class, 2); 37 | assertThat(medium.getId(), is(2)); 38 | assertThat(medium.getLastUpdated(), is(DateTime.parse("2012-04-10T14:00:00"))); 39 | assertThat(medium.getName(), is("Disc 1")); 40 | assertThat(medium.getPosition(), is(1)); 41 | assertThat(medium.getRelease().getId(), is(5)); 42 | 43 | Set expectedTrackIds = Sets.newHashSet(3, 4); 44 | Set actualTrackIds = Sets.newHashSet(); 45 | for (Track track : medium.getTracks()) { 46 | actualTrackIds.add(track.getId()); 47 | } 48 | assertThat(actualTrackIds, is(expectedTrackIds)); 49 | } 50 | 51 | @Test 52 | public void tracksAreOrderedByPosition() { 53 | Medium medium = (Medium) session.load(Medium.class, 2); 54 | List tracks = medium.getTracks(); 55 | assertThat(tracks.get(0).getPosition(), is(lessThan(tracks.get(1).getPosition()))); 56 | } 57 | 58 | @Test 59 | public void releaseReferenceDoesNotHitDatabase() { 60 | Medium medium = (Medium) session.load(Medium.class, 2); 61 | Release release = medium.getRelease(); 62 | assertThat(fetchCount(), is(1L)); 63 | } 64 | 65 | @Test 66 | public void tracksReferenceDoesNotHitDatabase() { 67 | Medium medium = (Medium) session.load(Medium.class, 2); 68 | List tracks = medium.getTracks(); 69 | assertThat(fetchCount(), is(1L)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/PartialDateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.CoreMatchers.nullValue; 20 | import static org.junit.Assert.assertFalse; 21 | import static org.junit.Assert.assertThat; 22 | import static org.junit.Assert.assertTrue; 23 | 24 | import org.joda.time.LocalDate; 25 | import org.junit.Test; 26 | 27 | public class PartialDateTest { 28 | 29 | @Test 30 | public void yearIsNullReturnsNullReleaseDate() { 31 | assertThat(new PartialDate(null, (short) 10, (short) 5).toLocalDate(), is(nullValue())); 32 | } 33 | 34 | @Test 35 | public void monthIsNullReturnsReleaseDateFromJanuary() { 36 | assertThat(new PartialDate((short) 2011, null, (short) 5).toLocalDate(), is(LocalDate.parse("2011-01-01"))); 37 | assertThat(new PartialDate((short) 2011, null, null).toLocalDate(), is(LocalDate.parse("2011-01-01"))); 38 | } 39 | 40 | @Test 41 | public void dayIsNullReturnsReleaseDateFromFirstOfMonth() { 42 | assertThat(new PartialDate((short) 2011, (short) 5, null).toLocalDate(), is(LocalDate.parse("2011-05-01"))); 43 | } 44 | 45 | @Test 46 | public void equalsTests() { 47 | PartialDate date1 = new PartialDate((short) 2011, (short) 5, null); 48 | PartialDate date2 = new PartialDate((short) 2011, (short) 5, (short) 1); 49 | assertFalse(date1.equals(date2)); 50 | PartialDate date3 = new PartialDate((short) 2011, (short) 5, (short) 1); 51 | assertTrue(date2.equals(date3)); 52 | PartialDate date4 = new PartialDate(null, (short) 5, (short) 1); 53 | assertFalse(date1.equals(date4)); 54 | } 55 | 56 | @Test 57 | public void compareToTests() { 58 | PartialDate date2 = new PartialDate((short) 2011, (short) 5, (short) 1); 59 | PartialDate date3 = new PartialDate((short) 2011, (short) 5, (short) 1); 60 | assertThat(date2.compareTo(date3), is(0)); 61 | PartialDate date1 = new PartialDate((short) 2011, (short) 5, null); 62 | assertThat(date1.compareTo(date2), is(-1)); 63 | PartialDate date4 = new PartialDate(null, (short) 5, (short) 1); 64 | assertThat(date1.compareTo(date4), is(1)); 65 | } 66 | 67 | @Test 68 | public void toStringTests() { 69 | PartialDate date; 70 | date = new PartialDate((short) 2011, null, null); 71 | assertThat(date.toString(), is("2011")); 72 | date = new PartialDate((short) 2011, (short) 5, null); 73 | assertThat(date.toString(), is("2011-05")); 74 | date = new PartialDate((short) 2011, (short) 5, (short) 6); 75 | assertThat(date.toString(), is("2011-05-06")); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/RecordingIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.Matchers.isEmptyString; 20 | import static org.junit.Assert.assertThat; 21 | 22 | import java.util.Set; 23 | import java.util.UUID; 24 | 25 | import org.joda.time.DateTime; 26 | import org.junit.Test; 27 | 28 | import com.google.common.collect.Sets; 29 | 30 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 31 | 32 | public class RecordingIT extends AbstractHibernateModelIT { 33 | 34 | @Test 35 | public void allFieldsArePopulated() { 36 | Set expectedGids = Sets.newHashSet(UUID.fromString("4ea1383f-aca7-4a39-9839-576cf3af438b"), 37 | UUID.fromString("6a27908d-9663-4e61-9ef3-e8b82c31dc14")); 38 | 39 | Recording recording = (Recording) session.load(Recording.class, 1); 40 | assertThat(recording.getId(), is(1)); 41 | assertThat(recording.getName(), is("The Saint")); 42 | assertThat(recording.getArtistCredit().getFullName(), is("Rick Astley")); 43 | assertThat(recording.getComment(), isEmptyString()); 44 | assertThat(recording.getGids(), is(expectedGids)); 45 | assertThat(recording.getLastUpdated(), is(DateTime.parse("2012-04-10T14:00:00"))); 46 | assertThat(recording.getLength(), is(1000)); 47 | } 48 | 49 | @Test 50 | public void recordingWithoutRedirectedGidsHasOneGid() { 51 | Recording recording = (Recording) session.load(Recording.class, 2); 52 | assertThat(recording.getGids().size(), is(1)); 53 | } 54 | 55 | @Test 56 | public void artistCreditReferenceDoesNotHitDatabase() { 57 | Recording recording = (Recording) session.load(Recording.class, 1); 58 | ArtistCredit credit = recording.getArtistCredit(); 59 | assertThat(fetchCount(), is(1L)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/ReleaseGroupIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.Matchers.hasSize; 20 | import static org.junit.Assert.assertThat; 21 | 22 | import java.util.Set; 23 | import java.util.UUID; 24 | 25 | import org.joda.time.DateTime; 26 | import org.junit.Test; 27 | 28 | import com.google.common.collect.Sets; 29 | 30 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 31 | 32 | public class ReleaseGroupIT extends AbstractHibernateModelIT { 33 | 34 | @Test 35 | public void allFieldsArePopulated() { 36 | Set expectedGids = Sets.newHashSet(UUID.fromString("a1f5f807-3851-48fb-838b-fb8a069f53e7"), 37 | UUID.fromString("188711ed-c99b-439c-844a-ca831f63a727")); 38 | 39 | ReleaseGroup releaseGroup = (ReleaseGroup) session.load(ReleaseGroup.class, 1); 40 | assertThat(releaseGroup.getArtistCredit().getFullName(), is("Rick Astley")); 41 | assertThat(releaseGroup.getComment(), is("release_group comment")); 42 | assertThat(releaseGroup.getGids(), is(expectedGids)); 43 | assertThat(releaseGroup.getId(), is(1)); 44 | assertThat(releaseGroup.getLastUpdated(), is(DateTime.parse("2012-04-10T14:00:00"))); 45 | assertThat(releaseGroup.getName(), is("The Best of Rick Astley")); 46 | assertThat(releaseGroup.getType(), is(ReleaseGroupPrimaryType.UNDEFINED)); 47 | } 48 | 49 | @Test 50 | public void releaseGroupPrimaryTypeIsNotUndefined() { 51 | ReleaseGroup releaseGroup = (ReleaseGroup) session.load(ReleaseGroup.class, 2); 52 | assertThat(releaseGroup.getType(), is(ReleaseGroupPrimaryType.ALBUM)); 53 | } 54 | 55 | @Test 56 | public void releaseGroupWithoutRedirectedGidsHasOneGid() { 57 | ReleaseGroup releaseGroup = (ReleaseGroup) session.load(ReleaseGroup.class, 2); 58 | assertThat(releaseGroup.getGids(), hasSize(1)); 59 | } 60 | 61 | @Test 62 | public void artistCreditReferenceDoesNotHitDatabase() { 63 | ReleaseGroup releaseGroup = (ReleaseGroup) session.load(ReleaseGroup.class, 1); 64 | ArtistCredit credit = releaseGroup.getArtistCredit(); 65 | assertThat(fetchCount(), is(1L)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/ReleaseGroupPrimaryTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.junit.Assert.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | public class ReleaseGroupPrimaryTypeTest { 24 | 25 | @Test 26 | public void statusReturnsReleaseGroupPrimaryTypeAlbum() { 27 | assertThat(ReleaseGroupPrimaryType.valueOf(1), is(ReleaseGroupPrimaryType.ALBUM)); 28 | } 29 | 30 | @Test 31 | public void statusReturnsReleaseGroupPrimaryTypeSingle() { 32 | assertThat(ReleaseGroupPrimaryType.valueOf(2), is(ReleaseGroupPrimaryType.SINGLE)); 33 | } 34 | 35 | @Test 36 | public void statusReturnsReleaseGroupPrimaryTypeEp() { 37 | assertThat(ReleaseGroupPrimaryType.valueOf(3), is(ReleaseGroupPrimaryType.EP)); 38 | } 39 | 40 | @Test 41 | public void statusReturnsReleaseGroupPrimaryTypeOther() { 42 | assertThat(ReleaseGroupPrimaryType.valueOf(11), is(ReleaseGroupPrimaryType.OTHER)); 43 | } 44 | 45 | @Test 46 | public void statusReturnsReleaseGroupPrimaryTypeBroadcast() { 47 | assertThat(ReleaseGroupPrimaryType.valueOf(12), is(ReleaseGroupPrimaryType.BROADCAST)); 48 | } 49 | 50 | @Test 51 | public void nullReturnsReleaseGroupPrimaryTypeUndefined() { 52 | Integer id = null; 53 | assertThat(ReleaseGroupPrimaryType.valueOf(id), is(ReleaseGroupPrimaryType.UNDEFINED)); 54 | } 55 | 56 | @Test(expected = IllegalArgumentException.class) 57 | public void unrecognisedStatusThrowsException() { 58 | ReleaseGroupPrimaryType.valueOf(5); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/ReleaseIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.Matchers.hasSize; 20 | import static org.hamcrest.Matchers.isEmptyString; 21 | import static org.hamcrest.Matchers.lessThan; 22 | import static org.hamcrest.Matchers.nullValue; 23 | import static org.junit.Assert.assertThat; 24 | 25 | import java.util.List; 26 | import java.util.Set; 27 | import java.util.UUID; 28 | 29 | import org.joda.time.DateTime; 30 | import org.joda.time.LocalDate; 31 | import org.junit.Test; 32 | 33 | import com.google.common.collect.Sets; 34 | 35 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 36 | 37 | public class ReleaseIT extends AbstractHibernateModelIT { 38 | 39 | @Test 40 | public void allFieldsArePopulated() { 41 | Set expectedGids = Sets.newHashSet(UUID.fromString("6dfe725f-de93-3b08-b3cb-5971e5bd6eb5"), 42 | UUID.fromString("5d32bacc-d62a-4e77-9f0e-d934e53d5359")); 43 | 44 | Release release = (Release) session.load(Release.class, 5); 45 | assertThat(release.getArtistCredit().getFullName(), is("Mono and Rick Astley feat. Hot Chip")); 46 | assertThat(release.getComment(), isEmptyString()); 47 | assertThat(release.getGids(), is(expectedGids)); 48 | assertThat(release.getId(), is(5)); 49 | assertThat(release.getLastUpdated(), is(DateTime.parse("2012-04-10T14:00:00"))); 50 | assertThat(release.getName(), is("Multi-Disc Extravaganza")); 51 | assertThat(release.getMediums(), hasSize(2)); 52 | assertThat(release.getStatus(), is(ReleaseStatus.UNDEFINED)); 53 | assertThat(release.getReleaseGroup().getId(), is(4)); 54 | assertThat(release.getReleaseDateForUnknownCountry().toLocalDate(), is(LocalDate.parse("2011-07-23"))); 55 | assertThat(release.getReleaseCountries(), hasSize(0)); 56 | } 57 | 58 | @Test 59 | public void releaseCountriesAreMappedWhenSpecified() { 60 | Set expected = Sets.newHashSet(new ReleaseCountry(4, 151, new PartialDate(null, (short) 7, 61 | (short) 23)), new ReleaseCountry(4, 113, new PartialDate((short) 2010, (short) 7, (short) 23)), 62 | new ReleaseCountry(4, 203, null)); 63 | 64 | Release release = (Release) session.load(Release.class, 4); 65 | assertThat(release.getReleaseDateForUnknownCountry(), is(nullValue())); 66 | assertThat(release.getReleaseCountries(), is(expected)); 67 | } 68 | 69 | @Test 70 | public void releaseStatusIsNotUndefined() { 71 | Release release = (Release) session.load(Release.class, 4); 72 | assertThat(release.getStatus(), is(ReleaseStatus.OFFICIAL)); 73 | } 74 | 75 | @Test 76 | public void mediumsAreOrderedByPosition() { 77 | Release release = (Release) session.load(Release.class, 5); 78 | List mediums = release.getMediums(); 79 | assertThat(mediums.get(0).getPosition(), is(lessThan(mediums.get(1).getPosition()))); 80 | } 81 | 82 | @Test 83 | public void releaseWithoutRedirectedGidsHasOneGid() { 84 | Release release = (Release) session.load(Release.class, 2); 85 | assertThat(release.getGids(), hasSize(1)); 86 | } 87 | 88 | @Test 89 | public void artistCreditReferenceDoesNotHitDatabase() { 90 | Release release = (Release) session.load(Release.class, 5); 91 | ArtistCredit credit = release.getArtistCredit(); 92 | assertThat(fetchCount(), is(1L)); 93 | } 94 | 95 | @Test 96 | public void mediumReferenceDoesNotHitDatabase() { 97 | Release release = (Release) session.load(Release.class, 5); 98 | List mediums = release.getMediums(); 99 | assertThat(fetchCount(), is(1L)); 100 | } 101 | 102 | @Test 103 | public void releaseGroupReferenceDoesNotHitDatabase() { 104 | Release release = (Release) session.load(Release.class, 5); 105 | ReleaseGroup releaseGroup = release.getReleaseGroup(); 106 | assertThat(fetchCount(), is(1L)); 107 | } 108 | 109 | @Test 110 | public void releaseUnknownCountryReferenceDoesNotHitDatabase() { 111 | Release release = (Release) session.load(Release.class, 5); 112 | PartialDate releaseDateForUnknownCountry = release.getReleaseDateForUnknownCountry(); 113 | assertThat(fetchCount(), is(1L)); 114 | } 115 | 116 | @Test 117 | public void releaseCountryReferenceDoesNotHitDatabase() { 118 | Release release = (Release) session.load(Release.class, 5); 119 | Set releaseCountries = release.getReleaseCountries(); 120 | assertThat(fetchCount(), is(1L)); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/ReleaseStatusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.junit.Assert.assertThat; 20 | 21 | import org.junit.Test; 22 | 23 | public class ReleaseStatusTest { 24 | 25 | @Test 26 | public void statusReturnsReleaseStateOfficial() { 27 | assertThat(ReleaseStatus.valueOf(1), is(ReleaseStatus.OFFICIAL)); 28 | } 29 | 30 | @Test 31 | public void statusReturnsReleaseStatePromotion() { 32 | assertThat(ReleaseStatus.valueOf(2), is(ReleaseStatus.PROMOTION)); 33 | } 34 | 35 | @Test 36 | public void statusReturnsReleaseStateBootleg() { 37 | assertThat(ReleaseStatus.valueOf(3), is(ReleaseStatus.BOOTLEG)); 38 | } 39 | 40 | @Test 41 | public void statusReturnsReleaseStatePseudoRelease() { 42 | assertThat(ReleaseStatus.valueOf(4), is(ReleaseStatus.PSEUDO_RELEASE)); 43 | } 44 | 45 | @Test 46 | public void nullReturnsReleaseStateUndefined() { 47 | Integer id = null; 48 | assertThat(ReleaseStatus.valueOf(id), is(ReleaseStatus.UNDEFINED)); 49 | } 50 | 51 | @Test(expected = IllegalArgumentException.class) 52 | public void unrecognisedStatusThrowsException() { 53 | ReleaseStatus.valueOf(5); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/fm/last/musicbrainz/data/model/TrackIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The musicbrainz-data Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package fm.last.musicbrainz.data.model; 17 | 18 | import static org.hamcrest.CoreMatchers.is; 19 | import static org.hamcrest.Matchers.hasSize; 20 | import static org.junit.Assert.assertThat; 21 | 22 | import java.util.Set; 23 | import java.util.UUID; 24 | 25 | import org.joda.time.DateTime; 26 | import org.junit.Test; 27 | 28 | import com.google.common.collect.Sets; 29 | 30 | import fm.last.musicbrainz.data.AbstractHibernateModelIT; 31 | 32 | public class TrackIT extends AbstractHibernateModelIT { 33 | 34 | @Test 35 | public void allFieldsArePopulated() { 36 | Set expectedGids = Sets.newHashSet(UUID.fromString("3c22f2da-6c1e-3f0a-baba-4147fede5eae"), 37 | UUID.fromString("7e53ce62-562c-4145-a9db-9736a3f04c27")); 38 | 39 | Track track = (Track) session.load(Track.class, 3); 40 | assertThat(track.getId(), is(3)); 41 | assertThat(track.getGids(), is(expectedGids)); 42 | assertThat(track.getArtistCredit().getFullName(), is("Rick Astley")); 43 | assertThat(track.getName(), is("The Saint")); 44 | assertThat(track.getPosition(), is(1)); 45 | assertThat(track.getNumber(), is("A-1")); 46 | assertThat(track.getRecording().getId(), is(1)); 47 | assertThat(track.getLength(), is(254160)); 48 | assertThat(track.getLastUpdated(), is(DateTime.parse("2013-05-24T11:03:00"))); 49 | } 50 | 51 | @Test 52 | public void trackWithoutRedirectedGidsHasOneGid() { 53 | Track track = (Track) session.load(Track.class, 4); 54 | assertThat(track.getGids(), hasSize(1)); 55 | } 56 | 57 | @Test 58 | public void artistCreditReferenceDoesNotHitDatabase() { 59 | Track track = (Track) session.load(Track.class, 3); 60 | ArtistCredit artistCredit = track.getArtistCredit(); 61 | assertThat(fetchCount(), is(1L)); 62 | } 63 | 64 | @Test 65 | public void recordingReferenceDoesNotHitDatabase() { 66 | Track track = (Track) session.load(Track.class, 3); 67 | Recording recording = track.getRecording(); 68 | assertThat(fetchCount(), is(1L)); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/test/resources/spring/musicbrainz-data-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/sql/musicbrainz-unittest.sql: -------------------------------------------------------------------------------- 1 | SET search_path = 'musicbrainz'; 2 | 3 | DELETE FROM medium; 4 | DELETE FROM track_gid_redirect; 5 | DELETE FROM track; 6 | DELETE FROM recording_gid_redirect; 7 | DELETE FROM recording; 8 | DELETE FROM track_name; 9 | DELETE FROM release_gid_redirect; 10 | DELETE FROM release; 11 | DELETE FROM release_group_gid_redirect; 12 | DELETE FROM release_group; 13 | DELETE FROM release_name; 14 | DELETE FROM release_group_primary_type; 15 | DELETE FROM release_status; 16 | DELETE FROM release_unknown_country; 17 | DELETE FROM release_country; 18 | DELETE FROM artist_credit; 19 | DELETE FROM artist_credit_name; 20 | DELETE FROM artist_gid_redirect; 21 | DELETE FROM artist; 22 | DELETE FROM artist_name; 23 | DELETE FROM artist_type; 24 | DELETE FROM gender; 25 | DELETE FROM area_gid_redirect; 26 | DELETE FROM area; 27 | DELETE FROM area_type; 28 | 29 | -- musicbrainz.artist_type 30 | 31 | INSERT INTO artist_type (id, name) VALUES (1, 'Person'); 32 | INSERT INTO artist_type (id, name) VALUES (2, 'Group'); 33 | INSERT INTO artist_type (id, name) VALUES (3, 'Other'); 34 | 35 | -- musicbrainz.gender 36 | 37 | INSERT INTO gender (id, name) VALUES (1, 'Male'); 38 | INSERT INTO gender (id, name) VALUES (2, 'Female'); 39 | INSERT INTO gender (id, name) VALUES (3, 'Other'); 40 | 41 | -- musicbrainz.release_status 42 | 43 | INSERT INTO release_status (id, name) VALUES (1, 'Official'); 44 | INSERT INTO release_status (id, name) VALUES (2, 'Promotion'); 45 | INSERT INTO release_status (id, name) VALUES (3, 'Bootleg'); 46 | INSERT INTO release_status (id, name) VALUES (4, 'Pseudo-Release'); 47 | 48 | -- musicbrainz.release_group_primary_type 49 | 50 | INSERT INTO release_group_primary_type (id, name) VALUES (1, 'Album'); 51 | INSERT INTO release_group_primary_type (id, name) VALUES (2, 'Single'); 52 | INSERT INTO release_group_primary_type (id, name) VALUES (3, 'EP'); 53 | INSERT INTO release_group_primary_type (id, name) VALUES (8, 'Audiobook'); 54 | INSERT INTO release_group_primary_type (id, name) VALUES (11, 'Other'); 55 | 56 | -- musicbrainz.area_type 57 | 58 | INSERT INTO area_type (id, name) VALUES (1, 'Country'); 59 | INSERT INTO area_type (id, name) VALUES (2, 'Subdivision'); 60 | 61 | -- musicbrainz.area 62 | 63 | INSERT INTO area (id, gid, name, sort_name, type, begin_date_year, begin_date_month, begin_date_day, end_date_year, end_date_month, end_date_day) VALUES (1178, 'f03d09b3-39dc-4083-afd6-159e3f0d462f', 'London', 'London', null, null, null, null, null, null, null); 64 | INSERT INTO area (id, gid, name, sort_name, type, begin_date_year, begin_date_month, begin_date_day, end_date_year, end_date_month, end_date_day) VALUES (397, '8dc97297-ac95-4d33-82bc-e07fab26fb5f', 'Tokyo', 'Tokyo', 2, null, null, null, null, null, null); 65 | 66 | INSERT INTO area (id, gid, name, sort_name, type, begin_date_year, begin_date_month, begin_date_day, end_date_year, end_date_month, end_date_day, ended) VALUES (151, 'c741c28e-cbec-3977-88c8-583a8af62522', 'Netherlands Antilles', 'Netherlands Antilles', 1, 1954, 9, 12, 2010, 12, 9, true); 67 | INSERT INTO area_gid_redirect (new_id, gid) VALUES (151, '6b43e5f2-49e8-46ce-94cb-a9b23e5bb4e8'); 68 | INSERT INTO area (id, gid, name, sort_name, type, begin_date_year, begin_date_month, begin_date_day, end_date_year, end_date_month, end_date_day) VALUES (113, 'b9f7d640-46e8-313e-b158-ded6d18593b3', 'South Korea', 'South Korea', 1, null, null, null, null, null, null); 69 | 70 | INSERT INTO area (id, gid, name, sort_name, type, begin_date_year, begin_date_month, begin_date_day, end_date_year, end_date_month, end_date_day) VALUES (203, '1333ff06-8e3d-3c8e-9f3a-13a2a38b41df', 'Switzerland', 'Switzerland', 1, null, null, null, null, null, null); 71 | 72 | UPDATE area SET last_updated = '2013-05-19 20:23:54' WHERE id = 1178; 73 | UPDATE area SET last_updated = '2013-05-15 16:49:41' WHERE id = 151; 74 | 75 | -- 76 | 77 | INSERT INTO artist_name (id, name) VALUES (1, 'Q and Not U'); 78 | 79 | INSERT INTO artist (id, gid, name, sort_name, begin_date_year, begin_date_month, begin_date_day, end_date_year, end_date_month, end_date_day, area, comment, ended, begin_area, end_area) VALUES (1, '994fcd41-2831-4318-9825-66bacbcf2cfe', 'Q and Not U', 'Q and Not U', 1950, 2, 3, 2001, 4, 5, 397, 'Soft Pyramids', true, 113, 151); 80 | INSERT INTO artist_gid_redirect (new_id, gid) VALUES (1, 'a934e33f-b3cb-47dd-9638-f7f1f25fe162'); 81 | UPDATE artist SET last_updated = '2012-04-10 14:00:00' WHERE id = 1; 82 | 83 | INSERT INTO artist_name (id, name) VALUES (2, 'Mono'); 84 | 85 | INSERT INTO artist (id, gid, name, sort_name, comment) VALUES (2, '194fcd41-2831-4318-9825-66bacbcf2cfe', 'Mono', 'Mono', 'Uk'); 86 | INSERT INTO artist (id, gid, name, sort_name, comment) VALUES (3, '294fcd41-2831-4318-9825-66bacbcf2cfe', 'Mono', 'Mono', 'Jp'); 87 | 88 | INSERT INTO artist_name (id, name) VALUES (3, 'Hot Chip'); 89 | 90 | INSERT INTO artist (id, gid, name, sort_name, type) VALUES (4, 'd8915e13-d67a-4aa0-9c0b-1f126af951af', 'Hot Chip', 'Hot Chip', 2); 91 | INSERT INTO artist_credit (id, name, artist_count) VALUES (2, 'Hot Chip', 1); 92 | INSERT INTO artist_credit_name (artist_credit, artist, position, join_phrase, name) VALUES (2, 4, 1, '', 'Hot Chip'); 93 | 94 | 95 | INSERT INTO artist_name (id, name) VALUES (4, 'Rick Astley'); 96 | 97 | INSERT INTO artist (id, gid, name, sort_name, type, gender) VALUES (5, 'db92a151-1ac2-438b-bc43-b82e149ddd50', 'Rick Astley', 'Rick Astley', 1, 1); 98 | INSERT INTO artist_credit (id, name, artist_count) VALUES (1, 'Rick Astley', 1); 99 | INSERT INTO artist_credit_name (artist_credit, artist, position, join_phrase, name) VALUES (1, 5, 1, '', 'Rick Astley'); 100 | 101 | INSERT INTO track_name (id, name) VALUES (1, 'The Saint'); 102 | INSERT INTO recording (id, artist_credit, gid, name, length) VALUES (1, 1, '4ea1383f-aca7-4a39-9839-576cf3af438b', 'The Saint', 1000); 103 | INSERT INTO recording_gid_redirect (new_id, gid) VALUES (1, '6a27908d-9663-4e61-9ef3-e8b82c31dc14'); 104 | UPDATE recording SET last_updated = '2012-04-10 14:00:00' WHERE id = 1; 105 | INSERT INTO track (id, gid, medium, artist_credit, name, position, number, recording) VALUES (1, '70c4bd53-f3ef-354f-97a9-7ed76915087a', 1, 1, 'The Saint', 1, '1', 1); 106 | INSERT INTO track_gid_redirect (new_id, gid) VALUES (1, '8f64df73-562c-4145-a9db-9736a3f04c27'); 107 | 108 | INSERT INTO track_name (id, name) VALUES (2, 'The Sinner'); 109 | INSERT INTO recording (id, artist_credit, gid, name) VALUES (2, 1, '2ea1383f-aca7-4a39-9839-576cf3af438b', 'The Sinner'); 110 | INSERT INTO track (id, gid, medium, artist_credit, name, position, number, recording) VALUES (2, 'a91e066b-4101-3f96-91e2-57b5d0dead60', 1, 1, 'The Sinner', 1, '1', 2); 111 | 112 | INSERT INTO track_name (id, name) VALUES (3, 'Never Gonna Give You Up'); 113 | INSERT INTO recording (id, artist_credit, gid, name) VALUES (3, 1, '770cc467-8dde-4d22-bc4c-a42f91e7515e', 'Never Gonna Give You Up'); 114 | INSERT INTO recording (id, artist_credit, gid, name) VALUES (4, 1, 'a45eb41b-5005-41b8-a0c9-17ba56ee3635', 'Never Gonna Give You Up'); 115 | 116 | INSERT INTO release_name (id, name) VALUES (1, 'The Best of Rick Astley'); 117 | INSERT INTO release_group (id, artist_credit, gid, name, comment) VALUES (1, 1, 'a1f5f807-3851-48fb-838b-fb8a069f53e7', 'The Best of Rick Astley', 'release_group comment'); 118 | UPDATE release_group SET last_updated = '2012-04-10 14:00:00' WHERE id = 1; 119 | INSERT INTO release_group_gid_redirect (new_id, gid) VALUES (1, '188711ed-c99b-439c-844a-ca831f63a727'); 120 | INSERT INTO release (id, artist_credit, gid, release_group, name) VALUES (1, 1, 'e1f5f807-3851-48fb-838b-fb8a069f53e7', 1, 'The Best of Rick Astley'); 121 | 122 | INSERT INTO release_name (id, name) VALUES (2, 'The Warning'); 123 | INSERT INTO release_group (id, artist_credit, gid, name, type) VALUES (2, 2, '4c616513-9b14-3dfd-b023-a7e77e69a029', 'The Warning', 1); 124 | INSERT INTO release (id, artist_credit, gid, release_group, name) VALUES (2, 2, 'f80addb0-1f8c-3c37-a4a9-6f8867be35fe', 2, 'The Warning'); 125 | INSERT INTO release (id, artist_credit, gid, release_group, name) VALUES (3, 2, '6ff468ec-c06d-3e90-b0eb-529af92784b7', 2, 'The Warning'); 126 | 127 | INSERT INTO release_name (id, name) VALUES (3, 'One Life Stand'); 128 | INSERT INTO release_group (id, artist_credit, gid, name) VALUES (3, 2, 'e83f684b-bc49-4ea2-91c4-b1583c741829', 'One Life Stand'); 129 | INSERT INTO release (id, artist_credit, gid, release_group, name, status) VALUES (4, 2, '5ced615f-cd92-3b08-b3cb-5971e5bd6eb5', 3, 'One Life Stand', 1); 130 | INSERT INTO release_country (release, country, date_year, date_month, date_day) VALUES (4, 151, null, 7, 23); 131 | INSERT INTO release_country (release, country, date_year, date_month, date_day) VALUES (4, 113, 2010, 7, 23); 132 | INSERT INTO release_country (release, country, date_year, date_month, date_day) VALUES (4, 203, null, null, null); 133 | 134 | -- for unit testing ArtistCredit, Medium 135 | 136 | INSERT INTO artist_name (id, name) VALUES (5, 'Mono and Rick Astley feat. Hot Chip'); 137 | INSERT INTO artist_credit (id, name, artist_count) VALUES (3, 'Mono and Rick Astley feat. Hot Chip', 3); 138 | INSERT INTO artist_credit_name (artist_credit, artist, position, join_phrase, name) VALUES (3, 4, 3, '', 'Hot Chip'); 139 | INSERT INTO artist_credit_name (artist_credit, artist, position, join_phrase, name) VALUES (3, 2, 1, ' and ', 'Mono'); 140 | INSERT INTO artist_credit_name (artist_credit, artist, position, join_phrase, name) VALUES (3, 5, 2, ' feat. ', 'Rick Astley'); 141 | 142 | INSERT INTO release_name (id, name) VALUES (4, 'Multi-Disc Extravaganza'); 143 | INSERT INTO release_group (id, artist_credit, gid, name) VALUES (4, 3, 'f94f795c-cd59-4ea2-91c4-b1583c741829', 'Multi-Disc Extravaganza'); 144 | INSERT INTO release (id, artist_credit, gid, release_group, name) VALUES (5, 3, '6dfe725f-de93-3b08-b3cb-5971e5bd6eb5', 4, 'Multi-Disc Extravaganza'); 145 | INSERT INTO release_gid_redirect (new_id, gid) VALUES (5, '5d32bacc-d62a-4e77-9f0e-d934e53d5359'); 146 | INSERT INTO release_unknown_country (release, date_year, date_month, date_day) VALUES (5, 2011, 7, 23); 147 | UPDATE release SET last_updated = '2012-04-10 14:00:00' WHERE id = 5; 148 | 149 | INSERT INTO medium (id, release, position) VALUES (3, 5, 2); 150 | INSERT INTO medium (id, release, position, name) VALUES (2, 5, 1, 'Disc 1'); 151 | UPDATE medium SET last_updated = '2012-04-10 14:00:00' WHERE id = 2; 152 | 153 | INSERT INTO track (id, gid, recording, medium, position, number, name, artist_credit, length) VALUES (4, '9324fa33-3f60-3f63-80b9-02a5134a5dd9', 2, 2, 2, 'A-2', 'The Sinner', 2, null); 154 | INSERT INTO track (id, gid, recording, medium, position, number, name, artist_credit, length) VALUES (3, '3c22f2da-6c1e-3f0a-baba-4147fede5eae', 1, 2, 1, 'A-1', 'The Saint', 1, 254160); 155 | INSERT INTO track_gid_redirect (new_id, gid) VALUES (3, '7e53ce62-562c-4145-a9db-9736a3f04c27'); 156 | UPDATE track SET last_updated = '2013-05-24 11:03:00' WHERE id = 3; 157 | --------------------------------------------------------------------------------