📄 statelesssessionimpl.java
字号:
}
private PersistenceContext temporaryPersistenceContext = new StatefulPersistenceContext(this);
public Object get(Class entityClass, Serializable id) {
return get( entityClass.getName(), id );
}
public Object get(Class entityClass, Serializable id, LockMode lockMode) {
return get( entityClass.getName(), id, lockMode );
}
public Object get(String entityName, Serializable id) {
return get(entityName, id, LockMode.NONE);
}
public Object get(String entityName, Serializable id, LockMode lockMode) {
errorIfClosed();
Object result = getFactory().getEntityPersister(entityName)
.load(id, null, lockMode, this);
temporaryPersistenceContext.clear();
return result;
}
public String guessEntityName(Object entity) throws HibernateException {
errorIfClosed();
return entity.getClass().getName();
}
public Object immediateLoad(String entityName, Serializable id) throws HibernateException {
throw new SessionException("proxies cannot be fetched by a stateless session");
}
public void initializeCollection(PersistentCollection collection, boolean writing)
throws HibernateException {
throw new SessionException("collections cannot be fetched by a stateless session");
}
public Object instantiate(String entityName, Serializable id) throws HibernateException {
errorIfClosed();
return getFactory().getEntityPersister(entityName).instantiate(id, EntityMode.POJO);
}
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable)
throws HibernateException {
errorIfClosed();
EntityPersister persister = getFactory().getEntityPersister(entityName);
if ( !eager && persister.hasProxy() ) {
return persister.createProxy(id, this);
}
Object loaded = temporaryPersistenceContext.getEntity( new EntityKey(id, persister, EntityMode.POJO) );
//TODO: if not loaded, throw an exception
return loaded==null ? get(entityName, id) : loaded;
}
public boolean isConnected() {
return jdbcContext.getConnectionManager().isCurrentlyConnected();
}
public boolean isTransactionInProgress() {
return jdbcContext.isTransactionInProgress();
}
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
throw new UnsupportedOperationException();
}
public Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters)
throws HibernateException {
throw new UnsupportedOperationException();
}
public List listFilter(Object collection, String filter, QueryParameters queryParameters)
throws HibernateException {
throw new UnsupportedOperationException();
}
public void setAutoClear(boolean enabled) {
throw new UnsupportedOperationException();
}
public void setCacheMode(CacheMode cm) {
throw new UnsupportedOperationException();
}
public void setFlushMode(FlushMode fm) {
throw new UnsupportedOperationException();
}
public Transaction getTransaction() throws HibernateException {
errorIfClosed();
return jdbcContext.getTransaction();
}
public Transaction beginTransaction() throws HibernateException {
errorIfClosed();
Transaction result = getTransaction();
result.begin();
return result;
}
public boolean isEventSource() {
return false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//TODO: COPY/PASTE FROM SessionImpl, pull up!
public List list(String query, QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
queryParameters.validateParameters();
HQLQueryPlan plan = getHQLQueryPlan( query, false );
boolean success = false;
List results = CollectionHelper.EMPTY_LIST;
try {
results = plan.performList( queryParameters, this );
success = true;
}
finally {
afterOperation(success);
}
temporaryPersistenceContext.clear();
return results;
}
public void afterOperation(boolean success) {
if ( !jdbcContext.isTransactionInProgress() ) {
jdbcContext.afterNontransactionalQuery(success);
}
}
public Criteria createCriteria(Class persistentClass, String alias) {
errorIfClosed();
return new CriteriaImpl( persistentClass.getName(), alias, this );
}
public Criteria createCriteria(String entityName, String alias) {
errorIfClosed();
return new CriteriaImpl(entityName, alias, this);
}
public Criteria createCriteria(Class persistentClass) {
errorIfClosed();
return new CriteriaImpl( persistentClass.getName(), this );
}
public Criteria createCriteria(String entityName) {
errorIfClosed();
return new CriteriaImpl(entityName, this);
}
public ScrollableResults scroll(CriteriaImpl criteria, ScrollMode scrollMode) {
errorIfClosed();
String entityName = criteria.getEntityOrClassName();
CriteriaLoader loader = new CriteriaLoader(
getOuterJoinLoadable(entityName),
factory,
criteria,
entityName,
getEnabledFilters()
);
return loader.scroll(this, scrollMode);
}
public List list(CriteriaImpl criteria) throws HibernateException {
errorIfClosed();
String[] implementors = factory.getImplementors( criteria.getEntityOrClassName() );
int size = implementors.length;
CriteriaLoader[] loaders = new CriteriaLoader[size];
Set spaces = new HashSet();
for( int i=0; i <size; i++ ) {
loaders[i] = new CriteriaLoader(
getOuterJoinLoadable( implementors[i] ),
factory,
criteria,
implementors[i],
getEnabledFilters()
);
spaces.addAll( loaders[i].getQuerySpaces() );
}
List results = Collections.EMPTY_LIST;
boolean success = false;
try {
for( int i=0; i<size; i++ ) {
final List currentResults = loaders[i].list(this);
currentResults.addAll(results);
results = currentResults;
}
success = true;
}
finally {
afterOperation(success);
}
temporaryPersistenceContext.clear();
return results;
}
private OuterJoinLoadable getOuterJoinLoadable(String entityName) throws MappingException {
EntityPersister persister = factory.getEntityPersister(entityName);
if ( !(persister instanceof OuterJoinLoadable) ) {
throw new MappingException( "class persister is not OuterJoinLoadable: " + entityName );
}
return ( OuterJoinLoadable ) persister;
}
public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
throws HibernateException {
errorIfClosed();
CustomLoader loader = new CustomLoader( customQuery, getFactory() );
boolean success = false;
List results;
try {
results = loader.list(this, queryParameters);
success = true;
}
finally {
afterOperation(success);
}
temporaryPersistenceContext.clear();
return results;
}
public ScrollableResults scrollCustomQuery(CustomQuery customQuery, QueryParameters queryParameters)
throws HibernateException {
errorIfClosed();
CustomLoader loader = new CustomLoader( customQuery, getFactory() );
return loader.scroll(queryParameters, this);
}
public ScrollableResults scroll(String query, QueryParameters queryParameters) throws HibernateException {
errorIfClosed();
HQLQueryPlan plan = getHQLQueryPlan( query, false );
return plan.performScroll( queryParameters, this );
}
public void afterScrollOperation() {
temporaryPersistenceContext.clear();
}
public void flush() {}
public String getFetchProfile() {
return null;
}
public JDBCContext getJDBCContext() {
return jdbcContext;
}
public void setFetchProfile(String name) {}
public void afterTransactionBegin(Transaction tx) {}
protected boolean autoFlushIfRequired(Set querySpaces) throws HibernateException {
// no auto-flushing to support in stateless session
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -