PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/jpa/core/src/main/java/org/jboss/as/jpa/persistenceprovider/PersistenceProviderLoader.java

#
Java | 72 lines | 24 code | 9 blank | 39 comment | 3 complexity | 77a165efb45e8077d8a27870ce04650a MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.jpa.persistenceprovider;
  23. import java.util.ServiceLoader;
  24. import javax.persistence.spi.PersistenceProvider;
  25. import org.jboss.as.jpa.config.Configuration;
  26. import org.jboss.modules.Module;
  27. import org.jboss.modules.ModuleIdentifier;
  28. import org.jboss.modules.ModuleLoadException;
  29. import org.jboss.modules.ModuleLoader;
  30. /**
  31. * For loading persistence provider modules
  32. *
  33. * @author Scott Marlow
  34. */
  35. public class PersistenceProviderLoader {
  36. /**
  37. * pre-loads the default persistence provider
  38. *
  39. * @throws ModuleLoadException
  40. */
  41. public static void loadDefaultProvider() throws ModuleLoadException {
  42. loadProviderModuleByName(Configuration.PROVIDER_MODULE_DEFAULT);
  43. }
  44. /**
  45. * Loads the specified JPA persistence provider module name
  46. *
  47. * @param moduleName
  48. * @throws ModuleLoadException
  49. */
  50. public static void loadProviderModuleByName(String moduleName) throws ModuleLoadException {
  51. final ModuleLoader moduleLoader = Module.getBootModuleLoader();
  52. Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName));
  53. final ServiceLoader<PersistenceProvider> serviceLoader =
  54. module.loadService(PersistenceProvider.class);
  55. if (serviceLoader != null) {
  56. for (PersistenceProvider provider1 : serviceLoader) {
  57. // persistence provider jar may contain multiple provider service implementations
  58. // save each provider
  59. PersistenceProviderResolverImpl.getInstance().addPersistenceProvider(provider1);
  60. }
  61. }
  62. }
  63. }