⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 componentpropertymapping.java

📁 一个hibernate的自动测试框架源码
💻 JAVA
字号:
/*
 * Copyright (c) 2005 Chris Richardson
 * 
 * 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 net.chrisrichardson.ormunit.hibernate;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import junit.framework.Assert;

import org.hibernate.mapping.Component;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;


public class ComponentPropertyMapping {

    private final Property property;
    private final Component componentValue;
	private AccessStrategy accessStrategy;

    public ComponentPropertyMapping(Property property, Component value, AccessStrategy accessStrategy) {
        this.property = property;
        this.componentValue = value;
		this.accessStrategy = accessStrategy;
    }

    public void assertField(String fieldName, String columnName) {
        Property subProperty = findProperty(fieldName);
        HibernateAssertUtil.assertPropertyColumn(columnName, subProperty);
    }

    public void assertManyToOneField(String fieldName, String foreignKeyColumnName) {
        Property subProperty = findProperty(fieldName);
        ManyToOne value = (ManyToOne) subProperty.getValue();
        HibernateAssertUtil.assertColumn(foreignKeyColumnName, value);
    }

    public void assertNonPersistentFields(Set nonPersistentFields) {
    	assertNonPersistentFields(nonPersistentFields, false);
    }
    
    public void assertNonPersistentFields(Set nonPersistentFields, boolean includeSuper) {
        Class type = componentValue.getComponentClass();
        Set unmappedFields = new HashSet();
        for (Iterator it = accessStrategy.getPersistableProperties(type, Object.class).iterator(); it.hasNext();) {
            String fieldName = (String) it.next();
            if (!nonPersistentFields.contains(fieldName)) {
                Property subProperty = findProperty(fieldName);
                if (subProperty == null)
                    unmappedFields.add(fieldName);
            }
        }
        if (!unmappedFields.isEmpty())
            Assert.fail("unmapped fields: " + unmappedFields);

    }

    public Property findProperty(String fieldName) {
        for (Iterator it = componentValue.getPropertyIterator(); it.hasNext(); ) {
            Property subProperty = (Property) it.next();
            if (subProperty.getName().equals(fieldName)) {
                return subProperty;
            }
        }
        return null;
    }

    public void assertCompositeSetField(String fieldName) {
        Property property = findProperty(fieldName);
        Value v = property.getValue();
        org.hibernate.mapping.Set value = (org.hibernate.mapping.Set) v;
    }

    public CompositeSetPropertyMapping getCompositeSetFieldMapping(String fieldName) {
        Property property = findProperty(fieldName);
        Value v = property.getValue();
        org.hibernate.mapping.Set value = (org.hibernate.mapping.Set) v;
        return new CompositeSetPropertyMapping(property, value, accessStrategy);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -