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


Java JdbcEnvironment类代码示例

本文整理汇总了Java中org.hibernate.engine.jdbc.env.spi.JdbcEnvironment的典型用法代码示例。如果您正苦于以下问题:Java JdbcEnvironment类的具体用法?Java JdbcEnvironment怎么用?Java JdbcEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JdbcEnvironment类属于org.hibernate.engine.jdbc.env.spi包,在下文中一共展示了JdbcEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mockContext

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
private void mockContext(final ImplicitNameSource source) {
	final MetadataBuildingContext context = Mockito.mock(MetadataBuildingContext.class);
	final InFlightMetadataCollector collector = Mockito.mock(InFlightMetadataCollector.class);
	final Database database = Mockito.mock(Database.class);
	final JdbcEnvironment jdbcEnvironment = Mockito.mock(JdbcEnvironment.class);
	final IdentifierHelper identifierHelper = Mockito.mock(IdentifierHelper.class);
	Mockito.when(identifierHelper.toIdentifier(ArgumentMatchers.anyString())).then(new Answer<Identifier>() {

		@Override
		public Identifier answer(final InvocationOnMock invocation) {
			return DatabaseIdentifier.toIdentifier((String)invocation.getArguments()[0]) ;
		}
	});
	Mockito.when(jdbcEnvironment.getIdentifierHelper()).thenReturn(identifierHelper);
	Mockito.when(database.getJdbcEnvironment()).thenReturn(jdbcEnvironment);
	Mockito.when(collector.getDatabase()).thenReturn(database);
	Mockito.when(context.getMetadataCollector()).thenReturn(collector);
	Mockito.when(source.getBuildingContext()).thenReturn(context);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:20,代码来源:ImplicitNamingStrategyNiceJpaImplTest.java

示例2: newJdbcEnvironment

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
private JdbcEnvironment newJdbcEnvironment() {

		JdbcEnvironment jdbcEnvironment = Mockito.mock(JdbcEnvironment.class);
		IdentifierHelper identifierHelper = Mockito.mock(IdentifierHelper.class);
		Mockito.when(identifierHelper.toIdentifier(ArgumentMatchers.anyString())).then(new Answer<Identifier>() {

			@Override
			public Identifier answer(InvocationOnMock invocation) {
				if (invocation.getArguments()[0] == null)
					return null;
				return new Identifier((String) invocation.getArguments()[0], false);
			}
		});
		Mockito.when(jdbcEnvironment.getIdentifierHelper()).thenReturn(identifierHelper);
		return jdbcEnvironment;
	}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:17,代码来源:SequenceIdentifierGeneratorStrategyProviderTest.java

示例3: toPhysicalTableName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
@Override
public Identifier toPhysicalTableName(Identifier identifier, JdbcEnvironment jdbcEnvironment) {
    String name = identifier.getText();
    if (name.startsWith("m_") || "hibernate_sequence".equals(name)) {
        return identifier;
    }

    name = name.substring(1);
    name = "m_" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
    name = RUtil.fixDBSchemaObjectNameLength(name);

    Identifier i = new Identifier(name, identifier.isQuoted());

    LOGGER.trace("toPhysicalTableName {} -> {}", identifier, i);

    return i;
}
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:18,代码来源:MidPointPhysicalNamingStrategy.java

示例4: convertToLimitedLowerCase

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
/**
 * Converts a given {@link Identifier} to the lower case representation. If
 * the given context has a character limit for identifiers, this will be
 * respected.
 *
 * @param context
 *            The JDBC context
 * @param identifier
 *            The identifier
 * @param prefix
 *            Optional prefix to use for the idenifiert. Will be ignored, if
 *            null
 * @return
 */
protected Identifier convertToLimitedLowerCase(JdbcEnvironment context, Identifier identifier, String prefix) {
	String identifierText = identifier.getText();

	if(prefix != null) {
		identifierText = prefix + identifierText;
	}

	// always convert to lowercase
	identifierText = identifierText.toLowerCase();

	// determine the length limit based on the JDBC context
	Integer lengthLimit = getIdentifierLengthLimit(context);

	// limit length if necessary
	if (lengthLimit != null && identifierText.length() > lengthLimit) {
		identifierText = StringUtils.substring(identifierText, 0, lengthLimit);
	}

	return Identifier.toIdentifier(identifierText);
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:35,代码来源:PhysicalNamingStrategyShogun2.java

示例5: getIdentifierLengthLimit

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
/**
 *
 * Determines the identifier length limit for the given JDBC context.
 * Returns null if no limitation is necessary.
 *
 * @param context
 *            The current JDBC context
 * @return The identifier length limit for the given context. null
 *         otherwise.
 */
protected Integer getIdentifierLengthLimit(JdbcEnvironment context) {
	// https://docs.jboss.org/hibernate/orm/5.0/javadocs/org/hibernate/dialect/package-summary.html
	String dialectName = context.getDialect().getClass().getSimpleName();

	if (dialectName.startsWith("Oracle")) {
		// identifier limit of 30 chars -->
		// http://stackoverflow.com/a/756569
		return LENGTH_LIMIT_ORACLE;
	} else if (context.getDialect() instanceof Shogun2OracleDialect) {
		// identifier limit of 30 chars -->
		return LENGTH_LIMIT_ORACLE;
	} else if (dialectName.startsWith("PostgreSQL")) {
		// identifier limit of 63 chars -->
		// http://stackoverflow.com/a/8218026
		return LENGTH_LIMIT_POSTGRESQL;
	}
	// H2 has no limit --> http://stackoverflow.com/a/30477403

	return null;
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:31,代码来源:PhysicalNamingStrategyShogun2.java

示例6: determineSequenceName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
@Override
protected QualifiedName determineSequenceName(final Properties params, final Dialect dialect, final JdbcEnvironment jdbcEnv) {
	// Make sure sequence are lower case and corresponds to table name
	params.put(SEQUENCE_PARAM, StringHelper.unquote(params.getProperty("identity_tables"))
			+ ConfigurationHelper.getString(CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX));
	return super.determineSequenceName(params, dialect, jdbcEnv);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:8,代码来源:SequenceIdentifierGeneratorStrategyProvider.java

示例7: newStyleGenerator

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
private OptimizedSequenceStyleGenerator newStyleGenerator() {
	return new OptimizedSequenceStyleGenerator() {
		@Override
		protected DatabaseStructure buildDatabaseStructure(Type type, Properties params, JdbcEnvironment jdbcEnvironment, boolean forceTableUse,
				QualifiedName sequenceName, int initialValue, int incrementSize) {
			return Mockito.mock(DatabaseStructure.class);
		}

	};
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:11,代码来源:SequenceIdentifierGeneratorStrategyProviderTest.java

示例8: newServiceRegistry

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
private ServiceRegistry newServiceRegistry() {
	JdbcEnvironment jdbcEnvironment = newJdbcEnvironment();
	ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
	Mockito.when(serviceRegistry.getService(JdbcEnvironment.class)).thenReturn(jdbcEnvironment);
	Mockito.when(jdbcEnvironment.getDialect()).thenReturn(new MySQL55Dialect());
	return serviceRegistry;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:8,代码来源:SequenceIdentifierGeneratorStrategyProviderTest.java

示例9: determineSequenceName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
@Override
protected QualifiedName determineSequenceName(Properties params, Dialect dialect, JdbcEnvironment jdbcEnv) {
	String tableName = params.getProperty(PersistentIdentifierGenerator.TABLE);
	String columnName = params.getProperty(PersistentIdentifierGenerator.PK);

	if (tableName != null && columnName != null) {
		StringBuilder sequenceNameBuilder = new StringBuilder();

		sequenceNameBuilder.append(tableName);
		sequenceNameBuilder.append(SEQUENCE_NAME_SEPARATOR);
		sequenceNameBuilder.append(columnName);
		sequenceNameBuilder.append(SEQUENCE_NAME_SEPARATOR);
		sequenceNameBuilder.append(SEQUENCE_NAME_SUFFIX);
		
		// todo : need to incorporate implicit catalog and schema names
		final Identifier catalog = jdbcEnv.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( CATALOG, params )
		);
		final Identifier schema =  jdbcEnv.getIdentifierHelper().toIdentifier(
				ConfigurationHelper.getString( SCHEMA, params )
		);
		return new QualifiedNameParser.NameParts(
				catalog,
				schema,
				jdbcEnv.getIdentifierHelper().toIdentifier( sequenceNameBuilder.toString() )
		);
	}
	throw new IllegalStateException("Unable to build the sequence name");
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:30,代码来源:PerTableSequenceStyleGenerator.java

示例10: toPhysicalColumnName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
@Override
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
    Identifier original = super.toPhysicalColumnName(name, context);
    if(original.getText().length() > 30) {
        return Identifier.toIdentifier(original.getText().substring(0, 30), original.isQuoted());
    }
    return original;
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:9,代码来源:OracleNamingStrategy.java

示例11: toPhysicalColumnName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
@Override
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
    Identifier i = super.toPhysicalColumnName(name, context);

    LOGGER.trace("toPhysicalColumnName {} -> {}", name, i);

    return i;
}
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:9,代码来源:MidPointPhysicalNamingStrategy.java

示例12: toPhysicalColumnName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
/**
 * Check if column {@link Identifier} equals reserved word. If true, add prefix to column name
 *
 * @param name    identifier to check
 * @param context JDBC env
 *
 * @return Identifier
 */
@Override
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
	// call superclass and get string value
	Identifier columnIdentifier = super.toPhysicalColumnName(name, context);
	String columnIdentifierText = columnIdentifier.getText();
	if (StringUtils.equalsAnyIgnoreCase(columnIdentifierText, RESERVED_WORDS_ORACLE)) {
		columnIdentifier = convertToLimitedLowerCase(context, columnIdentifier, columnNamePrefix);
	}

	return columnIdentifier;
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:20,代码来源:OracleNamingStrategyShogun2.java

示例13: assertExpectedPhysicalTableName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
/**
 * @param dialect
 * @param className
 * @param expectedPhysicalTableName
 */
private void assertExpectedPhysicalTableName(Dialect dialect, String className, String expectedPhysicalTableName) {
	JdbcEnvironment context = Mockito.mock(JdbcEnvironment.class);
	when(context.getDialect()).thenReturn(dialect);

	Identifier classIdentifier = Identifier.toIdentifier(className);
	String actualPhysicalName = namingStrategy.toPhysicalTableName(classIdentifier, context).getText();

	assertEquals(expectedPhysicalTableName, actualPhysicalName);
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:15,代码来源:PhysicalNamingStrategyShogun2Test.java

示例14: assertExpectedPhysicalColumnName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
/**
 * @param dialect
 * @param columnName
 * @param expectedPhysicalColumnName
 */
private void assertExpectedPhysicalColumnName(Dialect dialect, String columnName, String expectedPhysicalColumnName) {
	JdbcEnvironment context = Mockito.mock(JdbcEnvironment.class);
	when(context.getDialect()).thenReturn(dialect);

	Identifier classIdentifier = Identifier.toIdentifier(columnName);
	String actualPhysicalName = namingStrategy.toPhysicalColumnName(classIdentifier, context).getText();

	assertEquals(expectedPhysicalColumnName, actualPhysicalName);
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:15,代码来源:PhysicalNamingStrategyShogun2Test.java

示例15: assertExpectedPhysicalColumnName

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; //导入依赖的package包/类
/**
 * @param dialect
 * @param columnName
 * @param expectedPhysicalColumnName
 */
private void assertExpectedPhysicalColumnName(Dialect dialect, String columnName, String expectedPhysicalColumnName) {
	JdbcEnvironment context = Mockito.mock(JdbcEnvironment.class);
	when(context.getDialect()).thenReturn(dialect);

	Identifier classIdentifier = Identifier.toIdentifier(columnName);
	String actualPhysicalName = oracleNamingStrategyShogun2.toPhysicalColumnName(classIdentifier, context).getText();

	assertEquals(expectedPhysicalColumnName, actualPhysicalName);
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:15,代码来源:OracleNamingStrategyShogun2Test.java


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