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

org.onetwo.dbm.mapping.DbmMappedEntryImpl Maven / Gradle / Ivy

package org.onetwo.dbm.mapping;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.onetwo.common.annotation.AnnotationInfo;
import org.onetwo.common.utils.LangUtils;
import org.onetwo.dbm.core.spi.DbmInnerServiceRegistry;
import org.onetwo.dbm.mapping.SQLBuilderFactory.SqlBuilderType;

public class DbmMappedEntryImpl extends AbstractDbmMappedEntryImpl implements DbmMappedEntry {
	

	private EntrySQLBuilderImpl staticInsertOrUpdateSqlBuilder;
	private EntrySQLBuilderImpl staticInsertOrIgnoreSqlBuilder;
	private EntrySQLBuilderImpl staticInsertSqlBuilder;
	private EntrySQLBuilderImpl staticUpdateSqlBuilder;
	private EntrySQLBuilderImpl staticFetchAllSqlBuilder;
	private EntrySQLBuilderImpl staticFetchSqlBuilder;
	private EntrySQLBuilderImpl staticDeleteSqlBuilder;
	private EntrySQLBuilderImpl staticDeleteAllSqlBuilder;
	/*private EntrySQLBuilderImpl staticSeqSqlBuilder;
	private EntrySQLBuilderImpl staticCreateSeqSqlBuilder;*/
	private EntrySQLBuilderImpl staticSelectVersionSqlBuilder;
//	private EntrySQLBuilderImpl staticSelectLockSqlBuilder;
	
	public DbmMappedEntryImpl(String entityName, AnnotationInfo annotationInfo, TableInfo tableInfo, DbmInnerServiceRegistry serviceRegistry) {
		super(entityName, annotationInfo, tableInfo, serviceRegistry);
	}


	protected Collection getInsertableFields(){
		List insertables = new ArrayList();
		for (DbmMappedField field : getMappedColumns().values()) {
			if (field.getColumn()!=null && field.getColumn().isInsertable()) {
				insertables.add(field);
			}
		}
		return insertables;
	}
	
	public List getUpdateableFields(){
		List updatables = new ArrayList();
		for (DbmMappedField field : getMappedColumns().values()){
			if (field.getColumn()!=null && field.getColumn().isUpdatable()) {
				updatables.add(field);
			}
		}
		return updatables;
	}
	

	public Collection getSelectableField() {
		List cols = LangUtils.newArrayList();
		for(DbmMappedField field : this.getMappedColumns().values()){
			if (field.getColumn()==null) {
				continue;
			}
			if (field.getColumn().isLazy()) {
				continue;
			}
			if (field.getColumn().isSelectable()) {
				cols.add(field);
			}
		}
		return cols;
	}
	
	protected void buildStaticSQL(TableInfo taboleInfo){
//		List idColumns = taboleInfo.getPrimaryKey().getColumns();

		staticInsertOrUpdateSqlBuilder = createSQLBuilder(SqlBuilderType.insertOrUpdate);
		staticInsertOrUpdateSqlBuilder.append(getInsertableFields());
		staticInsertOrUpdateSqlBuilder.build();

		staticInsertOrIgnoreSqlBuilder = createSQLBuilder(SqlBuilderType.insertOrIgnore);
		staticInsertOrIgnoreSqlBuilder.append(getInsertableFields());
		staticInsertOrIgnoreSqlBuilder.build();
		
		staticInsertSqlBuilder = createSQLBuilder(SqlBuilderType.insert);
		staticInsertSqlBuilder.append(getInsertableFields());
		staticInsertSqlBuilder.build();
		
		staticUpdateSqlBuilder = createSQLBuilder(SqlBuilderType.update);
		staticUpdateSqlBuilder.append(getUpdateableFields());
		staticUpdateSqlBuilder.appendWhere(getIdentifyFields());
		staticUpdateSqlBuilder.appendWhere(getVersionField());
		staticUpdateSqlBuilder.build();
		
		staticDeleteSqlBuilder = createSQLBuilder(SqlBuilderType.delete);
		staticDeleteSqlBuilder.setNamedPlaceHoder(false);
		staticDeleteSqlBuilder.appendWhere(getIdentifyFields());
		staticDeleteSqlBuilder.appendWhere(getVersionField());
		staticDeleteSqlBuilder.build();
		
		/*staticSeqSqlBuilder = createSQLBuilder(SqlBuilderType.seq);
		staticSeqSqlBuilder.setNamedPlaceHoder(false);
		staticSeqSqlBuilder.build();
		
		staticCreateSeqSqlBuilder = createSQLBuilder(SqlBuilderType.createSeq);
		staticCreateSeqSqlBuilder.setNamedPlaceHoder(false);
		staticCreateSeqSqlBuilder.build();*/

		Collection columns = getSelectableField();
		staticFetchSqlBuilder = createSQLBuilder(SqlBuilderType.query);
		staticFetchSqlBuilder.setNamedPlaceHoder(false);
		staticFetchSqlBuilder.append(columns);
		staticFetchSqlBuilder.appendWhere(getIdentifyFields());
		staticFetchSqlBuilder.build();

		staticFetchAllSqlBuilder = createSQLBuilder(SqlBuilderType.query);
		staticFetchAllSqlBuilder.setNamedPlaceHoder(false);
		staticFetchAllSqlBuilder.append(columns);
		staticFetchAllSqlBuilder.build();

		staticDeleteAllSqlBuilder = createSQLBuilder(SqlBuilderType.delete);
		staticDeleteAllSqlBuilder.setNamedPlaceHoder(false);
		staticDeleteAllSqlBuilder.build();
		
		staticSelectVersionSqlBuilder = createSQLBuilder(SqlBuilderType.query);
		staticSelectVersionSqlBuilder.setNamedPlaceHoder(false);
		staticSelectVersionSqlBuilder.append(getVersionField());
		staticSelectVersionSqlBuilder.appendWhere(getIdentifyFields());
		staticSelectVersionSqlBuilder.build();
		

		/*staticSelectLockSqlBuilder = createSQLBuilder(SqlBuilderType.query);
		staticSelectLockSqlBuilder.setNamedPlaceHoder(false);
		staticSelectLockSqlBuilder.append(columns);
		staticFetchSqlBuilder.appendWhere(getIdentifyField());
		staticSelectLockSqlBuilder.build();*/
	}
	
	/*public EntrySQLBuilderImpl getStaticSelectLockSqlBuilder() {
		return staticSelectLockSqlBuilder;
	}*/



	@Override
	protected EntrySQLBuilderImpl getStaticInsertOrIgnoreSqlBuilder() {
		return staticInsertOrIgnoreSqlBuilder;
	}

	@Override
	protected EntrySQLBuilderImpl getStaticInsertOrUpdateSqlBuilder() {
		return staticInsertOrUpdateSqlBuilder;
	}

	@Override
	protected EntrySQLBuilderImpl getStaticInsertSqlBuilder() {
		return staticInsertSqlBuilder;
	}

	@Override
	protected EntrySQLBuilderImpl getStaticUpdateSqlBuilder() {
		return staticUpdateSqlBuilder;
	}

	@Override
	protected EntrySQLBuilderImpl getStaticDeleteSqlBuilder() {
		return staticDeleteSqlBuilder;
	}


	@Override
	public EntrySQLBuilder getStaticFetchSqlBuilder() {
		return staticFetchSqlBuilder;
	}

	public EntrySQLBuilder getStaticFetchAllSqlBuilder() {
		return staticFetchAllSqlBuilder;
	}


	@Override
	protected EntrySQLBuilder getStaticDeleteAllSqlBuilder() {
		return staticDeleteAllSqlBuilder;
	}

	@Override
	protected EntrySQLBuilder getStaticSelectVersionSqlBuilder() {
		return staticSelectVersionSqlBuilder;
	}

	/*public EntrySQLBuilderImpl getStaticCreateSeqSqlBuilder() {
		return staticCreateSeqSqlBuilder;
	}*/
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy