本文整理汇总了Java中org.hibernate.util.StringHelper类的典型用法代码示例。如果您正苦于以下问题:Java StringHelper类的具体用法?Java StringHelper怎么用?Java StringHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringHelper类属于org.hibernate.util包,在下文中一共展示了StringHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColumnName
import org.hibernate.util.StringHelper; //导入依赖的package包/类
private String getColumnName(String columnName)
{
if( columnName != null )
{
String col = columnOverrides.get(StringHelper.unqualify(columnName));
if( col != null )
{
columnName = col;
}
}
if( columnName != null && columnName.length() > 25 )
{
columnName = columnName.substring(0, 25);
}
return columnName;
}
示例2: getIdentityColumn
import org.hibernate.util.StringHelper; //导入依赖的package包/类
public String getIdentityColumn() {
checkInitialized();
String table = getTableAlias();
if ( table == null ) {
throw new IllegalStateException( "No table alias for node " + this );
}
String[] cols;
String propertyName;
if ( getEntityPersister() != null && getEntityPersister().getEntityMetamodel() != null
&& getEntityPersister().getEntityMetamodel().hasNonIdentifierPropertyNamedId() ) {
propertyName = getEntityPersister().getIdentifierPropertyName();
}
else {
propertyName = EntityPersister.ENTITY_ID;
}
if ( getWalker().getStatementType() == HqlSqlWalker.SELECT ) {
cols = getPropertyMapping( propertyName ).toColumns( table, propertyName );
}
else {
cols = getPropertyMapping( propertyName ).toColumns( propertyName );
}
String result = StringHelper.join( ", ", cols );
return cols.length == 1 ? result : "(" + result + ")";
}
示例3: parseFilter
import org.hibernate.util.StringHelper; //导入依赖的package包/类
private static void parseFilter(Element filterElement, Filterable filterable, Mappings model) {
final String name = filterElement.attributeValue( "name" );
String condition = filterElement.getTextTrim();
if ( StringHelper.isEmpty(condition) ) {
condition = filterElement.attributeValue( "condition" );
}
//TODO: bad implementation, cos it depends upon ordering of mapping doc
// fixing this requires that Collection/PersistentClass gain access
// to the Mappings reference from Configuration (or the filterDefinitions
// map directly) sometime during Configuration.buildSessionFactory
// (after all the types/filter-defs are known and before building
// persisters).
if ( StringHelper.isEmpty(condition) ) {
condition = model.getFilterDefinition(name).getDefaultFilterCondition();
}
if ( condition==null) {
throw new MappingException("no filter condition found for filter: " + name);
}
log.debug( "Applying filter [" + name + "] as [" + condition + "]" );
filterable.addFilter( name, condition );
}
示例4: logicalCollectionTableName
import org.hibernate.util.StringHelper; //导入依赖的package包/类
/**
* Returns either the table name if explicit or
* if there is an associated table, the concatenation of owner entity table and associated table
* otherwise the concatenation of owner entity table and the unqualified property name
*/
public String logicalCollectionTableName(String tableName,
String ownerEntityTable, String associatedEntityTable, String propertyName
) {
if ( tableName != null ) {
return tableName;
}
else {
//use of a stringbuffer to workaround a JDK bug
return new StringBuffer(ownerEntityTable).append("_")
.append(
associatedEntityTable != null ?
associatedEntityTable :
StringHelper.unqualify( propertyName )
).toString();
}
}
示例5: configure
import org.hibernate.util.StringHelper; //导入依赖的package包/类
public void configure(Configuration cfg) {
super.configure( cfg );
if ( !useAntlrParser ) {
cfg.setProperty( Environment.QUERY_TRANSLATOR, ClassicQueryTranslatorFactory.class.getName() );
try {
String dialectTrueRepresentation = Dialect.getDialect().toBooleanValueString( true );
// if this call succeeds, then the dialect is saying to represent true/false as int values...
Integer.parseInt( dialectTrueRepresentation );
String subs = cfg.getProperties().getProperty( Environment.QUERY_SUBSTITUTIONS );
if ( subs == null ) {
subs = "";
}
if ( StringHelper.isEmpty( subs ) ) {
subs = "true=1, false=0";
}
else {
subs += ", true=1, false=0";
}
cfg.getProperties().setProperty( Environment.QUERY_SUBSTITUTIONS, subs );
}
catch( NumberFormatException nfe ) {
// the Integer#parseInt call failed...
}
}
}
示例6: parsePath
import org.hibernate.util.StringHelper; //导入依赖的package包/类
/**
* Turns a path into an AST.
*
* @param path The path.
* @param factory The AST factory to use.
* @return An HQL AST representing the path.
*/
public static AST parsePath(String path, ASTFactory factory) {
String[] identifiers = StringHelper.split( ".", path );
AST lhs = null;
for ( int i = 0; i < identifiers.length; i++ ) {
String identifier = identifiers[i];
AST child = ASTUtil.create( factory, HqlSqlTokenTypes.IDENT, identifier );
if ( i == 0 ) {
lhs = child;
}
else {
lhs = ASTUtil.createBinarySubtree( factory, HqlSqlTokenTypes.DOT, ".", lhs, child );
}
}
if ( log.isDebugEnabled() ) {
log.debug( "parsePath() : " + path + " -> " + ASTUtil.getDebugString( lhs ) );
}
return lhs;
}
示例7: getAddForeignKeyConstraintString
import org.hibernate.util.StringHelper; //导入依赖的package包/类
public String getAddForeignKeyConstraintString(
String constraintName,
String[] foreignKey,
String referencedTable,
String[] primaryKey, boolean referencesPrimaryKey
) {
StringBuffer res = new StringBuffer(30)
.append(" foreign key ")
.append(constraintName)
.append(" (")
.append( StringHelper.join(", ", foreignKey) )
.append(") references ")
.append(referencedTable);
if(!referencesPrimaryKey) {
res.append(" (")
.append( StringHelper.join(", ", primaryKey) )
.append(')');
}
return res.toString();
}
示例8: getPojoPropertyAccessor
import org.hibernate.util.StringHelper; //导入依赖的package包/类
/**
* Retreives a PropertyAccessor specific for a PojoRepresentation with the given access strategy.
*
* @param pojoAccessorStrategy The access strategy.
* @return An appropriate accessor.
*/
private static PropertyAccessor getPojoPropertyAccessor(String pojoAccessorStrategy) {
if ( StringHelper.isEmpty( pojoAccessorStrategy ) || "property".equals( pojoAccessorStrategy ) ) {
return BASIC_PROPERTY_ACCESSOR;
}
else if ( "field".equals( pojoAccessorStrategy ) ) {
return DIRECT_PROPERTY_ACCESSOR;
}
else if ( "embedded".equals( pojoAccessorStrategy ) ) {
return EMBEDDED_PROPERTY_ACCESSOR;
}
else if ( "noop".equals(pojoAccessorStrategy) ) {
return NOOP_ACCESSOR;
}
else {
return resolveCustomAccessor( pojoAccessorStrategy );
}
}
示例9: buildCache
import org.hibernate.util.StringHelper; //导入依赖的package包/类
/**
* Builds a new {@link Cache} instance, and gets it's properties from the OSCache {@link Config}
* which reads the properties file (<code>oscache.properties</code>) from the classpath.
* If the file cannot be found or loaded, an the defaults are used.
*
* @param region
* @param properties
* @return
* @throws CacheException
*/
public Cache buildCache(String region, Properties properties) throws CacheException {
int refreshPeriod = PropertiesHelper.getInt(
StringHelper.qualify(region, OSCACHE_REFRESH_PERIOD),
OSCACHE_PROPERTIES,
CacheEntry.INDEFINITE_EXPIRY
);
String cron = OSCACHE_PROPERTIES.getProperty( StringHelper.qualify(region, OSCACHE_CRON) );
// construct the cache
final OSCache cache = new OSCache(refreshPeriod, cron, region);
Integer capacity = PropertiesHelper.getInteger( StringHelper.qualify(region, OSCACHE_CAPACITY), OSCACHE_PROPERTIES );
if ( capacity!=null ) cache.setCacheCapacity( capacity.intValue() );
return cache;
}
示例10: getAddForeignKeyConstraintString
import org.hibernate.util.StringHelper; //导入依赖的package包/类
/**
* The syntax used to add a foreign key constraint to a table.
*
* @param constraintName The FK constraint name.
* @param foreignKey The names of the columns comprising the FK
* @param referencedTable The table referenced by the FK
* @param primaryKey The explicit columns in the referencedTable referenced
* by this FK.
* @param referencesPrimaryKey if false, constraint should be
* explicit about which column names the constraint refers to
*
* @return the "add FK" fragment
*/
public String getAddForeignKeyConstraintString(
String constraintName,
String[] foreignKey,
String referencedTable,
String[] primaryKey,
boolean referencesPrimaryKey) {
StringBuffer res = new StringBuffer( 30 );
res.append( " add constraint " )
.append( constraintName )
.append( " foreign key (" )
.append( StringHelper.join( ", ", foreignKey ) )
.append( ") references " )
.append( referencedTable );
if ( !referencesPrimaryKey ) {
res.append( " (" )
.append( StringHelper.join( ", ", primaryKey ) )
.append( ')' );
}
return res.toString();
}
示例11: whereString
import org.hibernate.util.StringHelper; //导入依赖的package包/类
protected StringBuffer whereString(String alias, String[] columnNames, String subselect, int batchSize) {
if (subselect==null) {
return super.whereString(alias, columnNames, batchSize);
}
else {
StringBuffer buf = new StringBuffer();
if (columnNames.length>1) buf.append('(');
buf.append( StringHelper.join(", ", StringHelper.qualify(alias, columnNames) ) );
if (columnNames.length>1) buf.append(')');
buf.append(" in ")
.append('(')
.append(subselect)
.append(')');
return buf;
}
}
示例12: preprocess
import org.hibernate.util.StringHelper; //导入依赖的package包/类
private void preprocess(String token, QueryTranslatorImpl q) throws QueryException {
// ugly hack for cases like "elements(foo.bar.collection)"
// (multi-part path expression ending in elements or indices)
String[] tokens = StringHelper.split( ".", token, true );
if (
tokens.length > 5 &&
( CollectionPropertyNames.COLLECTION_ELEMENTS.equals( tokens[tokens.length - 1] )
|| CollectionPropertyNames.COLLECTION_INDICES.equals( tokens[tokens.length - 1] ) )
) {
pathExpressionParser.start( q );
for ( int i = 0; i < tokens.length - 3; i++ ) {
pathExpressionParser.token( tokens[i], q );
}
pathExpressionParser.token( null, q );
pathExpressionParser.end( q );
addJoin( pathExpressionParser.getWhereJoin(), q );
pathExpressionParser.ignoreInitialJoin();
}
}
示例13: toColumns
import org.hibernate.util.StringHelper; //导入依赖的package包/类
public String[] toColumns(String alias, String propertyName) throws QueryException {
//TODO: *two* hashmap lookups here is one too many...
String[] columns = (String[]) columnsByPropertyPath.get(propertyName);
if ( columns == null ) {
throw propertyException( propertyName );
}
String[] templates = (String[]) formulaTemplatesByPropertyPath.get(propertyName);
String[] result = new String[columns.length];
for ( int i=0; i<columns.length; i++ ) {
if ( columns[i]==null ) {
result[i] = StringHelper.replace( templates[i], Template.TEMPLATE, alias );
}
else {
result[i] = StringHelper.qualify( alias, columns[i] );
}
}
return result;
}
示例14: isTable
import org.hibernate.util.StringHelper; //导入依赖的package包/类
public boolean isTable(Object key) throws HibernateException {
if(key instanceof String) {
Table tbl = new Table((String)key);
if ( getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null ) {
return true;
} else {
String[] strings = StringHelper.split(".", (String) key);
if(strings.length==3) {
tbl = new Table(strings[2]);
tbl.setCatalog(strings[0]);
tbl.setSchema(strings[1]);
return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null;
} else if (strings.length==2) {
tbl = new Table(strings[1]);
tbl.setSchema(strings[0]);
return getTableMetadata( tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted() ) != null;
}
}
}
return false;
}
示例15: getAliasedLHSColumnNames
import org.hibernate.util.StringHelper; //导入依赖的package包/类
/**
* Get the aliased columns of the owning entity which are to
* be used in the join
*/
public static String[] getAliasedLHSColumnNames(
AssociationType type,
String alias,
int property,
int begin,
OuterJoinLoadable lhsPersister,
Mapping mapping
) {
if ( type.useLHSPrimaryKey() ) {
return StringHelper.qualify( alias, lhsPersister.getIdentifierColumnNames() );
}
else {
String propertyName = type.getLHSPropertyName();
if (propertyName==null) {
return ArrayHelper.slice(
lhsPersister.toColumns(alias, property),
begin,
type.getColumnSpan(mapping)
);
}
else {
return ( (PropertyMapping) lhsPersister ).toColumns(alias, propertyName); //bad cast
}
}
}