List of usage examples for org.hibernate InstantiationException getMessage
@Override
public String getMessage()
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
public S createTicketScheme(KenoSchemeDTO schemeDTO) { I issueData = issueDataDao.get(schemeDTO.getPeriodId()); checkConformPeriodInitConfig(issueData, schemeDTO); TicketPlatformInfo ticketPlatformInfo = ticketThenEntityManager .getTicketPlatformInfo(schemeDTO.getSponsorId()); checkTicketPlatformInfo(ticketPlatformInfo, schemeDTO);// ,??? S scheme = null;// w ww . jav a2s. c om try { scheme = schemeDao.getEntityClass().newInstance(); } catch (InstantiationException e) { throw new ServiceException(e.getMessage()); } catch (IllegalAccessException e) { throw new ServiceException(e.getMessage()); } scheme = newInstance(schemeDTO); scheme.setPeriodNumber(issueData.getPeriodNumber()); StringBuilder sb = new StringBuilder(50); sb.append("?").append(scheme.getLotteryType().getLotteryName()).append("") .append(scheme.getPeriodNumber()).append("").append(scheme.getMode().getModeName()) .append(scheme.getShareType().getShareName()).append("."); Transaction tran = userManager.createTransaction(TransactionType.SCHEME, sb.toString()); scheme.setTransactionId(tran.getId()); scheme.setSchemePrintState(SchemePrintState.UNPRINT); // / scheme.setOrderId(schemeDTO.getOrderId()); if (null != schemeDTO.getOfficialEndTime()) { scheme.setCommitTime(schemeDTO.getOfficialEndTime()); } // ?? if (null != schemeDTO.getPlatform()) { scheme.setPlatform(schemeDTO.getPlatform()); } scheme = doTicket(scheme, schemeDTO, ticketPlatformInfo, issueData); return scheme; }
From source file:com.cai310.lottery.service.lottery.keno.impl.KenoServiceImpl.java
/** * ?//from w ww . j a va 2 s. c o m * * @param dto * @return */ public S createScheme(KenoSchemeDTO schemeDTO) { I issueData = issueDataDao.get(schemeDTO.getPeriodId()); checkConformPeriodInitConfig(issueData, schemeDTO); User user = userManager.getUser(schemeDTO.getSponsorId()); checkUser(user, schemeDTO); S scheme = null; try { scheme = schemeDao.getEntityClass().newInstance(); } catch (InstantiationException e) { throw new ServiceException(e.getMessage()); } catch (IllegalAccessException e) { throw new ServiceException(e.getMessage()); } scheme = newInstance(schemeDTO); //?? if (null != schemeDTO.getPlatform()) { scheme.setPlatform(schemeDTO.getPlatform()); } Date commitTime = DateUtils.addMinutes(issueData.getEndedTime(), -kenoPlayer.getBeforeTime()); commitTime = DateUtils.addSeconds(commitTime, -kenoPlayer.getBeforeSecondsTime()); scheme.setCommitTime(commitTime); scheme.setPeriodNumber(issueData.getPeriodNumber()); scheme.setSponsorName(user.getUserName()); StringBuilder sb = new StringBuilder(50); sb.append("?").append(scheme.getLotteryType().getLotteryName()).append("") .append(scheme.getPeriodNumber()).append("").append(scheme.getMode().getModeName()) .append(scheme.getShareType().getShareName()).append("."); Transaction tran = userManager.createTransaction(TransactionType.SCHEME, sb.toString()); scheme.setTransactionId(tran.getId()); // ?? if (schemeDTO.isChase()) { Lottery lotteryType = scheme.getLotteryType(); ChasePlan chasePlan = new ChasePlan(); chasePlan.setPlatform(schemeDTO.getPlatform()); chasePlan.setLotteryType(lotteryType); chasePlan.setState(ChaseState.RUNNING); chasePlan.setUserId(user.getId()); chasePlan.setUserName(user.getUserName()); chasePlan.setTotalCost(schemeDTO.getTotalCostOfChase()); chasePlan.setRandom(schemeDTO.isRandomOfChase()); chasePlan.setRandomUnits(schemeDTO.getRandomUnitsOfChase()); chasePlan.setHasDan(false); chasePlan.setWonStop(schemeDTO.isWonStopOfChase()); chasePlan.setPrizeForWonStop(schemeDTO.getPrizeForWonStopOfChase()); chasePlan.setOutNumStop(schemeDTO.isOutNumStop()); chasePlan = this.setChasePlanPlayType(chasePlan, schemeDTO); chasePlan.setUnits(schemeDTO.getUnits()); chasePlan.setMode(schemeDTO.getMode()); chasePlan.setContent(schemeDTO.getContent()); chasePlan.setSchemeCost(schemeDTO.getSchemeCost()); chasePlan.setCapacityProfit(schemeDTO.getCapacityProfit()); try { chasePlan.setMultiples(schemeDTO.getMultiplesOfChase()); } catch (DataException e) { throw new ServiceException(e.getMessage()); } StringBuilder sb1 = new StringBuilder(20); sb1.append("??").append(lotteryType.getLotteryName()).append("?.") .append("?") .append(BigDecimalUtil.valueOf(chasePlan.getTotalCost()) + " ").append(" "); tran = userManager.createTransaction(TransactionType.CHASE, sb1.toString()); chasePlan.setTransactionId(tran.getId()); Prepayment chasePrepayment = userManager.createKenoPrepayment(chasePlan.getTransactionId(), user.getId(), BigDecimal.valueOf(chasePlan.getTotalCost()), PrepaymentType.CHASE, FundDetailType.CHASE, sb1.toString(), schemeDTO.getPlatform(), this.getLottery()); // ? chasePrepayment.getId() chasePlan.setPrepaymentId(chasePrepayment.getId()); if (schemeDTO.getStartChasePeriodId() != null) { if (scheme.getPeriodId().longValue() != schemeDTO.getStartChasePeriodId().longValue()) { I period = this.findIssueDataById(schemeDTO.getStartChasePeriodId()); chasePlan.setCurPeriodId(period.getPrevPreriodId()); chasePlan.setChasedCost(0); chasePlan = chasePlanEntityManager.saveChasePlan(chasePlan); scheme = null; return null; } } try { Integer nextMultiple = chasePlan.getNextMultiple();// ? if (nextMultiple == null || nextMultiple.intValue() <= 0) { throw new DataException("???"); } scheme.setMultiple(nextMultiple); scheme.setSchemeCost(scheme.getUnits() * nextMultiple * 2); } catch (DataException e) { throw new ServiceException(e.getMessage(), e); } try { chasePlan.chase(scheme.getPeriodId(), scheme.getSchemeCost()); } catch (DataException e) { throw new ServiceException(e.getMessage()); } chasePlan = chasePlanEntityManager.saveChasePlan(chasePlan); // scheme.setChaseId(chasePlan.getId()); BigDecimal subscriptionCost = BigDecimal.valueOf(scheme.getSchemeCost()); try { scheme.subscription(subscriptionCost); } catch (DataException e) { throw new ServiceException(e.getMessage(), e); } scheme = schemeDao.save(scheme); sb.setLength(0); sb.append("?").append(scheme.getLotteryType().getLotteryName()).append("") .append(scheme.getPeriodNumber()).append("").append("[") .append(scheme.getSchemeNumber()) .append("],??(?). "); Prepayment subscriptionPrepayment = userManager.transferKenoPrepayment(scheme.getTransactionId(), chasePlan.getPrepaymentId(), subscriptionCost, PrepaymentType.SUBSCRIPTION, FundDetailType.SUBSCRIPTION, sb.toString(), schemeDTO.getPlatform(), this.getLottery()); saveSubscription(scheme, subscriptionPrepayment.getId(), user, subscriptionCost, SubscriptionWay.INITIATE, schemeDTO.getPlatform()); return scheme; } else { switch (scheme.getShareType()) { case TOGETHER: scheme = doTogether(scheme, schemeDTO, user); break; case SELF: scheme = doSelf(scheme, schemeDTO, user); break; default: throw new ServiceException(": " + scheme.getShareType()); } // BigDecimal subscriptionCost = BigDecimal.valueOf(scheme.getSchemeCost()); // try { // scheme.subscription(subscriptionCost); // } catch (DataException e) { // throw new ServiceException(e.getMessage(), e); // } // scheme = schemeDao.save(scheme); // createSubscription(scheme, user, subscriptionCost, SubscriptionWay.INITIATE,schemeDTO.getPlatform(),schemeDTO.getZoomType()); return scheme; } }
From source file:com.jaspersoft.jasperserver.api.metadata.user.service.impl.ObjectPermissionServiceImpl.java
License:Open Source License
/** * Constructs an individual <code>BasicAclEntry</code> from the passed * <code>ObjectPermission</code> and <code>InternalURI</code>. * * <P>/*from ww w . j a va 2s. c om*/ * Guarantees to never return <code>null</code> (exceptions are thrown in * the event of any issues). * </p> * * @param propertiesInformation mandatory information about which instance * to create, the object identity, and the parent object identity * (<code>null</code> or empty <code>String</code>s prohibited for * <code>aclClass</code> and <code>aclObjectIdentity</code> * @param aclInformation optional information about the individual ACL * record (if <code>null</code> only an "inheritence marker" * instance is returned; if not <code>null</code>, it is prohibited * to present <code>null</code> or an empty <code>String</code> for * <code>recipient</code>) * * @return a fully populated instance suitable for use by external objects * * @throws IllegalArgumentException if the indicated ACL class could not be * created */ BasicAclEntry createBasicAclEntry(String targetURI, ObjectPermission aclInformation) { BasicAclEntry entry; try { entry = (BasicAclEntry) SimpleAclEntry.class.newInstance(); } catch (InstantiationException ie) { throw new IllegalArgumentException(ie.getMessage()); } catch (IllegalAccessException iae) { throw new IllegalArgumentException(iae.getMessage()); } entry.setAclObjectIdentity(new URIObjectIdentity(targetURI)); entry.setAclObjectParentIdentity(new URIObjectIdentity(getParentURI(targetURI))); if (aclInformation == null) { // this is an inheritance marker instance only entry.setMask(0); entry.setRecipient(RECIPIENT_USED_FOR_INHERITANCE_MARKER); } else { // this is an individual ACL entry entry.setMask(aclInformation.getPermissionMask()); entry.setRecipient(aclInformation.getPermissionRecipient()); } return entry; }
From source file:com.namphibian.pgdilato.PostgresqlUserDefinedArrayType.java
@Override public void setParameterValues(Properties params) { String classTypeName = params.getProperty(CLASS_TYPE); try {/*www . j a v a 2 s.c om*/ this.classType = ReflectHelper.classForName(classTypeName, this.getClass()); } catch (ClassNotFoundException cnfe) { throw new HibernateException("classType not found", cnfe); } String converterTypeName = params.getProperty(CONVERTER_TYPE); try { try { converter = (PgStructToClassInterface) ReflectHelper .classForName(converterTypeName, this.getClass()).newInstance(); //this.classType = ReflectHelper.classForName(classTypeName, this.getClass()); } catch (InstantiationException ex) { Logger.getLogger(PostgresqlUserDefinedArrayType.class.getName()).log(Level.SEVERE, null, ex); throw new HibernateException(ex.getMessage()); } catch (IllegalAccessException ex) { Logger.getLogger(PostgresqlUserDefinedArrayType.class.getName()).log(Level.SEVERE, null, ex); throw new HibernateException(ex.getMessage()); } } catch (ClassNotFoundException cnfe) { throw new HibernateException("classType not found", cnfe); } this.sqlType = Types.OTHER; this.pgsqlType = params.getProperty(PGSQL_TYPE); }
From source file:net.firejack.platform.core.utils.Factory.java
License:Apache License
private <T extends AbstractDTO> T convertTo0(Class<?> clazz, Object entity) { if (entity == null) return null; if (entity instanceof HibernateProxy) entity = ((HibernateProxy) entity).getHibernateLazyInitializer().getImplementation(); Object dto = null;/*from ww w . j a va 2 s. c o m*/ try { dto = clazz.newInstance(); List<FieldInfo> infos = fields.get(clazz); if (infos == null) { infos = getAllField(clazz, clazz, new ArrayList<FieldInfo>()); fields.put(clazz, infos); } for (FieldInfo info : infos) { Class<?> type = info.getType(); String fieldName = info.getField().getName(); Object value = get(entity, info.name(), type); if (value != null) { if (value instanceof AbstractModel || value.getClass().isAnnotationPresent(XmlAccessorType.class)) { if (contains(value)) { Object convert = get(value); set(dto, fieldName, convert); } else { add(value, null); Object convert = convertTo0(type, value); add(value, convert); set(dto, fieldName, convert); } } else if (value instanceof Collection) { Collection result = (Collection) value; Class<?> arrayType = info.getGenericType(); if (arrayType == null && result.size() != 0) { arrayType = result.iterator().next().getClass(); info.setGenericType(arrayType); } if (AbstractDTO.class.isAssignableFrom(arrayType)) { try { if (value instanceof PersistentCollection) { result = new ArrayList(); } else { result = (Collection) value.getClass().newInstance(); } } catch (InstantiationException e) { result = new ArrayList(); } for (Object o : (Collection) value) { Object convert = convertTo0(arrayType, o); result.add(convert); } } set(dto, fieldName, result); } else { set(dto, fieldName, value); } } } } catch (Exception e) { logger.warn(e.getMessage()); } return (T) dto; }
From source file:net.firejack.platform.core.utils.Factory.java
License:Apache License
private <T> T convertFrom0(Class<?> clazz, Object dto) { if (dto == null) return null; Object bean = null;/*from w w w . j a v a 2s. com*/ try { bean = clazz.newInstance(); List<FieldInfo> infos = fields.get(dto.getClass()); if (infos == null) { infos = getAllField(dto.getClass(), dto.getClass(), new ArrayList<FieldInfo>()); fields.put(dto.getClass(), infos); } for (FieldInfo info : infos) { if (info.readonly()) { continue; } String name = info.name(); Object entity = bean; clazz = entity.getClass(); String[] lookup = name.split("\\."); if (lookup.length > 1) { if (isNullValue(dto, info.getField().getName())) continue; for (int i = 0; i < lookup.length - 1; i++) { Object instance = get(entity, lookup[i], null); if (instance == null) { FieldInfo fieldInfo = getField(clazz, lookup[i]); Class<?> type = fieldInfo.getType(); if (!type.isInterface() && !Modifier.isAbstract(type.getModifiers())) { instance = type.newInstance(); set(entity, lookup[i], instance); entity = instance; clazz = type; } } else { entity = instance; clazz = instance.getClass(); } } name = lookup[lookup.length - 1]; } FieldInfo distField = getField(clazz, name); if (distField != null) { Class<?> type = distField.getType(); Object value = get(dto, info.getField().getName(), type); if (value != null) { if (value instanceof AbstractDTO) { if (contains(value)) { Object convert = get(value); set(entity, name, convert); } else { add(value, null); Object convert = convertFrom0(type, value); add(value, convert); set(entity, name, convert); } } else if (value instanceof Collection) { Collection result = (Collection) value; Class<?> arrayType = distField.getGenericType(); if (AbstractModel.class.isAssignableFrom(arrayType) || arrayType.isAnnotationPresent(XmlAccessorType.class)) { try { result = (Collection) value.getClass().newInstance(); } catch (InstantiationException e) { result = new ArrayList(); } for (Object o : (Collection) value) { Object convert = convertFrom0(arrayType, o); result.add(convert); } } set(entity, name, result); } else { set(entity, name, value); } } } } } catch (Exception e) { logger.warn(e.getMessage()); } return (T) bean; }
From source file:org.josescalia.common.dao.impl.CommonDaoImpl.java
/** * Method to get all entity data from database * * @return ArrayList of entity//from w w w . jav a2 s . com */ @Override public List<T> getAll() { T t = null; try { t = clazz.newInstance(); } catch (InstantiationException e) { logger.error(e.getMessage()); } catch (IllegalAccessException e) { logger.error(e.getMessage()); } if (t instanceof ReferenceBase) { Criteria criteria = getCurrentSession().createCriteria(t.getClass()); criteria.add(Restrictions.eq("deleted", 0)); return criteria.list(); } else if (t instanceof AuditableBase) { Criteria criteria = getCurrentSession().createCriteria(t.getClass()); return criteria.list(); } else { return (List<T>) getCurrentSession().createQuery("from " + clazz.getName()).list(); } }
From source file:org.josescalia.common.dao.impl.CommonDaoImpl.java
/** * This method is used to find list of object in the database using paired * field and value//from w w w . j ava2s . c o m * * @param paramFieldValue a paired field and value to search * @return List of object * */ @Override public List<T> findExact(Map<String, Object> paramFieldValue) throws Exception { T t = null; try { t = clazz.newInstance(); } catch (InstantiationException e) { throw new Exception(e.getMessage()); } catch (IllegalAccessException e) { throw new Exception(e.getMessage()); } List<T> rList = new ArrayList<T>(); String field = ""; Object value = null; for (Object key : paramFieldValue.keySet()) { field = (String) key.toString(); value = paramFieldValue.get(field); } String query = "from " + clazz.getName() + " where "; Criteria criteria = getCurrentSession().createCriteria(t.getClass()); if (value instanceof String) { criteria.add(Restrictions.eq(field, String.valueOf(value))); } else { criteria.add(Restrictions.eq(field, value)); } try { rList = criteria.list(); } catch (Exception e) { throw new Exception(e.getMessage()); } return rList; }
From source file:org.opentaps.foundation.entity.hibernate.Session.java
License:Open Source License
/** * Creates a Hibernate Query from the queryString. Check if the queryString * is for an entity which is an entity engine view-entity and if it is, * transfrom the HQL to native SQL first, then return it as the Query. If * not, just return the Query from the queryString. * * @param queryString a <code>String</code> value. * @return a <code>Query</code> value * @throws HibernateException if an error occurs *///from w ww.jav a 2 s .co m public Query createQuery(String queryString) throws HibernateException { try { // Now check if the entity is a view-entity Entity entity = HibernateUtil.getEntityInstanceByQueryString(queryString); // encryptFields of this GenericValue List<String> encryptParameters = HibernateUtil.getEncryptParametersByQueryString(queryString, delegator); if (entity.isView()) { // if it is a view-entity, we should transform hql to native sql // query. String nameQueryString = getNamedQuery("select" + entity.getClass().getSimpleName() + "s") .getQueryString(); String sqlString = nameQueryString + " " + HibernateUtil.hqlToSql(queryString, HibernateUtil.retrieveClassName(queryString), HibernateUtil.retrieveClassAlias(queryString), entity.fieldMapColumns.get(entity.getClass().getSimpleName())); Debug.logVerbose("Querying [" + entity.getBaseEntityName() + "] with query [" + sqlString + "]", MODULE); org.hibernate.Query hibernateQuery = hibernateSession.createSQLQuery(sqlString); // set result transformer to change result to the class of entity hibernateQuery.setResultTransformer(OpentapsTransformer.aliasToBean(entity.getClass())); Query query = new Query(hibernateQuery, entity.getBaseEntityName(), encryptParameters, crypto); return query; } else { // normal hql, should create a hibernate query and return it. org.hibernate.Query hibernateQuery = hibernateSession.createQuery(queryString); Query query = new Query(hibernateQuery, entity.getBaseEntityName(), encryptParameters, crypto); return query; } } catch (InstantiationException e) { Debug.logError(e, MODULE); throw new HibernateException(e.getMessage()); } catch (IllegalAccessException e) { Debug.logError(e, MODULE); throw new HibernateException(e.getMessage()); } catch (ClassNotFoundException e) { Debug.logError(e, MODULE); throw new HibernateException(e.getMessage()); } }
From source file:org.unitime.timetable.export.pointintimedata.PointInTimeDataReportsExportToCSV.java
License:Apache License
public static void execute(UserContext user, Printer out, PointInTimeDataReportsInterface.Report report, List<PointInTimeDataReportsInterface.IdValue> options) throws PointInTimeDataReportsException, PageAccessException { try {//from w w w.j a v a2s. c o m Class rptCls = BasePointInTimeDataReports.sPointInTimeDataReportRegister.get(report.getId()); BasePointInTimeDataReports rpt = null; try { rpt = (BasePointInTimeDataReports) rptCls.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (rpt == null) throw new IllegalArgumentException("Report " + report + " does not exist."); HashMap<BasePointInTimeDataReports.Parameter, String> parameterValues = new HashMap<BasePointInTimeDataReports.Parameter, String>(); for (BasePointInTimeDataReports.Parameter o : BasePointInTimeDataReports.Parameter.values()) { if (rpt.getParameters().contains(o)) { String value = null; for (PointInTimeDataReportsInterface.IdValue v : options) if (o.name().equals(v.getValue())) { value = v.getText(); break; } if (value == null || value.isEmpty()) { Map<Long, String> vals = o.values(user); if (vals == null || vals.isEmpty()) throw new PointInTimeDataReportsException( MESSAGES.errorUnableToSetParameterNoValues(o.name())); value = ""; for (Long id : vals.keySet()) { if (!value.isEmpty()) value += ","; value += id.toString(); } } parameterValues.put(o, value); } } org.hibernate.Session hibSession = SavedHQLDAO.getInstance().getSession(); ArrayList<String[]> reportOutput = rpt.execute(parameterValues, hibSession); int len = -1; for (String[] line : reportOutput) { if (len < 0) { len = length(line); if (line.length > 0 && line[0].startsWith("__")) out.hideColumn(0); out.printHeader(line); } else { out.printLine(line); } out.flush(); } } catch (PageAccessException e) { throw e; } catch (PointInTimeDataReportsException e) { throw e; } catch (Exception e) { sLog.error(e.getMessage(), e); throw new PointInTimeDataReportsException(MESSAGES.failedExecution( e.getMessage() + (e.getCause() == null ? "" : " (" + e.getCause().getMessage() + ")"))); } }