You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JdoProjectModelDAO.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package org.apache.maven.archiva.database.jdo;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.maven.archiva.database.ArchivaDatabaseException;
  21. import org.apache.maven.archiva.database.Constraint;
  22. import org.apache.maven.archiva.database.ObjectNotFoundException;
  23. import org.apache.maven.archiva.database.ProjectModelDAO;
  24. import org.apache.maven.archiva.model.ArchivaProjectModel;
  25. import org.apache.maven.archiva.model.jpox.ArchivaProjectModelKey;
  26. import java.util.List;
  27. /**
  28. * JdoProjectModelDAO
  29. *
  30. * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  31. * @version $Id$
  32. *
  33. * @plexus.component role-hint="jdo"
  34. */
  35. public class JdoProjectModelDAO
  36. implements ProjectModelDAO
  37. {
  38. /**
  39. * @plexus.requirement role-hint="archiva"
  40. */
  41. private JdoAccess jdo;
  42. public ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
  43. {
  44. ArchivaProjectModel model;
  45. try
  46. {
  47. model = getProjectModel( groupId, artifactId, version );
  48. }
  49. catch ( ArchivaDatabaseException e )
  50. {
  51. model = new ArchivaProjectModel();
  52. model.setGroupId( groupId );
  53. model.setArtifactId( artifactId );
  54. model.setVersion( version );
  55. }
  56. return model;
  57. }
  58. public ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version )
  59. throws ObjectNotFoundException, ArchivaDatabaseException
  60. {
  61. ArchivaProjectModelKey key = new ArchivaProjectModelKey();
  62. key.groupId = groupId;
  63. key.artifactId = artifactId;
  64. key.version = version;
  65. return (ArchivaProjectModel) jdo.getObjectById( ArchivaProjectModel.class, key, null );
  66. }
  67. public List<ArchivaProjectModel> queryProjectModels( Constraint constraint )
  68. throws ObjectNotFoundException, ArchivaDatabaseException
  69. {
  70. return jdo.queryObjects( ArchivaProjectModel.class, constraint );
  71. }
  72. public ArchivaProjectModel saveProjectModel( ArchivaProjectModel model )
  73. throws ArchivaDatabaseException
  74. {
  75. return (ArchivaProjectModel) jdo.saveObject( model );
  76. }
  77. public void deleteProjectModel( ArchivaProjectModel model )
  78. throws ArchivaDatabaseException
  79. {
  80. jdo.removeObject( model );
  81. }
  82. }