001/*
002 * Copyright (c) 2006-2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Florent Guillaume
011 */
012package org.nuxeo.ecm.core.storage.sql.coremodel;
013
014import org.nuxeo.ecm.core.repository.RepositoryFactory;
015import org.nuxeo.ecm.core.storage.sql.RepositoryDescriptor;
016import org.nuxeo.runtime.api.Framework;
017
018/**
019 * SQL repository factory.
020 * <p>
021 * This class is mentioned in the repository extension point defining a given repository. It is constructed by
022 * RepositoryManager#getOrRegisterRepository, itself called by the *ManagedConnectionFactory#createRepository of the RA.
023 */
024public class SQLRepositoryFactory implements RepositoryFactory {
025
026    private String repositoryName;
027
028    @Override
029    public void init(String repositoryName) {
030        this.repositoryName = repositoryName;
031    }
032
033    @Override
034    public Object call() {
035        SQLRepositoryService sqlRepositoryService = Framework.getLocalService(SQLRepositoryService.class);
036        RepositoryDescriptor descriptor = sqlRepositoryService.getRepositoryDescriptor(repositoryName);
037        return new SQLRepository(descriptor);
038    }
039
040}