Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.hql.spi;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Mappings;
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.hql.internal.ast.HqlSqlWalker;
import org.hibernate.internal.AbstractSessionImpl;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.SelectValues;
import org.hibernate.type.UUIDCharType;
/**
* @author Steve Ebersole
*/
public class PersistentTableBulkIdStrategy implements MultiTableBulkIdStrategy {
private static final CoreMessageLogger log = Logger.getMessageLogger(
CoreMessageLogger.class,
PersistentTableBulkIdStrategy.class.getName()
);
public static final String SHORT_NAME = "persistent";
public static final String CLEAN_UP_ID_TABLES = "hibernate.hql.bulk_id_strategy.persistent.clean_up";
public static final String SCHEMA = "hibernate.hql.bulk_id_strategy.persistent.schema";
public static final String CATALOG = "hibernate.hql.bulk_id_strategy.persistent.catalog";
private String catalog;
private String schema;
private boolean cleanUpTables;
private List tableCleanUpDdl;
@Override
public void prepare(
JdbcServices jdbcServices,
JdbcConnectionAccess connectionAccess,
Mappings mappings,
Mapping mapping,
Map settings) {
this.catalog = ConfigurationHelper.getString(
CATALOG,
settings,
ConfigurationHelper.getString( AvailableSettings.DEFAULT_CATALOG, settings )
);
this.schema = ConfigurationHelper.getString(
SCHEMA,
settings,
ConfigurationHelper.getString( AvailableSettings.DEFAULT_SCHEMA, settings )
);
this.cleanUpTables = ConfigurationHelper.getBoolean( CLEAN_UP_ID_TABLES, settings, false );
final Iterator entityMappings = mappings.iterateClasses();
final List
idTableDefinitions = new ArrayList
();
while ( entityMappings.hasNext() ) {
final PersistentClass entityMapping = entityMappings.next();
final Table idTableDefinition = generateIdTableDefinition( entityMapping );
idTableDefinitions.add( idTableDefinition );
}
exportTableDefinitions( idTableDefinitions, jdbcServices, connectionAccess, mappings, mapping );
}
protected Table generateIdTableDefinition(PersistentClass entityMapping) {
Table idTable = new Table( entityMapping.getTemporaryIdTableName() );
if ( catalog != null ) {
idTable.setCatalog( catalog );
}
if ( schema != null ) {
idTable.setSchema( schema );
}
Iterator itr = entityMapping.getTable().getPrimaryKey().getColumnIterator();
while( itr.hasNext() ) {
Column column = (Column) itr.next();
idTable.addColumn( column.clone() );
}
Column sessionIdColumn = new Column( "hib_sess_id" );
sessionIdColumn.setSqlType( "CHAR(36)" );
sessionIdColumn.setComment( "Used to hold the Hibernate Session identifier" );
idTable.addColumn( sessionIdColumn );
idTable.setComment( "Used to hold id values for the " + entityMapping.getEntityName() + " class" );
return idTable;
}
protected void exportTableDefinitions(
List