org.hibernate.mapping.PrimaryKey Java Examples

The following examples show how to use org.hibernate.mapping.PrimaryKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ViewBuilder.java    From teiid-spring-boot with Apache License 2.0 6 votes vote down vote up
private void addPrimaryKey(org.hibernate.mapping.Table ormTable, Table view, MetadataFactory mf) {
    PrimaryKey pk = ormTable.getPrimaryKey();
    List<String> pkColumns = new ArrayList<>();
    if (pk != null) {
        Iterator<org.hibernate.mapping.Column> it = pk.getColumnIterator();
        while (it.hasNext()) {
            org.hibernate.mapping.Column c = it.next();
            Column col = view.getColumnByName(c.getName());
            if (pk.isGenerated(dialect)) {
                col.setAutoIncremented(true);
            }
            pkColumns.add(c.getName());
        }
        mf.addPrimaryKey("PK", pkColumns, view);
    }

}
 
Example #2
Source File: TableGenerator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	final Dialect dialect = database.getJdbcEnvironment().getDialect();

	final Namespace namespace = database.locateNamespace(
			qualifiedTableName.getCatalogName(),
			qualifiedTableName.getSchemaName()
	);

	Table table = namespace.locateTable( qualifiedTableName.getObjectName() );
	if ( table == null ) {
		table = namespace.createTable( qualifiedTableName.getObjectName(), false );

		// todo : note sure the best solution here.  do we add the columns if missing?  other?
		final Column segmentColumn = new ExportableColumn(
				database,
				table,
				segmentColumnName,
				StringType.INSTANCE,
				dialect.getTypeName( Types.VARCHAR, segmentValueLength, 0, 0 )
		);
		segmentColumn.setNullable( false );
		table.addColumn( segmentColumn );

		// lol
		table.setPrimaryKey( new PrimaryKey( table ) );
		table.getPrimaryKey().addColumn( segmentColumn );

		final Column valueColumn = new ExportableColumn(
				database,
				table,
				valueColumnName,
				LongType.INSTANCE
		);
		table.addColumn( valueColumn );
	}

	// allow physical naming strategies a chance to kick in
	this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
			table.getQualifiedTableName(),
			dialect
	);
	table.addInitCommand( generateInsertInitCommand() );

	this.selectQuery = buildSelectQuery( dialect );
	this.updateQuery = buildUpdateQuery();
	this.insertQuery = buildInsertQuery();
}
 
Example #3
Source File: MultipleHiLoPerTableGenerator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void registerExportables(Database database) {
	final Namespace namespace = database.locateNamespace(
			qualifiedTableName.getCatalogName(),
			qualifiedTableName.getSchemaName()
	);

	Table table = namespace.locateTable( qualifiedTableName.getObjectName() );
	if ( table == null ) {
		table = namespace.createTable( qualifiedTableName.getObjectName(), false );

		// todo : note sure the best solution here.  do we add the columns if missing?  other?
		table.setPrimaryKey( new PrimaryKey( table ) );

		final Column pkColumn = new ExportableColumn(
				database,
				table,
				segmentColumnName,
				StringType.INSTANCE,
				database.getDialect().getTypeName( Types.VARCHAR, keySize, 0, 0 )
		);
		pkColumn.setNullable( false );
		table.addColumn( pkColumn );
		table.getPrimaryKey().addColumn( pkColumn );

		final Column valueColumn = new ExportableColumn(
				database,
				table,
				valueColumnName,
				LongType.INSTANCE
		);
		table.addColumn( valueColumn );
	}

	final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment();

	// allow physical naming strategies a chance to kick in
	tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
			table.getQualifiedTableName(),
			jdbcEnvironment.getDialect()
	);

	query = "select " +
			valueColumnName +
			" from " +
			jdbcEnvironment.getDialect().appendLockHint( LockMode.PESSIMISTIC_WRITE, tableName ) +
			" where " + segmentColumnName + " = '" + segmentName + "'" +
			jdbcEnvironment.getDialect().getForUpdateString();

	update = "update " +
			tableName +
			" set " +
			valueColumnName +
			" = ? where " +
			valueColumnName +
			" = ? and " +
			segmentColumnName +
			" = '" +
			segmentName
			+ "'";

	insert = "insert into " + tableName +
			"(" + segmentColumnName + ", " + valueColumnName + ") " +
			"values('" + segmentName + "', ?)";



}