本文整理汇总了Java中org.hibernate.util.StringHelper.split方法的典型用法代码示例。如果您正苦于以下问题:Java StringHelper.split方法的具体用法?Java StringHelper.split怎么用?Java StringHelper.split使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.util.StringHelper
的用法示例。
在下文中一共展示了StringHelper.split方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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();
}
}
示例4: isSequence
import org.hibernate.util.StringHelper; //导入方法依赖的package包/类
public boolean isSequence(Object key) {
if (key instanceof String){
String[] strings = StringHelper.split(".", (String) key);
return sequences.contains( strings[strings.length-1].toLowerCase());
}
return false;
}
示例5: configure
import org.hibernate.util.StringHelper; //导入方法依赖的package包/类
public void configure(Type type, Properties params, Dialect dialect)
throws MappingException {
String tableList = params.getProperty("tables");
if (tableList==null) tableList = params.getProperty(PersistentIdentifierGenerator.TABLES);
String[] tables = StringHelper.split(", ", tableList);
String column = params.getProperty("column");
if (column==null) column = params.getProperty(PersistentIdentifierGenerator.PK);
String schema = params.getProperty(PersistentIdentifierGenerator.SCHEMA);
String catalog = params.getProperty(PersistentIdentifierGenerator.CATALOG);
returnClass = type.getReturnedClass();
StringBuffer buf = new StringBuffer();
for ( int i=0; i<tables.length; i++ ) {
if (tables.length>1) {
buf.append("select ").append(column).append(" from ");
}
buf.append( Table.qualify( catalog, schema, tables[i] ) );
if ( i<tables.length-1) buf.append(" union ");
}
if (tables.length>1) {
buf.insert(0, "( ").append(" ) ids_");
column = "ids_." + column;
}
sql = "select max(" + column + ") from " + buf.toString();
}
示例6: testStr
import org.hibernate.util.StringHelper; //导入方法依赖的package包/类
public void testStr() {
Session session = openSession();
Transaction txn = session.beginTransaction();
Animal an = new Animal();
an.setBodyWeight(123.45f);
session.persist(an);
String str = (String) session.createQuery("select str(an.bodyWeight) from Animal an where str(an.bodyWeight) like '123%' or str(an.bodyWeight) like '1.23%'").uniqueResult();
if ( getDialect() instanceof DB2Dialect ) {
assertTrue( str.startsWith("1.234") );
}
else if ( getDialect() instanceof SQLServerDialect ) {
// no assertion as SQLServer always returns nulls here; even trying directly against the
// database, it seems to have problems with str() in the where clause...
}
else {
assertTrue( str.startsWith("123.4") );
}
if ( ! ( getDialect() instanceof SybaseDialect ) ) {
// In TransactSQL (the variant spoken by Sybase and SQLServer), the str() function
// is explicitly intended for numeric values only...
String dateStr1 = (String) session.createQuery("select str(current_date) from Animal").uniqueResult();
String dateStr2 = (String) session.createQuery("select str(year(current_date))||'-'||str(month(current_date))||'-'||str(day(current_date)) from Animal").uniqueResult();
System.out.println(dateStr1 + '=' + dateStr2);
if ( ! ( getDialect() instanceof Oracle9Dialect || getDialect() instanceof Oracle8iDialect ) ) { //Oracle renders the name of the month :(
String[] dp1 = StringHelper.split("-", dateStr1);
String[] dp2 = StringHelper.split("-", dateStr2);
for (int i=0; i<3; i++) {
if ( dp1[i].startsWith( "0" ) ) {
dp1[i] = dp1[i].substring( 1 );
}
assertEquals( dp1[i], dp2[i] );
}
}
}
session.delete(an);
txn.commit();
session.close();
}
示例7: concreteQueries
import org.hibernate.util.StringHelper; //导入方法依赖的package包/类
/**
* Handle Hibernate "implicit" polymorphism, by translating the query string into
* several "concrete" queries against mapped classes.
*/
public static String[] concreteQueries(String query, SessionFactoryImplementor factory) throws MappingException {
//scan the query string for class names appearing in the from clause and replace
//with all persistent implementors of the class/interface, returning multiple
//query strings (make sure we don't pick up a class in the select clause!)
//TODO: this is one of the ugliest and most fragile pieces of code in Hibernate....
String[] tokens = StringHelper.split( StringHelper.WHITESPACE + "(),", query, true );
if ( tokens.length == 0 ) return new String[]{query}; // just especially for the trivial collection filter
ArrayList placeholders = new ArrayList();
ArrayList replacements = new ArrayList();
StringBuffer templateQuery = new StringBuffer( 40 );
int count = 0;
String last = null;
int nextIndex = 0;
String next = null;
boolean isSelectClause = false;
templateQuery.append( tokens[0] );
if ( "select".equals( tokens[0].toLowerCase() ) ) isSelectClause = true;
for ( int i = 1; i < tokens.length; i++ ) {
//update last non-whitespace token, if necessary
if ( !ParserHelper.isWhitespace( tokens[i - 1] ) ) last = tokens[i - 1].toLowerCase();
// select-range is terminated by declaration of "from"
if ( "from".equals( tokens[i].toLowerCase() ) ) isSelectClause = false;
String token = tokens[i];
if ( !ParserHelper.isWhitespace( token ) || last == null ) {
//scan for next non-whitespace token
if ( nextIndex <= i ) {
for ( nextIndex = i + 1; nextIndex < tokens.length; nextIndex++ ) {
next = tokens[nextIndex].toLowerCase();
if ( !ParserHelper.isWhitespace( next ) ) break;
}
}
boolean process = !isSelectClause &&
isJavaIdentifier( token ) &&
isPossiblyClassName( last, next );
if (process) {
String importedClassName = getImportedClass( token, factory );
if ( importedClassName != null ) {
String[] implementors = factory.getImplementors( importedClassName );
String placeholder = "$clazz" + count++ + "$";
if ( implementors != null ) {
placeholders.add( placeholder );
replacements.add( implementors );
}
token = placeholder; // Note this!!
}
}
}
templateQuery.append( token );
}
String[] results = StringHelper.multiply( templateQuery.toString(), placeholders.iterator(), replacements.iterator() );
if ( results.length == 0 ) log.warn( "no persistent classes found for query class: " + query );
return results;
}