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

The following examples show how to use org.hibernate.internal.util.StringHelper#isNotEmpty() . 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: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static ColumnResult buildColumnResult(
			Element columnResultElement,
			XMLContext.Default defaults,
			ClassLoaderAccess classLoaderAccess) {
//		AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor( ColumnResult.class );
//		copyStringAttribute( columnResultDescriptor, columnResultElement, "name", true );
//		return AnnotationFactory.create( columnResultDescriptor );

		AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor( ColumnResult.class );
		copyStringAttribute( columnResultDescriptor, columnResultElement, "name", true );
		final String columnTypeName = columnResultElement.attributeValue( "class" );
		if ( StringHelper.isNotEmpty( columnTypeName ) ) {
			columnResultDescriptor.setValue( "type", resolveClassReference( columnTypeName, defaults, classLoaderAccess ) );
		}
		return AnnotationFactory.create( columnResultDescriptor );
	}
 
Example 2
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private JoinTable buildJoinTable(Element tree, XMLContext.Default defaults) {
	Element subelement = tree == null ? null : tree.element( "join-table" );
	final Class<JoinTable> annotationType = JoinTable.class;
	if ( subelement == null ) {
		return null;
	}
	//ignore java annotation, an element is defined
	AnnotationDescriptor annotation = new AnnotationDescriptor( annotationType );
	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() );
	}
	buildUniqueConstraints( annotation, subelement );
	buildIndex( annotation, subelement );
	annotation.setValue( "joinColumns", getJoinColumns( subelement, false ) );
	annotation.setValue( "inverseJoinColumns", getJoinColumns( subelement, true ) );
	return AnnotationFactory.create( annotation );
}
 
Example 3
Source File: NamedProcedureCallDefinition.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
ParameterDefinitions(StoredProcedureParameter[] parameters, Map<String, Object> queryHintMap) {
	if ( parameters == null || parameters.length == 0 ) {
		parameterStrategy = ParameterStrategy.POSITIONAL;
		parameterDefinitions = new ParameterDefinition[0];
	}
	else {
		parameterStrategy = StringHelper.isNotEmpty( parameters[0].name() )
				? ParameterStrategy.NAMED
				: ParameterStrategy.POSITIONAL;
		parameterDefinitions = new ParameterDefinition[ parameters.length ];

		for ( int i = 0; i < parameters.length; i++ ) {
			parameterDefinitions[i] = ParameterDefinition.from(
					parameterStrategy,
					parameters[i],
					// i+1 for the position because the apis say the numbers are 1-based, not zero
					i+1,
					queryHintMap
			);
		}
	}
}
 
Example 4
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 5
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getEnumerated(List<Annotation> annotationList, Element element) {
	Element subElement = element != null ? element.element( "enumerated" ) : null;
	if ( subElement != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Enumerated.class );
		String enumerated = subElement.getTextTrim();
		if ( "ORDINAL".equalsIgnoreCase( enumerated ) ) {
			ad.setValue( "value", EnumType.ORDINAL );
		}
		else if ( "STRING".equalsIgnoreCase( enumerated ) ) {
			ad.setValue( "value", EnumType.STRING );
		}
		else if ( StringHelper.isNotEmpty( enumerated ) ) {
			throw new AnnotationException( "Unknown EnumType: " + enumerated + ". " + SCHEMA_VALIDATION );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example 6
Source File: OptimizerFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determine the optimizer to use when there was not one explicitly specified.
 */
public static String determineImplicitOptimizerName(int incrementSize, Properties configSettings) {
	if ( incrementSize <= 1 ) {
		return StandardOptimizerDescriptor.NONE.getExternalName();
	}

	// see if the user defined a preferred pooled optimizer...
	final String preferredPooledOptimizerStrategy = configSettings.getProperty( AvailableSettings.PREFERRED_POOLED_OPTIMIZER );
	if ( StringHelper.isNotEmpty( preferredPooledOptimizerStrategy ) ) {
		return preferredPooledOptimizerStrategy;
	}

	// otherwise fallback to the fallback strategy (considering the deprecated PREFER_POOLED_VALUES_LO setting)
	return ConfigurationHelper.getBoolean( AvailableSettings.PREFER_POOLED_VALUES_LO, configSettings, false )
			? StandardOptimizerDescriptor.POOLED_LO.getExternalName()
			: StandardOptimizerDescriptor.POOLED.getExternalName();
}
 
Example 7
Source File: MappingReference.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static MappingReference consume(JaxbCfgMappingReferenceType jaxbMapping) {
	if ( StringHelper.isNotEmpty( jaxbMapping.getClazz() ) ) {
		return new MappingReference( MappingReference.Type.CLASS, jaxbMapping.getClazz() );
	}
	else if ( StringHelper.isNotEmpty( jaxbMapping.getFile() ) ) {
		return  new MappingReference( MappingReference.Type.FILE, jaxbMapping.getFile() );
	}
	else if ( StringHelper.isNotEmpty( jaxbMapping.getResource() ) ) {
		return new MappingReference( MappingReference.Type.RESOURCE, jaxbMapping.getResource() );
	}
	else if ( StringHelper.isNotEmpty( jaxbMapping.getJar() ) ) {
		return new MappingReference( MappingReference.Type.JAR, jaxbMapping.getJar() );
	}
	else if ( StringHelper.isNotEmpty( jaxbMapping.getPackage() ) ) {
		return new MappingReference( MappingReference.Type.PACKAGE, jaxbMapping.getPackage() );
	}
	else {
		throw new ConfigurationException( "<mapping/> named unexpected reference type" );
	}
}
 
Example 8
Source File: FastBootMetadataBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void applyJdbcConnectionProperties(Map<String, Object> configurationValues) {
    final String driver = (String) configurationValues.get(JPA_JDBC_DRIVER);
    if (StringHelper.isNotEmpty(driver)) {
        configurationValues.put(DRIVER, driver);
    }
    final String url = (String) configurationValues.get(JPA_JDBC_URL);
    if (StringHelper.isNotEmpty(url)) {
        configurationValues.put(URL, url);
    }
    final String user = (String) configurationValues.get(JPA_JDBC_USER);
    if (StringHelper.isNotEmpty(user)) {
        configurationValues.put(USER, user);
    }
    final String pass = (String) configurationValues.get(JPA_JDBC_PASSWORD);
    if (StringHelper.isNotEmpty(pass)) {
        configurationValues.put(PASS, pass);
    }
}
 
Example 9
Source File: RelationalValueSourceHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a {@link ColumnsAndFormulasSource}, build the corresponding list of
 * {@link ColumnSource}.  Any formula, rather than a column, will result in an exception.
 *
 * @param mappingDocument the mapping document
 * @param containingTableName The logical name of the table containing the relational values
 * @param columnsAndFormulasSource the adapter describing the value sources.
 *
 * @return The corresponding list.
 */
public static List<ColumnSource> buildColumnSources(
		MappingDocument mappingDocument,
		String containingTableName,
		RelationalValueSourceHelper.ColumnsAndFormulasSource columnsAndFormulasSource) {
	final List<RelationalValueSource> sources = buildValueSources(
			mappingDocument,
			containingTableName,
			columnsAndFormulasSource
	);

	final List<ColumnSource> columnSources = CollectionHelper.arrayList( sources.size() );
	for ( RelationalValueSource source : sources ) {
		if ( !ColumnSource.class.isInstance( source ) ) {
			final String errorMessage;
			if ( columnsAndFormulasSource.getSourceType().canBeNamed()
					&& StringHelper.isNotEmpty( columnsAndFormulasSource.getSourceName() ) ) {
				errorMessage = String.format(
						Locale.ENGLISH,
						"Expecting only columns in context of <%s name=\"%s\"/>, but found formula [%s]",
						columnsAndFormulasSource.getSourceType().getElementName(),
						columnsAndFormulasSource.getSourceName(),
						( (DerivedValueSource) source ).getExpression()
				);
			}
			else {
				errorMessage = String.format(
						Locale.ENGLISH,
						"Expecting only columns in context of <%s/>, but found formula [%s]",
						columnsAndFormulasSource.getSourceType().getElementName(),
						( (DerivedValueSource) source ).getExpression()
				);
			}
			throw new MappingException( errorMessage, mappingDocument.getOrigin() );
		}
		columnSources.add( (ColumnSource) source );
	}
	return columnSources;
}
 
Example 10
Source File: AbstractCollectionLoadQueryDetails.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void applyRootReturnOrderByFragments(SelectStatementBuilder selectStatementBuilder) {
	final String ordering = getQueryableCollection().getSQLOrderByString( getRootTableAlias() );
	if ( StringHelper.isNotEmpty( ordering ) ) {
		selectStatementBuilder.appendOrderByFragment( ordering );
	}
}
 
Example 11
Source File: EntityHierarchyBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void linkAnyWaiting(
		MappingDocument mappingDocument,
		AbstractEntitySourceImpl entitySource) {
	if ( toBeLinkedQueue == null ) {
		return;
	}

	List<ExtendsQueueEntry> waitingList = toBeLinkedQueue.remove( entitySource.jaxbEntityMapping().getEntityName() );
	if ( waitingList != null ) {
		processWaitingSubEntityMappings( entitySource, waitingList );
		waitingList.clear();
	}

	if ( StringHelper.isNotEmpty( entitySource.jaxbEntityMapping().getName() ) ) {
		final String entityClassName = entitySource.jaxbEntityMapping().getName();
		waitingList = toBeLinkedQueue.remove( entityClassName );
		if ( waitingList != null ) {
			processWaitingSubEntityMappings( entitySource, waitingList );
			waitingList.clear();
		}

		final String qualifiedEntityClassName = mappingDocument.qualifyClassName( entityClassName );
		if ( !entityClassName.equals( qualifiedEntityClassName ) ) {
			waitingList = toBeLinkedQueue.remove( qualifiedEntityClassName );
			if ( waitingList != null ) {
				processWaitingSubEntityMappings( entitySource, waitingList );
				waitingList.clear();
			}
		}
	}
}
 
Example 12
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String qualifyConverterAttributeName(String attributeNamePrefix, String specifiedAttributeName) {
	String qualifiedAttributeName;
	if ( StringHelper.isNotEmpty( specifiedAttributeName ) ) {
		if ( StringHelper.isNotEmpty( attributeNamePrefix ) ) {
			qualifiedAttributeName = attributeNamePrefix + '.' + specifiedAttributeName;
		}
		else {
			qualifiedAttributeName = specifiedAttributeName;
		}
	}
	else {
		qualifiedAttributeName = "";
	}
	return qualifiedAttributeName;
}
 
Example 13
Source File: EJB3NamingStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public String logicalColumnName(String columnName, String propertyName) {
	return StringHelper.isNotEmpty( columnName ) ? columnName : StringHelper.unqualify( propertyName );
}
 
Example 14
Source File: OverriddenMappingDefaults.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Builder setImplicitCascadeStyleName(String implicitCascadeStyleName) {
	if ( StringHelper.isNotEmpty( implicitCascadeStyleName ) ) {
		this.implicitCascadeStyleName = implicitCascadeStyleName;
	}
	return this;
}
 
Example 15
Source File: NamedProcedureCallDefinition.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static String normalize(String name) {
	return StringHelper.isNotEmpty( name ) ? name : null;
}
 
Example 16
Source File: SingularAttributeSourceOneToOneImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
SingularAttributeSourceOneToOneImpl(
		MappingDocument mappingDocument,
		AttributeSourceContainer container,
		final JaxbHbmOneToOneType oneToOneElement,
		final String logicalTableName,
		NaturalIdMutability naturalIdMutability) {
	super( mappingDocument, naturalIdMutability );
	this.oneToOneElement = oneToOneElement;

	this.referencedTypeName = oneToOneElement.getClazz() != null
			? metadataBuildingContext().qualifyClassName( oneToOneElement.getClazz() )
			: oneToOneElement.getEntityName();
	final JavaTypeDescriptor referencedTypeDescriptor = new JavaTypeDescriptor() {
		@Override
		public String getName() {
			return referencedTypeName;
		}
	};
	this.typeSource = new HibernateTypeSourceImpl( referencedTypeDescriptor );

	if ( StringHelper.isNotEmpty( oneToOneElement.getFormulaAttribute() ) ) {
		formulaSources = Collections.singletonList(
				(DerivedValueSource) new FormulaImpl( mappingDocument, logicalTableName, oneToOneElement.getFormulaAttribute() )
		);
	}
	else if ( !oneToOneElement.getFormula().isEmpty() ) {
		this.formulaSources = CollectionHelper.arrayList( oneToOneElement.getFormula().size() );
		for ( String expression : oneToOneElement.getFormula() ) {
			formulaSources.add(
					new FormulaImpl( mappingDocument, logicalTableName, expression )
			);
		}
	}
	else {
		this.formulaSources = Collections.emptyList();
	}

	this.attributeRole = container.getAttributeRoleBase().append( oneToOneElement.getName() );
	this.attributePath = container.getAttributePathBase().append( oneToOneElement.getName() );

	this.fetchCharacteristics = FetchCharacteristicsSingularAssociationImpl.interpretOneToOne(
			mappingDocument.getMappingDefaults(),
			oneToOneElement.getFetch(),
			oneToOneElement.getOuterJoin(),
			oneToOneElement.getLazy(),
			oneToOneElement.isConstrained()
	);

	this.toolingHintContext = Helper.collectToolingHints(
			container.getToolingHintContext(),
			oneToOneElement
	);
}
 
Example 17
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void bindManyToOneAttribute(
		final MappingDocument sourceDocument,
		final SingularAttributeSourceManyToOne manyToOneSource,
		ManyToOne manyToOneBinding,
		String referencedEntityName) {
	// NOTE : no type information to bind

	manyToOneBinding.setReferencedEntityName( referencedEntityName );
	if ( StringHelper.isNotEmpty( manyToOneSource.getReferencedEntityAttributeName() ) ) {
		manyToOneBinding.setReferencedPropertyName( manyToOneSource.getReferencedEntityAttributeName() );
		manyToOneBinding.setReferenceToPrimaryKey( false );
	}
	else {
		manyToOneBinding.setReferenceToPrimaryKey( true );
	}

	manyToOneBinding.setLazy( manyToOneSource.getFetchCharacteristics().getFetchTiming() == FetchTiming.DELAYED );
	manyToOneBinding.setUnwrapProxy( manyToOneSource.getFetchCharacteristics().isUnwrapProxies() );
	manyToOneBinding.setFetchMode(
			manyToOneSource.getFetchCharacteristics().getFetchStyle() == FetchStyle.SELECT
					? FetchMode.SELECT
					: FetchMode.JOIN
	);

	if ( manyToOneSource.isEmbedXml() == Boolean.TRUE ) {
		DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfEmbedXmlSupport();
	}

	manyToOneBinding.setIgnoreNotFound( manyToOneSource.isIgnoreNotFound() );

	if ( StringHelper.isNotEmpty( manyToOneSource.getExplicitForeignKeyName() ) ) {
		manyToOneBinding.setForeignKeyName( manyToOneSource.getExplicitForeignKeyName() );
	}

	final ManyToOneColumnBinder columnBinder = new ManyToOneColumnBinder(
			sourceDocument,
			manyToOneSource,
			manyToOneBinding,
			referencedEntityName
	);
	final boolean canBindColumnsImmediately = columnBinder.canProcessImmediately();
	if ( canBindColumnsImmediately ) {
		columnBinder.doSecondPass( null );
	}
	else {
		sourceDocument.getMetadataCollector().addSecondPass( columnBinder );
	}

	if ( !manyToOneSource.isIgnoreNotFound() ) {
		// we skip creating the FK here since this setting tells us there
		// cannot be a suitable/proper FK
		final ManyToOneFkSecondPass fkSecondPass = new ManyToOneFkSecondPass(
				sourceDocument,
				manyToOneSource,
				manyToOneBinding,
				referencedEntityName
		);

		if ( canBindColumnsImmediately && fkSecondPass.canProcessImmediately() ) {
			fkSecondPass.doSecondPass( null );
		}
		else {
			sourceDocument.getMetadataCollector().addSecondPass( fkSecondPass );
		}
	}

	manyToOneBinding.setCascadeDeleteEnabled( manyToOneSource.isCascadeDeleteEnabled() );
}
 
Example 18
Source File: Ejb3Column.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public boolean isFormula() {
	return StringHelper.isNotEmpty( formulaString );
}
 
Example 19
Source File: AbstractSchemaMigrator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected void applyUniqueKeys(
		Table table,
		TableInformation tableInfo,
		Dialect dialect,
		Metadata metadata,
		Formatter formatter,
		ExecutionOptions options,
		GenerationTarget... targets) {
	if ( uniqueConstraintStrategy == null ) {
		uniqueConstraintStrategy = determineUniqueConstraintSchemaUpdateStrategy( metadata );
	}

	if ( uniqueConstraintStrategy != UniqueConstraintSchemaUpdateStrategy.SKIP ) {
		final Exporter<Constraint> exporter = dialect.getUniqueKeyExporter();

		final Iterator ukItr = table.getUniqueKeyIterator();
		while ( ukItr.hasNext() ) {
			final UniqueKey uniqueKey = (UniqueKey) ukItr.next();
			// Skip if index already exists. Most of the time, this
			// won't work since most Dialects use Constraints. However,
			// keep it for the few that do use Indexes.
			IndexInformation indexInfo = null;
			if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
				indexInfo = tableInfo.getIndex( Identifier.toIdentifier( uniqueKey.getName() ) );
			}
			if ( indexInfo == null ) {
				if ( uniqueConstraintStrategy == UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) {
					applySqlStrings(
							true,
							exporter.getSqlDropStrings( uniqueKey, metadata ),
							formatter,
							options,
							targets
					);
				}

				applySqlStrings(
						true,
						exporter.getSqlCreateStrings( uniqueKey, metadata ),
						formatter,
						options,
						targets
				);
			}
		}
	}
}
 
Example 20
Source File: DefaultNamingStrategy.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the column name if explicit or the concatenation of the property name and the referenced column
 *
 */
public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) {
	return StringHelper.isNotEmpty( columnName ) ? columnName : propertyName + "_" + referencedColumn;
}