本文整理匯總了Java中org.hibernate.boot.MetadataSources.addAnnotatedClass方法的典型用法代碼示例。如果您正苦於以下問題:Java MetadataSources.addAnnotatedClass方法的具體用法?Java MetadataSources.addAnnotatedClass怎麽用?Java MetadataSources.addAnnotatedClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.boot.MetadataSources
的用法示例。
在下文中一共展示了MetadataSources.addAnnotatedClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildDomainMetamodel
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
public static SqmDomainMetamodel buildDomainMetamodel(Class... managedClasses) {
final MetadataSources metadataSources = new MetadataSources();
for ( Class managedClass : managedClasses ) {
metadataSources.addAnnotatedClass( managedClass );
}
final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
// at this point we have access to the mapping Metadata (PersistentClass, etc)
// use it to build the testing DomainMetamodel/TypeConfiguration
final ExplicitSqmDomainMetamodel domainMetamodel = new ExplicitSqmDomainMetamodel( metadata );
populateDatabaseModel( metadata, domainMetamodel );
populateMappingModel( metadata, domainMetamodel );
return domainMetamodel;
}
示例2: startHibernate
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
* @param nodeName Name of the grid providing caches.
* @return Session factory.
*/
SessionFactory startHibernate(String nodeName) {
log.info("Start hibernate on node: " + nodeName);
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
for (Map.Entry<String, String> e : hibernateProperties(nodeName, NONSTRICT_READ_WRITE.name()).entrySet())
builder.applySetting(e.getKey(), e.getValue());
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
builder.applySetting(DFLT_CACHE_NAME_PROPERTY, CACHE_NAME);
MetadataSources metadataSources = new MetadataSources(builder.build());
metadataSources.addAnnotatedClass(Entity1.class);
metadataSources.addAnnotatedClass(Entity2.class);
metadataSources.addAnnotatedClass(Entity3.class);
return metadataSources.buildMetadata().buildSessionFactory();
}
示例3: generate
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
* Method that actually creates the file.
*
* @param dbDialect to use
*/
private void generate(Dialect dialect) {
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
ssrb.applySetting("hibernate.dialect", dialect.getDialectClass());
StandardServiceRegistry standardServiceRegistry = ssrb.build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
for (Class clzz : jpaClasses) {
metadataSources.addAnnotatedClass(clzz);
}
Metadata metadata = metadataSources.buildMetadata();
SchemaExport export = new SchemaExport();
export.setDelimiter(";");
export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
//export.execute(true, false, false, true);
export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata);
}
示例4: createMetadataImplementor
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
public static MetadataImplementor createMetadataImplementor(String dialect, String[] hibernatePackagesToScan) {
final MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder()
.applySetting("hibernate.dialect", dialect)
.build());
for (String packageName : hibernatePackagesToScan) {
for (Class clazz : HibernateMetaDataHelper.getClasses(packageName)) {
metadata.addAnnotatedClass(clazz);
}
}
return (MetadataImplementor) metadata.buildMetadata();
}
示例5: testDbSchema
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Test
public void testDbSchema() {
MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder()
.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").build());
metadata.addAnnotatedClass(ConsoleEntity.class);
metadata.addAnnotatedClass(GameEntity.class);
metadata.addAnnotatedClass(UserEntity.class);
metadata.addAnnotatedClass(RoleEntity.class);
metadata.addAnnotatedClass(LibraryEntity.class);
metadata.addAnnotatedClass(BorrowEntity.class);
SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata());
export.create(Target.SCRIPT);
}
示例6: buildMetadata
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
protected Metadata buildMetadata() {
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (Class<? extends AbstractEntity> each: LoaderUtils.findImplementations(AbstractEntity.class, AbstractEntity.class)) {
metadataSources.addAnnotatedClass(each);
}
return metadataSources.getMetadataBuilder().applyPhysicalNamingStrategy(physicalNamingStrategy).build();
}
示例7: buildFactory
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Override
public SessionFactory buildFactory(String configFile) {
try {
//configuration = new Configuration().configure(configFile);
// StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
// .applySettings(configuration.getProperties());
// SessionFactory factory2 = configuration.buildSessionFactory(builder.build());
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
.configure(configFile)
.build();
MetadataSources metadataSources = new MetadataSources( standardRegistry );
DomainScanner instanceFromProperties = getScanner(configFile);
List<Class<? extends BaseDatabaseDomain>> scan = instanceFromProperties.scan(configFile);
for(Class<? extends BaseDatabaseDomain> temp:scan){
metadataSources.addAnnotatedClass(temp);
}
// new HibernateUtil().scanDomain(metadataSources);
Metadata metadata = metadataSources.getMetadataBuilder()
.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE )
.build();
SessionFactory factory2 = metadata.getSessionFactoryBuilder().build();
return factory2;
/*ProxoolConnectionProvider aConnectionProvider;*/
} catch (Exception e) {
steed.util.logging.LoggerFactory.getLogger().error("創建sessionFactory失敗",e);
}
return null;
}
示例8: setup
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Before
public void setup() throws Exception {
MetadataSources metadataSources = new MetadataSources();
metadataSources.addAnnotatedClass(TelephoneNumber.class);
StandardServiceRegistry serviceRegistry = getServiceRegistry(metadataSources);
this.metadata = metadataSources.getMetadataBuilder(serviceRegistry)
.applyPhysicalNamingStrategy(new SpringPhysicalNamingStrategy()).build();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:9,代碼來源:SpringPhysicalNamingStrategyTests.java
示例9: initializeFactory
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
* 初始化 hibernate 工廠
*
* @param driver
* 驅動
* @param url
* 連接地址
* @param user
* 用戶名
* @param password
* 密碼
*
*/
static void initializeFactory(String driver, String url, String user, String password, int fixedConnectionSize) {
// 引導 hibernate 日誌配置 see
System.setProperty("org.jboss.logging.provider", "slf4j");
// A StandardServiceRegistryBuilder
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder().configure(); // configures
// settings
// from
// hibernate.cfg.xml
// overwrite some config
registryBuilder.applySetting("hibernate.connection.driver_class", driver);
registryBuilder.applySetting("hibernate.connection.url", url);
registryBuilder.applySetting("hibernate.connection.username", user);
registryBuilder.applySetting("hibernate.connection.password", password);
// overwrite dialect
String usingDialect = "";
if (driver.toLowerCase().contains("mysql")) usingDialect = "org.hibernate.dialect.MySQLDialect";
else if (driver.toLowerCase().contains("oracle")) usingDialect = "org.hibernate.dialect.Oracle10gDialect";
registryBuilder.applySetting("hibernate.dialect", usingDialect);
log.info("[DataSource]::hibernate using dialect {}.", usingDialect);
// config with proxool
ProxoolHelper.addProxoolConfig(registryBuilder);
ProxoolHelper.configProxoolAlias(user, password, url, driver, fixedConnectionSize);
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = registryBuilder.build();
MetadataSources metadataSources = new MetadataSources(registry);
// attach other mappings
for (Class<?> cls : otherMappingsClasses)
metadataSources.addAnnotatedClass(cls);
// build session factory
sessionFactory = metadataSources.buildMetadata().buildSessionFactory();
}
示例10: HibernateUtil
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
public HibernateUtil(ArgumentParser argumentParser, WebLogParser logParser) throws ExceptionInInitializerError, IOException, CannotCompileException, NotFoundException {
try {
/** Izbrisemo razrede, ki jih je uprabnik podal za ignoriranje */
List<LogFieldType> list = logParser.getFieldType();
if (logParser.getIgnoreFieldTypes() != null) {
list.removeAll(logParser.getIgnoreFieldTypes());
}
/** Inicializacija ClassLoaderja */
this.loader = initClassLoader(argumentParser);
/** Nastavi dodatne lastnosti za Hibernate */
Properties props = initProperties(argumentParser);
/** Nastavi nastavitve za Hibernate */
serviceRegistry = new StandardServiceRegistryBuilder()
/** Dodaj nov ClassLoader Hibernatu */
.addService(ClassLoaderService.class, new ClassLoaderServiceImpl(loader))
/** Podaj nastavitve za Hibernate */
.applySettings(props)
.build();
/** Posreduj potrebene razrede za izdelavo in delovanje podatkovne baze Hibernatu */
MetadataSources sources = new MetadataSources(serviceRegistry);
for (Class c : initClasses(list, loader)) {
sources.addAnnotatedClass(c);
}
/** Izdelaj podatkovno bazo */
factory = sources.buildMetadata().buildSessionFactory();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
throw new ExceptionInInitializerError(e);
}
}
示例11: get
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
@Override
public DataStore get() {
// method to force class initialization
MetadataSources metadataSources = new MetadataSources(
new StandardServiceRegistryBuilder()
.configure("hibernate.cfg.xml")
.applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread")
.applySetting(Environment.URL, "jdbc:mysql://localhost:"
+ System.getProperty("mysql.port", "3306")
+ "/root?serverTimezone=UTC")
.applySetting(Environment.USER, "root")
.applySetting(Environment.PASS, "root")
.build());
metadataSources.addAnnotatedClass(HibernateUser.class);
MetadataImplementor metadataImplementor = (MetadataImplementor) metadataSources.buildMetadata();
// create example tables from beans
SchemaExport schemaExport = new SchemaExport(metadataImplementor); //.setHaltOnError(true);
schemaExport.drop(false, true);
schemaExport.execute(false, true, false, true);
if (!schemaExport.getExceptions().isEmpty()) {
throw new RuntimeException(schemaExport.getExceptions().toString());
}
LATEST_HIBERNATE_STORE = new AbstractHibernateStore.Builder(metadataImplementor.buildSessionFactory())
.withScrollEnabled(true)
.withScrollMode(ScrollMode.FORWARD_ONLY)
.build();
BridgeableRedisStore hbaseStore = new BridgeableRedisStore();
return new MultiplexManager(LATEST_HIBERNATE_STORE, hbaseStore);
}
示例12: startHibernate
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
* @param accessType Cache access typr.
* @param igniteInstanceName Name of the grid providing caches.
* @return Session factory.
*/
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
builder.applySetting(e.getKey(), e.getValue());
builder.applySetting(USE_STRUCTURED_CACHE, "true");
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);
MetadataSources metadataSources = new MetadataSources(builder.build());
metadataSources.addAnnotatedClass(Entity1.class);
metadataSources.addAnnotatedClass(Entity2.class);
metadataSources.addAnnotatedClass(Entity3.class);
metadataSources.addAnnotatedClass(Entity4.class);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited())
((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
return metadata.buildSessionFactory();
}
示例13: startHibernate
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
* Starts Hibernate.
*
* @param accessType Cache access type.
* @param igniteInstanceName Ignite instance name.
* @return Session factory.
*/
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
StandardServiceRegistryBuilder builder = registryBuilder();
for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
builder.applySetting(e.getKey(), e.getValue());
// Use the same cache for Entity and Entity2.
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
StandardServiceRegistry srvcRegistry = builder.build();
MetadataSources metadataSources = new MetadataSources(srvcRegistry);
for (Class entityClass : getAnnotatedClasses())
metadataSources.addAnnotatedClass(entityClass);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited())
((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName() );
return metadata.buildSessionFactory();
}
示例14: generateMetadata
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
protected MetadataSources generateMetadata(Class<? extends Dialect> dialect, String defaultSchema, Collection<String> classNames) throws ClassNotFoundException {
Assert.notNull(dialect, "dialect is invalid [null]");
StandardServiceRegistryBuilder registryBuilder =
new StandardServiceRegistryBuilder()
.applySetting(Environment.DIALECT, dialect.getName())
.applySetting(Environment.HBM2DDL_AUTO, "create-drop")
.applySetting(Environment.SHOW_SQL, "true")
.applySetting(Environment.FORMAT_SQL, "true")
.applySetting(Environment.USE_SQL_COMMENTS, "true")
.applySetting(Environment.ORDER_INSERTS, "true")
.applySetting(Environment.ORDER_UPDATES, "true");
if (StringUtils.hasText(defaultSchema)) {
registryBuilder.applySetting(Environment.DEFAULT_SCHEMA, defaultSchema);
}
MetadataSources metadata = new MetadataSources(registryBuilder.build());
if (classNames != null) {
for (String className : classNames) {
metadata.addAnnotatedClass(Class.forName(className));
}
}
return metadata;
}
示例15: newSessionFactory
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
private SessionFactory newSessionFactory() {
final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
.enableAutoClose();
Integrator integrator = integrator();
if (integrator != null) {
bsrb.applyIntegrator(integrator);
}
final BootstrapServiceRegistry bsr = bsrb.build();
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
.applySettings(properties())
.build();
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (Class annotatedClass : entities()) {
metadataSources.addAnnotatedClass(annotatedClass);
}
String[] packages = packages();
if (packages != null) {
for (String annotatedPackage : packages) {
metadataSources.addPackage(annotatedPackage);
}
}
String[] resources = resources();
if (resources != null) {
for (String resource : resources) {
metadataSources.addResource(resource);
}
}
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
metadataBuilder.enableNewIdentifierGeneratorSupport(true);
metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);
MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
Interceptor interceptor = interceptor();
if (interceptor != null) {
sfb.applyInterceptor(interceptor);
}
return sfb.build();
}