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

com.jpattern.orm.classmapper.TableMap Maven / Gradle / Ivy

There is a newer version: 3.5.1
Show newest version
package com.jpattern.orm.classmapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jpattern.orm.crud.AColumnValueGenerator;
import com.jpattern.orm.crud.NullColumnValueGenerator;
import com.jpattern.orm.query.LockMode;

/**
 * 
 * @author Francesco Cina
 *
 * 08/giu/2011
 */
public class TableMap implements ITableMap {

	private final List primaryKeyFieldList = new ArrayList();
	private final Map columnNamesMap = new HashMap();
	private final Map javaFieldNamesMap = new HashMap();
	private final Map generatorByColumnName = new HashMap();
	private final Map generatorByJavaFieldName = new HashMap();
	private boolean versionable = false;
	private String versionJavaFieldName = "";
	private LockMode versionLoadLockMode = LockMode.NO_LOCK;
	private String schemaName;
	private String tableName;

	@Override
	public String getSchemaName() {
		if (schemaName==null) {
			schemaName = "";
		}
		return schemaName;
	}

	@Override
	public String getTableName() {
		if (tableName==null) {
			tableName = "";
		}
		return tableName;
	}

	@Override
	public String getTableNameWithSchema() {
		final String schema = getSchemaName();
		if (schema.length()==0) {
			return getTableName();
		}
		return schema + "." + getTableName();
	}

	public void addColumnMapping(String javaFieldName, String columnName, AColumnValueGenerator columnValueGenerator) {
		if ( (javaFieldName!=null) && (columnName!=null) ) {
			columnNamesMap.put(javaFieldName, columnName);
			javaFieldNamesMap.put(columnName, javaFieldName);
			generatorByColumnName.put(columnName, columnValueGenerator);
			generatorByJavaFieldName.put(javaFieldName, columnValueGenerator);
		}
	}

	@Override
	public String getDBColumnName(String javaFieldName) {
		if (columnNamesMap.containsKey(javaFieldName)) {
			return columnNamesMap.get(javaFieldName);
		}
		return "";
	}

	@Override
	public String getJavaFieldName(String dbColumnName) {
		if (javaFieldNamesMap.containsKey(dbColumnName)) {
			return javaFieldNamesMap.get(dbColumnName);
		}
		return "";
	}

	@Override
	public List getPrimaryKeyFieldNames() {
		return primaryKeyFieldList;
	}

	public void addPrimaryKey(String primaryKeyField) {
		primaryKeyFieldList.add(primaryKeyField);
	}

	public void setSchemaName(String schemaName) {
		this.schemaName = schemaName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	@Override
	public List getAllFieldNames() {
		return new ArrayList( columnNamesMap.keySet() );
	}

	@Override
	public AColumnValueGenerator getGeneratorByColumnName(String columnName) {
		if (generatorByColumnName.containsKey(columnName))  {
			return generatorByColumnName.get(columnName);
		}
		return new NullColumnValueGenerator("");
	}

	@Override
	public AColumnValueGenerator getGeneratorByJavaFieldName(String javaFieldName) {
		if (generatorByJavaFieldName.containsKey(javaFieldName))  {
			return generatorByJavaFieldName.get(javaFieldName);
		}
		return new NullColumnValueGenerator("");
	}

	public void setVersionable(boolean versionable) {
		this.versionable = versionable;
	}

	@Override
	public boolean isVersionable() {
		return versionable;
	}

	public void setVersionJavaFieldName(String versionJavaFieldName) {
		this.versionJavaFieldName = versionJavaFieldName;
	}

	@Override
	public String getVersionJavaFieldName() {
		return versionJavaFieldName;
	}

	public void setVersionLoadLockMode(LockMode versionLoadLockMode) {
		this.versionLoadLockMode = versionLoadLockMode;
	}

	@Override
	public LockMode getVersionLoadLockMode() {
		return versionLoadLockMode;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy