List of usage examples for java.sql ResultSet getBoolean
boolean getBoolean(String columnLabel) throws SQLException;
ResultSet
object as a boolean
in the Java programming language. From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java
private void addTableRowFromResultSet(DataTable aTable, ResultSet aResultSet) { String columnName;/*from w w w. j ava2 s . c om*/ DataField dataField; Logger appLogger = mAppMgr.getLogger(this, "addTableRowFromResultSet"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); FieldRow fieldRow = aTable.newRow(); for (DataField pField : aTable.getColumnBag().getFields()) { dataField = new DataField(pField); try { columnName = columnName(pField.getName()); switch (pField.getType()) { case Integer: dataField.setValue(aResultSet.getInt(columnName)); break; case Long: dataField.setValue(aResultSet.getLong(columnName)); break; case Float: dataField.setValue(aResultSet.getFloat(columnName)); break; case Double: dataField.setValue(aResultSet.getDouble(columnName)); break; case Boolean: dataField.setValue(aResultSet.getBoolean(columnName)); break; case Date: dataField.setValue(aResultSet.getDate(columnName)); break; case Time: dataField.setValue(aResultSet.getTime(columnName)); break; case DateTime: dataField.setValue(aResultSet.getTimestamp(columnName)); break; default: dataField.setValue(aResultSet.getString(columnName)); break; } if (!aResultSet.wasNull()) aTable.setValueByName(fieldRow, pField.getName(), dataField.getValue()); } catch (SQLException e) { appLogger.error(String.format("SQL Exception (%s): %s", pField.getName(), e.getMessage())); } catch (NSException e) { appLogger.error(String.format("NS Exception (%s): %s", pField.getName(), e.getMessage())); } } aTable.addRow(fieldRow); appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:org.bytesoft.openjtcc.supports.logger.DbTransactionLoggerImpl.java
private Map<XidImpl, CompensableArchive> loadNativeService(Connection connection) { Map<XidImpl, CompensableArchive> serviceMap = new HashMap<XidImpl, CompensableArchive>(); PreparedStatement stmt = null; ResultSet rs = null; try {// ww w . j a va2 s. com StringBuilder ber = new StringBuilder(); ber.append("select s.global_tx_id, s.branch_qualifier, s.coordinator, s.bean_name, s.variable"); ber.append(", s.try_committed, s.confirmed, s.cancelled, s.committed, s.rolledback "); ber.append("from tcc_compensable s "); ber.append("left join tcc_transaction t on ("); ber.append(" t.application = s.application "); ber.append(" and t.endpoint = s.endpoint "); ber.append(" and t.global_tx_id = s.global_tx_id "); ber.append(") where s.application = ? and s.endpoint = ? and t.deleted = ?"); stmt = connection.prepareStatement(ber.toString()); stmt.setString(1, this.instanceKey.getApplication()); stmt.setString(2, this.instanceKey.getEndpoint()); stmt.setBoolean(3, false); rs = stmt.executeQuery(); while (rs.next()) { String globalTransactionId = rs.getString("global_tx_id"); String branchQualifier = rs.getString("branch_qualifier"); boolean coordinator = rs.getBoolean("coordinator"); String beanName = rs.getString("bean_name"); CompensableArchive holder = new CompensableArchive(); holder.launchSvc = coordinator; byte[] globalBytes = ByteUtils.stringToByteArray(globalTransactionId); XidImpl globalXid = this.xidFactory.createGlobalXid(globalBytes); if (coordinator) { holder.branchXid = globalXid; } else { byte[] branchBytes = ByteUtils.stringToByteArray(branchQualifier); XidImpl branchXid = this.xidFactory.createBranchXid(globalXid, branchBytes); holder.branchXid = branchXid; } boolean tryCommitted = rs.getBoolean("try_committed"); boolean confirmed = rs.getBoolean("confirmed"); boolean cancelled = rs.getBoolean("cancelled"); boolean committed = rs.getBoolean("committed"); boolean rolledback = rs.getBoolean("rolledback"); holder.tryCommitted = tryCommitted; holder.confirmed = confirmed; holder.cancelled = cancelled; holder.committed = committed; holder.rolledback = rolledback; CompensableInfo info = new CompensableInfo(); info.setIdentifier(beanName); Compensable<Serializable> service = this.compensableMarshaller.unmarshallCompensable(info); holder.service = service; Blob blob = rs.getBlob("variable"); Serializable variable = null; if (blob != null) { InputStream input = blob.getBinaryStream(); if (input != null) { byte[] bytes = this.streamToByteArray(input); try { variable = (Serializable) this.serializer.deserialize(bytes); } catch (IOException e) { // ignore } } } holder.variable = variable; serviceMap.put(globalXid, holder); } } catch (Exception ex) { ex.printStackTrace(); } finally { closeResultSet(rs); closeStatement(stmt); } return serviceMap; }
From source file:com.sfs.whichdoctor.dao.CreditDAOImpl.java
/** * Load credit.// w ww . ja va2 s. c o m * * @param rs the rs * @param loadDetails the load details * * @return the credit bean * * @throws SQLException the SQL exception */ private CreditBean loadCredit(final ResultSet rs, final BuilderBean loadDetails) throws SQLException { CreditBean credit = new CreditBean(); // Create resource bean and fill with dataset info. credit.setId(rs.getInt("CreditId")); credit.setGUID(rs.getInt("GUID")); credit.setAbbreviation(rs.getString("Abbreviation")); credit.setTypeName(rs.getString("Type")); credit.setClassName(rs.getString("CreditType")); credit.setNumber(rs.getString("CreditNo")); credit.setDescription(rs.getString("Description")); credit.setPersonId(rs.getInt("PersonId")); if (credit.getPersonId() > 0) { credit.setPerson(loadPerson(rs, credit.getPersonId(), loadDetails)); } credit.setOrganisationId(rs.getInt("OrganisationId")); if (credit.getOrganisationId() > 0) { credit.setOrganisation(loadOrganisation(rs, credit.getOrganisationId(), loadDetails)); } credit.setValue(rs.getDouble("Value")); credit.setNetValue(rs.getDouble("NetValue")); try { credit.setIssued(rs.getDate("Issued")); } catch (SQLException e) { credit.setIssued(null); } credit.setCancelled(rs.getBoolean("Cancelled")); credit.setGSTRate(rs.getDouble("GSTRate")); if (loadDetails.getBoolean("DEBITS_FULL")) { int debitGUID = rs.getInt("InvoiceId"); if (debitGUID > 0) { DebitBean debit = new DebitBean(); try { debit = this.getDebitDAO().loadGUID(debitGUID); } catch (Exception e) { dataLogger.error("Error loading debit for credit: " + e.getMessage()); } if (debit.getId() > 0) { credit.setDebit(debit); } } } credit.setSecurity(rs.getString("Security")); credit.setActive(rs.getBoolean("Active")); if (loadDetails.getBoolean("HISTORY")) { try { credit.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } credit.setCreatedBy(rs.getString("CreatedBy")); try { credit.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } credit.setModifiedBy(rs.getString("ModifiedBy")); try { credit.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } credit.setExportedBy(rs.getString("ExportedBy")); } if (loadDetails.getBoolean("TAGS")) { try { credit.setTags(this.getTagDAO().load(credit.getGUID(), loadDetails.getString("USERDN"), true)); } catch (Exception e) { dataLogger.error("Error loading tags for credit: " + e.getMessage()); } } if (loadDetails.getBoolean("MEMO")) { try { credit.setMemo(this.getMemoDAO().load(credit.getGUID(), loadDetails.getBoolean("MEMO_FULL"))); } catch (Exception e) { dataLogger.error("Error loading memos for credit: " + e.getMessage()); } } if (loadDetails.getBoolean("GROUPS")) { credit.setGroups(loadGroups(credit.getGUID())); } if (loadDetails.getBoolean("CREATED")) { UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("CreatedFirstName")); user.setLastName(rs.getString("CreatedLastName")); credit.setCreatedUser(user); } if (loadDetails.getBoolean("MODIFIED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ModifiedBy")); user.setPreferredName(rs.getString("ModifiedFirstName")); user.setLastName(rs.getString("ModifiedLastName")); credit.setModifiedUser(user); } if (loadDetails.getBoolean("EXPORTED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ExportedBy")); user.setPreferredName(rs.getString("ExportedFirstName")); user.setLastName(rs.getString("ExportedLastName")); credit.setExportedUser(user); } return credit; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskPgSql.CFAsteriskPgSqlSysClusterTable.java
public void deleteSysClusterByIdIdx(CFSecurityAuthorization Authorization, int argSingletonId) { final String S_ProcName = "deleteSysClusterByIdIdx"; ResultSet resultSet = null; try {/*w w w .j av a 2 s .c o m*/ Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerDbSchemaName() + ".sp_delete_sysclus_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByIdIdx == null) { stmtDeleteByIdIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByIdIdx.setInt(argIdx++, argSingletonId); resultSet = stmtDeleteByIdIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskPgSql.CFAsteriskPgSqlAuditActionTable.java
public void deleteAuditActionByIdIdx(CFSecurityAuthorization Authorization, short argAuditActionId) { final String S_ProcName = "deleteAuditActionByIdIdx"; ResultSet resultSet = null; try {//from w w w . j a v a 2s . c om Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerDbSchemaName() + ".sp_delete_auditaction_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByIdIdx == null) { stmtDeleteByIdIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByIdIdx.setShort(argIdx++, argAuditActionId); resultSet = stmtDeleteByIdIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlAuditActionTable.java
public void deleteAuditActionByIdIdx(CFAccAuthorization Authorization, short argAuditActionId) { final String S_ProcName = "deleteAuditActionByIdIdx"; ResultSet resultSet = null; try {/* w ww .ja v a 2s . co m*/ Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerSchemaDbName() + ".sp_delete_auditaction_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByIdIdx == null) { stmtDeleteByIdIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByIdIdx.setShort(argIdx++, argAuditActionId); resultSet = stmtDeleteByIdIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstPgSql.CFAstPgSqlAuditActionTable.java
public void deleteAuditActionByIdIdx(CFAstAuthorization Authorization, short argAuditActionId) { final String S_ProcName = "deleteAuditActionByIdIdx"; ResultSet resultSet = null; try {//from w ww. j a va 2 s. c om Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerSchemaDbName() + ".sp_delete_auditaction_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByIdIdx == null) { stmtDeleteByIdIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByIdIdx.setShort(argIdx++, argAuditActionId); resultSet = stmtDeleteByIdIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstPgSql.CFAstPgSqlAuditActionTable.java
public void deleteAuditActionByIdIdx(CFAstAuthorization Authorization, short argAuditActionId) { final String S_ProcName = "deleteAuditActionByIdIdx"; ResultSet resultSet = null; try {/*w ww .ja v a2 s . c o m*/ Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerDbSchemaName() + ".sp_delete_auditaction_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByIdIdx == null) { stmtDeleteByIdIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByIdIdx.setShort(argIdx++, argAuditActionId); resultSet = stmtDeleteByIdIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:com.flexive.core.storage.genericSQL.GenericSQLFulltextIndexer.java
/** * {@inheritDoc}//from www .ja v a2 s . com */ @Override public void rebuildIndexForProperty(long propertyId) { PreparedStatement ps = null; Statement stmtAssignment = null; Statement stmtFetch = null; try { final DBStorage storage = StorageManager.getStorageImpl(); final ContentStorage contentStorage = storage.getContentStorage(TypeStorageMode.Hierarchical); final String TRUE = storage.getBooleanTrueExpression(); stmtAssignment = con.createStatement(); stmtFetch = con.createStatement(); // 1 2 3 4 5 6 7 8 9 10 11 ResultSet rs = stmtAssignment.executeQuery( "SELECT a.id, p.datatype, m.typeid, m.tblname, m.colname, m.lvl, a.xpath, p.id, p.sysinternal, s.tbltype, m.group_assid " + "FROM " + DatabaseConst.TBL_STRUCT_PROPERTIES + " p, " + DatabaseConst.TBL_STRUCT_ASSIGNMENTS + " a LEFT JOIN " + DatabaseConst.TBL_STRUCT_FLATSTORE_MAPPING + " m ON (m.assid=a.id) LEFT JOIN " + DatabaseConst.TBL_STRUCT_FLATSTORE_INFO + " s ON (m.tblname=s.tblname)" + "WHERE p.ISFULLTEXTINDEXED=" + TRUE + " AND a.APROPERTY=p.id" + (propertyId >= 0 ? " AND p.id=" + propertyId : "") + " ORDER BY p.datatype"); //1..ID,2..VER,3..LANG,4..ASSIGN,5..XMULT,6..VALUE ps = con.prepareStatement(getInsertSql()); int batchCounter; long totalCount = 0; while (rs != null && rs.next()) { long assignmentId = rs.getLong(1); ps.setLong(4, assignmentId); //assignment id long currentPropertyId = rs.getLong(8); FxDataType dataType = FxDataType.getById(rs.getInt(2)); boolean systemInternalProperty = rs.getBoolean(9); if (systemInternalProperty || !dataType.isTextType()) continue; //do not index system internal properties or non-text properties long flatTypeId = rs.getLong(3); if (!rs.wasNull()) { //flatstorage String xpath = rs.getString(7); final String xmult; int xpathDepth = 1; if (!StringUtils.isEmpty(xpath)) { xpathDepth = XPathElement.getDepth(xpath); xmult = XPathElement.addDefaultIndices("", xpathDepth); } else { xmult = "1"; } ps.setString(5, xmult); final FxFlatStorageInfo.Type flatType = FxFlatStorageInfo.Type.forId(rs.getInt(10)); // 1 2 3 4 ResultSet rsData = stmtFetch.executeQuery("SELECT ID,VER,LANG," + rs.getString(5) + // 5 (flatType == TypeGroups ? ",XMULT" : "") + " FROM " + rs.getString(4) + " WHERE TYPEID=" + flatTypeId + " AND LVL=" + rs.getInt(6) + (flatType == TypeGroups ? " AND GROUP_ASSID=" + rs.getLong(11) : "")); batchCounter = 0; while (rsData != null && rsData.next()) { String value = rsData.getString(4); if (rsData.wasNull() || StringUtils.isEmpty(value)) continue; ps.setLong(1, rsData.getLong(1)); ps.setInt(2, rsData.getInt(2)); ps.setInt(3, rsData.getInt(3)); if (flatType == TypeGroups) { // xmult is based on the base group's xmult final String groupXMult = rsData.getString(5); final int missingIndices = Math.max(0, xpathDepth - XPathElement.getDepth(groupXMult)); ps.setString(5, XPathElement.addDefaultIndices(groupXMult, missingIndices)); } ps.setString(6, value.trim().toUpperCase()); ps.addBatch(); batchCounter++; totalCount++; if (batchCounter % 1000 == 0) ps.executeBatch(); //insert every 1000 rows } if (rsData != null) rsData.close(); ps.executeBatch(); } else { //hierarchical storage String[] columns = contentStorage.getColumns(currentPropertyId, systemInternalProperty, dataType); final String columnSelect = dataType == FxDataType.Binary ? "b.XMLMETA" : "d." + columns[0]; //first column is the one responsible for indexing final String tableAppend = dataType == FxDataType.Binary ? "," + DatabaseConst.TBL_CONTENT_BINARY + " b" : ""; final String whereAppend = dataType == FxDataType.Binary ? " AND b.ID=d." + columns[0] + " AND b.VER=1 AND b.QUALITY=1" : ""; // 1 2 3 4 5 ResultSet rsData = stmtFetch.executeQuery("SELECT d.ID,d.VER,d.LANG,d.XMULT," + columnSelect + " FROM " + DatabaseConst.TBL_CONTENT_DATA + " d" + tableAppend + " WHERE d.ASSIGN=" + assignmentId + whereAppend); batchCounter = 0; while (rsData != null && rsData.next()) { String value = rsData.getString(4); if (rsData.wasNull() || StringUtils.isEmpty(value)) continue; ps.setLong(1, rsData.getLong(1)); ps.setInt(2, rsData.getInt(2)); ps.setInt(3, rsData.getInt(3)); ps.setString(5, rsData.getString(4)); final String ftValue; switch (dataType) { case Binary: final String xmlMeta = rsData.getString(5); ftValue = FxXMLUtils.getElementData(xmlMeta, "text"); break; case HTML: case String1024: case Text: ftValue = rsData.getString(5); break; default: ftValue = null; } if (!StringUtils.isEmpty(ftValue)) { ps.setString(6, ftValue.trim().toUpperCase()); ps.addBatch(); batchCounter++; totalCount++; } if (batchCounter % 1000 == 0) ps.executeBatch(); //insert every 1000 rows } if (rsData != null) rsData.close(); ps.executeBatch(); } } LOG.info("Added " + totalCount + " entries to fulltext index."); commitChanges(); } catch (SQLException e) { throw new FxDbException(e, "ex.db.sqlError", e.getMessage()).asRuntimeException(); } catch (FxNotFoundException e) { //ContentStorage was not found throw e.asRuntimeException(); } finally { Database.closeObjects(GenericSQLFulltextIndexer.class, ps, stmtAssignment, stmtFetch); } }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}//from ww w . j a va 2s . c o m */ @Override public FxScriptMapping loadScriptMapping(long scriptId) throws FxLoadException, SQLException { FxScriptMapping mapping; PreparedStatement ps_a = null, ps_t = null; String sql; Connection con = Database.getDbConnection(); List<FxScriptMappingEntry> e_ass; List<FxScriptMappingEntry> e_types; FxEnvironmentImpl environment = ((FxEnvironmentImpl) CacheAdmin.getEnvironment()).deepClone(); try { // 1 2 3 4 sql = "SELECT ASSIGNMENT,DERIVED_USAGE,ACTIVE,STYPE FROM " + TBL_SCRIPT_MAPPING_ASSIGN + " WHERE SCRIPT=?"; ps_a = con.prepareStatement(sql); sql = "SELECT TYPEDEF,DERIVED_USAGE,ACTIVE,STYPE FROM " + TBL_SCRIPT_MAPPING_TYPES + " WHERE SCRIPT=?"; ps_t = con.prepareStatement(sql); ResultSet rs; ps_a.setLong(1, scriptId); ps_t.setLong(1, scriptId); rs = ps_a.executeQuery(); e_ass = new ArrayList<FxScriptMappingEntry>(20); e_types = new ArrayList<FxScriptMappingEntry>(20); while (rs != null && rs.next()) { long[] derived; if (!rs.getBoolean(2)) derived = new long[0]; else { List<FxAssignment> ass = environment.getDerivedAssignments(rs.getLong(1)); derived = new long[ass.size()]; for (int i = 0; i < ass.size(); i++) derived[i] = ass.get(i).getId(); } e_ass.add(new FxScriptMappingEntry(FxScriptEvent.getById(rs.getLong(4)), scriptId, rs.getBoolean(3), rs.getBoolean(2), rs.getLong(1), derived)); } rs = ps_t.executeQuery(); while (rs != null && rs.next()) { long[] derived; if (!rs.getBoolean(2)) derived = new long[0]; else { List<FxType> types = environment.getType(rs.getLong(1)).getDerivedTypes(); derived = new long[types.size()]; for (int i = 0; i < types.size(); i++) derived[i] = types.get(i).getId(); } e_types.add(new FxScriptMappingEntry(FxScriptEvent.getById(rs.getLong(4)), scriptId, rs.getBoolean(3), rs.getBoolean(2), rs.getLong(1), derived)); } mapping = new FxScriptMapping(scriptId, e_types, e_ass); } catch (SQLException exc) { throw new FxLoadException(LOG, exc, "ex.scripting.mapping.load.failed", exc.getMessage()); } catch (FxNotFoundException e) { throw new FxLoadException(e); } finally { try { if (ps_t != null) ps_t.close(); } catch (SQLException e) { //ignore } Database.closeObjects(ScriptingEngineBean.class, con, ps_a); } return mapping; }