All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.querydsl.core.alias.Alias Maven / Gradle / Ivy

There is a newer version: 6.8
Show newest version
/*
 * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.querydsl.core.alias;

import com.querydsl.core.types.EntityPath;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.*;
import com.querydsl.core.util.StringUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.Nullable;

/**
 * {@code Alias} provides alias factory methods
 *
 * 

Example: * *

{@code
 * Employee e = alias(Employee.class, "e");
 * for (String name : query.from($(e),employees)
 *     .where($(e.getDepartment().getId()).eq(1001))
 *     .list($(e.getName()))) {
 *     System.out.println(name);
 * }
 * }
* *

using the following static imports * *

{@code
 * import static com.mysema.query.alias.Alias.$;
 * import static com.mysema.query.alias.Alias.alias;
 * }
* * @author tiwe */ @SuppressWarnings("PMD") public final class Alias { private static final AliasFactory aliasFactory = new AliasFactory(new DefaultPathFactory(), new DefaultTypeSystem()); private static final SimplePath it = Expressions.path(Object.class, "it"); // exclude $-methods from Checkstyle checks // CHECKSTYLE:OFF /** * Convert the given alias to an expression * * @param * @return expression */ public static > D $() { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @param * @return expression */ public static ArrayPath $(D[] arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(BigDecimal arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(BigInteger arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static BooleanPath $(Boolean arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(Byte arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @param * @return expression */ public static > EnumPath $(T arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @param * @return expression */ @SuppressWarnings("unchecked") public static CollectionPath> $(Collection arg) { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof CollectionPath) { return (CollectionPath>) arg; // NOSONAR } else if (arg instanceof ManagedObject) { return (CollectionPath>) ((ManagedObject) arg).__mappedPath(); } else { return (CollectionPath>) current; } } /** * Convert the given alias to an expression * * @param arg alias * @param * @return expression */ public static > ComparablePath $(D arg) { return Alias.getPath(arg); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(Double arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(Float arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(Integer arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static DatePath $(java.sql.Date arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static DateTimePath $(java.util.Date arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @param * @return expression */ @SuppressWarnings("unchecked") public static ListPath> $(List arg) { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof ListPath) { return (ListPath>) arg; // NOSONAR } else if (arg instanceof ManagedObject) { return (ListPath>) ((ManagedObject) arg).__mappedPath(); } else { return (ListPath>) current; } } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(Long arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @param * @param * @return expression */ @SuppressWarnings("unchecked") public static MapPath> $(Map arg) { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof MapPath) { return (MapPath>) arg; // NOSONAR } else if (arg instanceof ManagedObject) { return (MapPath>) ((ManagedObject) arg).__mappedPath(); } else { return (MapPath>) current; } } /** * Convert the given alias to an expression * * @param arg alias * @param * @return expression */ @SuppressWarnings("unchecked") public static SetPath> $(Set arg) { final Object current = aliasFactory.getCurrentAndReset(); if (arg instanceof SetPath) { return (SetPath>) arg; // NOSONAR } else if (arg instanceof ManagedObject) { return (SetPath>) ((ManagedObject) arg).__mappedPath(); } else { return (SetPath>) current; } } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static NumberPath $(Short arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static StringPath $(String arg) { return aliasFactory.getCurrentAndReset(); } /** * Convert the given alias to an expression * * @param arg alias * @return expression */ public static TimePath