mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-16 21:01:10 +08:00
96 lines
3.1 KiB
Java
96 lines
3.1 KiB
Java
/*
|
|
* Copyright 2011, Mysema Ltd
|
|
*
|
|
* 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.mysema.query.sql;
|
|
|
|
import org.junit.Test;
|
|
|
|
import com.mysema.query.types.PathMetadataFactory;
|
|
import com.mysema.query.types.path.NumberPath;
|
|
|
|
@SuppressWarnings("serial")
|
|
public class KeyTest {
|
|
|
|
// @Table("USER")
|
|
public static class QUser extends RelationalPathBase<QUser>{
|
|
|
|
public final NumberPath<Integer> id = createNumber("ID", Integer.class);
|
|
|
|
public final NumberPath<Integer> department = createNumber("DEPARTMENT", Integer.class);
|
|
|
|
public final NumberPath<Integer> superiorId = createNumber("SUPERIOR_ID", Integer.class);
|
|
|
|
public final PrimaryKey<QUser> idKey = createPrimaryKey(id);
|
|
|
|
public final ForeignKey<QDepartment> departmentKey = createForeignKey(department, "ID");
|
|
|
|
public final ForeignKey<QUser> superiorIdKey = createForeignKey(superiorId,"ID");
|
|
|
|
public QUser(String path) {
|
|
super(QUser.class, PathMetadataFactory.forVariable(path), null, "USER");
|
|
}
|
|
|
|
}
|
|
|
|
// @Table("DEPARTMENT")
|
|
public static class QDepartment extends RelationalPathBase<QDepartment> {
|
|
|
|
public final NumberPath<Integer> id = createNumber("ID", Integer.class);
|
|
|
|
public final NumberPath<Integer> company = createNumber("COMPANY", Integer.class);
|
|
|
|
public final PrimaryKey<QDepartment> idKey = createPrimaryKey(id);
|
|
|
|
public final ForeignKey<QCompany> companyKey = createForeignKey(company, "ID");
|
|
|
|
public QDepartment(String path) {
|
|
super(QDepartment.class, PathMetadataFactory.forVariable(path), null, "DEPARTMENT");
|
|
}
|
|
|
|
}
|
|
|
|
// @Table("COMPANY")
|
|
public static class QCompany extends RelationalPathBase<QCompany> {
|
|
|
|
public final NumberPath<Integer> id = createNumber("ID", Integer.class);
|
|
|
|
public final PrimaryKey<QCompany> idKey = createPrimaryKey(id);
|
|
|
|
public QCompany(String path) {
|
|
super(QCompany.class, PathMetadataFactory.forVariable(path), null, "COMPANY");
|
|
}
|
|
|
|
}
|
|
|
|
@Test
|
|
public void test(){
|
|
QUser user = new QUser("user");
|
|
QUser user2 = new QUser("user2");
|
|
QDepartment department = new QDepartment("department");
|
|
QCompany company = new QCompany("company");
|
|
|
|
// superiorId -> id
|
|
query().from(user).innerJoin(user.superiorIdKey, user2);
|
|
|
|
// department -> id / company -> id
|
|
query().from(user)
|
|
.innerJoin(user.departmentKey, department)
|
|
.innerJoin(department.companyKey, company);
|
|
}
|
|
|
|
private SQLQuery query(){
|
|
return new SQLQueryImpl(SQLTemplates.DEFAULT);
|
|
}
|
|
|
|
}
|