本文整理汇总了Java中org.hibernate.boot.Metadata类的典型用法代码示例。如果您正苦于以下问题:Java Metadata类的具体用法?Java Metadata怎么用?Java Metadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Metadata类属于org.hibernate.boot包,在下文中一共展示了Metadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSqlDropStrings
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@Override
public String[] getSqlDropStrings(Table table, Metadata metadata)
{
// Check for actually existing table and indices.
if (!tableExists(table))
return new String[] {};
Set<String> existingIndices = getIndicesExcludingPK(table);
if (existingIndices.isEmpty())
return super.getSqlDropStrings(table, metadata);
List<String> dropIndices = new ArrayList<>();
for (String index : existingIndices)
{
dropIndices.add("DROP INDEX `" + index + "`");
}
String[] tableDrop = super.getSqlDropStrings(table, metadata);
String[] res = new String[dropIndices.size() + tableDrop.length];
dropIndices.toArray(res);
System.arraycopy(tableDrop, 0, res, dropIndices.size(), tableDrop.length);
return res;
}
示例2: getAlterTableToDropUniqueKeyCommand
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@Override
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata)
{
// First check that this unique key actually is present, as this is a
// lot faster than trying to drop it and then fail.
initIndices();
UniqueIndex idx = indices.getIndex(uniqueKey);
if (idx == null)
{
return null;
}
// Remove from cache
indices.removeIndex(uniqueKey);
final StringBuilder buf = new StringBuilder("DROP INDEX ");
buf.append(dialect.quote(uniqueKey.getName()));
return buf.toString();
}
示例3: applyConstraints
import org.hibernate.boot.Metadata; //导入依赖的package包/类
protected void applyConstraints(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).createOnly(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
if (isApplyingConstraints(sql)) {
sqls.add(sql);
}
}
execute(sqls, true);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
示例4: createTables
import org.hibernate.boot.Metadata; //导入依赖的package包/类
protected void createTables(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).createOnly(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
if (shouldInclude(sql) && !isApplyingConstraints(sql))
sqls.add(sql);
}
execute(sqls, true);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
FileUtils.deleteFile(tempFile);
}
}
示例5: dropConstraints
import org.hibernate.boot.Metadata; //导入依赖的package包/类
protected void dropConstraints(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).drop(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
if (isDroppingConstraints(sql))
sqls.add(sql);
}
execute(sqls, false);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
示例6: cleanDatabase
import org.hibernate.boot.Metadata; //导入依赖的package包/类
protected void cleanDatabase(Metadata metadata) {
File tempFile = null;
try {
tempFile = File.createTempFile("schema", ".sql");
new SchemaExport().setOutputFile(tempFile.getAbsolutePath())
.setFormat(false).drop(EnumSet.of(TargetType.SCRIPT), metadata);
List<String> sqls = new ArrayList<>();
for (String sql: FileUtils.readLines(tempFile)) {
sqls.add(sql);
}
execute(sqls, false);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
示例7: start
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@Override
public void start() {
if (Bootstrap.isServerRunning(Bootstrap.installDir)) {
logger.error("Please stop server before cleaning database");
System.exit(1);
}
checkDataVersion(false);
Metadata metadata = buildMetadata();
cleanDatabase(metadata);
if (getDialect().toLowerCase().contains("hsql")) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
logger.info("Database is cleaned successfully");
System.exit(0);
}
示例8: integrate
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
EventListenerRegistry service = serviceRegistry.getService(org.hibernate.event.service.spi.EventListenerRegistry.class);
StandardPBEStringEncryptor encrypt = new StandardPBEStringEncryptor();
encrypt.setPassword("test_password");
RenderedMessageEncryptEventListener encryptListener = new RenderedMessageEncryptEventListener();
encryptListener.setStringEncryptor(encrypt);
RenderedMessageDecryptEventListener decryptListener = new RenderedMessageDecryptEventListener();
decryptListener.setStringEncryptor(encrypt);
FullTextIndexEventListener fullTextListener = new FullTextIndexEventListener();
service.appendListeners(EventType.PRE_UPDATE, encryptListener);
service.prependListeners(EventType.POST_UPDATE, decryptListener);
service.appendListeners(EventType.PRE_INSERT, encryptListener);
service.prependListeners(EventType.POST_INSERT, decryptListener);
service.appendListeners(EventType.POST_LOAD, decryptListener);
}
示例9: start
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@Override
public void start() {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.applySetting("hibernate.connection.username", config.persistence.user)
.applySetting("hibernate.connection.password", config.persistence.pass)
.applySetting("hibernate.connection.driver_class", config.persistence.driver)
.applySetting("hibernate.connection.url", config.persistence.url)
.applySetting("hibernate.dialect", config.persistence.dialect)
.applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
.applySetting("hibernate.hbm2ddl.auto", "update")
.applySetting("hibernate.show_sql", config.persistence.showSQL + "")
.build();
MetadataSources sources = new MetadataSources(registry);
Timings.time("RegisterDBEntities", () ->
new Reflections().getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));
try {
Metadata metadata = sources.buildMetadata();
sessionFactory = metadata.buildSessionFactory();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(registry);
e.printStackTrace();
}
}
示例10: setup
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@Before
public void setup() {
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
.applySetting( "hibernate.show_sql", "true" )
.applySetting( "hibernate.format_sql", "true" )
.applySetting( "hibernate.hbm2ddl.auto", "update" )
.applySetting( "hibernate.dialect", "org.hibernate.dialect.H2Dialect" )
.applySetting( "hibernate.connection.driver_class", "org.h2.Driver" )
.applySetting( "hibernate.connection.url", "jdbc:h2:mem:testdbHibernate" )
.applySetting( "hibernate.connection.username", "sa" )
.applySetting( "hibernate.connection.password", "" )
.applySetting( "hibernate.use_sql_comment", "true" )
;
Metadata metadata = null;
if(packageBase()== null){
metadata= new MetadataSources( srb.build() ).addAnnotatedClass(getEntityClass()).buildMetadata();
}else{
metadata= new MetadataSources( srb.build() )
.addAnnotatedClass(Item.class)
.addAnnotatedClass(Offer.class)
.addPackage(packageBase()).buildMetadata();
}
sf = metadata.buildSessionFactory();
}
示例11: setup
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@BeforeClass
public static void setup() {
// @formatter:off
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
.applySetting("hibernate.show_sql", "true")
.applySetting("hibernate.format_sql", "true")
.applySetting("hibernate.hbm2ddl.auto", "update")
.applySetting("use_sql_comments", "true")
.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.applySetting("hibernate.connection.driver_class", "org.h2.Driver")
.applySetting("hibernate.connection.url", "jdbc:h2:mem:testdbHibernate")
.applySetting("hibernate.connection.username", "sa")
.applySetting("hibernate.connection.password", "")
.applySetting("hibernate.use_sql_comment", "true");
Metadata metadata = null;
log.info("+++ setup");
metadata = new MetadataSources(srb.build()).addAnnotatedClass(EmailMessage.class).addAnnotatedClass(Email.class).buildMetadata();
sf = metadata.buildSessionFactory();
// @formatter:on
}
示例12: setup
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@BeforeClass
public static void setup() {
// @formatter:off
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
.applySetting("hibernate.show_sql", "true")
.applySetting("hibernate.format_sql", "true")
.applySetting("hibernate.hbm2ddl.auto", "update")
.applySetting("use_sql_comments", "true")
.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.applySetting("hibernate.connection.driver_class", "org.h2.Driver")
.applySetting("hibernate.connection.url", "jdbc:h2:mem:testdbHibernate")
.applySetting("hibernate.connection.username", "sa")
.applySetting("hibernate.connection.password", "")
.applySetting("hibernate.use_sql_comment", "true");
Metadata metadata = null;
log.info("+++ setup");
metadata = new MetadataSources(srb.build()).addAnnotatedClass(Address.class).addAnnotatedClass(User.class).buildMetadata();
sf = metadata.buildSessionFactory();
// @formatter:on
}
示例13: testEntityToDatabaseBindingMetadata
import org.hibernate.boot.Metadata; //导入依赖的package包/类
@Test
public void testEntityToDatabaseBindingMetadata() {
Metadata metadata = MetadataExtractorIntegrator.INSTANCE.getMetadata();
for ( PersistentClass persistentClass : metadata.getEntityBindings()) {
Table table = persistentClass.getTable();
LOGGER.info( "Entity: {} is mapped to table: {}",
persistentClass.getClassName(),
table.getName()
);
for(Iterator propertyIterator =
persistentClass.getPropertyIterator(); propertyIterator.hasNext(); ) {
Property property = (Property) propertyIterator.next();
for(Iterator columnIterator =
property.getColumnIterator(); columnIterator.hasNext(); ) {
Column column = (Column) columnIterator.next();
LOGGER.info( "Property: {} is mapped on table column: {} of type: {}",
property.getName(),
column.getName(),
column.getSqlType()
);
}
}
}
}
示例14: generate
import org.hibernate.boot.Metadata; //导入依赖的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);
}
示例15: metadataBuilder
import org.hibernate.boot.Metadata; //导入依赖的package包/类
private Block metadataBuilder() {
return unit -> {
MetadataBuilder mb = unit.get(MetadataBuilder.class);
expect(mb.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE))
.andReturn(mb);
expect(mb.applyScanEnvironment(unit.get(ScanEnvironment.class))).andReturn(mb);
SessionFactoryBuilder sfb = unit.mock(SessionFactoryBuilder.class);
unit.registerMock(SessionFactoryBuilder.class, sfb);
Metadata md = unit.mock(Metadata.class);
expect(md.getSessionFactoryBuilder()).andReturn(sfb);
expect(mb.build()).andReturn(md);
unit.registerMock(Metadata.class, md);
};
}