| /***************************************************************************** |
| * Copyright (c) 2018 CEA LIST and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * CEA LIST - Initial API and implementation |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.cdo.benchmarks.tests; |
| |
| import java.util.List; |
| import java.util.Properties; |
| |
| import org.eclipse.emf.cdo.common.branch.CDOBranch; |
| import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; |
| import org.eclipse.emf.cdo.explorer.CDOExplorerUtil; |
| import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; |
| import org.eclipse.emf.cdo.explorer.repositories.CDORepository; |
| import org.eclipse.emf.cdo.internal.explorer.AbstractElement; |
| import org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutImpl; |
| import org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryImpl; |
| import org.eclipse.emf.cdo.internal.explorer.repositories.RemoteCDORepository; |
| import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration; |
| import org.eclipse.emf.cdo.net4j.CDONet4jUtil; |
| import org.eclipse.emf.cdo.session.CDOSession; |
| import org.eclipse.emf.cdo.transaction.CDOTransaction; |
| import org.eclipse.emf.common.util.URI; |
| import org.eclipse.net4j.Net4jUtil; |
| import org.eclipse.net4j.connector.IConnector; |
| import org.eclipse.net4j.tcp.TCPUtil; |
| import org.eclipse.net4j.util.container.ContainerUtil; |
| import org.eclipse.net4j.util.container.IManagedContainer; |
| import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; |
| import org.eclipse.net4j.util.security.PasswordCredentialsProvider; |
| import org.eclipse.papyrus.infra.core.services.ServiceMultiException; |
| |
| /** |
| * @author VL222926 |
| * |
| */ |
| public class CDOPapyrusModelCreation extends AbstractModelCreation { |
| |
| private static final String HOST_AND_PORT = "localhost:2036"; |
| |
| private static final String USER_NAME = "Administrator"; |
| |
| private static final String PASSWORD = "0000"; |
| |
| |
| private CDOSession session; |
| private CDOCheckout checkout; |
| private CDORepository repository; |
| private CDOTransaction transaction; |
| |
| final String PAPYRUS_CDO_SECURED_REPOSITORY = "PapyrusCDOSecuredRepository"; |
| |
| |
| |
| public final void connect() throws Exception { |
| connect(getHostAndPort(), getUser(), getPassword()); |
| } |
| |
| /** |
| * @return |
| */ |
| private String getPassword() { |
| return PASSWORD; |
| } |
| |
| /** |
| * @return |
| */ |
| private String getUser() { |
| return USER_NAME; |
| } |
| |
| /** |
| * @return |
| */ |
| private String getHostAndPort() { |
| return HOST_AND_PORT; |
| } |
| |
| private void connect(final String serverURI, final String login, final String password) throws Exception { |
| try { |
| // Prepare container |
| final IManagedContainer container = ContainerUtil.createContainer(); |
| Net4jUtil.prepareContainer(container); // Register Net4j factories |
| TCPUtil.prepareContainer(container); // Register TCP factories |
| CDONet4jUtil.prepareContainer(container); // Register CDO factories |
| container.activate(); |
| |
| // Create connector |
| final IConnector connector = TCPUtil.getConnector(container, serverURI); |
| |
| // Create configuration |
| final CDONet4jSessionConfiguration configuration = CDONet4jUtil.createNet4jSessionConfiguration(); |
| configuration.setConnector(connector); |
| configuration.setRepositoryName(PAPYRUS_CDO_SECURED_REPOSITORY); |
| final IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(login, password); |
| configuration.setCredentialsProvider(credentialsProvider); |
| |
| final Properties properties = new Properties(); |
| |
| properties.setProperty(AbstractElement.PROP_TYPE, CDORepository.TYPE_REMOTE); |
| properties.setProperty(AbstractElement.PROP_LABEL, PAPYRUS_CDO_SECURED_REPOSITORY); |
| properties.setProperty(CDORepositoryImpl.PROP_NAME, PAPYRUS_CDO_SECURED_REPOSITORY); |
| properties.setProperty(RemoteCDORepository.PROP_CONNECTOR_TYPE, "tcp"); //$NON-NLS-1$ |
| // TODO : is it serverURI? |
| properties.setProperty(RemoteCDORepository.PROP_CONNECTOR_DESCRIPTION, serverURI); |
| |
| repository = CDOExplorerUtil.getRepositoryManager().addRepository(properties, credentialsProvider.getCredentials()); |
| repository.connect(); |
| |
| // Open session |
| session = configuration.openNet4jSession(); |
| |
| this.checkout = createCheckout("PapyrusPerfoTestCheckout"); //$NON-NLS-1$ |
| |
| |
| } catch (final Exception e) { |
| throw e; |
| } |
| |
| } |
| |
| private CDOCheckout createCheckout(final String checkoutName) { |
| final Properties properties = new Properties(); |
| properties.setProperty(AbstractElement.PROP_TYPE, CDOCheckout.TYPE_ONLINE_HISTORICAL); |
| properties.setProperty(AbstractElement.PROP_LABEL, checkoutName); |
| properties.setProperty(CDOCheckoutImpl.PROP_REPOSITORY, this.repository.getID()); |
| properties.setProperty(CDOCheckoutImpl.PROP_BRANCH_ID, Integer.toString(CDOBranch.MAIN_BRANCH_ID)); |
| properties.setProperty(CDOCheckoutImpl.PROP_TIME_STAMP, Long.toString(CDOBranchPoint.UNSPECIFIED_DATE)); |
| properties.setProperty(CDOCheckoutImpl.PROP_READ_ONLY, Boolean.toString(false)); |
| |
| final CDOCheckout checkout = CDOExplorerUtil.getCheckoutManager().addCheckout(properties); |
| checkout.open(); |
| return checkout; |
| } |
| |
| /** |
| * Gets the running session. |
| * |
| * @return the running session |
| */ |
| protected CDOSession getSession() { |
| return this.session; |
| } |
| |
| |
| |
| public CDOTransaction getOpenTransaction() { |
| if (transaction != null) { |
| return transaction; |
| } |
| |
| transaction = session.openTransaction(this.modelSet); |
| |
| |
| return transaction; |
| } |
| |
| |
| public void closeTransaction() { |
| if (null != this.transaction) { |
| this.transaction.close(); |
| } |
| transaction = null;// TODO : probably missing in QS |
| } |
| |
| |
| /** |
| * @see org.eclipse.papyrus.cdo.perfo.tests.impl.IPapyrusModelCreation#initPapyrusEnvironnement(java.lang.String, java.lang.String, List<String>) |
| * |
| * @param folderName |
| * @param modelName |
| * @throws Exception |
| */ |
| @Override |
| public void initPapyrusEnvironnement(final String folderName, final String modelName, final List<String> profilesName) throws Exception { |
| connect(); |
| createModelSet(folderName, modelName, profilesName); |
| } |
| |
| |
| protected URI createBaseURI() { |
| URI uri = URI.createURI("cdo.checkout://1/home"); |
| return uri.appendSegment(getUser()); |
| |
| } |
| |
| /** |
| * @throws ServiceMultiException |
| * @see org.eclipse.papyrus.cdo.benchmarks.tests.IPapyrusModelCreation#disposeAll() |
| * |
| */ |
| @Override |
| public void disposeAll() throws ServiceMultiException { |
| closeTransaction(); |
| super.disposeAll(); |
| } |
| |
| } |