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

The following examples show how to use org.hibernate.internal.util.StringHelper#nullIfEmpty() . 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: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Yuck.  This is needed because JPA lets users define "global building options"
 * in {@code orm.xml} mappings.  Forget that there are generally multiple
 * {@code orm.xml} mappings if using XML approach...  Ugh
 */
public void apply(JpaOrmXmlPersistenceUnitDefaults jpaOrmXmlPersistenceUnitDefaults) {
	if ( !mappingDefaults.shouldImplicitlyQuoteIdentifiers() ) {
		mappingDefaults.implicitlyQuoteIdentifiers = jpaOrmXmlPersistenceUnitDefaults.shouldImplicitlyQuoteIdentifiers();
	}

	if ( mappingDefaults.getImplicitCatalogName() == null ) {
		mappingDefaults.implicitCatalogName = StringHelper.nullIfEmpty(
				jpaOrmXmlPersistenceUnitDefaults.getDefaultCatalogName()
		);
	}

	if ( mappingDefaults.getImplicitSchemaName() == null ) {
		mappingDefaults.implicitSchemaName = StringHelper.nullIfEmpty(
				jpaOrmXmlPersistenceUnitDefaults.getDefaultSchemaName()
		);
	}
}
 
Example 2
Source File: Helper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static Caching createNaturalIdCaching(JaxbHbmNaturalIdCacheType cacheElement) {
	if ( cacheElement == null ) {
		return new Caching( TruthValue.UNKNOWN );
	}

	return new Caching(
			StringHelper.nullIfEmpty( cacheElement.getRegion() ),
			null,
			false,
			TruthValue.TRUE
	);
}
 
Example 3
Source File: PluralAttributeKeySourceImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public PluralAttributeKeySourceImpl(
		MappingDocument mappingDocument,
		final JaxbHbmKeyType jaxbKey,
		final AttributeSourceContainer container) {
	super( mappingDocument );

	this.explicitFkName = StringHelper.nullIfEmpty( jaxbKey.getForeignKey() );
	this.referencedPropertyName = StringHelper.nullIfEmpty( jaxbKey.getPropertyRef() );
	this.cascadeDeletesAtFkLevel = jaxbKey.getOnDelete() != null
			&& "cascade".equals( jaxbKey.getOnDelete().value() );
	this.nullable = jaxbKey.isNotNull() == null || !jaxbKey.isNotNull();
	this.updateable = jaxbKey.isUpdate() == null || jaxbKey.isUpdate();

	this.valueSources = RelationalValueSourceHelper.buildValueSources(
			sourceMappingDocument(),
			null, // todo : collection table name
			new RelationalValueSourceHelper.AbstractColumnsAndFormulasSource() {
				@Override
				public XmlElementMetadata getSourceType() {
					return XmlElementMetadata.KEY;
				}

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

				@Override
				public String getColumnAttribute() {
					return StringHelper.nullIfEmpty( jaxbKey.getColumnAttribute() );
				}

				@Override
				public List getColumnOrFormulaElements() {
					return jaxbKey.getColumn();
				}

			}
	);
}
 
Example 4
Source File: PluralAttributeKeySourceImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public PluralAttributeKeySourceImpl(
		MappingDocument mappingDocument,
		final JaxbHbmManyToOneType jaxbKey,
		final AttributeSourceContainer container) {
	super( mappingDocument );

	this.explicitFkName = StringHelper.nullIfEmpty( jaxbKey.getForeignKey() );
	this.referencedPropertyName = StringHelper.nullIfEmpty( jaxbKey.getPropertyRef() );
	this.cascadeDeletesAtFkLevel = jaxbKey.getOnDelete() != null
			&& "cascade".equals( jaxbKey.getOnDelete().value() );
	this.nullable = jaxbKey.isNotNull() == null || !jaxbKey.isNotNull();
	this.updateable = jaxbKey.isUpdate();

	this.valueSources = RelationalValueSourceHelper.buildValueSources(
			sourceMappingDocument(),
			null, // todo : collection table name
			new RelationalValueSourceHelper.AbstractColumnsAndFormulasSource() {
				@Override
				public XmlElementMetadata getSourceType() {
					return XmlElementMetadata.KEY;
				}

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

				@Override
				public String getColumnAttribute() {
					return StringHelper.nullIfEmpty( jaxbKey.getColumnAttribute() );
				}

				@Override
				public List getColumnOrFormulaElements() {
					return jaxbKey.getColumnOrFormula();
				}

			}
	);
}
 
Example 5
Source File: Collection.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setCacheRegionName(String cacheRegionName) {
	this.cacheRegionName = StringHelper.nullIfEmpty( cacheRegionName );
}
 
Example 6
Source File: RootClass.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setCacheRegionName(String cacheRegionName) {
	this.cacheRegionName = StringHelper.nullIfEmpty( cacheRegionName );
}
 
Example 7
Source File: Column.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setCustomRead(String customRead) {
	this.customRead = StringHelper.nullIfEmpty( customRead );
}
 
Example 8
Source File: NamedQueryBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static boolean processNamedQueryContentItem(
		Object content,
		NamedSQLQueryDefinitionBuilder builder,
		ImplicitResultSetMappingDefinition.Builder implicitResultSetMappingBuilder,
		JaxbHbmNamedNativeQueryType namedQueryBinding,
		HbmLocalMetadataBuildingContext context) {
	if ( String.class.isInstance( content ) ) {
		// Especially when the query string is wrapped in CDATA we will get
		// "extra" Strings here containing just spaces and/or newlines.  This
		// bit tries to account for them.
		final String contentString = StringHelper.nullIfEmpty( ( (String) content ).trim() );
		if ( contentString != null ) {
			builder.setQuery( (String) content );
			return true;
		}
		else {
			return false;
		}
	}
	else if ( JAXBElement.class.isInstance( content ) ) {
		return processNamedQueryContentItem(
				( (JAXBElement) content ).getValue(),
				builder,
				implicitResultSetMappingBuilder,
				namedQueryBinding,
				context
		);
	}

	if ( JaxbHbmQueryParamType.class.isInstance( content ) ) {
		final JaxbHbmQueryParamType paramTypeBinding = (JaxbHbmQueryParamType) content;
		builder.addParameterType( paramTypeBinding.getName(), paramTypeBinding.getType() );
	}
	else if ( JaxbHbmSynchronizeType.class.isInstance( content ) ) {
		final JaxbHbmSynchronizeType synchronizedSpace = (JaxbHbmSynchronizeType) content;
		builder.addSynchronizedQuerySpace( synchronizedSpace.getTable() );
	}
	else if ( JaxbHbmNativeQueryScalarReturnType.class.isInstance( content ) ) {
		implicitResultSetMappingBuilder.addReturn( (JaxbHbmNativeQueryScalarReturnType) content );
	}
	else if ( JaxbHbmNativeQueryReturnType.class.isInstance( content ) ) {
		implicitResultSetMappingBuilder.addReturn( (JaxbHbmNativeQueryReturnType) content );
	}
	else if ( JaxbHbmNativeQueryJoinReturnType.class.isInstance( content ) ) {
		implicitResultSetMappingBuilder.addReturn( (JaxbHbmNativeQueryJoinReturnType) content );
	}
	else if ( JaxbHbmNativeQueryCollectionLoadReturnType.class.isInstance( content ) ) {
		implicitResultSetMappingBuilder.addReturn( (JaxbHbmNativeQueryCollectionLoadReturnType) content );
	}
	else {
		throw new org.hibernate.boot.MappingException(
				String.format(
						Locale.ENGLISH,
						"Encountered unexpected content type [%s] for named native query [%s] : [%s]",
						content.getClass().getName(),
						namedQueryBinding.getName(),
						content.toString()
				),
				context.getOrigin()
		);
	}

	return false;
}