当前位置: 首页>>代码示例>>Java>>正文


Java PrimaryKey类代码示例

本文整理汇总了Java中org.hibernate.mapping.PrimaryKey的典型用法代码示例。如果您正苦于以下问题:Java PrimaryKey类的具体用法?Java PrimaryKey怎么用?Java PrimaryKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PrimaryKey类属于org.hibernate.mapping包,在下文中一共展示了PrimaryKey类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: classMapping

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
private Mappings classMapping(Database database, Mappings mappings) {

        for (Schema schema : database.getSchemas()) {
            for (com.manydesigns.portofino.model.database.Table aTable :
                    schema.getTables()) {
                logger.debug("Class - {}", aTable.getQualifiedName());
                com.manydesigns.portofino.model.database.PrimaryKey primaryKey =
                        aTable.getPrimaryKey();
                if (primaryKey == null) {
                    logger.debug("Skipping table without primary key: {}",
                            aTable.getQualifiedName());
                    continue;
                }
                if (!primaryKey.isValid()) {
                    logger.debug("Skipping table with invalid primary key: {}",
                            aTable.getQualifiedName());
                    continue;
                }
                RootClass clazz = createTableMapping(mappings, aTable);
                if(clazz != null) {
                    mappings.addClass(clazz);
                    mappings.addImport(clazz.getEntityName(), clazz.getEntityName());
                }
            }
        }
        return mappings;
    }
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:28,代码来源:HibernateConfig.java

示例2: normalizePrimaryKeys

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
private void normalizePrimaryKeys(Table table, String entityName) {
	PrimaryKey pk = table.getPrimaryKey();
	if (pk != null) {
		String name = strategy.primaryKeyName(entityName, table.getName());
		pk.setName(name);
	}
}
 
开发者ID:andreluiznsilva,项目名称:hibernate-conventions,代码行数:8,代码来源:MappingConventions.java

示例3: getPrimaryColName

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
public static String getPrimaryColName(Table table) throws ServiceException {
    String colName = "";
    try {
        PrimaryKey pk = table.getPrimaryKey();
        List lst = pk.getColumns();
        Column col = (Column) lst.get(0);
        colName = col.getName();
    } catch(Exception e) {
        throw ServiceException.FAILURE("HibernateUtil.getPrimaryColName", e);
    }
    return colName;
}
 
开发者ID:mobilipia,项目名称:Deskera-HRMS,代码行数:13,代码来源:HibernateUtil.java

示例4: createPKComposite

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
protected void createPKComposite(Mappings mappings,
                                 com.manydesigns.portofino.model.database.Table mdTable,
                                 String pkName, RootClass clazz,
                                 Table tab,
                                 List<com.manydesigns.portofino.model.database.Column> columnPKList) {


    PrimaryKey primaryKey = new PrimaryKey();
    primaryKey.setName(pkName);
    primaryKey.setTable(tab);

    clazz.setEmbeddedIdentifier(true);
    Component component = new Component(mappings, clazz);
    component.setDynamic(mdTable.getActualJavaClass()==null);
    String name;
    name = mdTable.getQualifiedName();

    component.setRoleName(name + ".id");
    component.setEmbedded(true);
    //component.setNodeName("id");
    component.setKey(true);
    component.setNullValue("undefined");

    if (!component.isDynamic()){
        component.setComponentClassName
                (mdTable.getJavaClass()); //TODO verificare se non si intende actualJavaClass
    }

    boolean hasErrors = false;
    for (com.manydesigns.portofino.model.database.Column
            column : columnPKList) {
        if (column == null ) {
            throw new InternalError("Null column");
        }

        Column col = createColumn(mappings, tab, column);

        hasErrors = col == null || hasErrors;

        if(col != null) {
            primaryKey.addColumn(col);
            Property prop = createProperty(column, col.getValue());
            prop.setCascade("none");
            //prop.setPropertyAccessorName("property"); interferisce con il generator più sotto
            prop.setPersistentClass(clazz);
            component.addProperty(prop);

            //Generator not supported for embedded map identifier
            //See https://forum.hibernate.org/viewtopic.php?t=945273
            //See Component.buildIdentifierGenerator()
            /*String columnName = column.getColumnName();
            PrimaryKeyColumn pkCol = mdTable.getPrimaryKey().findPrimaryKeyColumnByName(columnName);
            if(pkCol == null) {
                logger.error("Column without corresponding PrimaryKeyColumn: {}", columnName);
                hasErrors = true;
                continue;
            }
            Generator generator = pkCol.getGenerator();
            setPKColumnGenerator(mappings, clazz, tab, column, value, generator);*/
        }
    }
    if (hasErrors) {
        // TODO : se la PK non e' buona, tutta la tabella dovrebbe saltare
        logger.error("Table "+name+": Skipping primary key");
        return;
    }

    tab.setIdentifierValue(component);
    clazz.setIdentifier(component);
    clazz.setDiscriminatorValue(name);

    tab.setPrimaryKey(primaryKey);
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:74,代码来源:HibernateConfig.java

示例5: createPKSingle

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
protected void createPKSingle(Mappings mappings,
                              com.manydesigns.portofino.model.database.Table mdTable,
                              String pkName, RootClass clazz,
                              Table tab,
                              List<com.manydesigns.portofino.model.database.Column> columnPKList) {
    PrimaryKeyColumn pkcol = mdTable.getPrimaryKey().getPrimaryKeyColumns().get(0);
    com.manydesigns.portofino.model.database.Column column = columnPKList.get(0);
    final PrimaryKey primaryKey = new PrimaryKey();
    primaryKey.setName(pkName); //TODO quote?
    primaryKey.setTable(tab);
    tab.setPrimaryKey(primaryKey);

    Column col = createColumn(mappings, tab, column);

    if (col == null) {
        // TODO : se la PK non e' buona, tutta la tabella dovrebbe saltare
        logger.error("Skipping primary key "+pkName);
        return;
    }

    SimpleValue id = (SimpleValue) col.getValue();
    //Make the defaults explicit. See section 5.1.4.5. Assigned identifiers in the Hibernate reference
    //(http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html)
    id.setIdentifierGeneratorStrategy("assigned");
    id.setNullValue("undefined");

    tab.getPrimaryKey().addColumn(col);
    
    Property prop = createProperty(column, id);
    clazz.addProperty(prop);
    prop.setPropertyAccessorName(mappings.getDefaultAccess());

    prop.setInsertable(false);
    prop.setUpdateable(false);

    Generator generator = pkcol.getGenerator();

    setPKColumnGenerator(mappings, clazz, tab, column, id, generator);

    tab.setIdentifierValue(id);
    clazz.setIdentifier(id);
    clazz.setIdentifierProperty(prop);
    clazz.setDiscriminatorValue(mdTable.getQualifiedName());

}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:46,代码来源:HibernateConfig.java

示例6: validatePrimaryKeys

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
private void validatePrimaryKeys(Table table) {
	PrimaryKey primaryKey = table.getPrimaryKey();
	if (primaryKey != null) {
		validateMaxLength(primaryKey.getName());
	}
}
 
开发者ID:andreluiznsilva,项目名称:hibernate-conventions,代码行数:7,代码来源:MappingConventions.java

示例7: createPKComposite

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
protected void createPKComposite(Mappings mappings,
                                 com.manydesigns.portofino.model.database.Table mdTable,
                                 String pkName, RootClass clazz,
                                 Table tab,
                                 List<com.manydesigns.portofino.model.database.Column> columnPKList) {


    PrimaryKey primaryKey = new PrimaryKey();
    primaryKey.setName(pkName);
    primaryKey.setTable(tab);

    clazz.setEmbeddedIdentifier(true);
    Component component = new Component(mappings, clazz);
    component.setDynamic(mdTable.getActualJavaClass()==null);
    String name;
    name = mdTable.getQualifiedName();

    component.setRoleName(name + ".id");
    component.setEmbedded(true);
    //component.setNodeName("id");
    component.setKey(true);
    component.setNullValue("undefined");

    if (!component.isDynamic()){
        component.setComponentClassName
                (mdTable.getJavaClass()); //TODO verificare se non si intende actualJavaClass
    }

    boolean hasErrors = false;
    for (com.manydesigns.portofino.model.database.Column
            column : columnPKList) {
        if (column == null ) {
            throw new InternalError("Null column");
        }

        Column col = createColumn(mappings, tab, column);

        hasErrors = col == null || hasErrors;

        if(col != null) {
            primaryKey.addColumn(col);
            Property prop = createProperty(column, col.getValue());
            prop.setCascade("none");
            //prop.setPropertyAccessorName("property"); interferisce con il generator più sotto
            prop.setPersistentClass(clazz);
            component.addProperty(prop);

            //Generator not supported for embedded map identifier
            //See https://forum.hibernate.org/viewtopic.php?t=945273
            //See Component.buildIdentifierGenerator()
            /*String columnName = column.getColumnName();
            PrimaryKeyColumn pkCol = mdTable.getPrimaryKey().findPrimaryKeyColumnByName(columnName);
            if(pkCol == null) {
                logger.error("Column without corresponding PrimaryKeyColumn: {}", columnName);
                hasErrors = true;
                continue;
            }
            Generator generator = pkCol.getGenerator();
            setPKColumnGenerator(mappings, clazz, tab, column, value, generator);*/
        }
    }
    if (hasErrors) {
        // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare
        logger.error("Skipping primary key");
        return;
    }

    tab.setIdentifierValue(component);
    clazz.setIdentifier(component);
    clazz.setDiscriminatorValue(name);

    tab.setPrimaryKey(primaryKey);
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:74,代码来源:HibernateConfig.java

示例8: createPKSingle

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
protected void createPKSingle(Mappings mappings,
                              com.manydesigns.portofino.model.database.Table mdTable,
                              String pkName, RootClass clazz,
                              Table tab,
                              List<com.manydesigns.portofino.model.database.Column> columnPKList) {
    PrimaryKeyColumn pkcol =mdTable.getPrimaryKey().getPrimaryKeyColumns().get(0);
    com.manydesigns.portofino.model.database.Column
            column = columnPKList.get(0);
    final PrimaryKey primaryKey = new PrimaryKey();
    primaryKey.setName(pkName);
    primaryKey.setTable(tab);
    tab.setPrimaryKey(primaryKey);

    Column col = createColumn(mappings, tab, column);

    if (col == null) {
        // TODO PAOLO: se la PK non e' buona, tutta la tabella dovrebbe saltare
        logger.error("Skipping primary key");
        return;
    }

    SimpleValue id = (SimpleValue) col.getValue();
    //Make the defaults explicit. See section 5.1.4.5. Assigned identifiers in the Hibernate reference
    //(http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html)
    id.setIdentifierGeneratorStrategy("assigned");
    id.setNullValue("undefined");

    tab.getPrimaryKey().addColumn(col);
    
    Property prop = createProperty(column, id);
    clazz.addProperty(prop);
    prop.setPropertyAccessorName(mappings.getDefaultAccess());
    //PropertyGeneration generation = PropertyGeneration.parse(null);
    //prop.setGeneration(generation);

    prop.setInsertable(false);
    prop.setUpdateable(false);

    Generator generator = pkcol.getGenerator();

    setPKColumnGenerator(mappings, clazz, tab, column, id, generator);

    tab.setIdentifierValue(id);
    clazz.setIdentifier(id);
    clazz.setIdentifierProperty(prop);
    clazz.setDiscriminatorValue(mdTable.getQualifiedName());

}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:49,代码来源:HibernateConfig.java

示例9: translate

import org.hibernate.mapping.PrimaryKey; //导入依赖的package包/类
@Override
public void translate(TranslatorContext tc) {
    DatabaseCollector collector = tc.getDatabaseCollector();
    Map<String, TableIdentifier> mapped = new HashMap<>();
    RDBMS rdbms = setupRDBMS(tc);
    Map<String, Join> tableToJoin = new HashMap<>();
    Map<TableIdentifier,PrimaryKey> pks = new HashMap<>();

    rdbms.setDialect((String) tc.getMap().get("rdbmsDialect"));

    for (Iterator<Table> i = collector.iterateTables(); i.hasNext();) {
        Table table = i.next();
        if(table.getColumnSpan()==0) {
            LOGGER.warn("Table without column found and it will be ignored. Its name is '" + table + "'.");
            continue;
        }
        /*
        // TODO analyze this case
        if(revengStrategy.isManyToManyTable(table)) {}
        */

        Map<String, ForeignKey> fks = new HashMap<>();

        TableIdentifier tableIdentifier = TableIdentifier.create(table);
        String id = tableIdentifier.toString();

        pks.put(tableIdentifier,table.getPrimaryKey());

        if(!mapped.containsKey(id)) {
            mapped.put(id, tableIdentifier);
        } else {
            throw new IllegalStateException("Table mapped twice");
        }

        Join join = null;
        if(tableToJoin.get(id) == null){
            join = new Join();
            join.setProjectionMappings(new ArrayList<ProjectionMapping>());
            join.setTables(new ArrayList<com.redhat.lightblue.metadata.rdbms.model.Table>());
            join.setJoinTablesStatement("");
            rdbms.getSQLMapping().getJoins().add(join);
            tableToJoin.put(id,join);
        }else{
            join = tableToJoin.get(id);
        }

        for (Iterator<ForeignKey> j =  table.getForeignKeyIterator(); j.hasNext();) {
            ForeignKey fk = j.next();
            Table referencedTable = fk.getReferencedTable();
            TableIdentifier ti = TableIdentifier.create(referencedTable);
            tableToJoin.put(ti.toString(),join);
            for (Iterator<Column> z =  fk.getColumns().iterator(); z.hasNext();) {
                Column c =  z.next();
                fks.put(c.getName(),fk);
                String joinTable = join.getJoinTablesStatement();
                if(joinTable.length() !=  0){
                    joinTable = joinTable + " AND ";
                }
                join.setJoinTablesStatement(joinTable + table.getName() + "." + c.getName() + "=" + referencedTable.getName() + "." + c.getName());
            }
        }

        for (Iterator<Column> j = table.getColumnIterator(); j.hasNext();) {
            Column column = j.next();
            if(fks.get(column.getName())== null ){
                ColumnToField field = setupColumnToField(table, column);
                rdbms.getSQLMapping().getColumnToFieldMap().add(field);

                ProjectionMapping projectionMapping = setupProjectionMapping(column);
                join.getProjectionMappings().add(projectionMapping);
            }
        }

        com.redhat.lightblue.metadata.rdbms.model.Table rdbmTable = new com.redhat.lightblue.metadata.rdbms.model.Table();
        rdbmTable.setName(table.getName());
        join.getTables().add(rdbmTable);
    }
}
 
开发者ID:lightblue-platform,项目名称:lightblue-rdbms,代码行数:79,代码来源:JoinedTablesSQLMappingTranslator.java


注:本文中的org.hibernate.mapping.PrimaryKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。