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

com.ohmdb.dsl.OhmDbDSL Maven / Gradle / Ivy

package com.ohmdb.dsl;

/*
 * #%L
 * ohmdb-dsl
 * %%
 * Copyright (C) 2013 - 2014 Nikolche Mihajlovski
 * %%
 * 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.
 * #L%
 */

import com.ohmdb.abstracts.RWRelation;
import com.ohmdb.api.Ids;
import com.ohmdb.api.Join;
import com.ohmdb.api.JoinMode;
import com.ohmdb.api.ManyToMany;
import com.ohmdb.api.ManyToOne;
import com.ohmdb.api.OneToMany;
import com.ohmdb.api.OneToOne;
import com.ohmdb.api.Parameter;
import com.ohmdb.api.Relation;
import com.ohmdb.api.Table;
import com.ohmdb.dsl.impl.ParamImpl;
import com.ohmdb.dsl.join.JoinImpl;
import com.ohmdb.dsl.join.LinkMatcher;
import com.ohmdb.dsl.rel.ManyToManyImpl;
import com.ohmdb.dsl.rel.ManyToOneImpl;
import com.ohmdb.dsl.rel.OneToManyImpl;
import com.ohmdb.dsl.rel.OneToOneImpl;

public abstract class OhmDbDSL {

	protected final LinkMatcher linkMatcher;

	public OhmDbDSL(LinkMatcher linkMatcher) {
		this.linkMatcher = linkMatcher;
	}

	public  ManyToOne manyToOne(Table from, String name, Table to) {
		return new ManyToOneImpl(relation(from, name, to, false, true, false));
	}

	public  OneToMany oneToMany(Table from, String name, Table to) {
		return new OneToManyImpl(relation(from, name, to, false, false, true));
	}

	public  ManyToMany manyToMany(Table from, String name, Table to) {
		return new ManyToManyImpl(relation(from, name, to, false, true, true));
	}

	public  ManyToMany manyToManySymmetric(Table from, String name,
			Table to) {
		return new ManyToManyImpl(relation(from, name, to, true, true, true));
	}

	public  OneToOne oneToOne(Table from, String name, Table to) {
		return new OneToOneImpl(relation(from, name, to, false, false, false));
	}

	public  OneToOne oneToOneSymmetric(Table from, String name, Table to) {
		return new OneToOneImpl(relation(from, name, to, true, false, false));
	}

	public  Parameter param(String name, Class type) {
		return new ParamImpl(name, type);
	}

	public  Join join(Ids from, Relation relation, Ids to) {
		return new JoinImpl(linkMatcher, from, relation, to, JoinMode.INNER);
	}

	public  Join leftJoin(Ids from, Relation relation, Ids to) {
		return new JoinImpl(linkMatcher, from, relation, to, JoinMode.LEFT_OUTER);
	}

	public  Join rightJoin(Ids from, Relation relation, Ids to) {
		return new JoinImpl(linkMatcher, from, relation, to, JoinMode.RIGHT_OUTER);
	}

	public  Join fullJoin(Ids from, Relation relation, Ids to) {
		return new JoinImpl(linkMatcher, from, relation, to, JoinMode.FULL_OUTER);
	}

	protected abstract  RWRelation relation(Table from, String name, Table to, boolean symmetric,
			boolean manyFroms, boolean manyTos);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy