Example usage for org.hibernate.mapping Column Column

List of usage examples for org.hibernate.mapping Column Column

Introduction

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

Prototype

public Column(String columnName) 

Source Link

Usage

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java

License:Apache License

private String[] getColumnTypesForColumnNames(EntityType<?> entityType, String[] columnNames, Table[] tables) {
    String[] columnTypes = new String[columnNames.length];
    for (int i = 0; i < columnNames.length; i++) {
        Column column = null;//  w  w w  . ja v a2  s.  c  om
        for (int j = 0; j < tables.length; j++) {
            column = tables[j].getColumn(new Column(columnNames[i]));
            if (column != null) {
                break;
            }
        }

        if (column == null) {
            throw new IllegalArgumentException(
                    "Could not find column '" + columnNames[i] + "' in entity: " + entityType.getName());
        }

        columnTypes[i] = column.getSqlType();
    }

    return columnTypes;
}

From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.java

License:Open Source License

/**
 * Returns maximum valid folder URI length
 *
 * The method is used for futher lazy initialization of resourceUriLength.
 * Loads sessionFactory bean from application context as LocalSessionFactoryBean class instance.
 * Bean is needed for getting hibernate Configuration object which stores configuration metadata.
 *
 * @return maximum valid folder URI length.
 *
 *
 * *///from   w  ww.  ja  v a 2  s. co  m
private int getMaxUriLength() {
    if (resourceUriLength >= 0) {
        return resourceUriLength;
    }

    //If resourceUriLength is not initialized yet
    LocalSessionFactoryBean localSessionFactoryBean = (LocalSessionFactoryBean) applicationContext
            .getBean("&sessionFactory");

    String entityName = RepoFolder.class.getCanonicalName();
    PersistentClass persistentClass = localSessionFactoryBean.getConfiguration().getClassMapping(entityName);

    resourceUriLength = persistentClass.getTable().getColumn(new Column("URI")).getLength();
    return resourceUriLength;
}

From source file:com.zutubi.pulse.master.transfer.jdbc.HibernateUniqueKeyTable.java

License:Apache License

public static Table getMapping() {
    Table table = new Table("hibernate_unique_key");
    Column column = new Column("next_hi");
    SimpleValue value = new SimpleValue(null, table);
    value.setTypeName(int.class.getName());
    column.setValue(value);// w  w  w  .  j a va  2  s.  c o m
    column.setSqlTypeCode(Types.INTEGER);
    table.addColumn(column);
    return table;
}

From source file:net.lshift.hibernate.migrations.AlterTableBuilder.java

License:Apache License

private static Column buildColumnDefinition(String name, int sqlType, int length, boolean nullable,
        Object defaultVal) {/*  w  w  w .  j av  a 2  s.c  om*/
    Column col = new Column(name);
    col.setSqlTypeCode(sqlType);
    col.setNullable(nullable);
    col.setLength(length);
    col.setDefaultValue(defaultVal != null ? defaultVal.toString() : null);
    return col;
}

From source file:net.lshift.hibernate.migrations.AlterTableBuilder.java

License:Apache License

public AlterTableBuilder addForeignKey(String name, String[] columnNames, String referencedTable,
        String[] referencedColumns) {
    ForeignKey fk = new ForeignKey();
    fk.setName(name);//from   w  w w  .  j  a  v  a  2s  .c  om
    for (String col : columnNames)
        fk.addColumn(new Column(col));
    fk.setTable(new Table(table));

    PrimaryKey refPrimaryKey = new PrimaryKey();
    for (String col : referencedColumns)
        refPrimaryKey.addColumn(new Column(col));
    Table refTable = new Table(referencedTable);
    refTable.setPrimaryKey(refPrimaryKey);

    fk.setReferencedTable(refTable);

    String defaultCatalog = config.getProperties().getProperty(Environment.DEFAULT_CATALOG);
    String defaultSchema = config.getProperties().getProperty(Environment.DEFAULT_SCHEMA);

    // fk.sqlConstraintString appears to generate incorrect SQL against MySQL in some instances.
    // The referenced columns are not always correctly listed.
    //    alterFragments.add(" add index " + fk.getName() + " (" + StringHelper.join(", ", columnNames) +
    //        "), add constraint " + fk.getName() + " foreign key (" + StringHelper.join(", ", columnNames) +
    //        " references " + referencedTable + " (" + StringHelper.join(", ", referencedColumns) + ")");
    alterFragments.add(fk.sqlConstraintString(dialect, fk.getName(), defaultCatalog, defaultSchema));
    return this;
}

From source file:net.lshift.hibernate.migrations.AlterTableBuilder.java

License:Apache License

public AlterTableBuilder addUniqueConstraint(String columnName) {
    UniqueKey uk = new UniqueKey();
    uk.addColumn(new Column(columnName));

    String constraintString = uk.sqlConstraintString(dialect);
    if (constraintString != null) {
        alterFragments.add("add " + constraintString);
    }//from  w ww  .j  av  a2 s. c o m

    return this;
}

From source file:net.lshift.hibernate.migrations.AlterTableBuilder.java

License:Apache License

public AlterTableBuilder addUniqueConstraint(String name, String... columnNames) {
    UniqueKey uk = new UniqueKey();
    for (String col : columnNames)
        uk.addColumn(new Column(col));

    String defaultCatalog = config.getProperties().getProperty(Environment.DEFAULT_CATALOG);
    String defaultSchema = config.getProperties().getProperty(Environment.DEFAULT_SCHEMA);

    alterFragments.add(uk.sqlConstraintString(dialect, name, defaultCatalog, defaultSchema));
    return this;
}

From source file:net.lshift.hibernate.migrations.AlterTableBuilder.java

License:Apache License

public AlterTableBuilder addPrimaryKey(String... cols) {
    PrimaryKey pk = new PrimaryKey();
    for (String col : cols) {
        pk.addColumn(new Column(col));
    }//  w w  w.java 2  s  .co  m
    alterFragments.add("add " + pk.sqlConstraintString(dialect));
    return this;
}

From source file:net.lshift.hibernate.migrations.AlterTableBuilder.java

License:Apache License

public AlterTableBuilder replacePrimaryKey(String... cols) {
    PrimaryKey pk = new PrimaryKey();
    for (String col : cols) {
        pk.addColumn(new Column(col));
    }/*  w  ww .  j a  v  a2 s.c o  m*/
    if (dialectExtension.supportsPrimaryKeyReplace()) {
        alterFragments.add("drop primary key, add " + pk.sqlConstraintString(dialect));
    } else {
        dropPrimaryKey().addPrimaryKey(cols);
    }
    return this;
}

From source file:net.lshift.hibernate.migrations.CreateTableBuilder.java

License:Apache License

public CreateTableBuilder column(String name, int sqlType, int length, boolean nullable, Object defaultVal) {
    Column col = new Column(name);
    col.setNullable(nullable);/*from   ww w .  java 2 s  .c  o m*/
    col.setSqlTypeCode(sqlType);
    col.setLength(length);
    col.setDefaultValue(defaultVal != null ? defaultVal.toString() : null);

    columns.add(col);

    return this;
}