@Override protected void doActivate() throws Exception { // Initialize container. IManagedContainer container = getContainer(); // Initialize store. IStore store = createStore(container); // Initialize properties. Map<String, String> properties = new HashMap<String, String>(); properties.put(IRepository.Props.OVERRIDE_UUID, ""); initProperties(container, properties); repository = new EmbeddedRepository(this); ((InternalRepository) repository).setContainer(container); ((InternalRepository) repository).setName(repositoryName); ((InternalRepository) repository).setStore((InternalStore) store); ((InternalRepository) repository).setProperties(properties); activateRepository(repository); repository.addListener( new LifecycleEventAdapter() { @Override protected void onDeactivated(ILifecycle lifecycle) { CDOEmbeddedRepositoryConfig.this.deactivate(); } }); }
public void loadCommitInfos( final CDOBranch branch, final long startTime, final long endTime, CDOCommitInfoHandler handler) { if (endTime < CDOBranchPoint.UNSPECIFIED_DATE) { throw new IllegalArgumentException("Counting not supported"); } ObjectSet<DB4OCommitInfo> resultSet = getObjectContainer() .query( new Predicate<DB4OCommitInfo>() { private static final long serialVersionUID = 1L; @Override public boolean match(DB4OCommitInfo info) { if (startTime != CDOBranchPoint.UNSPECIFIED_DATE && info.getTimeStamp() < startTime) { return false; } if (endTime != CDOBranchPoint.UNSPECIFIED_DATE && info.getTimeStamp() > endTime) { return false; } if (branch != null && !(info.getBranchID() == branch.getID())) { return false; } return true; } }); InternalRepository repository = getStore().getRepository(); InternalCDOCommitInfoManager commitInfoManager = repository.getCommitInfoManager(); InternalCDOBranchManager branchManager = repository.getBranchManager(); // Although not specified in the API, the test suite // suggests CommitInfos should be returned ordered by timeStamp // TODO Specify this in the API! List<DB4OCommitInfo> infos = new ArrayList<DB4OCommitInfo>(resultSet); Collections.sort( infos, new Comparator<DB4OCommitInfo>() { public int compare(DB4OCommitInfo arg0, DB4OCommitInfo arg1) { return CDOCommonUtil.compareTimeStamps(arg0.getTimeStamp(), arg1.getTimeStamp()); } }); for (DB4OCommitInfo info : infos) { info.handle(branchManager, commitInfoManager, handler); } }
private void createAllClassMappings() { InternalRepository repository = (InternalRepository) getStore().getRepository(); InternalCDOPackageRegistry packageRegistry = repository.getPackageRegistry(false); for (InternalCDOPackageInfo packageInfo : packageRegistry.getPackageInfos()) { if (!packageInfo.isSystemPackage()) { for (EClassifier eClassifier : packageInfo.getEPackage().getEClassifiers()) { if (eClassifier instanceof EClass) { EClass eClass = (EClass) eClassifier; if (isMapped(eClass)) { getClassMapping(eClass); // Get or create it } } } } } }
@Requires(IRepositoryConfig.CAPABILITY_OFFLINE) @Skips("DB.ranges") // Too slow in DB.ranges (11 minutes), see bug 357441 public void testOfflineCloneSynchronization() throws Exception { disableConsole(); // create an offline clone. InternalRepository clone = getRepository(); waitForOnline(clone); // create master session & transaction. InternalRepository master = getRepository("master"); CDOSession masterSession = openSession(master.getName()); CDOTransaction masterTransaction = masterSession.openTransaction(); // create client session & transaction. CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); // doing this that client notifications are built upon RevisionDeltas instead of RevisionKeys. session.options().setPassiveUpdateMode(PassiveUpdateMode.CHANGES); // create additional client sessions. CDOView[] cloneViews = new CDOView[NUM_CLIENT_VIEWS + 1]; for (int i = 0; i < NUM_CLIENT_VIEWS; i++) { CDOView view = session.openView(); cloneViews[i] = view; } cloneViews[NUM_CLIENT_VIEWS] = transaction; // create resource and base model. CDOResource resource = masterTransaction.createResource(getResourcePath("/my/resource")); Company company = getModel1Factory().createCompany(); Category catA = getModel1Factory().createCategory(); catA.setName("CatA"); company.getCategories().add(catA); Category catB = getModel1Factory().createCategory(); catB.setName("CatB"); company.getCategories().add(catB); resource.getContents().add(company); for (int i = 0; i < NUM_PRODUCTS; i++) { Product1 product = getModel1Factory().createProduct1(); product.setName("Product" + i); catA.getProducts().add(product); } masterTransaction.commit(); transaction.waitForUpdate(masterTransaction.getLastCommitTime(), 1000); // touch the objects on the views to actually receive updates. for (CDOView view : cloneViews) { Category vCatA = (Category) view.getObject(CDOUtil.getCDOObject(catA).cdoID()); Category vCatB = (Category) view.getObject(CDOUtil.getCDOObject(catB).cdoID()); vCatB.getName(); for (Product1 vProduct : vCatA.getProducts()) { vProduct.getName(); } } // do a lot of changes on master session. long start = System.currentTimeMillis(); for (int i = 0; i < NUM_PRODUCTS; i++) { Product1 p = catA.getProducts().remove(0); catB.getProducts().add(p); catB.getProducts().move(0, p); masterTransaction.commit(); } Thread.sleep(100); catA.setName(catA.getName() + " empty"); masterTransaction.commit(); System.out.println( MessageFormat.format( "## Committing changes on {0} products took: {1}", NUM_PRODUCTS, System.currentTimeMillis() - start)); // session.waitForUpdate(masterTransaction.getLastCommitTime(), 5000); for (CDOView view : cloneViews) { view.waitForUpdate(masterTransaction.getLastCommitTime(), 5000); } // adding this sleep as the waitForUpdate does not seem to work as expected in case of an error. sleep(5000); System.out.println("## Started checking...."); // check if all changes are made. Category cloneCatA = (Category) transaction.getObject(CDOUtil.getCDOObject(catA).cdoID()); Category cloneCatB = (Category) transaction.getObject(CDOUtil.getCDOObject(catB).cdoID()); System.out.println( "CatA IdVersion: " + CDOUtil.getCDOObject(cloneCatA).cdoRevision().toString()); System.out.println( "CatB IdVersion: " + CDOUtil.getCDOObject(cloneCatB).cdoRevision().toString()); assertEquals(NUM_PRODUCTS, cloneCatB.getProducts().size()); assertEquals(0, cloneCatA.getProducts().size()); assertEquals(catA.getName(), cloneCatA.getName()); }
public InternalSession openSession(InternalRepository repository, boolean passiveUpdateEnabled) { session = repository.getSessionManager().openSession(this); session.setPassiveUpdateEnabled(passiveUpdateEnabled); return session; }