001/**
002 * Copyright 2013 John Ericksen
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.androidtransfuse.processor;
017
018import org.androidtransfuse.CodeGenerationScope;
019import org.androidtransfuse.annotations.ScopeReference;
020import org.androidtransfuse.config.EnterableScope;
021import org.androidtransfuse.transaction.ScopedTransactionWorker;
022import org.androidtransfuse.transaction.Transaction;
023import org.androidtransfuse.transaction.TransactionWorker;
024
025import javax.inject.Inject;
026import javax.inject.Provider;
027
028/**
029 * @author John Ericksen
030 */
031public class ScopedTransactionFactory {
032
033    private final EnterableScope codeGenerationScope;
034
035    @Inject
036    public ScopedTransactionFactory(
037            @ScopeReference(CodeGenerationScope.class) EnterableScope codeGenerationScope) {
038        this.codeGenerationScope = codeGenerationScope;
039    }
040
041    public <V, R> Transaction<V, R> buildTransaction(V value, Provider<? extends TransactionWorker<V, R>> workerProvider) {
042        return new Transaction<V, R>(value, new ScopedTransactionWorker<V, R>(codeGenerationScope, workerProvider));
043    }
044}