当前位置: 首页>>代码示例>>Java>>正文


Java CDOTransaction类代码示例

本文整理汇总了Java中org.eclipse.emf.cdo.transaction.CDOTransaction的典型用法代码示例。如果您正苦于以下问题:Java CDOTransaction类的具体用法?Java CDOTransaction怎么用?Java CDOTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CDOTransaction类属于org.eclipse.emf.cdo.transaction包,在下文中一共展示了CDOTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startCDOServer

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
@BeforeClass
public static void startCDOServer() throws IOException, CommitException {
    server = new CDOServer(false);
    server.start();
    IConnector connector = M2DocCDOUtils
            .getConnector(CDOServer.PROTOCOL + "://" + CDOServer.IP + ":" + CDOServer.PORT);
    CDOSession session = M2DocCDOUtils.openSession(connector, CDOServer.REPOSITORY_NAME, CDOServer.USER_NAME,
            CDOServer.PASSWORD);
    final CDOTransaction transaction = M2DocCDOUtils.openTransaction(session);
    final CDOResource resource = transaction.createResource("anydsl.ecore");
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
    final Resource anyDSLResource = resourceSet.getResource(URI.createFileURI("resources/anydsl.ecore"), true);
    resource.getContents().addAll(anyDSLResource.getContents());
    resource.save(null);
    transaction.commit();
    transaction.close();
    session.close();
    connector.close();

    if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
        ConfigurationProviderService.getInstance().register(CONFIGURATION_PROVIDER);
        M2DocUtils.registerServicesConfigurator(SERVICES_CONFIGURATOR_DESCRIPTOR);
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:ServerWithoutAuthentication.java

示例2: startCDOServer

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
@BeforeClass
public static void startCDOServer() throws IOException, CommitException {
    server = new CDOServer(true);
    server.start();
    IConnector connector = M2DocCDOUtils
            .getConnector(CDOServer.PROTOCOL + "://" + CDOServer.IP + ":" + CDOServer.PORT);
    CDOSession session = M2DocCDOUtils.openSession(connector, CDOServer.REPOSITORY_NAME, CDOServer.USER_NAME,
            CDOServer.PASSWORD);
    final CDOTransaction transaction = M2DocCDOUtils.openTransaction(session);
    final CDOResource resource = transaction.createResource("anydsl.ecore");
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
    final Resource anyDSLResource = resourceSet.getResource(URI.createFileURI("resources/anydsl.ecore"), true);
    resource.getContents().addAll(anyDSLResource.getContents());
    resource.save(null);
    transaction.commit();
    transaction.close();
    session.close();
    connector.close();

    if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
        ConfigurationProviderService.getInstance().register(CONFIGURATION_PROVIDER);
        M2DocUtils.registerServicesConfigurator(SERVICES_CONFIGURATOR_DESCRIPTOR);
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:ServerWithAuthentication.java

示例3: createResourceSetForModels

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
@Override
public ResourceSet createResourceSetForModels(Generation generation) {
    final ResourceSet res;

    final Map<String, String> options = GenconfUtils.getOptions(generation);
    final String cdoServer = options.get(M2DocCDOUtils.CDO_SERVER_OPTION);
    if (cdoServer != null) {
        final String repository = options.get(M2DocCDOUtils.CDO_REPOSITORY_OPTION);
        final String branch = options.get(M2DocCDOUtils.CDO_BRANCH_OPTION);
        final String login = options.get(M2DocCDOUtils.CDO_LOGIN_OPTION);
        final String password = options.get(M2DocCDOUtils.CDO_PASSWORD_OPTION);
        final IConnector connector = M2DocCDOUtils.getConnector(cdoServer);
        connectors.put(generation, connector);
        final CDOSession session = M2DocCDOUtils.openSession(connector, repository, login, password);
        final CDOTransaction transaction = M2DocCDOUtils.openTransaction(session, branch);
        transactions.put(generation, transaction);
        res = transaction.getResourceSet();
        res.getURIConverter().getURIHandlers().add(0, new M2DocCDOURIHandler((InternalCDOView) transaction));
    } else {
        res = null;
    }

    return res;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:25,代码来源:CDOConfigurationProvider.java

示例4: createUsers

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
private static void createUsers(CDOTransaction transaction) {
	CDOResource r1 = transaction.getOrCreateResource("u1");
	r1.getContents().clear();

	User u1 = ModelFactory.eINSTANCE.createUser();
	u1.setName("Bob");
	r1.getContents().add(u1);

	CDOResource r2 = transaction.getOrCreateResource("u2");
	r2.getContents().clear();

	User u2 = ModelFactory.eINSTANCE.createUser();
	u2.setName("Peter");
	u2.getFriends().add(u1);
	r2.getContents().add(u2);
}
 
开发者ID:emfjson,项目名称:emfjson-samples,代码行数:17,代码来源:Main.java

示例5: openTransaction

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
/**
 * Open a {@link CDOTransaction} on the given {@link CDOBranch}. Caller is responsible of
 * {@link CDOTransaction#close() closing} the resulting transaction.
 * 
 * @param session
 *            the {@link CDOSession} to use to open the {@link CDOTransaction}
 * @param branchName
 *            the branch name or <code>null</code> for the main branch
 * @return a new {@link CDOTransaction}
 */
public static CDOTransaction openTransaction(CDOSession session, String branchName) {
	final CDOTransaction res;
	if (branchName != null) {
		CDOBranch branch = session.getBranchManager().getBranch(branchName);
		if (branch != null) {
			res = session.openTransaction(branch);
		} else {
			res = null;
			throw new IllegalArgumentException("The branch " + branchName + " doesn't exist.");
		}
	} else {
		res = session.openTransaction();
	}
	return res;
}
 
开发者ID:ModelWriter,项目名称:Source,代码行数:26,代码来源:CDOUtils.java

示例6: save

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
public void save(Map<?, ?> options) throws IOException {
    CDOViewSet cdoVS = CDOUtil.getViewSet(getResourceSet());
    CDOTransaction trans = Arrays.stream(cdoVS.getViews()).filter(CDOTransaction.class::isInstance)
            .map(CDOTransaction.class::cast).findFirst().orElse(null);
    if (trans == null) {
        throw new IOException("Could not gather a transaction to perform the save operation.");
    }
    String realCdoRepositoryPath = getRealCDORepositoryPath(trans);
    XMISerializer accessor = new XMISerializer(this, prepareOptions(options));
    doSave(accessor, trans, realCdoRepositoryPath);
    try {
        trans.commit();
    } catch (CommitException e) {
        throw new IOException(e);
    }
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:17,代码来源:VirtualCDOFileResource.java

示例7: delete

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
private static boolean delete(IFile launcher) {
    CDOSession session = CDOConnectionManager.getInstance().acquireSession(launcher.getProject());
    try {
        CDOTransaction transaction = session.openTransaction();
        try {
            if (delete(launcher, transaction)) {
                transaction.commit();
                return true;
            }
            return false;
        } catch (CommitException e) {
            LOGGER.error("Could not commit changes.", e);
            return false;
        } finally {
            IOUtil.closeSilent(transaction);
        }
    } finally {
        CDOConnectionManager.getInstance().releaseSession(session);
    }
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:21,代码来源:DeleteDiagramFromRepositoryCommand.java

示例8: reset

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
public static boolean reset(CDOSession session, CDOCommitInfo commit, IResource resource) {
    CDOBranch mainBranch = session.getBranchManager().getMainBranch();
    CDOBranch branch = mainBranch.createBranch("revert_" + System.currentTimeMillis());
    boolean result = reset(session, commit, resource, branch);
    if (result) {
        CDOTransaction mergeTransaction = session.openTransaction(mainBranch);
        try {
            String changedObjectLabel = getLabelFor(resource);
            DateFormat df = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
            String commitComment = String.format("Reset of %s to previous commit (%s) by %s.", changedObjectLabel,
                    df.format(new Date(commit.getTimeStamp())), System.getProperty("user.name"));
            mergeTransaction.setCommitComment(commitComment);
            mergeTransaction.merge(branch, new NilFixingCDOMerger());
            try {
                mergeTransaction.commit();
            } catch (CommitException e) {
                LOGGER.error("Merge commit of reverted changes failed.", e);
                return false;
            }
        } finally {
            IOUtil.closeSilent(mergeTransaction);
        }
    }
    return result;
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:26,代码来源:ResetToPreviousStateCommand.java

示例9: deleteProjectFromRepository

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
private static boolean deleteProjectFromRepository(IProject project) {
    CDOSession session = null;
    try {
        session = CDOConnectionManager.getInstance().acquireSession(project);
        CDOTransaction transaction = session.openTransaction();
        CDOResourceFolder resource = transaction.getResourceFolder(project.getName());
        if (resource == null) {
            LOGGER.error("Project {} doesn't exist in repository.", project);
            return false;
        }
        EcoreUtil.delete(resource);
        try {
            transaction.commit();
        } catch (CommitException e) {
            LOGGER.error("Could not delete project {} from repository.", project.getName(), e);
            return false;
        }
    } finally {
        CDOConnectionManager.getInstance().releaseSession(session);
    }
    return true;
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:23,代码来源:DeleteProjectFromRepositoryCommand.java

示例10: createCDOResource

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
private static CDOResourceFolder createCDOResource(IProject project, String cdoRepoPath,
		IListener listener) throws CommitException {
	CDOSession cdoSession = CDOConnectionManager.getInstance().acquireSession(project);
	CDOResourceFolder result = null;
	try {
		CDOView cdoView = cdoSession.openView();
		cdoView.addListener(listener);
		cdoView.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);
		if (!cdoView.hasResource(cdoRepoPath)) {
			CDOTransaction transaction = cdoSession.openTransaction();
			transaction.createResourceFolder(cdoRepoPath);
			transaction.commit();
			transaction.close();
		}
		result = cdoView.getResourceFolder(cdoRepoPath);
		return result;
	} finally {
		if (result == null) {
			CDOConnectionManager.getInstance().releaseSession(cdoSession);
		}
	}
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:23,代码来源:CDOHandlingBackgroundTask.java

示例11: fixStaleReferences

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
private void fixStaleReferences(CDOTransaction transaction) {
    Collection<CDOCommitInfo> infos = Lists.newArrayList();
    transaction.getSession().getCommitInfoManager().getCommitInfos(transaction.getBranch(), lastMergeTimeBranch,
            CDOView.UNSPECIFIED_DATE, infos::add);
    Set<CrossReferenceSetting> candidates = infos.stream()
            .flatMap(i -> findPossibleStaleReferences(transaction.getSession(), i).stream())
            .collect(Collectors.toSet());
    for (CrossReferenceSetting setting : candidates) {
        try {
            CDOObject eObject = transaction.getObject(setting.getObject());
            fixStaleReference(eObject, setting);
        } catch (ObjectNotFoundException e) {
            LOGGER.warn("Attempt to fix a stale reference on an non existing object.", e);
        }
    }
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:17,代码来源:TransformationManager.java

示例12: postGenerate

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
@Override
public List<URI> postGenerate(Generation generation, URI templateURI, URI generatedURI,
        DocumentTemplate documentTemplate) {
    final CDOTransaction transaction = transactions.get(generation);
    if (transaction != null) {
        final CDOSession session = transaction.getSession();
        transaction.close();
        session.close();
        connectors.remove(generation).close();
    }
    return Collections.emptyList();
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:13,代码来源:CDOConfigurationProvider.java

示例13: openTransaction

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
/**
 * Open a {@link CDOTransaction} on the given {@link CDOBranch}. Caller is responsible of
 * {@link CDOTransaction#close() closing} the resulting transaction.
 * 
 * @param session
 *            the {@link CDOSession} to use to open the {@link CDOTransaction}
 * @param branchName
 *            the branch name or <code>null</code> for the main branch
 * @return a new {@link CDOTransaction}
 */
public static CDOTransaction openTransaction(CDOSession session, String branchName) {
    final CDOTransaction res;
    if (branchName != null) {
        CDOBranch branch = session.getBranchManager().getBranch(branchName);
        if (branch != null) {
            res = session.openTransaction(branch);
        } else {
            res = session.openTransaction();
        }
    } else {
        res = session.openTransaction();
    }
    return res;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:25,代码来源:M2DocCDOUtils.java

示例14: doSave

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
@Override
protected void doSave(XMISerializer serializer, CDOTransaction trans, String realCdoRepositoryPath)
        throws IOException {
    CDOTextResource textRes = trans.getOrCreateTextResource(realCdoRepositoryPath);
    textRes.setEncoding(DEFAULT_CHARSET_NAME);
    StringWriter writer = new StringWriter();
    try (WriterOutputStream wos = new WriterOutputStream(writer, DEFAULT_CHARSET)) {
        serializer.serialize(wos);
        try (StringReader reader = new StringReader(writer.getBuffer().toString())) {
            CDOClob clob = new CDOClob(reader);
            textRes.setContents(clob);
        }
    }
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:15,代码来源:TextbasedCDOResource.java

示例15: doSave

import org.eclipse.emf.cdo.transaction.CDOTransaction; //导入依赖的package包/类
@Override
protected void doSave(XMISerializer serializer, CDOTransaction trans, String realCdoRepositoryPath) throws IOException {
       CDOBinaryResource binRes = trans.getOrCreateBinaryResource(realCdoRepositoryPath);
       try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
       	serializer.serialize(baos);
           CDOBlob blob = new CDOBlob(new ByteArrayInputStream(baos.toByteArray()));
           binRes.setContents(blob);
       }
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:10,代码来源:BinarybasedCDOResource.java


注:本文中的org.eclipse.emf.cdo.transaction.CDOTransaction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。