@Override public Map<String, Object> saveMap(Map<String, Object> object, Class clazz) throws Exception { StringBuilder sql = new StringBuilder(); EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz); sql.append("INSERT INTO "); sql.append(entityInfo.getTableName()); sql.append("("); List<String> columns = new ArrayList<String>(); List<Object> values = new ArrayList<Object>(); Map<String, String> ptcMap = ClassUtils.propToColumnMap.get(entityInfo.getClazzName()); for (Map.Entry<String, Object> entry : object.entrySet()) { columns.add(ptcMap.get(entry.getKey())); values.add(entry.getValue()); } sql.append(StringUtils.join(columns, ",")); sql.append(") VALUES("); String[] params = new String[values.size()]; Arrays.fill(params, "?"); sql.append(StringUtils.join(params, ",")); sql.append(")"); if (entityInfo.getStrategy().equals(GenerationType.IDENTITY)) { Long id = addReutrnId(sql.toString(), values); if (id != null) { object.put(entityInfo.getPkName(), id); } } else { add(sql.toString(), values); } return object; }
/* * Returns list of sensors currently loaded in the system * */ public static String getListOfSensors() { StringBuilder s = new StringBuilder(); Iterator iter = Mappings.getAllVSensorConfigs(); sensors.clear(); coordinates.clear(); while (iter.hasNext()) { VSensorConfig sensorConfig = (VSensorConfig) iter.next(); Double longitude = sensorConfig.getLongitude(); Double latitude = sensorConfig.getLatitude(); Double altitude = sensorConfig.getAltitude(); String sensor = sensorConfig.getName(); if ((latitude != null) && (longitude != null) && (altitude != null)) { Point point = new Point(latitude, longitude, altitude); coordinates.add(point); sensors.add(sensor); s.append(sensor) .append(" => ") .append(longitude) .append(" : ") .append(latitude) .append("\n"); } } return s.toString(); }
/* * Returns list of sensors currently loaded in the system * */ public static String getListOfSensors() { StringBuilder s = new StringBuilder(); Iterator iter = Mappings.getAllVSensorConfigs(); while (iter.hasNext()) { VSensorConfig sensorConfig = (VSensorConfig) iter.next(); Double longitude = sensorConfig.getLongitude(); Double latitude = sensorConfig.getLatitude(); String sensor = sensorConfig.getName(); if ((latitude != null) && (longitude != null)) { Point point = geometryFactory.createPoint( new Coordinate(longitude.doubleValue(), latitude.doubleValue())); coordinates.add(point); sensors.add(sensor); s.append(sensor) .append(" => ") .append(longitude) .append(" : ") .append(latitude) .append(NEWLINE); } } return s.toString(); }
/** Create the data-service for select data by given key operation. */ private void addSelectWithKeyOperation( DataService dataServiceObject, String schema, DatabaseMetaData metaData, String dbName, String tableName, String pKey) throws SQLException, DataServiceFault, NullPointerException { Map<String, WithParam> paramMap = new HashMap<String, WithParam>(); List<String> paramList = new ArrayList<String>(); ResultSet columnNames = getColumnNames(metaData, schema, dbName, tableName, null); String colomNames = ""; int i = 0; while (columnNames.next()) { String name = columnNames.getString(DBConstants.DataServiceGenerator.COLUMN_NAME); // get the colomn names for the query if (i == 0) { colomNames = " " + name; } else { colomNames = colomNames + ", " + name; } i++; if (pKey.equals(name)) { WithParam withParam = new WithParam(pKey, pKey, pKey, DBConstants.DataServiceGenerator.QUERY_PARAM); paramMap.put(pKey, withParam); paramList.add(pKey); } } Set<String> requiredRoles = new HashSet<String>(); String queryId = DBConstants.DataServiceGenerator.SELECT_WITH_KEY + tableName + DBConstants.DataServiceGenerator._QUERY; String OpName = DBConstants.DataServiceGenerator.SELECT_WITH_KEY + tableName + DBConstants.DataServiceGenerator._OPERATION; CallQuery callQuery = new CallQuery(dataServiceObject, queryId, paramMap, requiredRoles); List<CallQuery> callQueries = new ArrayList<CallQuery>(); callQueries.add(callQuery); CallQueryGroup callQueryGroup = new CallQueryGroup(callQueries); // batchRequest=false // parentOperation=null Operation operation = new Operation(dataServiceObject, OpName, null, callQueryGroup, false, null, false, false); dataServiceObject.addOperation(operation); dataServiceObject.addQuery( this.getSelectWithKeyQuery( paramList, pKey, queryId, tableName, dataServiceObject, metaData, dbName, schema, colomNames)); }
/** * 构建ResultMap对象 * * @param id * @param clazz * @param configuration * @return */ private ResultMap buildResultMap(String id, Class<?> clazz, Configuration configuration) { // 判断是否已经存在缓存里 if (configuration.hasResultMap(id)) { return configuration.getResultMap(id); } List<ResultMapping> resultMappings = Lists.newArrayList(); Map<String, Field> columns = EntityUtil.getFields(clazz); for (Map.Entry<String, Field> column : columns.entrySet()) { Field field = column.getValue(); String fieldName = field.getName(); Class<?> columnTypeClass = resolveResultJavaType(clazz, fieldName, null); List<ResultFlag> flags = Lists.newArrayList(); if (field.isAnnotationPresent(Id.class)) { flags.add(ResultFlag.ID); } String columnName = column.getKey(); resultMappings.add( buildResultMapping(configuration, fieldName, columnName, columnTypeClass, flags)); } // 构建ResultMap ResultMap.Builder resultMapBuilder = new ResultMap.Builder(configuration, id, clazz, resultMappings); ResultMap rm = resultMapBuilder.build(); // 放到缓存中 configuration.addResultMap(rm); return rm; }
/** Creates a Pooled connection and adds it to the connection pool. */ private void installConnection() throws EmanagerDatabaseException { logger.debug("enter"); PooledConnection connection; try { connection = poolDataSource.getPooledConnection(); connection.addConnectionEventListener(this); connection.getConnection().setAutoCommit(false); synchronized (connectionPool) { connectionPool.add(connection); logger.debug("Database connection added."); } } catch (SQLException ex) { logger.fatal("exception caught while obtaining database " + "connection: ex = " + ex); SQLException ex1 = ex.getNextException(); while (ex1 != null) { logger.fatal("chained sql exception ex1 = " + ex1); SQLException nextEx = ex1.getNextException(); ex1 = nextEx; } String logString; EmanagerDatabaseException ede; logString = EmanagerDatabaseStatusCode.DatabaseConnectionFailure.getStatusCodeDescription() + ex.getMessage(); logger.fatal(logString); ede = new EmanagerDatabaseException( EmanagerDatabaseStatusCode.DatabaseConnectionFailure, logString); throw ede; } }
public boolean catalogAlreadyExists(Connection conn) { boolean result = false; try { List<String> constants = TUtil.newList(); constants.add(CatalogConstants.TB_META); constants.add(CatalogConstants.TB_SPACES); constants.add(CatalogConstants.TB_DATABASES); constants.add(CatalogConstants.TB_TABLES); constants.add(CatalogConstants.TB_COLUMNS); constants.add(CatalogConstants.TB_OPTIONS); constants.add(CatalogConstants.TB_INDEXES); constants.add(CatalogConstants.TB_STATISTICS); constants.add(CatalogConstants.TB_PARTITION_METHODS); constants.add(CatalogConstants.TB_PARTTIONS); constants.add(CatalogConstants.TB_PARTTION_KEYS); for (String constant : constants) { if (checkExistence(conn, DatabaseObjectType.TABLE, constant)) { return true; } } } catch (SQLException e) { throw new TajoInternalError(e); } return result; }
/** Returns a connection to the database */ public synchronized Connection get() throws DataException { // ensure we haven't used too many connections if (usedConnections.size() >= MAX_CONNECTIONS) { throw new DataException( "The database connection pool is out of connections -- a maximum number of " + MAX_CONNECTIONS); } // if try { // do we have enough connections to assign one out? if (freeConnections.size() == 0) { freeConnections.add(createConnection()); } // return the first free connection Connection conn = freeConnections.remove(0); usedConnections.add(conn); // Logger.global.info("Gave out a connection from the pool. Free size is now: " + // freeConnections.size() + "/" + (freeConnections.size() + usedConnections.size())); return conn; } catch (Exception e) { throw new DataException( "An error occurred while retrieving a database connection from the pool", e); } } // get
@Override public String execute() throws Exception { Connection conn = null; List<Slice> slices = new LinkedList<Slice>(); try { conn = Constants.DATASOURCE.getConnection(); PreparedStatement stmt = conn.prepareStatement(SqlQuery.SERVICES_ON_HOSTS_BY_PROJECT.getSql()); stmt.setInt(1, idProject); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String name = rs.getString("name") == null ? rs.getString("ip") : rs.getString("name"); int count = rs.getInt("conteggio"); Slice slice = new Slice(); slice.setLabel(name + "[" + count + "]"); slice.setTooltip(name + "\n" + count + " running services"); slice.setValue(count); slices.add(slice); } rs.close(); stmt.close(); } catch (SQLException e) { return ERROR; } finally { if (conn != null) conn.close(); } String[] colors = { "000000", "0000ff", "00ffff", "00ff00", "ffff00", "ff0000", "ff00ff", "ffffff" }; if (slices.size() != 0) { int increment = 0; for (Slice slice : slices) { slice.setColour("#" + colors[increment]); increment = (increment + 1) % colors.length; } if (slices.size() % colors.length == 1) slices.get(slices.size() - 1).setColour(colors[1]); } pieChart = new PieChart(); List<ElementPie> elements = new LinkedList<ElementPie>(); ElementPie element = new ElementPie(); element.setAlpha(0.9f); pieChart.setTitle( new Title( "Services Distribution", "{" + getText("avgProjectActivityPieChart.title.style") + "}")); element.setValues(slices); element.setGradientFill(true); element.setRadius(50); element.setStartAngle(0); elements.add(element); pieChart.setBg_colour(getText("chart.defaultBgColor")); pieChart.setBorder(1); pieChart.setAnimate(true); pieChart.setElements(elements); return SUCCESS; }
/** * Get viewable subsystem list * * @param request * @return never null, elements are nds.schema.SubSystem */ public List getSubSystems(HttpServletRequest request) { UserWebImpl userWeb = ((UserWebImpl) WebUtils.getSessionContextManager(request.getSession()) .getActor(nds.util.WebKeys.USER)); ArrayList subs = new ArrayList(); if (userWeb.getUserId() == userWeb.GUEST_ID) { return subs; } List al = (List) userWeb.getProperty("subsystems"); // elements are subystem.id TableManager manager = TableManager.getInstance(); if (al != null) { for (int i = 0; i < al.size(); i++) { int sid = ((Integer) al.get(i)).intValue(); SubSystem ss = manager.getSubSystem(sid); if (ss != null) subs.add(ss); } } else { // search all tablecategoris for subsystem // add users subsystems param al = new ArrayList(); String[] sub_list; try { String subsystems = (String) QueryEngine.getInstance() .doQueryOne("SELECT subsystems from users where id=" + userWeb.getUserId()); if (Validator.isNotNull(subsystems)) { sub_list = subsystems.split(","); for (int m = 0; m < sub_list.length; m++) { SubSystem usersub = manager.getSubSystem(sub_list[m].trim()); if (usersub != null) { if (usersub.getId() == 10) continue; al.add(new Integer(usersub.getId())); subs.add(usersub); } } userWeb.setProperty("subsystems", al); return subs; } } catch (QueryException e) { logger.error("Fail to load subsystems from users", e); } for (int i = 0; i < manager.getSubSystems().size(); i++) { SubSystem ss = (SubSystem) manager.getSubSystems().get(i); if (containsViewableChildren(request, ss)) { al.add(new Integer(ss.getId())); subs.add(ss); } } userWeb.setProperty("subsystems", al); } return subs; }
/** * @param verificationMapFromUnpackedFiles Map of BBI files names to their corresponding * verifications * @param listOfBBIfiles List with BBI files extracted from the archive * @return List of DTOs containing BBI filename, verification id, outcome of parsing (true/false), * and reason of rejection (if the bbi file was rejected) */ private List<BBIOutcomeDTO> processListOfBBIFiles( Map<String, Map<String, String>> verificationMapFromUnpackedFiles, List<File> listOfBBIfiles, User calibratorEmployee) throws ParseException { List<BBIOutcomeDTO> resultsOfBBIProcessing = new ArrayList<>(); for (File bbiFile : listOfBBIfiles) { Map<String, String> correspondingVerificationMap = verificationMapFromUnpackedFiles.get(bbiFile.getName()); String correspondingVerification = correspondingVerificationMap.get(Constants.VERIFICATION_ID); BBIOutcomeDTO.ReasonOfRejection reasonOfRejection = null; if (correspondingVerification == null) { try { correspondingVerification = createNewVerificationFromMap(correspondingVerificationMap, calibratorEmployee); parseAndSaveBBIFile(bbiFile, correspondingVerification, bbiFile.getName()); Verification verification = verificationService.findById(correspondingVerification); verification.setStatus(Status.CREATED_BY_CALIBRATOR); verificationService.saveVerification(verification); } catch (NoSuchElementException e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_COUNTER_SIZE_AND_SYMBOL; logger.info(e); } catch (Exception e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.BBI_IS_NOT_VALID; logger.info(e); } } else { try { updateVerificationFromMap(correspondingVerificationMap, correspondingVerification); parseAndSaveBBIFile(bbiFile, correspondingVerification, bbiFile.getName()); } catch (NoSuchElementException e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_COUNTER_SIZE_AND_SYMBOL; logger.info(e); } catch (IOException e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.BBI_IS_NOT_VALID; logger.info(e); } catch (Exception e) { reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_VERIFICATION_CODE; logger.info(e); } } if (reasonOfRejection == null) { resultsOfBBIProcessing.add( BBIOutcomeDTO.accept(bbiFile.getName(), correspondingVerification)); } else { resultsOfBBIProcessing.add( BBIOutcomeDTO.reject(bbiFile.getName(), correspondingVerification, reasonOfRejection)); } } return resultsOfBBIProcessing; }
/** * @param arg0 * @roseuid 3F4E5F400123 */ public void connectionClosed(ConnectionEvent event) { logger.debug("Enter: " + event.getSource()); synchronized (connectionPool) { if (!SHUTTING_DOWN) { if (connectionPool.size() < connectionPoolSize) { logger.debug("Reading Connection: " + event.getSource()); connectionPool.add(event.getSource()); } } } }
public Map<String, List> fetchHoldingItem(boolean cursor) throws SQLException { String holdingId = ""; String tempHoldingId = ""; List itemIds = new ArrayList(); Map<String, List> map = null; if (cursor) { while (holdingItemResultSet.next()) { holdingId = "who-" + holdingItemResultSet.getString("HOLDINGS_ID"); if (StringUtils.isNotEmpty(tempHoldingId) && !tempHoldingId.equals(holdingId)) { if (itemIds.size() > 0) { map = new HashMap<>(); map.put(tempHoldingId, itemIds); return map; } } itemIds.add("wio-" + holdingItemResultSet.getString("ITEM_ID")); tempHoldingId = holdingId; } } else { holdingItemResultSet.previous(); // while(holdingItemResultSet.previous()) { // break; // } while (holdingItemResultSet.next()) { holdingId = "who-" + holdingItemResultSet.getString("HOLDINGS_ID"); if (StringUtils.isNotEmpty(tempHoldingId) && !tempHoldingId.equals(holdingId)) { if (itemIds.size() > 0) { map = new HashMap<>(); map.put(tempHoldingId, itemIds); return map; } } itemIds.add("wio-" + holdingItemResultSet.getString("ITEM_ID")); tempHoldingId = holdingId; } } if (itemIds.size() > 0) { map = new HashMap<>(); map.put(tempHoldingId, itemIds); return map; } else { map = null; } holdingItemResultSet.close(); return map; }
public Map<String, List> fetchBibHolding(boolean cursor) throws SQLException { String holdingId = ""; String tempHoldingId = ""; List bibIds = new ArrayList(); Map<String, List> map = null; if (cursor) { while (bibHoldingsResultSet.next()) { holdingId = "who-" + bibHoldingsResultSet.getString("HOLDINGS_ID"); if (StringUtils.isNotEmpty(tempHoldingId) && !tempHoldingId.equals(holdingId)) { if (bibIds.size() > 0) { map = new HashMap<>(); bibIds.remove(0); map.put(tempHoldingId, bibIds); return map; } } bibIds.add("wbm-" + bibHoldingsResultSet.getString("BIB_ID")); tempHoldingId = holdingId; } } else { while (bibHoldingsResultSet.next()) { holdingId = "who-" + bibHoldingsResultSet.getString("HOLDINGS_ID"); if (StringUtils.isNotEmpty(tempHoldingId) && !tempHoldingId.equals(holdingId)) { map = new HashMap<>(); map.put(tempHoldingId, bibIds); return map; } bibIds.add("wbm-" + bibHoldingsResultSet.getString("BIB_ID")); tempHoldingId = holdingId; } } if (bibIds.size() > 0) { map = new HashMap<>(); bibIds.remove(0); map.put(tempHoldingId, bibIds); return map; } else { map = null; } bibHoldingsResultSet.close(); return map; }
public List<PromoterRowGateway> findAll() { List result = new ArrayList(); List promoters = jdbcTemplate.queryForList(findAllStatement); for (int i = 0; i < promoters.size(); i++) result.add(PromoterRowGateway.load(dataSource, (Map) promoters.get(i))); return result; }
public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) { final String S_ProcName = "CFBamMssCFIterateNumberTypeRef.enumerateDetails() "; if (genContext == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 1, "genContext"); } ICFLibAnyObj genDef = genContext.getGenDef(); if (genDef == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()"); } List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>(); if (genDef instanceof ICFBamNumberTypeObj) { Iterator<ICFBamTableColObj> elements = ((ICFBamNumberTypeObj) genDef).getOptionalChildrenRef().iterator(); while (elements.hasNext()) { list.add(elements.next()); } } else { throw CFLib.getDefaultExceptionFactory() .newUnsupportedClassException( getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFBamNumberTypeObj"); } return (list.listIterator()); }
@SuppressWarnings("unchecked") @Test public void testAppendCloudServiceGuidConstraint() throws Exception { CustomerDAO dao = new CustomerDAO(); // list List<String> list = new LinkedList<String>(); list.add("val1"); list.add("val2"); SearchConstraint sc = new SearchConstraint("TEST_PROP", SearchConstraintOperator.CONSTRAINT_IN_LIST, list); String got = dao.appendCloudServiceGuidConstraint(sc); String expected = CustomerDAO.SQL_CUSTOMER_QUERY_CLOUD_SERVICE_CONSTRAINT + "in (E'val1',E'val2'))"; assertEquals("Wrong constraint added.", expected, got); // equal sc = new SearchConstraint( ICustomerService.PROP_CLOUD_SERVICE_GUID, SearchConstraintOperator.CONSTRAINT_EQUALS, "val3"); got = dao.appendCloudServiceGuidConstraint(sc); expected = CustomerDAO.SQL_CUSTOMER_QUERY_CLOUD_SERVICE_CONSTRAINT + "= E'val3' and g_inner.disabled = false)"; assertEquals("Wrong constraint added.", expected, got); }
/** * Find all the year records in a Calendar, it need not be a standard period (used in MRP) * * @param C_Calendar_ID calendar * @param ctx context * @param trx trx * @return MYear[] */ public static MYear[] getAllYearsInCalendar(int C_Calendar_ID, Ctx ctx, Trx trx) { List<MYear> years = new ArrayList<MYear>(); String sql = "SELECT * FROM C_Year WHERE " + "IsActive='Y' AND C_Calendar_ID = ? "; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trx); pstmt.setInt(1, C_Calendar_ID); rs = pstmt.executeQuery(); while (rs.next()) years.add(new MYear(ctx, rs, trx)); } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } MYear[] retValue = new MYear[years.size()]; years.toArray(retValue); return retValue; }
public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) { final String S_ProcName = "CFAsteriskMssCFIterateHostNodeConfFile.enumerateDetails() "; if (genContext == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 1, "genContext"); } ICFLibAnyObj genDef = genContext.getGenDef(); if (genDef == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()"); } List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>(); if (genDef instanceof ICFAsteriskHostNodeObj) { Iterator<ICFAsteriskConfigurationFileObj> elements = ((ICFAsteriskHostNodeObj) genDef).getOptionalComponentsConfFile().iterator(); while (elements.hasNext()) { list.add(elements.next()); } } else { throw CFLib.getDefaultExceptionFactory() .newUnsupportedClassException( getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFAsteriskHostNodeObj"); } return (list.listIterator()); }
public void deleteSecDeviceByUserIdx(UUID SecUserId) { CFSecuritySecDeviceByUserIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey(); key.setRequiredSecUserId(SecUserId); if (indexByUserIdx == null) { indexByUserIdx = new HashMap< CFSecuritySecDeviceByUserIdxKey, Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj>>(); } if (indexByUserIdx.containsKey(key)) { Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> dict = indexByUserIdx.get(key); ((ICFSecuritySchema) schema.getBackingStore()) .getTableSecDevice() .deleteSecDeviceByUserIdx(schema.getAuthorization(), SecUserId); Iterator<ICFSecuritySecDeviceObj> iter = dict.values().iterator(); ICFSecuritySecDeviceObj obj; List<ICFSecuritySecDeviceObj> toForget = new LinkedList<ICFSecuritySecDeviceObj>(); while (iter.hasNext()) { obj = iter.next(); toForget.add(obj); } iter = toForget.iterator(); while (iter.hasNext()) { obj = iter.next(); obj.forget(true); } indexByUserIdx.remove(key); } else { ((ICFSecuritySchema) schema.getBackingStore()) .getTableSecDevice() .deleteSecDeviceByUserIdx(schema.getAuthorization(), SecUserId); } }
public void upgradeBaseSchema(Connection conn, int currentVersion) { if (!isLoaded()) { throw new TajoInternalError("Database schema files are not loaded."); } final List<SchemaPatch> candidatePatches = new ArrayList<>(); Statement stmt; for (SchemaPatch patch : this.catalogStore.getPatches()) { if (currentVersion >= patch.getPriorVersion()) { candidatePatches.add(patch); } } Collections.sort(candidatePatches); try { stmt = conn.createStatement(); } catch (SQLException e) { throw new TajoInternalError(e); } for (SchemaPatch patch : candidatePatches) { for (DatabaseObject object : patch.getObjects()) { try { stmt.executeUpdate(object.getSql()); LOG.info(object.getName() + " " + object.getType() + " was created or altered."); } catch (SQLException e) { throw new TajoInternalError(e); } } } CatalogUtil.closeQuietly(stmt); }
public void forgetSecGroupIncludeByIncludeIdx(long ClusterId, int IncludeGroupId) { if (indexByIncludeIdx == null) { return; } CFSecuritySecGroupIncludeByIncludeIdxKey key = ((ICFInternetSchema) schema.getBackingStore()) .getFactorySecGroupInclude() .newIncludeIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredIncludeGroupId(IncludeGroupId); if (indexByIncludeIdx.containsKey(key)) { Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapIncludeIdx = indexByIncludeIdx.get(key); if (mapIncludeIdx != null) { List<ICFSecuritySecGroupIncludeObj> toForget = new LinkedList<ICFSecuritySecGroupIncludeObj>(); ICFSecuritySecGroupIncludeObj cur = null; Iterator<ICFSecuritySecGroupIncludeObj> iter = mapIncludeIdx.values().iterator(); while (iter.hasNext()) { cur = iter.next(); toForget.add(cur); } iter = toForget.iterator(); while (iter.hasNext()) { cur = iter.next(); cur.forget(true); } } indexByIncludeIdx.remove(key); } }
public void forgetSecDeviceByUserIdx(UUID SecUserId) { if (indexByUserIdx == null) { return; } CFSecuritySecDeviceByUserIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey(); key.setRequiredSecUserId(SecUserId); if (indexByUserIdx.containsKey(key)) { Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> mapUserIdx = indexByUserIdx.get(key); if (mapUserIdx != null) { List<ICFSecuritySecDeviceObj> toForget = new LinkedList<ICFSecuritySecDeviceObj>(); ICFSecuritySecDeviceObj cur = null; Iterator<ICFSecuritySecDeviceObj> iter = mapUserIdx.values().iterator(); while (iter.hasNext()) { cur = iter.next(); toForget.add(cur); } iter = toForget.iterator(); while (iter.hasNext()) { cur = iter.next(); cur.forget(true); } } indexByUserIdx.remove(key); } }
public void deleteTaxByTenantIdx(long TenantId) { CFAccTaxByTenantIdxKey key = ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey(); key.setRequiredTenantId(TenantId); if (indexByTenantIdx == null) { indexByTenantIdx = new HashMap<CFAccTaxByTenantIdxKey, Map<CFAccTaxPKey, ICFAccTaxObj>>(); } if (indexByTenantIdx.containsKey(key)) { Map<CFAccTaxPKey, ICFAccTaxObj> dict = indexByTenantIdx.get(key); ((ICFAccSchema) schema.getBackingStore()) .getTableTax() .deleteTaxByTenantIdx(schema.getAuthorization(), TenantId); Iterator<ICFAccTaxObj> iter = dict.values().iterator(); ICFAccTaxObj obj; List<ICFAccTaxObj> toForget = new LinkedList<ICFAccTaxObj>(); while (iter.hasNext()) { obj = iter.next(); toForget.add(obj); } iter = toForget.iterator(); while (iter.hasNext()) { obj = iter.next(); obj.forget(true); } indexByTenantIdx.remove(key); } else { ((ICFAccSchema) schema.getBackingStore()) .getTableTax() .deleteTaxByTenantIdx(schema.getAuthorization(), TenantId); } }
public List getBooksByCost(String cost) { List al = new ArrayList(); try { con = JdbcUtil.getMysqlConnection(); ps = con.prepareStatement("select *from jlcbooks where cost=?"); ps.setString(1, cost); rs = ps.executeQuery(); while (rs.next()) { Book bo = new Book(); bo.setBid(rs.getString(1)); bo.setBname(rs.getString(2)); bo.setAuthor(rs.getString(3)); bo.setPub(rs.getString(4)); bo.setCost(rs.getString(5)); bo.setEdi(rs.getString(6)); bo.setIsbn(rs.getString(7)); al.add(bo); } } catch (Exception e) { e.printStackTrace(); } finally { JdbcUtil.cleanup(ps, con); } return al; }
public void forgetISOCountryCurrencyByCurrencyIdx(short ISOCurrencyId) { if (indexByCurrencyIdx == null) { return; } CFSecurityISOCountryCurrencyByCurrencyIdxKey key = ((ICFInternetSchema) schema.getBackingStore()) .getFactoryISOCountryCurrency() .newCurrencyIdxKey(); key.setRequiredISOCurrencyId(ISOCurrencyId); if (indexByCurrencyIdx.containsKey(key)) { Map<CFSecurityISOCountryCurrencyPKey, ICFSecurityISOCountryCurrencyObj> mapCurrencyIdx = indexByCurrencyIdx.get(key); if (mapCurrencyIdx != null) { List<ICFSecurityISOCountryCurrencyObj> toForget = new LinkedList<ICFSecurityISOCountryCurrencyObj>(); ICFSecurityISOCountryCurrencyObj cur = null; Iterator<ICFSecurityISOCountryCurrencyObj> iter = mapCurrencyIdx.values().iterator(); while (iter.hasNext()) { cur = iter.next(); toForget.add(cur); } iter = toForget.iterator(); while (iter.hasNext()) { cur = iter.next(); cur.forget(true); } } indexByCurrencyIdx.remove(key); } }
public void forgetTaxByTenantIdx(long TenantId) { if (indexByTenantIdx == null) { return; } CFAccTaxByTenantIdxKey key = ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey(); key.setRequiredTenantId(TenantId); if (indexByTenantIdx.containsKey(key)) { Map<CFAccTaxPKey, ICFAccTaxObj> mapTenantIdx = indexByTenantIdx.get(key); if (mapTenantIdx != null) { List<ICFAccTaxObj> toForget = new LinkedList<ICFAccTaxObj>(); ICFAccTaxObj cur = null; Iterator<ICFAccTaxObj> iter = mapTenantIdx.values().iterator(); while (iter.hasNext()) { cur = iter.next(); toForget.add(cur); } iter = toForget.iterator(); while (iter.hasNext()) { cur = iter.next(); cur.forget(true); } } indexByTenantIdx.remove(key); } }
/** * Find the periods in a calendar year it need not be a standard period (used in MRP) * * @param C_Year_ID Year * @param periodType Period Type * @param ctx context * @param trx trx * @return MPeriod[] */ public static MPeriod[] getAllPeriodsInYear(int C_Year_ID, String periodType, Ctx ctx, Trx trx) { List<MPeriod> periods = new ArrayList<MPeriod>(); String sql = "SELECT * FROM C_Period WHERE IsActive='Y'"; sql = sql + " AND C_Year_ID = ?"; if (periodType != null) sql = sql + " AND PeriodType = ? "; sql = sql + " order by StartDate "; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trx); pstmt.setInt(1, C_Year_ID); if (periodType != null) pstmt.setString(2, periodType); rs = pstmt.executeQuery(); while (rs.next()) periods.add(new MPeriod(ctx, rs, trx)); } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } MPeriod[] retValue = new MPeriod[periods.size()]; periods.toArray(retValue); return retValue; }
/** * 生成泛型对应的ResultMap * * @param namespace * @param clazz * @param conf * @return */ private List<ResultMap> getResultMap(String namespace, Class<?> clazz, Configuration conf) { String dynamicResultMapId = namespace + "." + GENERATE_RESULT_MAP_NAME; ResultMap dynamicResultMap = buildResultMap(dynamicResultMapId, clazz, conf); List<ResultMap> resultMaps = Lists.newArrayList(); resultMaps.add(dynamicResultMap); return Collections.unmodifiableList(resultMaps); }
public CFSecuritySecDeviceBuff[] readBuffByUserIdx( CFSecurityAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "readBuffByUserIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_secdev_by_useridx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffByUserIdx == null) { stmtReadBuffByUserIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByUserIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByUserIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByUserIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByUserIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByUserIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByUserIdx.setString(argIdx++, SecUserId.toString()); try { resultSet = stmtReadBuffByUserIdx.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } List<CFSecuritySecDeviceBuff> buffList = new LinkedList<CFSecuritySecDeviceBuff>(); while ((resultSet != null) && resultSet.next()) { CFSecuritySecDeviceBuff buff = unpackSecDeviceResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFSecuritySecDeviceBuff[] retBuff = new CFSecuritySecDeviceBuff[buffList.size()]; Iterator<CFSecuritySecDeviceBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }