/** * Joins the elements of the given iterable to a string, separated by the given separator string. * * @param iterable the iterable to join * @param separator the separator string * @return a string made up of the string representations of the given iterable members, separated by the given * separator string */ public static String join(Iterable<?> iterable, String separator) { if ( iterable == null ) { return null; } return join( iterable.iterator(), separator ); }
public static MongoDBIndexType from(String type) { if ( StringHelper.isEmpty( type ) ) { return NORMAL; } if ( TEXT.type.equals( type ) ) { return TEXT; } else if ( TWODSPHERE.type.equals( type ) ) { return TWODSPHERE; } else if ( TWOD.type.equals( type ) ) { return TWOD; } throw new IllegalArgumentException( "Unsupported MongoDB index type " + type ); } }
public IndexOption getOptionForIndex(String indexName) { if ( StringHelper.isNullOrEmptyString( indexName ) ) { return new IndexOption(); } if ( !indexOptions.containsKey( indexName ) ) { return new IndexOption( indexName ); } return indexOptions.get( indexName ); }
@Override public String toString() { StringBuilder sb = new StringBuilder( "Association[" ).append( StringHelper.lineSeparator() ); Iterator<RowKey> rowKeys = getKeys().iterator(); while ( rowKeys.hasNext() ) { RowKey rowKey = rowKeys.next(); sb.append( " " ).append( rowKey ).append( "=" ).append( get( rowKey ) ); if ( rowKeys.hasNext() ) { sb.append( "," ).append( StringHelper.lineSeparator() ); } } sb.append( StringHelper.lineSeparator() ).append( "]" ); return sb.toString(); } }
private void appendStoredProcedureParamValue(String storedProcedureName, StringBuilder commandLine, Object paramValue) { if ( paramValue == null ) { // I don't think this can happen but, just in case, null should be a valid JSON value commandLine.append( "null" ); } else { if ( requiresQuotes( paramValue ) ) { // be sure to escape the double quotes String escapedValue = StringHelper.escapeDoubleQuotesForJson( paramValue.toString() ); commandLine.append( '"' ).append( escapedValue ).append( '"' ); } else { commandLine.append( paramValue ); } } }
log.debug( "result row: " + StringHelper.toString( keys ) );
private String toShortString(Association association) { if ( association == null ) { return null; } StringBuilder sb = new StringBuilder( "Association[" ); Iterator<RowKey> rowKeys = association.getKeys().iterator(); while ( rowKeys.hasNext() ) { RowKey rowKey = rowKeys.next(); sb.append( toShortString( rowKey ) ).append( "=" ).append( toShortString( association.get( rowKey ) ) ); if ( rowKeys.hasNext() ) { sb.append( "," ).append( StringHelper.lineSeparator() ); } } sb.append( "]" ); return sb.toString(); }
private void appendStoredProcedureParamValue(String storedProcedureName, StringBuilder commandLine, Object paramValue) { if ( paramValue == null ) { // I don't think this can happen but, just in case, null should be a valid JSON value commandLine.append( "null" ); } else { if ( requiresQuotes( paramValue ) ) { // be sure to escape the double quotes String escapedValue = StringHelper.escapeDoubleQuotesForJson( paramValue.toString() ); commandLine.append( '"' ).append( escapedValue ).append( '"' ); } else { commandLine.append( paramValue ); } } }
@Override public String toString() { final StringBuilder builder = new StringBuilder( "Tuple Context {" ); builder.append( "selectableColumns: [" ); builder.append( StringHelper.join( selectableColumns, ", " ) ); builder.append( "] }" ); return builder.toString(); } }
private Boolean getAsBoolean() { Object configuredValue = getConfiguredValue(); if ( StringHelper.isNullOrEmptyString( configuredValue ) ) { return getDefaultValue() != null ? (Boolean) getDefaultValue() : null; } return ( configuredValue instanceof Boolean ) ? (Boolean) configuredValue : Boolean.valueOf( configuredValue.toString().trim() ); }
public static MongoDBIndexType from(String type) { if ( StringHelper.isEmpty( type ) ) { return NORMAL; } if ( TEXT.type.equals( type ) ) { return TEXT; } else if ( TWODSPHERE.type.equals( type ) ) { return TWODSPHERE; } else if ( TWOD.type.equals( type ) ) { return TWOD; } throw new IllegalArgumentException( "Unsupported MongoDB index type " + type ); } }
public String getColumnName(OgmEntityPersister persister, List<String> propertyPath) { String propertyName = StringHelper.join( propertyPath, "." ); String identifierPropertyName = persister.getIdentifierPropertyName(); if ( propertyName.equals( identifierPropertyName ) ) { return MongoDBDialect.ID_FIELDNAME; } String column = getColumn( persister, propertyPath ); if ( propertyPath.size() > 1 && propertyPath.get( 0 ).equals( identifierPropertyName ) ) { column = MongoDBDialect.ID_FIELDNAME + "." + column.substring( propertyPath.get( 0 ).length() + 1 ); } return column; } }
/** * parse JSON * @param json * @return * @see <a href="http://stackoverflow.com/questions/34436952/json-parse-equivalent-in-mongo-driver-3-x-for-java"> JSON.parse equivalent</a> */ private static Object parseAsObject(String json) { if ( StringHelper.isNullOrEmptyString( json ) ) { return null; } Document object = Document.parse( "{ 'json': " + json + "}" ); return object.get( "json" ); }
/** * Register the entity as batch loadable, if enabled * * Copied from {@link org.hibernate.type.ManyToOneType#scheduleBatchLoadIfNeeded} */ private void scheduleBatchLoadIfNeeded(Serializable id, SharedSessionContractImplementor session) throws MappingException { //cannot batch fetch by unique key (property-ref associations) if ( StringHelper.isEmpty( delegate.getRHSUniqueKeyPropertyName() ) && id != null ) { EntityPersister persister = session.getFactory().getMetamodel().entityPersister( delegate.getAssociatedEntityName() ); EntityKey entityKey = session.generateEntityKey( id, persister ); if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); } } }
public String getColumnName(OgmEntityPersister persister, List<String> propertyPath) { String propertyName = StringHelper.join( propertyPath, "." ); String identifierPropertyName = persister.getIdentifierPropertyName(); if ( propertyName.equals( identifierPropertyName ) ) { return MongoDBDialect.ID_FIELDNAME; } String column = getColumn( persister, propertyPath ); if ( propertyPath.size() > 1 ) { String prop = propertyPath.get( 0 ); if ( prop.equals( identifierPropertyName ) ) { if ( column.startsWith( identifierPropertyName + "." ) ) { column = column.substring( prop.length() + 1 ); } column = MongoDBDialect.ID_FIELDNAME + "." + column; } } return column; } }
private String getAsString() { String stringValue = StringHelper.isNullOrEmptyString( getConfiguredValue() ) ? null : getConfiguredValue().toString().trim(); return stringValue == null ? (String) getDefaultValue() : stringValue; }
protected final Object getIdentifier(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException { if ( value == null ) { return null; } final EntityPersister persister = sessionFactory.getMetamodel().entityPersister( delegate.getAssociatedEntityName() ); final String uniqueKeyPropertyName = delegate.getRHSUniqueKeyPropertyName(); if ( StringHelper.isEmpty( uniqueKeyPropertyName ) ) { return persister.getIdentifier( value, null ); } else { Object propertyValue = persister.getPropertyValue( value, uniqueKeyPropertyName ); // We now have the value of the property-ref we reference. However, // we need to dig a little deeper, as that property might also be // an entity type, in which case we need to resolve its identifier Type type = persister.getPropertyType( uniqueKeyPropertyName ); GridType gridType = typeTranslator.getType( type ); if ( gridType.isEntityType() ) { propertyValue = getIdentifier( propertyValue, sessionFactory ); } return propertyValue; } }
private void appendComponentCollectionPath(StringBuilder columnNameBuilder, OgmCollectionPersister persister, Iterator<String> pathIterator) { if ( pathIterator.hasNext() ) { String property = pathIterator.next(); Type subType = associationPropertyType( persister.getType(), property ); if ( subType.isComponentType() ) { property += "." + StringHelper.join( pathIterator, "." ); } else if ( subType.isAssociationType() ) { throw new UnsupportedOperationException( "Queries on collection in embeddables are not supported: " + property ); } columnNameBuilder.append( persister.toColumns( property )[0] ); } }
/** * parse JSON * @param json * @return * @see <a href="http://stackoverflow.com/questions/34436952/json-parse-equivalent-in-mongo-driver-3-x-for-java"> JSON.parse equivalent</a> */ private static Object parseAsObject(String json) { if ( StringHelper.isNullOrEmptyString( json ) ) { return null; } Document object = Document.parse( "{ 'json': " + json + "}" ); return object.get( "json" ); }
protected final Object getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException { if ( value == null ) { return null; } //isNotEmbedded copied from EntityType#isNotEmbedded boolean isNotEmbedded = isNotEmbedded( session ); if ( isNotEmbedded ) { return value; } final String associatedEntityName = delegate.getAssociatedEntityName(); final String uniqueKeyPropertyName = delegate.getRHSUniqueKeyPropertyName(); if ( StringHelper.isEmpty( uniqueKeyPropertyName ) ) { return ForeignKeys.getEntityIdentifierIfNotUnsaved( associatedEntityName, value, session ); //tolerates nulls } else { final EntityPersister persister = session.getFactory().getMetamodel().entityPersister( delegate.getAssociatedEntityName() ); Object propertyValue = persister.getPropertyValue( value, uniqueKeyPropertyName ); // We now have the value of the property-ref we reference. However, // we need to dig a little deeper, as that property might also be // an entity type, in which case we need to resolve its identifier Type type = persister.getPropertyType( uniqueKeyPropertyName ); GridType gridType = typeTranslator.getType( type ); if ( gridType.isEntityType() ) { propertyValue = ( (EntityType) gridType ).getIdentifier( propertyValue, session ); } return propertyValue; } }