本文整理汇总了Java中org.hibernate.ejb.HibernateEntityManager类的典型用法代码示例。如果您正苦于以下问题:Java HibernateEntityManager类的具体用法?Java HibernateEntityManager怎么用?Java HibernateEntityManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HibernateEntityManager类属于org.hibernate.ejb包,在下文中一共展示了HibernateEntityManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIdMetadata
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
Map<String, Object> response = new HashMap<String, Object>();
SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
if (metadata == null) {
return null;
}
String idProperty = metadata.getIdentifierPropertyName();
response.put("name", idProperty);
Type idType = metadata.getIdentifierType();
response.put("type", idType);
return response;
}
示例2: getIdMetadata
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
Map<String, Object> response = new HashMap<String, Object>();
SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
if (metadata == null) {
return null;
}
String idProperty = metadata.getIdentifierPropertyName();
response.put("name", idProperty);
Type idType = metadata.getIdentifierType();
response.put("type", idType);
return response;
}
示例3: init
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
private void init(HibernateEntityManager hem) {
hem.getSession().doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
String dbName = connection.getMetaData().getDatabaseProductName();
if (dbName.equals(MSSQLDialect.PRODUCT_NAME)) {
dialect = new MSSQLDialect();
} else if (dbName.equals(PostgresDialect.PRODUCT_NAME)) {
dialect = new PostgresDialect();
} else if (dbName.equals(H2Dialect.PRODUCT_NAME)) {
dialect = new H2Dialect();
} else if (dbName.equals(MySQLDialect.PRODUCT_NAME)) {
dialect = new MySQLDialect();
} else {
dialect = new DefaultDialect();
}
}
});
}
示例4: execute
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public IndicatorListResult execute(final GetIndicators cmd, final UserExecutionContext context) throws CommandException {
final EntityManager entityManager = em();
// Creates a new instance for every call.
// Be careful, this must NOT be a singleton because the DAO is stateful.
final IndicatorDAO indicatorDAO = new IndicatorHibernateDAO();
if(entityManager instanceof HibernateEntityManager) {
findIndicators((HibernateEntityManager)entityManager, indicatorDAO, cmd.getUserDatabaseId());
} else {
throw new UnsupportedOperationException("Entity manager type not supported. Required org.hibernate.ejb.HibernateEntityManager, found: " + entityManager.getClass().getName());
}
return indicatorDAO.getResult();
}
示例5: save
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
/**
* Saves a business object.
*
* @see org.kuali.rice.krad.dao.BusinessObjectDao#save(org.kuali.rice.krad.bo.PersistableBusinessObject)
*/
public PersistableBusinessObject save(PersistableBusinessObject bo) throws DataAccessException {
/* KC determined this is not needed for JPA
// if collections exist on the BO, create a copy and use to process the
// collections to ensure
// that removed elements are deleted from the database
Set<String> boCollections = getPersistenceStructureService().listCollectionObjectTypes(bo.getClass()).keySet();
PersistableBusinessObject savedBo = null;
if (!boCollections.isEmpty()) {
// refresh bo to get db copy of collections
savedBo = (PersistableBusinessObject) ObjectUtils.deepCopy(bo);
for (String boCollection : boCollections) {
if (getPersistenceStructureService().isCollectionUpdatable(savedBo.getClass(), boCollection)) {
savedBo.refreshReferenceObject(boCollection);
}
}
}
*/
if (entityManager.contains(bo) && ((HibernateEntityManager)entityManager).getSession().isReadOnly(bo)) {
((HibernateEntityManager)entityManager).getSession().setReadOnly(bo, false); // are we read only? turn that off...
}
return reattachAndSave(bo);
}
示例6: createBlob
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public Blob createBlob(MultipartFile uploadedFile) throws IOException {
Long size = uploadedFile.getSize();
InputStream inputStream = uploadedFile.getInputStream();
//We'll work with Blob instances and streams so that the uploaded files are never read into memory
return ((HibernateEntityManager) em).getSession().getLobHelper().createBlob(inputStream, size);
}
示例7: readGenericEntity
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public Object readGenericEntity(Class<?> clazz, Object id) {
Map<String, Object> md = daoHelper.getIdMetadata(clazz, (HibernateEntityManager) em);
AbstractSingleColumnStandardBasicType type = (AbstractSingleColumnStandardBasicType) md.get("type");
if (type instanceof LongType) {
id = Long.parseLong(String.valueOf(id));
} else if (type instanceof IntegerType) {
id = Integer.parseInt(String.valueOf(id));
}
return em.find(clazz, id);
}
示例8: getPropertyNames
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public List<String> getPropertyNames(Class<?> entityClass, HibernateEntityManager entityManager) {
ClassMetadata metadata = getSessionFactory(entityManager).getClassMetadata(entityClass);
List<String> propertyNames = new ArrayList<String>();
Collections.addAll(propertyNames, metadata.getPropertyNames());
return propertyNames;
}
示例9: getPropertyTypes
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public List<Type> getPropertyTypes(Class<?> entityClass, HibernateEntityManager entityManager) {
ClassMetadata metadata = getSessionFactory(entityManager).getClassMetadata(entityClass);
List<Type> propertyTypes = new ArrayList<Type>();
Collections.addAll(propertyTypes, metadata.getPropertyTypes());
return propertyTypes;
}
示例10: readOffersByAutomaticDeliveryType
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public List<Offer> readOffersByAutomaticDeliveryType() {
//TODO change this to a JPA criteria
Criteria criteria = ((HibernateEntityManager) em).getSession().createCriteria(OfferImpl.class);
Date myDate = getCurrentDateAfterFactoringInDateResolution();
Calendar c = Calendar.getInstance();
c.setTime(myDate);
c.add(Calendar.DATE, +1);
criteria.add(Restrictions.lt("startDate", c.getTime()));
c = Calendar.getInstance();
c.setTime(myDate);
c.add(Calendar.DATE, -1);
criteria.add(Restrictions.or(Restrictions.isNull("endDate"), Restrictions.gt("endDate", c.getTime())));
criteria.add(Restrictions.or(Restrictions.eq("archiveStatus.archived", 'N'),
Restrictions.isNull("archiveStatus.archived")));
// Automatically Added or (Automatically Added is null and deliveryType is Automatic)
criteria.add(Restrictions.or(Restrictions.eq("automaticallyAdded", true),
Restrictions.and(Restrictions.isNull("automaticallyAdded"),
Restrictions.eq("deliveryType", "AUTOMATIC"))));
criteria.setCacheable(true);
criteria.setCacheRegion("query.Offer");
return criteria.list();
}
示例11: getPolymorphicClasses
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
protected String[] getPolymorphicClasses(Class<?> clazz) {
DynamicDaoHelperImpl helper = new DynamicDaoHelperImpl();
Class<?>[] classes = helper.getAllPolymorphicEntitiesFromCeiling(clazz,
helper.getSessionFactory((HibernateEntityManager) em),
true,
useCache());
String[] result = new String[classes.length];
for (int i = 0; i < classes.length; i++) {
result[i] = classes[i].getName();
}
return result;
}
示例12: readGenericEntity
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public <T> T readGenericEntity(Class<T> clazz, Object id) {
clazz = (Class<T>) DynamicDaoHelperImpl.getNonProxyImplementationClassIfNecessary(clazz);
Map<String, Object> md = daoHelper.getIdMetadata(clazz, (HibernateEntityManager) em);
AbstractSingleColumnStandardBasicType type = (AbstractSingleColumnStandardBasicType) md.get("type");
if (type instanceof LongType) {
id = Long.parseLong(String.valueOf(id));
} else if (type instanceof IntegerType) {
id = Integer.parseInt(String.valueOf(id));
}
return em.find(clazz, id);
}
示例13: getPropertyNames
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public List<String> getPropertyNames(Class<?> entityClass, HibernateEntityManager entityManager) {
entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
ClassMetadata metadata = getSessionFactory(entityManager).getClassMetadata(entityClass);
List<String> propertyNames = new ArrayList<String>();
Collections.addAll(propertyNames, metadata.getPropertyNames());
return propertyNames;
}
示例14: getPropertyTypes
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
@Override
public List<Type> getPropertyTypes(Class<?> entityClass, HibernateEntityManager entityManager) {
entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
ClassMetadata metadata = getSessionFactory(entityManager).getClassMetadata(entityClass);
List<Type> propertyTypes = new ArrayList<Type>();
Collections.addAll(propertyTypes, metadata.getPropertyTypes());
return propertyTypes;
}
示例15: activateSession
import org.hibernate.ejb.HibernateEntityManager; //导入依赖的package包/类
private static void activateSession() {
Map<Object, Object> resourceMap = TransactionSynchronizationManager.getResourceMap();
for (Map.Entry<Object, Object> entry : resourceMap.entrySet()) {
if (entry.getKey() instanceof EntityManagerFactory && entry.getValue() instanceof EntityManagerHolder) {
((HibernateEntityManager) ((EntityManagerHolder) entry.getValue()).getEntityManager()).getSession();
}
}
}