/
Bootstrap.java
executable file
·51 lines (42 loc) · 2.2 KB
/
Bootstrap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.alvazan.orm.impl.bindings;
import java.util.Map;
import com.alvazan.orm.api.base.AbstractBootstrap;
import com.alvazan.orm.api.base.DbTypeEnum;
import com.alvazan.orm.api.base.NoSqlEntityManagerFactory;
import com.alvazan.orm.api.spi.db.NoSqlRawSession;
import com.alvazan.orm.api.spi.layer2.Converter;
import com.alvazan.orm.api.spi.layer2.DboDatabaseMeta;
import com.alvazan.orm.api.spi.layer2.NoSqlSessionFactory;
import com.alvazan.orm.layer1.base.BaseEntityManagerFactoryImpl;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class Bootstrap extends AbstractBootstrap {
@SuppressWarnings("rawtypes")
@Override
public NoSqlEntityManagerFactory createInstance(DbTypeEnum type, Map<String, String> properties, Map<Class, Converter> converters) {
Injector injector = Guice.createInjector(new ProductionBindings(type));
NoSqlEntityManagerFactory factory = injector.getInstance(NoSqlEntityManagerFactory.class);
NoSqlRawSession inst = injector.getInstance(NoSqlRawSession.class);
inst.start(properties);
BaseEntityManagerFactoryImpl impl = (BaseEntityManagerFactoryImpl)factory;
impl.setInjector(injector);
//The expensive scan all entities occurs here...
impl.setup(properties, converters);
return impl;
}
/**
* A raw interface for non-ORM situations where flush can still be used to send all addIndex,removeIndex and persists, removes
* all at the same time. This is especially useful as if addIndex fails BEFORE you flush, nothing is sent(no persists, removes)
* so there is nothing to really resolve. We try to fail fast in persist, remove, addIndex, and removeIndex. Then at flush
* time, we actually write out everything (at which point stuff can fail leading to inconsistency that needs to be cleaned up,
* but we will log everything that was being written on failure and what was success and what failed)
*
* @param type
* @param metaDb
* @return
*/
public static NoSqlSessionFactory createRawInstance(DbTypeEnum type, DboDatabaseMeta metaDb) {
Injector injector = Guice.createInjector(new ProductionBindings(type, metaDb));
return injector.getInstance(NoSqlSessionFactory.class);
}
}