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


Java PersistService.stop方法代码示例

本文整理汇总了Java中com.google.inject.persist.PersistService.stop方法的典型用法代码示例。如果您正苦于以下问题:Java PersistService.stop方法的具体用法?Java PersistService.stop怎么用?Java PersistService.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.inject.persist.PersistService的用法示例。


在下文中一共展示了PersistService.stop方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.google.inject.persist.PersistService; //导入方法依赖的package包/类
public static void main(String[] args) {
    // admin/admin is default user, created for each new db
    final Injector injector = Guice.createInjector(new DbModule("memory:sample", "admin", "admin"));

    // to initialize db context we must manually call start
    final PersistService persistService = injector.getInstance(PersistService.class);
    persistService.start();

    try {
        final SampleService service = injector.getInstance(SampleService.class);

        System.out.println("Overall records: " + service.count());

        final ODocument rec = service.selectLast();
        System.out.println("Last record: " + rec.toJSON());

        service.replaceName(rec.<String>field("name"), "test");
        // pay attention to record @version property in console
        System.out.println("Renamed record: " + service.findByName("test").toJSON());
        System.out.println("Records count is the same: " + service.count());
    } finally {
        // at the end service must be stopped
        persistService.stop();
    }
}
 
开发者ID:xvik,项目名称:guice-persist-orient-examples,代码行数:26,代码来源:InMemoryDbApp.java

示例2: main

import com.google.inject.persist.PersistService; //导入方法依赖的package包/类
public static void main(String[] args) {
    final Injector injector = Guice.createInjector(new RepoDbModule("memory:sample", "admin", "admin"));
    final PersistService persistService = injector.getInstance(PersistService.class);
    persistService.start();

    try {
        final SampleRepository repository = injector.getInstance(SampleRepository.class);

        System.out.println("Overall records: " + repository.count());

        Sample sample = repository.first();
        // not detached entity will not contain data outside of transaction (its a proxy!)
        System.out.println("Last record (not detached): " + sample);
        // use list here just to show how multiple entities could be returned
        List<Sample> samples = repository.selectDetached();
        sample = samples.get(0);
        System.out.println("Detached record: " + sample);

        // without detaching name would be null
        int res = repository.updateName("test", sample.getName());
        System.out.println("Rename result: " + res);
        // pay attention to record @version property in console
        System.out.println("Renamed record: " + repository.findByNameDetached("test"));
        System.out.println("Records count is the same: " + repository.count());

        System.out.println("Document search: " + repository.findDocumentByName("test"));
    } finally {
        // at the end service must be stopped
        persistService.stop();
    }
}
 
开发者ID:xvik,项目名称:guice-persist-orient-examples,代码行数:32,代码来源:RepoDemoApp.java

示例3: main

import com.google.inject.persist.PersistService; //导入方法依赖的package包/类
public static void main(String[] args) {
    final Injector injector = Guice.createInjector(new ObjectDbModule("memory:sample", "admin", "admin"));
    final PersistService persistService = injector.getInstance(PersistService.class);
    persistService.start();

    try {
        final SampleService service = injector.getInstance(SampleService.class);

        System.out.println("Overall records: " + service.count());
        System.out.println("Overall records with query: " + service.count2());

        Sample sample = service.selectLast();
        // not detached entity will not contain data outside of transaction (its a proxy!)
        System.out.println("Last record (not detached): " + sample);
        sample = service.detach(sample);
        System.out.println("Last record (detached): " + sample);

        // without detaching name would be null
        service.replaceName(sample.getName(), "test");
        // pay attention to record @version property in console
        System.out.println("Renamed record: " + service.detach(service.findByName("test")));
        System.out.println("Records count is the same: " + service.count());
    } finally {
        // at the end service must be stopped
        persistService.stop();
    }
}
 
开发者ID:xvik,项目名称:guice-persist-orient-examples,代码行数:28,代码来源:ObjectDemoApp.java

示例4: main

import com.google.inject.persist.PersistService; //导入方法依赖的package包/类
public static void main(String[] args) {
    final Injector injector = Guice.createInjector(new GraphDbModule("memory:sample", "admin", "admin"));
    final PersistService persistService = injector.getInstance(PersistService.class);
    persistService.start();

    try {
        final SampleService service = injector.getInstance(SampleService.class);

        System.out.println("Overall records: " + service.count());
        // if you commit edge type creation in scheme initializer you will see that edge was created automatically
        // but with warning
        System.out.println("Edge types: " + Joiner.on(", ").join(service.getEdgeClasses()));

        final Vertex sample = service.selectLast();
        System.out.println("Last record: " + sample);
        System.out.println("By the way, it's backed by document: " + ((OrientVertex) sample).getRecord().toJSON());

        service.replaceName(sample.<String>getProperty("name"), "test");
        // pay attention to record @version property in console
        final Vertex renamed = service.findByName("test");
        System.out.println("Renamed record: " + renamed + " name=" + renamed.getProperty("name"));
        System.out.println("Records count is the same: " + service.count());

        System.out.println();
        Vertex parent = service.getParent(renamed.<String>getProperty("name"));
        System.out.println("Parent record: " + parent + " with name " + parent.getProperty("name"));
        List<Vertex> children = service.getChildren(parent.<String>getProperty("name"));
        System.out.println("Parent children: " + Joiner.on(", ").join(children));

        // now add new child to node already having a child
        System.out.println();
        final Vertex child = service.addChild(parent, "Child!", 12);
        System.out.println("Added new element: " + child);
        System.out.println("Records count now is: " + service.count());

        children = service.getChildren(parent.<String>getProperty("name"));
        System.out.println("Parent children after addition: " + Joiner.on(", ").join(children));

        children = service.getChildren2(parent);
        System.out.println("Parent children after addition (using api): " + Joiner.on(", ").join(children));

    } finally {
        // at the end service must be stopped
        persistService.stop();
    }
}
 
开发者ID:xvik,项目名称:guice-persist-orient-examples,代码行数:47,代码来源:GraphDemoApp.java

示例5: main

import com.google.inject.persist.PersistService; //导入方法依赖的package包/类
public static void main(String[] args) {
    final Injector injector = Guice.createInjector(new DbModule("plocal:" + DB_PATH, "admin", "admin"));
    final PersistService persistService = injector.getInstance(PersistService.class);
    persistService.start();

    try {
        final SampleService service = injector.getInstance(SampleService.class);
        // run multiple times: each time count will increase
        System.out.println("Overall records: " + service.count());

        // as an sample we will use service without unit of work defined
        // so transaction must be defined manually
        final NoTxService noTxService = injector.getInstance(NoTxService.class);
        // normally you will simply inject this as PersistentContext<ODatabaseDocumentTx>
        final PersistentContext<ODatabaseDocumentTx> context = injector.getInstance(
                Key.get(new TypeLiteral<PersistentContext<ODatabaseDocumentTx>>() {
                }));

        context.doInTransaction(() -> {
            // unit of work defined
            noTxService.doSomething();
            return null;
        });


        // now do one more manual transaction but with provided db object
        final ODocument rec = context.doInTransaction(db -> {
            // service use @Transactional annotation for unit of work definition
            // in this case annotation will be ignored because unit of work is already defined
            final long cnt = service.count();

            // manually insert record
            final ODocument rec1 = db.newInstance(ManualSchemeInitializer.CLASS_NAME)
                    .field("name", "Sample" + cnt)
                    .field("amount", (int) (Math.random() * 200))
                    .save();
            // detaching object before let it leave transaction scope
            rec1.detach();
            return rec1;
        });

        System.out.println("Just inserted record: " + rec.toJSON());
    } finally {
        // at the end service must be stopped
        persistService.stop();
    }
}
 
开发者ID:xvik,项目名称:guice-persist-orient-examples,代码行数:48,代码来源:LocalDbApp.java

示例6: JpaDeinitializer

import com.google.inject.persist.PersistService; //导入方法依赖的package包/类
@Inject
public JpaDeinitializer(PersistService service) {
    service.stop();
}
 
开发者ID:valdasraps,项目名称:resthub,代码行数:5,代码来源:JpaDeinitializer.java

示例7: Finalizer

import com.google.inject.persist.PersistService; //导入方法依赖的package包/类
@Inject
public Finalizer(PersistService persistService) {
    persistService.stop();
}
 
开发者ID:premium-minds,项目名称:billy,代码行数:5,代码来源:CoreJPATestPersistenceDependencyModule.java


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