private String injectCatalogAndSchema(String ddlString) { String rtn = StringHelper.replace( ddlString, CATALOG_NAME_PLACEHOLDER, catalogName == null ? "" : catalogName); rtn = StringHelper.replace(rtn, SCHEMA_NAME_PLACEHOLDER, schemaName == null ? "" : schemaName); return rtn; }
@Override protected void addColumnBinding(SimpleValue value) { if (StringHelper.isEmpty(mappedBy)) { // was the column explicitly quoted in the mapping/annotation // TODO: in metamodel, we need to better split global quoting and explicit quoting w/ respect // to logical names boolean isLogicalColumnQuoted = StringHelper.isQuoted(getLogicalColumnName()); final ObjectNameNormalizer nameNormalizer = getBuildingContext().getObjectNameNormalizer(); final String logicalColumnName = nameNormalizer.normalizeIdentifierQuotingAsString(getLogicalColumnName()); final String referencedColumn = nameNormalizer.normalizeIdentifierQuotingAsString(getReferencedColumn()); final String unquotedLogColName = StringHelper.unquote(logicalColumnName); final String unquotedRefColumn = StringHelper.unquote(referencedColumn); String logicalCollectionColumnName = StringHelper.isNotEmpty(unquotedLogColName) ? unquotedLogColName : getPropertyName() + '_' + unquotedRefColumn; logicalCollectionColumnName = getBuildingContext() .getMetadataCollector() .getDatabase() .getJdbcEnvironment() .getIdentifierHelper() .toIdentifier(logicalCollectionColumnName, isLogicalColumnQuoted) .render(); getBuildingContext() .getMetadataCollector() .addColumnNameBinding(value.getTable(), logicalCollectionColumnName, getMappingColumn()); } }
private AnnotationInstance overrideSchemaCatalogByDefault( AnnotationInstance annotationInstance, EntityMappingsMocker.Default defaults) { List<AnnotationValue> newAnnotationValueList = new ArrayList<AnnotationValue>(); newAnnotationValueList.addAll(annotationInstance.values()); boolean schemaDefined = false; boolean catalogDefined = false; if (annotationInstance.value("schema") != null) { schemaDefined = true; } if (annotationInstance.value("catalog") != null) { catalogDefined = true; } if (schemaDefined && catalogDefined) { return annotationInstance; } if (!catalogDefined && StringHelper.isNotEmpty(defaults.getCatalog())) { newAnnotationValueList.add( AnnotationValue.createStringValue("catalog", defaults.getCatalog())); } if (!schemaDefined && StringHelper.isNotEmpty(defaults.getSchema())) { newAnnotationValueList.add(AnnotationValue.createStringValue("schema", defaults.getSchema())); } return MockHelper.create( annotationInstance.name(), annotationInstance.target(), MockHelper.toArray(newAnnotationValueList)); }
private Map buildSettings() { Map settings = getConfig(); addMappings(settings); if (createSchema()) { settings.put(org.hibernate.cfg.AvailableSettings.HBM2DDL_AUTO, "create-drop"); final String secondSchemaName = createSecondSchema(); if (StringHelper.isNotEmpty(secondSchemaName)) { if (!(getDialect() instanceof H2Dialect)) { throw new UnsupportedOperationException( "Only H2 dialect supports creation of second schema."); } Helper.createH2Schema(secondSchemaName, settings); } } if (StringHelper.isNotEmpty(getAuditStrategy())) { settings.put(EnversSettings.AUDIT_STRATEGY, getAuditStrategy()); } if (!autoRegisterListeners()) { settings.put(EnversIntegrator.AUTO_REGISTER, "false"); } settings.put(EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false"); settings.put(org.hibernate.cfg.AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); settings.put(org.hibernate.cfg.AvailableSettings.DIALECT, getDialect().getClass().getName()); return settings; }
private String getWholeAssociationPath(CriteriaImpl.Subcriteria subcriteria) { String path = subcriteria.getPath(); // some messy, complex stuff here, since createCriteria() can take an // aliased path, or a path rooted at the creating criteria instance Criteria parent = null; if (path.indexOf('.') > 0) { // if it is a compound path String testAlias = StringHelper.root(path); if (!testAlias.equals(subcriteria.getAlias())) { // and the qualifier is not the alias of this criteria // -> check to see if we belong to some criteria other // than the one that created us parent = aliasCriteriaMap.get(testAlias); } } if (parent == null) { // otherwise assume the parent is the the criteria that created us parent = subcriteria.getParent(); } else { path = StringHelper.unroot(path); } if (parent.equals(rootCriteria)) { // if its the root criteria, we are done return path; } else { // otherwise, recurse return getWholeAssociationPath((CriteriaImpl.Subcriteria) parent) + '.' + path; } }
/* 247: */ /* 248: */ static String buildSafeClassName(String className, String defaultPackageName) /* 249: */ { /* 250:286 */ if ((className.indexOf('.') < 0) && (StringHelper.isNotEmpty(defaultPackageName))) { /* 251:287 */ className = StringHelper.qualify(defaultPackageName, className); /* 252: */ } /* 253:289 */ return className; /* 254: */ }
public static Identifier resolveIdentifier( String explicitName, String defaultName, boolean globalQuoting) { String name = StringHelper.isNotEmpty(explicitName) ? explicitName : defaultName; if (globalQuoting) { name = StringHelper.quote(name); } return Identifier.toIdentifier(name); }
public String toSubselectString(String ukname) { String[] joinColumns = ukname == null ? StringHelper.qualify(alias, loadable.getIdentifierColumnNames()) : ((PropertyMapping) loadable).toColumns(alias, ukname); return "select " + StringHelper.join(", ", joinColumns) + queryString; }
static String buildSafeClassName(String className, String defaultPackageName) { if (className != null && className.indexOf('.') < 0 && StringHelper.isNotEmpty(defaultPackageName)) { className = StringHelper.qualify(defaultPackageName, className); } return className; }
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { String[] columns = criteriaQuery.findColumns(propertyName, criteria); String result = StringHelper.join(" and ", StringHelper.suffix(columns, " is null")); if (columns.length > 1) result = '(' + result + ')'; return result; // TODO: get SQL rendering out of this package! }
void applyDefaults(SchemaAware schemaAware, EntityMappingsMocker.Default defaults) { if (hasSchemaOrCatalogDefined(defaults)) { if (StringHelper.isEmpty(schemaAware.getSchema())) { schemaAware.setSchema(defaults.getSchema()); } if (StringHelper.isEmpty(schemaAware.getCatalog())) { schemaAware.setCatalog(defaults.getCatalog()); } } }
public static List<RelationalValueSource> buildValueSources( ValueSourcesAdapter valueSourcesAdapter, LocalBindingContext bindingContext) { List<RelationalValueSource> result = new ArrayList<RelationalValueSource>(); if (StringHelper.isNotEmpty(valueSourcesAdapter.getColumnAttribute())) { if (valueSourcesAdapter.getColumnOrFormulaElements() != null && !valueSourcesAdapter.getColumnOrFormulaElements().isEmpty()) { throw new org.hibernate.metamodel.source.MappingException( "column/formula attribute may not be used together with <column>/<formula> subelement", bindingContext.getOrigin()); } if (StringHelper.isNotEmpty(valueSourcesAdapter.getFormulaAttribute())) { throw new org.hibernate.metamodel.source.MappingException( "column and formula attributes may not be used together", bindingContext.getOrigin()); } result.add( new ColumnAttributeSourceImpl( valueSourcesAdapter.getContainingTableName(), valueSourcesAdapter.getColumnAttribute(), valueSourcesAdapter.isIncludedInInsertByDefault(), valueSourcesAdapter.isIncludedInUpdateByDefault(), valueSourcesAdapter.isForceNotNull())); } else if (StringHelper.isNotEmpty(valueSourcesAdapter.getFormulaAttribute())) { if (valueSourcesAdapter.getColumnOrFormulaElements() != null && !valueSourcesAdapter.getColumnOrFormulaElements().isEmpty()) { throw new org.hibernate.metamodel.source.MappingException( "column/formula attribute may not be used together with <column>/<formula> subelement", bindingContext.getOrigin()); } // column/formula attribute combo checked already result.add( new FormulaImpl( valueSourcesAdapter.getContainingTableName(), valueSourcesAdapter.getFormulaAttribute())); } else if (valueSourcesAdapter.getColumnOrFormulaElements() != null && !valueSourcesAdapter.getColumnOrFormulaElements().isEmpty()) { for (Object columnOrFormulaElement : valueSourcesAdapter.getColumnOrFormulaElements()) { if (JaxbColumnElement.class.isInstance(columnOrFormulaElement)) { result.add( new ColumnSourceImpl( valueSourcesAdapter.getContainingTableName(), (JaxbColumnElement) columnOrFormulaElement, valueSourcesAdapter.isIncludedInInsertByDefault(), valueSourcesAdapter.isIncludedInUpdateByDefault(), valueSourcesAdapter.isForceNotNull())); } else { result.add( new FormulaImpl( valueSourcesAdapter.getContainingTableName(), (String) columnOrFormulaElement)); } } } return result; }
public static Iterable<CascadeStyle> interpretCascadeStyles( String cascades, LocalBindingContext bindingContext) { final Set<CascadeStyle> cascadeStyles = new HashSet<CascadeStyle>(); if (StringHelper.isEmpty(cascades)) { cascades = bindingContext.getMappingDefaults().getCascadeStyle(); } for (String cascade : StringHelper.split(",", cascades)) { cascadeStyles.add(CascadeStyle.getCascadeStyle(cascade)); } return cascadeStyles; }
private String createAttributePath(String prefix, String name) { String path = ""; if (StringHelper.isNotEmpty(prefix)) { path += prefix; } if (StringHelper.isNotEmpty(path) && !path.endsWith(PROPERTY_PATH_SEPARATOR)) { path += PROPERTY_PATH_SEPARATOR; } path += name; return path; }
protected String resolveFileName(InterfaceInfo element) { String filename = StringHelper.replace(getFilePattern(), "{class-name}", element.getName()); String packageLocation = StringHelper.replace(getConfiguration().getPackageName() + ".dao", ".", "/"); if (StringHelper.isEmpty(packageLocation)) { packageLocation = "."; // done to ensure default package classes doesn't end up in the root of the // filesystem when outputdir="" } filename = StringHelper.replace(filename, "{package-name}", packageLocation); return filename; }
@Override public String toString() { return "ForeignKeyKey{" + "columns=" + StringHelper.join(",", columns) + ", referencedClassName='" + referencedClassName + '\'' + ", referencedColumns=" + StringHelper.join(",", referencedColumns) + '}'; }
private Ignore buildIgnore(String reason, String comment, String jiraKey) { StringBuilder buffer = new StringBuilder(reason); if (StringHelper.isNotEmpty(comment)) { buffer.append("; ").append(comment); } if (StringHelper.isNotEmpty(jiraKey)) { buffer.append(" (").append(jiraKey).append(')'); } return new IgnoreImpl(buffer.toString()); }
public void validateParameters() { super.validateParameters(); if (StringHelper.isEmpty(query) && queries.isEmpty()) { throw new BuildException("Need to specify at least one query."); } for (Iterator iter = queries.iterator(); iter.hasNext(); ) { HQL hql = (HQL) iter.next(); if (StringHelper.isEmpty(hql.query)) { throw new BuildException("Query must not be empty"); } } }
private void applyNamedAttributeNodes( NamedAttributeNode[] namedAttributeNodes, NamedEntityGraph namedEntityGraph, AbstractGraphNode graphNode) { for (NamedAttributeNode namedAttributeNode : namedAttributeNodes) { if (StringHelper.isNotEmpty(namedAttributeNode.subgraph())) { final SubgraphImpl subgraph = graphNode.addSubgraph(namedAttributeNode.value()); applyNamedSubgraphs(namedEntityGraph, namedAttributeNode.subgraph(), subgraph); } if (StringHelper.isNotEmpty(namedAttributeNode.keySubgraph())) { final SubgraphImpl subgraph = graphNode.addKeySubgraph(namedAttributeNode.value()); applyNamedSubgraphs(namedEntityGraph, namedAttributeNode.keySubgraph(), subgraph); } } }
/** * 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()); } }
/* 148: */ /* 149: */ private static AnnotationValue enumValue(String name, DotName typeName, Enum value) /* 150: */ { /* 151:182 */ if ((value != null) && (StringHelper.isNotEmpty(value.toString()))) { /* 152:183 */ return AnnotationValue.createEnumValue(name, typeName, value.toString()); /* 153: */ } /* 154:185 */ return null; /* 155: */ }
private void addJoinNodes(QueryNode query, JoinSequence join, FromElement fromElement) { JoinFragment joinFragment = join.toJoinFragment( walker.getEnabledFilters(), fromElement.useFromFragment() || fromElement.isDereferencedBySuperclassOrSubclassProperty(), fromElement.getWithClauseFragment(), fromElement.getWithClauseJoinAlias()); String frag = joinFragment.toFromFragmentString(); String whereFrag = joinFragment.toWhereFragmentString(); // If the from element represents a JOIN_FRAGMENT and it is // a theta-style join, convert its type from JOIN_FRAGMENT // to FROM_FRAGMENT if (fromElement.getType() == JOIN_FRAGMENT && (join.isThetaStyle() || StringHelper.isNotEmpty(whereFrag))) { fromElement.setType(FROM_FRAGMENT); fromElement .getJoinSequence() .setUseThetaStyle(true); // this is used during SqlGenerator processing } // If there is a FROM fragment and the FROM element is an explicit, then add the from part. if (fromElement.useFromFragment() /*&& StringHelper.isNotEmpty( frag )*/) { String fromFragment = processFromFragment(frag, join).trim(); LOG.debugf("Using FROM fragment [%s]", fromFragment); processDynamicFilterParameters(fromFragment, fromElement, walker); } syntheticAndFactory.addWhereFragment(joinFragment, whereFrag, query, fromElement, walker); }
@SuppressWarnings("unchecked") protected void addMappings(Map settings) { String[] mappings = getMappings(); if (mappings != null) { settings.put(AvailableSettings.HBXML_FILES, StringHelper.join(",", mappings)); } }
private static void bind(MetadataImplementor metadata, AnnotationInstance typeDefAnnotation) { String name = JandexHelper.getValue(typeDefAnnotation, "name", String.class); String defaultForType = JandexHelper.getValue(typeDefAnnotation, "defaultForType", String.class); String typeClass = JandexHelper.getValue(typeDefAnnotation, "typeClass", String.class); boolean noName = StringHelper.isEmpty(name); boolean noDefaultForType = defaultForType == null || defaultForType.equals(void.class.getName()); if (noName && noDefaultForType) { throw new AnnotationException( "Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass " + typeClass); } Map<String, String> parameterMaps = new HashMap<String, String>(); AnnotationInstance[] parameterAnnotations = JandexHelper.getValue(typeDefAnnotation, "parameters", AnnotationInstance[].class); for (AnnotationInstance parameterAnnotation : parameterAnnotations) { parameterMaps.put( JandexHelper.getValue(parameterAnnotation, "name", String.class), JandexHelper.getValue(parameterAnnotation, "value", String.class)); } if (!noName) { bind(name, typeClass, parameterMaps, metadata); } if (!noDefaultForType) { bind(defaultForType, typeClass, parameterMaps, metadata); } }
public SelectFragment addColumn(String tableAlias, String columnName, String columnAlias) { columns.add(StringHelper.qualify(tableAlias, columnName)); // columns.add(columnName); // aliases.add(tableAlias); columnAliases.add(columnAlias); return this; }
private String toText(Identifier identifier) { if (identifier == null) { throw new IllegalArgumentException("Identifier cannot be null; bad usage"); } if (identifier.isQuoted() && storesMixedCaseQuotedIdentifiers) { return identifier.getText(); } else if ((identifier.isQuoted() && storesUpperCaseQuotedIdentifiers) || (!identifier.isQuoted() && storesUpperCaseIdentifiers)) { return StringHelper.toUpperCase(identifier.getText()); } else if ((identifier.isQuoted() && storesLowerCaseQuotedIdentifiers) || (!identifier.isQuoted() && storesLowerCaseIdentifiers)) { return StringHelper.toLowerCase(identifier.getText()); } return identifier.getText(); }
/* 47: */ /* 48: */ private static AnnotationValue stringValue(String name, String value) /* 49: */ { /* 50: 86 */ if (StringHelper.isNotEmpty(value)) { /* 51: 87 */ return AnnotationValue.createStringValue(name, value); /* 52: */ } /* 53: 89 */ return null; /* 54: */ }
public NamedEntityGraphDefinition( NamedEntityGraph annotation, String jpaEntityName, String entityName) { this.annotation = annotation; this.jpaEntityName = jpaEntityName; this.entityName = entityName; this.name = StringHelper.isEmpty(annotation.name()) ? jpaEntityName : annotation.name(); }
/* 91: */ /* 92: */ private static AnnotationValue classValue(String name, String className, ServiceRegistry serviceRegistry) /* 93: */ { /* 94:123 */ if (StringHelper.isNotEmpty(className)) { /* 95:124 */ return AnnotationValue.createClassValue(name, getType(className, serviceRegistry)); /* 96: */ } /* 97:126 */ return null; /* 98: */ }
private static AnnotationValue classValue( String name, String className, ServiceRegistry serviceRegistry) { if (StringHelper.isNotEmpty(className)) { return AnnotationValue.createClassValue(name, getType(className, serviceRegistry)); } return null; }