Example usage for org.hibernate.mapping SimpleValue setIdentifierGeneratorProperties

List of usage examples for org.hibernate.mapping SimpleValue setIdentifierGeneratorProperties

Introduction

In this page you can find the example usage for org.hibernate.mapping SimpleValue setIdentifierGeneratorProperties.

Prototype

public void setIdentifierGeneratorProperties(Properties identifierGeneratorProperties) 

Source Link

Document

Sets the identifierGeneratorProperties.

Usage

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

private void manageIdentityGenerator(Mappings mappings, Table tab, SimpleValue id) {
    id.setIdentifierGeneratorStrategy("identity");
    Properties params = new Properties();
    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());

    params.setProperty(PersistentIdentifierGenerator.SCHEMA, escapeName(tab.getSchema()));
    id.setIdentifierGeneratorProperties(params);
    id.setNullValue(null);/*ww  w.ja va2 s.c om*/
}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

private void manageSequenceGenerator(Mappings mappings, Table tab, SimpleValue id,
        SequenceGenerator generator) {//from   w  ww .  ja  va  2  s.c om
    id.setIdentifierGeneratorStrategy("enhanced-sequence");
    Properties params = new Properties();
    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());
    params.put(SequenceStyleGenerator.SEQUENCE_PARAM, escapeName(generator.getName()));
    params.setProperty(SequenceStyleGenerator.SCHEMA, escapeName(tab.getSchema()));
    id.setIdentifierGeneratorProperties(params);
    id.setNullValue(null);
}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

private void manageTableGenerator(Mappings mappings, Table tab, SimpleValue id,
        com.manydesigns.portofino.model.database.TableGenerator generator) {
    id.setIdentifierGeneratorStrategy("enhanced-table");
    Properties params = new Properties();
    params.put(TableGenerator.TABLE, tab);
    params.put(TableGenerator.TABLE_PARAM, escapeName(generator.getTable()));
    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());
    params.put(TableGenerator.SEGMENT_COLUMN_PARAM, escapeName(generator.getKeyColumn()));
    params.put(TableGenerator.SEGMENT_VALUE_PARAM, generator.getKeyValue());
    params.put(TableGenerator.VALUE_COLUMN_PARAM, escapeName(generator.getValueColumn()));
    params.setProperty(TableGenerator.SCHEMA, escapeName(tab.getSchema()));
    id.setIdentifierGeneratorProperties(params);
    id.setNullValue(null);//from ww w  . ja v a  2  s.  co m
}

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

private void manageIncrementGenerator(Mappings mappings, Table tab, SimpleValue id, String entityName) {
    id.setIdentifierGeneratorStrategy("increment");
    Properties params = new Properties();
    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());
    params.setProperty(PersistentIdentifierGenerator.SCHEMA, escapeName(tab.getSchema()));
    params.put(IncrementGenerator.ENTITY_NAME, entityName);
    id.setIdentifierGeneratorProperties(params);
    id.setNullValue(null);//from   ww  w.  j  av  a  2s .  co  m
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

@SuppressWarnings("unchecked")
protected void bindSimpleId(GrailsDomainClassProperty identifier, RootClass entity, Mappings mappings,
        Identity mappedId, String sessionFactoryBeanName) {

    Mapping mapping = getMapping(identifier.getDomainClass());
    boolean useSequence = mapping != null && mapping.isTablePerConcreteClass();

    // create the id value
    SimpleValue id = new SimpleValue(mappings, entity.getTable());
    // set identifier on entity

    Properties params = new Properties();
    entity.setIdentifier(id);/*from   w  w w . j  av a 2  s  .  co m*/

    if (mappedId == null) {
        // configure generator strategy
        id.setIdentifierGeneratorStrategy(useSequence ? "sequence-identity" : "native");
    } else {
        String generator = mappedId.getGenerator();
        if ("native".equals(generator) && useSequence) {
            generator = "sequence-identity";
        }
        id.setIdentifierGeneratorStrategy(generator);
        params.putAll(mappedId.getParams());
        if ("assigned".equals(generator)) {
            id.setNullValue("undefined");
        }
    }

    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());

    if (mappings.getSchemaName() != null) {
        params.setProperty(PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName());
    }
    if (mappings.getCatalogName() != null) {
        params.setProperty(PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName());
    }
    id.setIdentifierGeneratorProperties(params);

    // bind value
    bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName);

    // create property
    Property prop = new Property();
    prop.setValue(id);

    // bind property
    bindProperty(identifier, prop, mappings);
    // set identifier property
    entity.setIdentifierProperty(prop);

    id.getTable().setIdentifierValue(id);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

@SuppressWarnings("unchecked")
private static void bindSimpleId(GrailsDomainClassProperty identifier, RootClass entity, Mappings mappings,
        Identity mappedId, String sessionFactoryBeanName) {

    // create the id value
    SimpleValue id = new SimpleValue(mappings, entity.getTable());
    // set identifier on entity

    Properties params = new Properties();
    entity.setIdentifier(id);//from   w  w w.j av a  2 s  .  c o m

    if (mappedId != null) {
        id.setIdentifierGeneratorStrategy(mappedId.getGenerator());
        params.putAll(mappedId.getParams());
        if ("assigned".equals(mappedId.getGenerator())) {
            id.setNullValue("undefined");
        }
    } else {
        // configure generator strategy
        id.setIdentifierGeneratorStrategy("native");
    }

    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());

    if (mappings.getSchemaName() != null) {
        params.setProperty(PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName());
    }
    if (mappings.getCatalogName() != null) {
        params.setProperty(PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName());
    }
    id.setIdentifierGeneratorProperties(params);

    // bind value
    bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName);

    // create property
    Property prop = new Property();
    prop.setValue(id);

    // bind property
    bindProperty(identifier, prop, mappings);
    // set identifier property
    entity.setIdentifierProperty(prop);

    id.getTable().setIdentifierValue(id);
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

@SuppressWarnings("unchecked")
protected void bindSimpleId(PersistentProperty identifier, RootClass entity, Mappings mappings,
        Identity mappedId, String sessionFactoryBeanName) {

    Mapping mapping = getMapping(identifier.getOwner());
    boolean useSequence = mapping != null && mapping.isTablePerConcreteClass();

    // create the id value
    SimpleValue id = new SimpleValue(mappings, entity.getTable());
    // set identifier on entity

    Properties params = new Properties();
    entity.setIdentifier(id);/*from ww  w  . ja  v a  2  s .co  m*/

    if (mappedId == null) {
        // configure generator strategy
        id.setIdentifierGeneratorStrategy(useSequence ? "sequence-identity" : "native");
    } else {
        String generator = mappedId.getGenerator();
        if ("native".equals(generator) && useSequence) {
            generator = "sequence-identity";
        }
        id.setIdentifierGeneratorStrategy(generator);
        params.putAll(mappedId.getParams());
        if ("assigned".equals(generator)) {
            id.setNullValue("undefined");
        }
    }

    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer());

    if (mappings.getSchemaName() != null) {
        params.setProperty(PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName());
    }
    if (mappings.getCatalogName() != null) {
        params.setProperty(PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName());
    }
    id.setIdentifierGeneratorProperties(params);

    // bind value
    bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName);

    // create property
    Property prop = new Property();
    prop.setValue(id);

    // bind property
    bindProperty(identifier, prop, mappings);
    // set identifier property
    entity.setIdentifierProperty(prop);

    id.getTable().setIdentifierValue(id);
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

@SuppressWarnings("unchecked")
protected void bindSimpleId(PersistentProperty identifier, RootClass entity, InFlightMetadataCollector mappings,
        Identity mappedId, String sessionFactoryBeanName) {

    Mapping mapping = getMapping(identifier.getOwner());
    boolean useSequence = mapping != null && mapping.isTablePerConcreteClass();

    // create the id value
    SimpleValue id = new SimpleValue(mappings, entity.getTable());
    // set identifier on entity

    Properties params = new Properties();
    entity.setIdentifier(id);//from www  .j a va2  s .  co m

    if (mappedId == null) {
        // configure generator strategy
        id.setIdentifierGeneratorStrategy(useSequence ? "sequence-identity" : "native");
    } else {
        String generator = mappedId.getGenerator();
        if ("native".equals(generator) && useSequence) {
            generator = "sequence-identity";
        }
        id.setIdentifierGeneratorStrategy(generator);
        params.putAll(mappedId.getParams());
        if (params.containsKey(SEQUENCE_KEY)) {
            params.put(SequenceStyleGenerator.SEQUENCE_PARAM, params.getProperty(SEQUENCE_KEY));
        }
        if ("assigned".equals(generator)) {
            id.setNullValue("undefined");
        }
    }

    String schemaName = getSchemaName(mappings);
    String catalogName = getCatalogName(mappings);

    params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
            this.metadataBuildingContext.getObjectNameNormalizer());

    if (schemaName != null) {
        params.setProperty(PersistentIdentifierGenerator.SCHEMA, schemaName);
    }
    if (catalogName != null) {
        params.setProperty(PersistentIdentifierGenerator.CATALOG, catalogName);
    }
    id.setIdentifierGeneratorProperties(params);

    // bind value
    bindSimpleValue(identifier, null, id, EMPTY_PATH, mappings, sessionFactoryBeanName);

    // create property
    Property prop = new Property();
    prop.setValue(id);

    // bind property
    bindProperty(identifier, prop, mappings);
    // set identifier property
    entity.setIdentifierProperty(prop);

    id.getTable().setIdentifierValue(id);
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

protected void bindSimpleValue(PersistentProperty grailsProp, PersistentProperty parentProperty,
        SimpleValue simpleValue, String path, PropertyConfig propertyConfig, String sessionFactoryBeanName) {
    setTypeForPropertyConfig(grailsProp, simpleValue, propertyConfig);
    final PropertyConfig mappedForm = (PropertyConfig) grailsProp.getMapping().getMappedForm();
    if (mappedForm.isDerived() && !(grailsProp instanceof TenantId)) {
        Formula formula = new Formula();
        formula.setFormula(propertyConfig.getFormula());
        simpleValue.addFormula(formula);
    } else {/*  www  . j  av  a 2s .c o  m*/
        Table table = simpleValue.getTable();
        boolean hasConfig = propertyConfig != null;

        String generator = hasConfig ? propertyConfig.getGenerator() : null;
        if (generator != null) {
            simpleValue.setIdentifierGeneratorStrategy(generator);
            Properties params = propertyConfig.getTypeParams();
            if (params != null) {
                Properties generatorProps = new Properties();
                generatorProps.putAll(params);

                if (generatorProps.containsKey(SEQUENCE_KEY)) {
                    generatorProps.put(SequenceStyleGenerator.SEQUENCE_PARAM,
                            generatorProps.getProperty(SEQUENCE_KEY));
                }
                simpleValue.setIdentifierGeneratorProperties(generatorProps);
            }
        }

        // Add the column definitions for this value/property. Note that
        // not all custom mapped properties will have column definitions,
        // in which case we still need to create a Hibernate column for
        // this value.
        List<?> columnDefinitions = hasConfig ? propertyConfig.getColumns()
                : Arrays.asList(new Object[] { null });
        if (columnDefinitions.isEmpty()) {
            columnDefinitions = Arrays.asList(new Object[] { null });
        }

        for (Object columnDefinition : columnDefinitions) {
            ColumnConfig cc = (ColumnConfig) columnDefinition;
            Column column = new Column();

            // Check for explicitly mapped column name and SQL type.
            if (cc != null) {
                if (cc.getName() != null) {
                    column.setName(cc.getName());
                }
                if (cc.getSqlType() != null) {
                    column.setSqlType(cc.getSqlType());
                }
            }

            column.setValue(simpleValue);

            if (cc != null) {
                if (cc.getLength() != -1) {
                    column.setLength(cc.getLength());
                }
                if (cc.getPrecision() != -1) {
                    column.setPrecision(cc.getPrecision());
                }
                if (cc.getScale() != -1) {
                    column.setScale(cc.getScale());
                }
                if (!mappedForm.isUniqueWithinGroup()) {
                    column.setUnique(cc.isUnique());
                }
            }

            bindColumn(grailsProp, parentProperty, column, cc, path, table, sessionFactoryBeanName);

            if (table != null) {
                table.addColumn(column);
            }

            simpleValue.addColumn(column);
        }
    }
}