1 package org.apache.onami.persist; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import javax.inject.Provider; 23 import javax.inject.Singleton; 24 import javax.transaction.UserTransaction; 25 26 import static org.apache.onami.persist.Preconditions.checkNotNull; 27 28 /** 29 * Provider fro {@link UserTransaction} which retrieves the value from the JNDI context. 30 */ 31 @Singleton 32 class UserTransactionProviderByJndiLookup 33 implements Provider<UserTransaction> 34 { 35 36 private final String jndiName; 37 38 private final JndiLookupHelper jndiLookupHelper; 39 40 /** 41 * Constructor. 42 * 43 * @param jndiName jndi name of the entity manager factory. Must not be {@code null}. 44 */ 45 UserTransactionProviderByJndiLookup( @UserTransactionJndiName String jndiName, JndiLookupHelper jndiLookupHelper ) 46 { 47 this.jndiName = checkNotNull( jndiName, "jndiName is mandatory!" ); 48 this.jndiLookupHelper = checkNotNull( jndiLookupHelper, "jndiLookupHelper is mandatory!" ); 49 } 50 51 /** 52 * Gets a {@link UserTransaction} by looking it up in the JNDI context. 53 * 54 * @return the found entity user transaction 55 * @throws RuntimeException when no user transaction was found. 56 */ 57 //@Override 58 public UserTransaction get() 59 { 60 return jndiLookupHelper.doJndiLookup( UserTransaction.class, jndiName ); 61 } 62 63 }