⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractcollectionpersister.java

📁 介绍了hibernate的入门有一些基本常用的事例
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				if ( entries.hasNext() ) {					try {						collection.preInsert( this );						int i = 0;						int count = 0;						while ( entries.hasNext() ) {							final Object entry = entries.next();							if ( collection.entryExists( entry, i ) ) {								int offset = 1;								PreparedStatement st = null;								if ( isInsertCallable() ) {									CallableStatement callstatement = session.getBatcher()										.prepareBatchCallableStatement( getSQLInsertRowString() );									callstatement.registerOutParameter( offset++, Types.NUMERIC ); // TODO: should we require users to return number of update rows ?									st = callstatement;								}								else {									st = session.getBatcher().prepareBatchStatement( getSQLInsertRowString() );								}								//TODO: copy/paste from insertRows()								int loc = writeKey( st, id, offset, session );								if ( hasIdentifier ) {									loc = writeIdentifier( st, collection.getIdentifier(entry, i), loc, session );								}								if ( hasIndex /*&& !indexIsFormula*/ ) {									loc = writeIndex( st, collection.getIndex(entry, i, this), loc, session );								}								//if ( !elementIsFormula ) {									loc = writeElement(st, collection.getElement(entry), loc, session );								//}								session.getBatcher().addToBatch( 1 );								collection.afterRowInsert( this, entry, i );								count++;							}							i++;						}						if ( log.isDebugEnabled() ) log.debug( "done inserting collection: " + count + " rows inserted" );					}					catch ( SQLException sqle ) {						session.getBatcher().abortBatch( sqle );						throw sqle;					}				}				else {					if ( log.isDebugEnabled() ) log.debug( "collection was empty" );				}			}			catch ( SQLException sqle ) {				throw JDBCExceptionHelper.convert(				        sqlExceptionConverter,				        sqle,				        "could not insert collection: " + 				        MessageHelper.collectionInfoString( this, id, getFactory() ),				        getSQLInsertRowString()				);			}		}	}		protected boolean isRowDeleteEnabled() {		return true;	}	public void deleteRows(PersistentCollection collection, Serializable id, SessionImplementor session)			throws HibernateException {		if ( !isInverse && isRowDeleteEnabled() ) {			if ( log.isDebugEnabled() ) {				log.debug( "Deleting rows of collection: " + MessageHelper.collectionInfoString( this, id, getFactory() ) );			}						boolean deleteByIndex = !isOneToMany() && hasIndex && !indexIsFormula;						try {				//delete all the deleted entries				Iterator deletes = collection.getDeletes( this, !deleteByIndex );				if ( deletes.hasNext() ) {					int offset = 1;					int count = 0;					PreparedStatement st = null;					if ( isDeleteCallable() ) {						CallableStatement callstatement = session.getBatcher()							.prepareBatchCallableStatement( getSQLDeleteRowString() );						callstatement.registerOutParameter( offset++, Types.NUMERIC ); // TODO: should we require users to return number of update rows ?						st = callstatement;					}					else {						st = session.getBatcher().prepareBatchStatement( getSQLDeleteRowString() );					}					try {						int i=0;						while ( deletes.hasNext() ) {							Object entry = deletes.next();							int loc = offset;							if ( hasIdentifier ) {								loc = writeIdentifier( st, entry, loc, session );							}							else {								//if ( !isOneToMany() ) {									loc = writeKey( st, id, loc, session );								//}								if (deleteByIndex) {									loc = writeIndexToWhere( st, entry, loc, session );								}								else {									loc = writeElementToWhere( st, entry, loc, session );								}							}							session.getBatcher().addToBatch( -1 );							count++;							i++;						}					}					catch ( SQLException sqle ) {						session.getBatcher().abortBatch( sqle );						throw sqle;					}					if ( log.isDebugEnabled() ) log.debug( "done deleting collection rows: " + count + " deleted" );				}				else {					if ( log.isDebugEnabled() ) log.debug( "no rows to delete" );				}			}			catch ( SQLException sqle ) {				throw JDBCExceptionHelper.convert(				        sqlExceptionConverter,				        sqle,				        "could not delete collection rows: " + 				        MessageHelper.collectionInfoString( this, id, getFactory() ),				        getSQLDeleteRowString()				);			}		}	}		protected boolean isRowInsertEnabled() {		return true;	}	public void insertRows(PersistentCollection collection, Serializable id, SessionImplementor session)			throws HibernateException {		if ( !isInverse && isRowInsertEnabled() ) {			if ( log.isDebugEnabled() ) {				log.debug( "Inserting rows of collection: " + MessageHelper.collectionInfoString( this, id, getFactory() ) );			}			try {				//insert all the new entries				Iterator entries = collection.entries(this);				boolean callable = isInsertCallable();				try {					collection.preInsert( this );					int i = 0;					int count = 0;					int offset = 1;					while ( entries.hasNext() ) {						Object entry = entries.next();						PreparedStatement st = null;						if ( collection.needsInserting( entry, i, elementType ) ) {							if ( st == null ) {								if ( callable ) {									CallableStatement callstatement = session.getBatcher()										.prepareBatchCallableStatement( getSQLInsertRowString() );									callstatement.registerOutParameter( offset++, Types.NUMERIC ); // TODO: should we require users to return number of update rows ?									st = callstatement;								}								else {									st = session.getBatcher().prepareBatchStatement( getSQLInsertRowString() );								}							}							//TODO: copy/paste from recreate()							int loc = writeKey( st, id, offset, session );							if ( hasIdentifier ) {								loc = writeIdentifier( st, collection.getIdentifier(entry, i), loc, session );							}							if ( hasIndex /*&& !indexIsFormula*/ ) {								loc = writeIndex( st, collection.getIndex(entry, i, this), loc, session );							}							//if ( !elementIsFormula ) {								loc = writeElement(st, collection.getElement(entry), loc, session );							//}							session.getBatcher().addToBatch( 1 );							collection.afterRowInsert( this, entry, i );							count++;						}						i++;					}					if ( log.isDebugEnabled() ) log.debug( "done inserting rows: " + count + " inserted" );				}				catch ( SQLException sqle ) {					session.getBatcher().abortBatch( sqle );					throw sqle;				}			}			catch ( SQLException sqle ) {				throw JDBCExceptionHelper.convert(				        sqlExceptionConverter,				        sqle,				        "could not insert collection rows: " + 				        MessageHelper.collectionInfoString( this, id, getFactory() ),				        getSQLInsertRowString()				);			}		}	}	public String getRole() {		return role;	}	public String getOwnerEntityName() {		return entityName;	}	public EntityPersister getOwnerEntityPersister() {		return ownerPersister;	}	public IdentifierGenerator getIdentifierGenerator() {		return identifierGenerator;	}	public Type getIdentifierType() {		return identifierType;	}	public boolean hasOrphanDelete() {		return hasOrphanDelete;	}	public Type toType(String propertyName) throws QueryException {		if ( "index".equals( propertyName ) ) return indexType;		return elementPropertyMapping.toType( propertyName );	}	public abstract boolean isManyToMany();	public String[] toColumns(String alias, String propertyName)			throws QueryException {		if ( "index".equals( propertyName ) ) {			if ( isManyToMany() ) {				throw new QueryException( "index() function not supported for many-to-many association" );			}			return StringHelper.qualify( alias, indexColumnNames );		}		return elementPropertyMapping.toColumns( alias, propertyName );	}	public String[] toColumns(String propertyName)			throws QueryException {		if ( "index".equals( propertyName ) ) {			if ( isManyToMany() ) {				throw new QueryException( "index() function not supported for many-to-many association" );			}			return indexColumnNames;		}		return elementPropertyMapping.toColumns( propertyName );	}	public Type getType() {		return elementPropertyMapping.getType(); //==elementType ??	}	public String getName() {		return getRole();	}	public EntityPersister getElementPersister() {		if ( elementPersister == null ) throw new AssertionFailure( "not an association" );		return ( Loadable ) elementPersister;	}	public boolean isCollection() {		return true;	}	public Serializable[] getCollectionSpaces() {		return spaces;	}	protected abstract String generateDeleteString();	protected abstract String generateDeleteRowString();	protected abstract String generateUpdateRowString();	protected abstract String generateInsertRowString();	public void updateRows(PersistentCollection collection, Serializable id, SessionImplementor session) 	throws HibernateException {		if ( !isInverse && collection.isRowUpdatePossible() ) {			if ( log.isDebugEnabled() ) log.debug( "Updating rows of collection: " + role + "#" + id );			//update all the modified entries			int count = doUpdateRows( id, collection, session );			if ( log.isDebugEnabled() ) log.debug( "done updating rows: " + count + " updated" );		}	}	protected abstract int doUpdateRows(Serializable key, PersistentCollection collection, SessionImplementor session) 	throws HibernateException;	public CollectionMetadata getCollectionMetadata() {		return this;	}	public SessionFactoryImplementor getFactory() {		return factory;	}	protected String filterFragment(String alias) throws MappingException {		return hasWhere() ? " and " + getSQLWhereString( alias ) : "";	}	public String filterFragment(String alias, Map enabledFilters) throws MappingException {		StringBuffer sessionFilterFragment = new StringBuffer();		// if we have any defined filters, see if they have been enabled on the session;		// and if so, prepend them to the filterFragment		if ( getFilterNames() != null && getFilterNames().length > 0 ) {			for ( int i = 0, max = getFilterNames().length; i < max; i++ ) {				if ( enabledFilters.containsKey( getFilterNames()[i] ) ) {					final String condition = getFilterConditions()[i];					if ( StringHelper.isNotEmpty( condition ) ) {						sessionFilterFragment.append( " and " )								.append( StringHelper.replace( condition, FilterImpl.MARKER, alias ) );					}				}			}		}		return sessionFilterFragment.append( filterFragment( alias ) ).toString();	}	public String oneToManyFilterFragment(String alias) throws MappingException {		return "";	}	protected boolean isInsertCallable() {		return insertCallable;	}	protected boolean isUpdateCallable() {		return updateCallable;	}	protected boolean isDeleteCallable() {		return deleteCallable;	}	protected boolean isDeleteAllCallable() {		return deleteAllCallable;	}	protected String[] getFilterNames() {		return filterNames;	}	protected String[] getFilterConditions() {		return filterConditions;	}	public String toString() {		return StringHelper.unqualify( getClass().getName() ) + '(' + role + ')';	}	public boolean isVersioned() {		return isVersioned && getOwnerEntityPersister().isVersioned();	}		public String getNodeName() {		return nodeName;	}	public String getElementNodeName() {		return elementNodeName;	}	public String getIndexNodeName() {		return indexNodeName;	}	protected SQLExceptionConverter getSQLExceptionConverter() {		return sqlExceptionConverter;	}	public CacheEntryStructure getCacheEntryStructure() {		return cacheEntryStructure;	}	public boolean isAffectedByEnabledFilters(SessionImplementor session) {		final Map enabledFilters = session.getEnabledFilters();		for ( int i = 0, max = filterNames.length; i < max; i++ ) {			if ( enabledFilters.containsKey( filterNames[i] ) ) {				return true;			}		}		return false;	}	public boolean isSubselectLoadable() {		return subselectLoadable;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -