Java Code Examples for org.hibernate.internal.util.StringHelper#isEmpty()

The following examples show how to use org.hibernate.internal.util.StringHelper#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardArchiveDescriptorFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ArchiveDescriptor buildArchiveDescriptor(URL url, String entry) {
	final String protocol = url.getProtocol();
	if ( "jar".equals( protocol ) ) {
		return new JarProtocolArchiveDescriptor( this, url, entry );
	}
	else if ( StringHelper.isEmpty( protocol )
			|| "file".equals( protocol )
			|| "vfszip".equals( protocol )
			|| "vfsfile".equals( protocol ) ) {
		final File file = new File( extractLocalFilePath( url ) );
		if ( file.isDirectory() ) {
			return new ExplodedArchiveDescriptor( this, url, entry );
		}
		else {
			return new JarFileBasedArchiveDescriptor( this, url, entry );
		}
	}
	else {
		//let's assume the url can return the jar as a zip stream
		return new JarInputStreamBasedArchiveDescriptor( this, url, entry );
	}
}
 
Example 2
Source File: AbstractSchemaMigrator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void applySqlString(
		boolean quiet,
		String sqlString,
		Formatter formatter,
		ExecutionOptions options,
		GenerationTarget... targets) {
	if ( !StringHelper.isEmpty( sqlString ) ) {
		String sqlStringFormatted = formatter.format( sqlString );
		for ( GenerationTarget target : targets ) {
			try {
				target.accept( sqlStringFormatted );
			}
			catch (CommandAcceptanceException e) {
				if ( !quiet ) {
					options.getExceptionHandler().handleException( e );
				}
				// otherwise ignore the exception
			}
		}
	}
}
 
Example 3
Source File: SchemaCreatorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void applySqlString(
		String sqlString,
		Formatter formatter,
		ExecutionOptions options,
		GenerationTarget... targets) {
	if ( StringHelper.isEmpty( sqlString ) ) {
		return;
	}

	try {
		String sqlStringFormatted = formatter.format( sqlString );
		for ( GenerationTarget target : targets ) {
			target.accept( sqlStringFormatted );
		}
	}
	catch (CommandAcceptanceException e) {
		options.getExceptionHandler().handleException( e );
	}
}
 
Example 4
Source File: QueryJoinFragment.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add the condition string to the join fragment.
 *
 * @param condition
 * @return true if the condition was added, false if it was already in the fragment.
 */
public boolean addCondition(String condition) {
	// if the condition is not already there...
	if (
			!StringHelper.isEmpty( condition ) &&
			afterFrom.toString().indexOf( condition.trim() ) < 0 &&
			afterWhere.toString().indexOf( condition.trim() ) < 0
	) {
		if ( !condition.startsWith( " and " ) ) {
			afterWhere.append( " and " );
		}
		afterWhere.append( condition );
		return true;
	}
	else {
		return false;
	}
}
 
Example 5
Source File: EntityBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void bindDiscriminatorValue() {
	if ( StringHelper.isEmpty( discriminatorValue ) ) {
		Value discriminator = persistentClass.getDiscriminator();
		if ( discriminator == null ) {
			persistentClass.setDiscriminatorValue( name );
		}
		else if ( "character".equals( discriminator.getType().getName() ) ) {
			throw new AnnotationException(
					"Using default @DiscriminatorValue for a discriminator of type CHAR is not safe"
			);
		}
		else if ( "integer".equals( discriminator.getType().getName() ) ) {
			persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
		}
		else {
			persistentClass.setDiscriminatorValue( name ); //Spec compliant
		}
	}
	else {
		//persistentClass.getDiscriminator()
		persistentClass.setDiscriminatorValue( discriminatorValue );
	}
}
 
Example 6
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getCollectionTable(List<Annotation> annotationList, Element element, XMLContext.Default defaults) {
	Element subelement = element != null ? element.element( "collection-table" ) : null;
	if ( subelement != null ) {
		AnnotationDescriptor annotation = new AnnotationDescriptor( CollectionTable.class );
		copyStringAttribute( annotation, subelement, "name", false );
		copyStringAttribute( annotation, subelement, "catalog", false );
		if ( StringHelper.isNotEmpty( defaults.getCatalog() )
				&& StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) ) ) {
			annotation.setValue( "catalog", defaults.getCatalog() );
		}
		copyStringAttribute( annotation, subelement, "schema", false );
		if ( StringHelper.isNotEmpty( defaults.getSchema() )
				&& StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) ) ) {
			annotation.setValue( "schema", defaults.getSchema() );
		}
		JoinColumn[] joinColumns = getJoinColumns( subelement, false );
		if ( joinColumns.length > 0 ) {
			annotation.setValue( "joinColumns", joinColumns );
		}
		buildUniqueConstraints( annotation, subelement );
		buildIndex( annotation, subelement );
		annotationList.add( AnnotationFactory.create( annotation ) );
	}
}
 
Example 7
Source File: LoadQueryJoinAndFetchProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private String resolveAdditionalJoinCondition(String rhsTableAlias, String withClause, Joinable joinable, AssociationType associationType) {
	// turns out that the call to AssociationType#getOnCondition in the initial code really just translates to
	// calls to the Joinable.filterFragment() method where the Joinable is either the entity or
	// collection persister
	final String filter = associationType!=null?
			associationType.getOnCondition( rhsTableAlias, factory, queryInfluencers.getEnabledFilters() ):
			joinable.filterFragment(
				rhsTableAlias,
				queryInfluencers.getEnabledFilters()
	);

	if ( StringHelper.isEmpty( withClause ) && StringHelper.isEmpty( filter ) ) {
		return "";
	}
	else if ( StringHelper.isNotEmpty( withClause ) && StringHelper.isNotEmpty( filter ) ) {
		return filter + " and " + withClause;
	}
	else {
		// only one is non-empty...
		return StringHelper.isNotEmpty( filter ) ? filter : withClause;
	}
}
 
Example 8
Source File: ConfigurationHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles interpolation processing for a single property.
 *
 * @param property The property value to be processed for interpolation.
 * @return The (possibly) interpolated property value.
 */
public static String resolvePlaceHolder(String property) {
	if ( property.indexOf( PLACEHOLDER_START ) < 0 ) {
		return property;
	}
	StringBuilder buff = new StringBuilder();
	char[] chars = property.toCharArray();
	for ( int pos = 0; pos < chars.length; pos++ ) {
		if ( chars[pos] == '$' ) {
			// peek ahead
			if ( chars[pos+1] == '{' ) {
				// we have a placeholder, spin forward till we find the end
				String systemPropertyName = "";
				int x = pos + 2;
				for (  ; x < chars.length && chars[x] != '}'; x++ ) {
					systemPropertyName += chars[x];
					// if we reach the end of the string w/o finding the
					// matching end, that is an exception
					if ( x == chars.length - 1 ) {
						throw new IllegalArgumentException( "unmatched placeholder start [" + property + "]" );
					}
				}
				String systemProperty = extractFromSystem( systemPropertyName );
				buff.append( systemProperty == null ? "" : systemProperty );
				pos = x + 1;
				// make sure spinning forward did not put us past the end of the buffer...
				if ( pos >= chars.length ) {
					break;
				}
			}
		}
		buff.append( chars[pos] );
	}
	String rtn = buff.toString();
	return StringHelper.isEmpty( rtn ) ? null : rtn;
}
 
Example 9
Source File: AbstractSchemaMigrator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void applyIndexes(
		Table table,
		TableInformation tableInformation,
		Dialect dialect,
		Metadata metadata,
		Formatter formatter,
		ExecutionOptions options,
		GenerationTarget... targets) {
	final Exporter<Index> exporter = dialect.getIndexExporter();

	final Iterator<Index> indexItr = table.getIndexIterator();
	while ( indexItr.hasNext() ) {
		final Index index = indexItr.next();
		if ( !StringHelper.isEmpty( index.getName() ) ) {
			IndexInformation existingIndex = null;
			if ( tableInformation != null ) {
				existingIndex = findMatchingIndex( index, tableInformation );
			}
			if ( existingIndex == null ) {
				applySqlStrings(
						false,
						exporter.getSqlCreateStrings( index, metadata ),
						formatter,
						options,
						targets
				);
			}
		}
	}
}
 
Example 10
Source File: Identifier.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an identifier instance.
 *
 * @param text The identifier text.
 * @param quoted Is this a quoted identifier?
 */
public Identifier(String text, boolean quoted) {
	if ( StringHelper.isEmpty( text ) ) {
		throw new IllegalIdentifierException( "Identifier text cannot be null" );
	}
	if ( isQuoted( text ) ) {
		throw new IllegalIdentifierException( "Identifier text should not contain quote markers (` or \")" );
	}
	this.text = text;
	this.isQuoted = quoted;
}
 
Example 11
Source File: TableReactiveIdentifierGenerator.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected String determineSegmentValue(Properties params) {
	String segmentValue = params.getProperty( SEGMENT_VALUE_PARAM );
	if ( StringHelper.isEmpty( segmentValue ) ) {
		segmentValue = determineDefaultSegmentValue( params );
	}
	return segmentValue;
}
 
Example 12
Source File: DatabaseIdentifier.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static DatabaseIdentifier toIdentifier(String text) {
	if ( StringHelper.isEmpty( text ) ) {
		return null;
	}
	else if ( isQuoted( text ) ) {
		// exclude the quotes from text
		final String unquotedtext = text.substring( 1, text.length() - 1 );
		return new DatabaseIdentifier( unquotedtext );
	}
	else {
		return new DatabaseIdentifier( text );
	}
}
 
Example 13
Source File: AbstractArchiveDescriptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static String normalizeEntryBasePrefix(String entryBasePrefix) {
	if ( StringHelper.isEmpty( entryBasePrefix ) || entryBasePrefix.length() == 1 ) {
		return null;
	}

	return entryBasePrefix.startsWith( "/" ) ? entryBasePrefix.substring( 1 ) : entryBasePrefix;
}
 
Example 14
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private SecondaryTables getSecondaryTables(Element tree, XMLContext.Default defaults) {
	List<Element> elements = tree == null ?
			new ArrayList<>() :
			(List<Element>) tree.elements( "secondary-table" );
	List<SecondaryTable> secondaryTables = new ArrayList<>( 3 );
	for ( Element element : elements ) {
		AnnotationDescriptor annotation = new AnnotationDescriptor( SecondaryTable.class );
		copyStringAttribute( annotation, element, "name", false );
		copyStringAttribute( annotation, element, "catalog", false );
		if ( StringHelper.isNotEmpty( defaults.getCatalog() )
				&& StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) ) ) {
			annotation.setValue( "catalog", defaults.getCatalog() );
		}
		copyStringAttribute( annotation, element, "schema", false );
		if ( StringHelper.isNotEmpty( defaults.getSchema() )
				&& StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) ) ) {
			annotation.setValue( "schema", defaults.getSchema() );
		}
		buildUniqueConstraints( annotation, element );
		buildIndex( annotation, element );
		annotation.setValue( "pkJoinColumns", buildPrimaryKeyJoinColumns( element ) );
		secondaryTables.add( AnnotationFactory.create( annotation ) );
	}
	/*
	 * You can't have both secondary table in XML and Java,
	 * since there would be no way to "remove" a secondary table
	 */
	if ( secondaryTables.size() == 0 && defaults.canUseJavaAnnotations() ) {
		SecondaryTable secTableAnn = getPhysicalAnnotation( SecondaryTable.class );
		overridesDefaultInSecondaryTable( secTableAnn, defaults, secondaryTables );
		SecondaryTables secTablesAnn = getPhysicalAnnotation( SecondaryTables.class );
		if ( secTablesAnn != null ) {
			for ( SecondaryTable table : secTablesAnn.value() ) {
				overridesDefaultInSecondaryTable( table, defaults, secondaryTables );
			}
		}
	}
	if ( secondaryTables.size() > 0 ) {
		AnnotationDescriptor descriptor = new AnnotationDescriptor( SecondaryTables.class );
		descriptor.setValue( "value", secondaryTables.toArray( new SecondaryTable[secondaryTables.size()] ) );
		return AnnotationFactory.create( descriptor );
	}
	else {
		return null;
	}
}
 
Example 15
Source File: PluralAttributeSequentialIndexSourceImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public PluralAttributeSequentialIndexSourceImpl(
		MappingDocument sourceMappingDocument,
		final JaxbHbmIndexType jaxbIndex) {
	super( sourceMappingDocument );
	this.base = 0;
	this.xmlNodeName = null;
	if ( StringHelper.isEmpty( jaxbIndex.getType() ) ) {
		this.typeSource = new HibernateTypeSourceImpl( "integer" );
	}
	else {
		this.typeSource = new HibernateTypeSourceImpl( jaxbIndex.getType() );
	}
	this.valueSources = RelationalValueSourceHelper.buildValueSources(
			sourceMappingDocument,
			null,
			new RelationalValueSourceHelper.AbstractColumnsAndFormulasSource() {
				@Override
				public XmlElementMetadata getSourceType() {
					return XmlElementMetadata.INDEX;
				}

				@Override
				public String getSourceName() {
					return null;
				}

				@Override
				public String getColumnAttribute() {
					return jaxbIndex.getColumnAttribute();
				}

				@Override
				public SizeSource getSizeSource() {
					return Helper.interpretSizeSource(
							jaxbIndex.getLength(),
							(Integer) null,
							null
					);
				}

				@Override
				public List getColumnOrFormulaElements() {
					return jaxbIndex.getColumn();
				}
			}
	);
}
 
Example 16
Source File: Ejb3Column.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public boolean isNameDeferred() {
	return mappingColumn == null || StringHelper.isEmpty( mappingColumn.getName() );
}
 
Example 17
Source File: LoadQueryJoinAndFetchProcessor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void renderManyToManyJoin(
		Join join,
		JoinFragment joinFragment) {

	// for many-to-many we have 3 table aliases.  By way of example, consider a normal m-n: User<->Role
	// where User is the FetchOwner and Role (User.roles) is the Fetch.  We'd have:
	//		1) the owner's table : user - in terms of rendering the joins (not the fetch select fragments), the
	// 			lhs table alias is only needed to qualify the lhs join columns, but we already have the qualified
	// 			columns here (aliasedLhsColumnNames)
	//final String ownerTableAlias = ...;
	//		2) the m-n table : user_role
	//		3) the element table : role
	final EntityPersister entityPersister = ( (EntityQuerySpace) join.getRightHandSide() ).getEntityPersister();
	final String entityTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(
		join.getRightHandSide().getUid()
	);

	if ( StringHelper.isEmpty( entityTableAlias ) ) {
		throw new IllegalStateException( "Collection element (many-to-many) table alias cannot be empty" );
	}

	final String manyToManyFilter;
	if ( JoinDefinedByMetadata.class.isInstance( join ) &&
			CollectionPropertyNames.COLLECTION_ELEMENTS.equals( ( (JoinDefinedByMetadata) join ).getJoinedPropertyName() ) ) {
		final CollectionQuerySpace leftHandSide = (CollectionQuerySpace) join.getLeftHandSide();
		final CollectionPersister persister = leftHandSide.getCollectionPersister();
		manyToManyFilter = persister.getManyToManyFilterFragment(
				entityTableAlias,
				queryInfluencers.getEnabledFilters()
		);
	}
	else {
		manyToManyFilter = null;
	}

	addJoins(
			join,
			joinFragment,
			(Joinable) entityPersister,
			manyToManyFilter
	);
}
 
Example 18
Source File: CollectionPropertyHolder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void applyLocalConvert(
		Convert convertAnnotation,
		XProperty collectionProperty,
		Map<String,AttributeConversionInfo> elementAttributeConversionInfoMap,
		Map<String,AttributeConversionInfo> keyAttributeConversionInfoMap) {

	// IMPL NOTE : the rules here are quite more lenient than what JPA says.  For example, JPA says
	// that @Convert on a Map always needs to specify attributeName of key/value (or prefixed with
	// key./value. for embedded paths).  However, we try to see if conversion of either is disabled
	// for whatever reason.  For example, if the Map is annotated with @Enumerated the elements cannot
	// be converted so any @Convert likely meant the key, so we apply it to the key

	final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, collectionProperty );
	if ( collection.isMap() ) {
		boolean specCompliant = StringHelper.isNotEmpty( info.getAttributeName() )
				&& ( info.getAttributeName().startsWith( "key" )
				|| info.getAttributeName().startsWith( "value" ) );
		if ( !specCompliant ) {
			log.nonCompliantMapConversion( collection.getRole() );
		}
	}

	if ( StringHelper.isEmpty( info.getAttributeName() ) ) {
		// the @Convert did not name an attribute...
		if ( canElementBeConverted && canKeyBeConverted ) {
			throw new IllegalStateException(
					"@Convert placed on Map attribute [" + collection.getRole()
							+ "] must define attributeName of 'key' or 'value'"
			);
		}
		else if ( canKeyBeConverted ) {
			keyAttributeConversionInfoMap.put( "", info );
		}
		else if ( canElementBeConverted ) {
			elementAttributeConversionInfoMap.put( "", info );
		}
		// if neither, we should not be here...
	}
	else {
		// the @Convert named an attribute...

		// we have different "resolution rules" based on whether element and key can be converted
		final String keyPath;
		final String elementPath;

		if ( canElementBeConverted && canKeyBeConverted ) {
			keyPath = removePrefix( info.getAttributeName(), "key" );
			elementPath = removePrefix( info.getAttributeName(), "value" );

			if ( keyPath == null && elementPath == null ) {
				// specified attributeName needs to have 'key.' or 'value.' prefix
				throw new IllegalStateException(
						"@Convert placed on Map attribute [" + collection.getRole()
								+ "] must define attributeName of 'key' or 'value'"
				);
			}
		}
		else if ( canKeyBeConverted ) {
			keyPath = removePrefix( info.getAttributeName(), "key", info.getAttributeName() );
			elementPath = null;
		}
		else {
			keyPath = null;
			elementPath = removePrefix( info.getAttributeName(), "value", info.getAttributeName() );
		}

		if ( keyPath != null ) {
			keyAttributeConversionInfoMap.put( keyPath, info );
		}
		else if ( elementPath != null ) {
			elementAttributeConversionInfoMap.put( elementPath, info );
		}
		else {
			// specified attributeName needs to have 'key.' or 'value.' prefix
			throw new IllegalStateException(
					String.format(
							Locale.ROOT,
							"Could not determine how to apply @Convert(attributeName='%s') to collection [%s]",
							info.getAttributeName(),
							collection.getRole()
					)
			);
		}
	}
}
 
Example 19
Source File: NavigableRole.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public boolean isRoot() {
	return parent == null && StringHelper.isEmpty( navigableName );
}
 
Example 20
Source File: CompositePropertyMapping.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Builds the relative path.  Used to delegate {@link #toType(String)},
 * {@link #toColumns(String, String)} and {@link #toColumns(String)} calls out to {@link #parentPropertyMapping}.
 * <p/>
 * Called from {@link #toParentPropertyPath}.
 * <p/>
 * Override this to adjust how the relative property path is built for this mapping.
 *
 * @param propertyName The incoming property name to "path append".
 *
 * @return The relative path
 */
protected String resolveParentPropertyPath(String propertyName) {
	if ( StringHelper.isEmpty( parentPropertyName ) ) {
		return propertyName;
	}
	else {
		return parentPropertyName + '.' + propertyName;
	}
}