Java Code Examples for org.springframework.jdbc.support.rowset.SqlRowSet#getString()

The following examples show how to use org.springframework.jdbc.support.rowset.SqlRowSet#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllUserActorConnectorTest.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
/**
 * 资源共享
 * <p>1.使用场景:将任务共享给所有用户</p>
 * <p>2.预置条件:<p>
 *          1.发布一条带有任务分配(分配所有人)的流程定义
 * <p>3.处理过程:首先,启动任务使流程进入分配任务节点上</p>
 * <p>4.测试用例:</p>
 * <p>		1.执行完成后,相应查看资源分配是否是所以人都能看得到</p>
 * <p>		2.执行完成后,相应查看foxbpm_run_taskidentitylink 记录是否任务的处理者是foxbpm_all_user</p>
 */
@Test
@Deployment(resources = { "org/foxbpm/connector/test/actorconnector/AllUserActorConnector/AllUserActorConnectorTest_1.bpmn" })
public void testAllUserActorConnector() {
	Authentication.setAuthenticatedUserId("admin");
	// 启动流程
	runtimeService.startProcessInstanceByKey("AllUserActorConnectorTest_1");

	Task task = taskService.createTaskQuery().processDefinitionKey("AllUserActorConnectorTest_1").taskNotEnd().singleResult();
	// 同时分配给两个人
	String taskId = task.getId();
	SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet("select * from foxbpm_run_taskidentitylink WHERE TASK_ID = '" + taskId + "'");

	String userId = null;
	if (sqlRowSet.next()) {
		userId = sqlRowSet.getString("USER_ID");
	}
	assertEquals("foxbpm_all_user", userId);
}
 
Example 2
Source File: SelectRoleTest.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
/**
 * 任务分配给一个角色或多个角色
 * <p>1.使用场景:需要将任务分配给一个角色或多个角色</p>
 * <p>2.预置条件:<p>
 *          1.存在角色
 * <p>3.处理过程:首先,启动任务使流程进入分配任务节点上</p>
 * <p>4.测试用例:</p>
 * <p>		1.执行完成后,相应查看资源是否分配给相应角色</p>
 */
@Test
@Deployment(resources = { "org/foxbpm/connector/test/actorconnector/SelectRole/SelectRoleTest_1.bpmn" })
public void testSelectDepartment0() {
	Authentication.setAuthenticatedUserId("admin");
	// 预置角色
	jdbcTemplate.execute("insert into au_roleinfo(roleid,rolename) VALUES ('2001','2001')");
	// 预置用户用户
	jdbcTemplate.execute("insert into au_userInfo(userId,USERNAME) VALUES ('a','管理员Tst')");
	// 设置用户和部门关系
	jdbcTemplate.execute("insert into au_group_relation(guid,userid,groupid,grouptype) VALUES ('10000000000000001','a','2001','role')");
	// 启动流程触发任务分配
	runtimeService.startProcessInstanceByKey("SelectRoleTest_1");
	Task task = (Task) taskService.createTaskQuery().processDefinitionKey("SelectRoleTest_1").taskNotEnd().singleResult();
	// 同时分配给两个人
	String taskId = task.getId();
	SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet("select * from foxbpm_run_taskidentitylink WHERE TASK_ID = '" + taskId + "'");
	String groupId = null;
	while (sqlRowSet.next()) {
		groupId = sqlRowSet.getString("GROUP_ID");
	}
	assertEquals("2001", groupId);
}
 
Example 3
Source File: JdbcEventStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean userHasAccess( SqlRowSet rowSet )
{
    if ( rowSet.wasNull() )
    {
        return true;
    }

    if ( rowSet.getString( "uga_access" ) == null && rowSet.getString( "ua_access" ) == null && rowSet.getString( "deco_publicaccess" ) == null )
    {
        return false;
    }

    return AccessStringHelper.isEnabled( rowSet.getString( "deco_publicaccess" ), AccessStringHelper.Permission.DATA_READ );
}
 
Example 4
Source File: HibernateTimeZoneIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 5
Source File: SelectDepartmentTest.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
/**
 * 任务分配给部门下的子部门
 * <p>1.使用场景:需要将任务分配给一个部门下的子部门</p>
 * <p>2.预置条件:<p>
 *          1.存在父部门和子部门
 * <p>3.处理过程:首先,启动任务使流程进入分配任务节点上</p>
 * <p>4.测试用例:</p>
 * <p>		1.执行完成后,相应查看资源分配是否是在子部门上</p>
 */
@Test
@Deployment(resources = { "org/foxbpm/connector/test/actorconnector/SelectDepartment/SelectDepartmentTest_1.bpmn" })
public void testSelectDepartment() {
	Authentication.setAuthenticatedUserId("admin");
	// 预置部门用户
	jdbcTemplate.execute("insert into au_orginfo(orgid,suporgid) VALUES ('2001','2001')");
	jdbcTemplate.execute("insert into au_orginfo(orgid,suporgid) VALUES ('2002','2001')");
	// 预置用户用户
	jdbcTemplate.execute("insert into au_userInfo(userId,USERNAME) VALUES ('a','管理员Tst')");
	jdbcTemplate.execute("insert into au_userInfo(userId,USERNAME) VALUES ('b','管理员Tst')");
	// 设置用户和部门关系
	jdbcTemplate.execute("insert into au_group_relation(guid,userid,groupid,grouptype) VALUES ('10000000000000000','admin','2001','dept')");
	jdbcTemplate.execute("insert into au_group_relation(guid,userid,groupid,grouptype) VALUES ('10000000000000001','a','2002','dept')");
	jdbcTemplate.execute("insert into au_group_relation(guid,userid,groupid,grouptype) VALUES ('10000000000000002','b','2002','dept')");
	// 启动流程触发任务分配
	runtimeService.startProcessInstanceByKey("SelectDepartmentTest_1");

	String groupId = null;
	Task task = (Task) taskService.createTaskQuery().processDefinitionKey("SelectDepartmentTest_1").taskNotEnd().singleResult();
	System.out.println(task.getId());
	String taskId = task.getId();
	SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet("select * from foxbpm_run_taskidentitylink WHERE TASK_ID = '" + taskId + "'");

	if (sqlRowSet.next()) {
		groupId = sqlRowSet.getString("GROUP_ID");
	}
	assertEquals("2002", groupId);
}
 
Example 6
Source File: MySqlEnumExtractorTest.java    From celerio with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void film() {
    SqlRowSet queryForRowSet = jdbcTemplate().queryForRowSet("show columns from film where type like 'enum%'");
    while (queryForRowSet.next()) {
        String field = queryForRowSet.getString("Field");
        String type = queryForRowSet.getString("Type");
        MysqlEnumValuesExtractor mysqlEnumValuesExtractor = new MysqlEnumValuesExtractor();
        System.out.println("Extracting values from " + field + "." + type);
        for (String a : mysqlEnumValuesExtractor.extract(type)) {
            System.out.println(a);
        }
    }
}
 
Example 7
Source File: HibernateTimeZoneIT.java    From alchemy with Apache License 2.0 5 votes vote down vote up
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 8
Source File: HibernateTimeZoneTest.java    From ehcache3-samples with Apache License 2.0 5 votes vote down vote up
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 9
Source File: HibernateTimeZoneTest.java    From Spring-5.0-Projects with MIT License 5 votes vote down vote up
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 10
Source File: HibernateTimeZoneIT.java    From java-microservices-examples with Apache License 2.0 5 votes vote down vote up
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 11
Source File: HibernateTimeZoneIT.java    From java-microservices-examples with Apache License 2.0 5 votes vote down vote up
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 12
Source File: RightsDataServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void menuRights(HttpServletResponse response, Long menuId, String locale, long tenantId)
		throws IOException, PersistenceException {
	MenuDAO menuDao = (MenuDAO) Context.get().getBean(MenuDAO.class);
	Menu menu = menuDao.findById(menuId);
	menuDao.initialize(menu);

	// Prepare a map of users
	Map<Long, String> users = getUsers(menu.getTenantId());

	PrintWriter writer = response.getWriter();
	writer.write("<list>");

	// Prepare the query on the folder group in join with groups
	StringBuffer query = new StringBuffer(
			"select A.ld_groupid, B.ld_name, B.ld_type from ld_menugroup as A, ld_group B where A.ld_menuid = ");
	query.append("" + menu.getId());
	query.append(" and B.ld_deleted=0 and A.ld_groupid = B.ld_id and B.ld_tenantid = " + menu.getTenantId());
	query.append(" order by B.ld_type asc, B.ld_name asc");

	SqlRowSet set = menuDao.queryForRowSet(query.toString(), null, null);

	/*
	 * Iterate over records composing the response XML document
	 */
	while (set.next()) {
		long groupId = set.getLong(1);
		String groupName = set.getString(2);
		int groupType = set.getInt(3);
		long userId = 0L;
		if (groupType == Group.TYPE_USER)
			userId = Long.parseLong(groupName.substring(groupName.lastIndexOf('_') + 1));

		writer.print("<right>");
		writer.print("<entityId>" + groupId + "</entityId>");

		if (groupType == Group.TYPE_DEFAULT)
			writer.print("<entity><![CDATA[" + I18N.message("group", locale) + ": " + groupName + "]]></entity>");
		else
			writer.print(
					"<entity><![CDATA[" + I18N.message("user", locale) + ": " + users.get(userId) + "]]></entity>");

		writer.print("<type>" + groupType + "</type>");
		writer.print("</right>");
	}

	writer.write("</list>");
}
 
Example 13
Source File: RightsDataServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void folderRights(HttpServletResponse response, Long folderId, String locale)
		throws IOException, PersistenceException {
	FolderDAO folderDao = (FolderDAO) Context.get().getBean(FolderDAO.class);
	Folder folder = folderDao.findById(folderId);
	folderDao.initialize(folder);

	Folder ref = folder;
	if (folder.getSecurityRef() != null) {
		ref = folderDao.findById(folder.getSecurityRef());
		folderDao.initialize(ref);
	}

	// Prepare a map of users
	Map<Long, String> users = getUsers(ref.getTenantId());

	PrintWriter writer = response.getWriter();
	writer.write("<list>");

	// Prepare the query on the folder group in join with groups
	StringBuffer query = new StringBuffer(
			"select A.ld_groupid, B.ld_name, B.ld_type, A.ld_write, A.ld_add, A.ld_security, A.ld_immutable, A.ld_delete, A.ld_rename, A.ld_import, A.ld_export, A.ld_sign, A.ld_archive, A.ld_workflow, A.ld_download, ");
	query.append(
			" A.ld_calendar, A.ld_subscription, A.ld_print, A.ld_password, A.ld_move, A.ld_email, A.ld_automation from ld_foldergroup as A, ld_group B where A.ld_folderid = ");
	query.append("" + ref.getId());
	query.append(" and B.ld_tenantid = " + ref.getTenantId());
	query.append(" and B.ld_deleted=0 and A.ld_groupid = B.ld_id order by B.ld_type asc, B.ld_name asc");

	SqlRowSet set = folderDao.queryForRowSet(query.toString(), null, null);

	/*
	 * Iterate over records composing the response XML document
	 */
	while (set.next()) {
		long groupId = set.getLong(1);
		String groupName = set.getString(2);
		int groupType = set.getInt(3);
		long userId = 0L;
		if (groupType == Group.TYPE_USER)
			userId = Long.parseLong(groupName.substring(groupName.lastIndexOf('_') + 1));

		writer.print("<right>");
		writer.print("<entityId>" + groupId + "</entityId>");

		if (groupType == Group.TYPE_DEFAULT)
			writer.print("<entity><![CDATA[" + I18N.message("group", locale) + ": " + groupName + "]]></entity>");
		else
			writer.print(
					"<entity><![CDATA[" + I18N.message("user", locale) + ": " + users.get(userId) + "]]></entity>");

		writer.print("<read>true</read>");
		writer.print("<write>" + (set.getInt(4) == 1 ? true : false) + "</write>");
		writer.print("<add>" + (set.getInt(5) == 1 ? true : false) + "</add>");
		writer.print("<security>" + (set.getInt(6) == 1 ? true : false) + "</security>");
		writer.print("<immutable>" + (set.getInt(7) == 1 ? true : false) + "</immutable>");
		writer.print("<delete>" + (set.getInt(8) == 1 ? true : false) + "</delete>");
		writer.print("<rename>" + (set.getInt(9) == 1 ? true : false) + "</rename>");
		writer.print("<import>" + (set.getInt(10) == 1 ? true : false) + "</import>");
		writer.print("<export>" + (set.getInt(11) == 1 ? true : false) + "</export>");
		writer.print("<sign>" + (set.getInt(12) == 1 ? true : false) + "</sign>");
		writer.print("<archive>" + (set.getInt(13) == 1 ? true : false) + "</archive>");
		writer.print("<workflow>" + (set.getInt(14) == 1 ? true : false) + "</workflow>");
		writer.print("<download>" + (set.getInt(15) == 1 ? true : false) + "</download>");
		writer.print("<calendar>" + (set.getInt(16) == 1 ? true : false) + "</calendar>");
		writer.print("<subscription>" + (set.getInt(17) == 1 ? true : false) + "</subscription>");
		writer.print("<print>" + (set.getInt(18) == 1 ? true : false) + "</print>");
		writer.print("<password>" + (set.getInt(19) == 1 ? true : false) + "</password>");
		writer.print("<move>" + (set.getInt(20) == 1 ? true : false) + "</move>");
		writer.print("<email>" + (set.getInt(21) == 1 ? true : false) + "</email>");
		writer.print("<automation>" + (set.getInt(22) == 1 ? true : false) + "</automation>");
		writer.print("<type>" + groupType + "</type>");
		writer.print("</right>");

	}

	writer.write("</list>");
}
 
Example 14
Source File: TicketsDataServlet.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	try {
		Session session = ServiceUtil.validateSession(request);

		response.setContentType("text/xml");
		response.setCharacterEncoding("UTF-8");

		// Avoid resource caching
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-store");
		response.setDateHeader("Expires", 0);

		Integer max = request.getParameter("max") != null ? Integer.parseInt(request.getParameter("max")) : null;

		PrintWriter writer = response.getWriter();
		writer.write("<list>");

		TicketDAO dao = (TicketDAO) Context.get().getBean(TicketDAO.class);
		StringBuffer query = new StringBuffer(
				"select A.ld_id, A.ld_ticketid, A.ld_docid, A.ld_creation, A.ld_expired, A.ld_count, A.ld_maxcount, A.ld_suffix, A.ld_enabled, B.ld_filename, B.ld_folderid from ld_ticket as A, ld_document as B where A.ld_deleted = 0 and A.ld_type = 0 and A.ld_tenantid="
						+ session.getTenantId()
						+ " and B.ld_deleted=0 and A.ld_docid=B.ld_id order by A.ld_creation desc");

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		df.setTimeZone(TimeZone.getTimeZone("UTC"));

		SqlRowSet set = dao.queryForRowSet(query.toString(), null, max);

		/*
		 * Iterate over records composing the response XML document
		 */
		while (set.next()) {
			Integer count = set.getInt(6);
			Integer maxCount = set.getInt(7);
			Date creation = set.getDate(4);
			Date expired = set.getDate(5);
			boolean enabled = set.getInt(9) == 1;
			String fileName = set.getString(10);
			String suffix = set.getString(8);
			if (suffix != null && StringUtils.isNotEmpty(suffix.trim()))
				fileName = fileName + ".pdf";

			writer.print("<ticket>");
			writer.print("<id>" + set.getInt(1) + "</id>");
			writer.print("<ticketId><![CDATA[" + set.getString(2) + "]]></ticketId>");
			writer.print("<docId>" + set.getLong(3) + "</docId>");
			writer.print("<creation>" + df.format(creation) + "</creation>");
			writer.print("<expired>" + df.format(expired) + "</expired>");
			writer.print("<count>" + count + "</count>");
			if (maxCount != null)
				writer.print("<maxCount>" + maxCount + "</maxCount>");
			if (StringUtils.isNotEmpty(suffix))
				writer.print("<suffix><![CDATA[" + suffix + "]]></suffix>");
			writer.print("<eenabled>" + (enabled ? "0" : "2") + "</eenabled>");
			writer.print("<valid>" + (enabled && (maxCount == null || maxCount > count)
					&& (expired == null || expired.getTime() > new Date().getTime())) + "</valid>");
			writer.print("<fileName><![CDATA[" + fileName + "]]></fileName>");
			writer.print("<icon>"
					+ FilenameUtils.getBaseName(IconSelector.selectIcon(FilenameUtils.getExtension(fileName)))
					+ "</icon>");
			writer.print("<folderId>" + set.getLong(11) + "</folderId>");
			writer.print("</ticket>");
		}
		writer.write("</list>");
	} catch (Throwable e) {
		log.error(e.getMessage(), e);
		if (e instanceof ServletException)
			throw (ServletException) e;
		else if (e instanceof IOException)
			throw (IOException) e;
		else
			throw new ServletException(e.getMessage(), e);
	}
}
 
Example 15
Source File: OLATUpgrade_7_3_0.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
  * @param string
  */
 private void migrateDataFromGUIPreferences(final UpgradeManager upgradeManager, final UpgradeHistoryData uhd) {

     if (!uhd.getBooleanDataValue(TASK_MIGRATE_DATA_FROM_GUI_PROPERTIES_DONE)) {
         GUIPreferencesParser parser = new GUIPreferencesParser();
         JdbcTemplate template = new JdbcTemplate(upgradeManager.getDataSource());
         SqlRowSet srs = template
                 .queryForRowSet("SELECT textvalue, identity FROM  o_property WHERE identity IS NOT NULL AND textvalue IS NOT NULL AND textvalue LIKE  '%InfoSubscription::subs%'");
         Long identityKey = 0L;
         int rowCount = 0;
int counter = 0;
         while (srs.next()) {
             try {

                 String prefsXml = srs.getString("textvalue");
                 identityKey = srs.getLong("identity");
                 Identity identity = security.loadIdentityByKey(identityKey);

                 Document doc = parser.createDocument(prefsXml);

                 List<String> infoSubscriptions = parser.parseDataForInputQuery(doc, parser.queryInfo);
                 persistInfo(infoSubscriptions, "InfoSubscription::subscribed", identity);

                 List<String> calendarSubscriptions = parser.parseDataForInputQuery(doc, parser.queryCal);
                 persistInfo(calendarSubscriptions, "CourseCalendarSubscription::subs", identity);

                 List<String> infoSubscriptionsNot = parser.parseDataForInputQuery(doc, parser.queryInfoNot);
                 persistInfo(infoSubscriptionsNot, "InfoSubscription::notdesired", identity);

                 List<String> calendarSubscriptionsNot = parser.parseDataForInputQuery(doc, parser.queryCalNot);
                 persistInfo(calendarSubscriptionsNot, "CourseCalendarSubscription::notdesired", identity);

             } catch (Exception e) {
                 log.error("could not migrate gui preferences for identity: " + identityKey, e);
             }
  	  counter++;
     if (counter % 10 == 0) {
		DBFactory.getInstance().intermediateCommit();
	}

             rowCount++;
         }
   // Final commit 
DBFactory.getInstance().intermediateCommit();

         uhd.setBooleanDataValue(TASK_MIGRATE_DATA_FROM_GUI_PROPERTIES_DONE, true);
         upgradeManager.setUpgradesHistory(uhd, VERSION);
     }

 }
 
Example 16
Source File: OLATUpgrade_7_3_0.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * @param string
 */
private void migrateDataFromGUIPreferences(final UpgradeManager upgradeManager, final UpgradeHistoryData uhd) {

    if (!uhd.getBooleanDataValue(TASK_MIGRATE_DATA_FROM_GUI_PROPERTIES_DONE)) {
        GUIPreferencesParser parser = new GUIPreferencesParser();
        JdbcTemplate template = new JdbcTemplate(upgradeManager.getDataSource());
        SqlRowSet srs = template
                .queryForRowSet("SELECT textvalue, identity FROM  o_property WHERE identity IS NOT NULL AND textvalue IS NOT NULL AND textvalue LIKE  '%InfoSubscription::subs%'");
        Long identityKey = 0L;
        int rowCount = 0;
        int counter = 0;
        while (srs.next()) {
            try {

                String prefsXml = srs.getString("textvalue");
                identityKey = srs.getLong("identity");
                Identity identity = security.loadIdentityByKey(identityKey);

                Document doc = parser.createDocument(prefsXml);

                List<String> infoSubscriptions = parser.parseDataForInputQuery(doc, parser.queryInfo);
                persistInfo(infoSubscriptions, "InfoSubscription::subscribed", identity);

                List<String> calendarSubscriptions = parser.parseDataForInputQuery(doc, parser.queryCal);
                persistInfo(calendarSubscriptions, "CourseCalendarSubscription::subs", identity);

                List<String> infoSubscriptionsNot = parser.parseDataForInputQuery(doc, parser.queryInfoNot);
                persistInfo(infoSubscriptionsNot, "InfoSubscription::notdesired", identity);

                List<String> calendarSubscriptionsNot = parser.parseDataForInputQuery(doc, parser.queryCalNot);
                persistInfo(calendarSubscriptionsNot, "CourseCalendarSubscription::notdesired", identity);

            } catch (Exception e) {
                log.error("could not migrate gui preferences for identity: " + identityKey, e);
            }
            counter++;
            if (counter % 10 == 0) {
                DBFactory.getInstance().intermediateCommit();
            }

            rowCount++;
        }
        // Final commit
        DBFactory.getInstance().intermediateCommit();

        uhd.setBooleanDataValue(TASK_MIGRATE_DATA_FROM_GUI_PROPERTIES_DONE, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }

}
 
Example 17
Source File: BizDataObjectBehaviorImpl.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public List<BizDataObject> getDataObjects(String dataSource) {
	LOG.debug("getDataObjects(String dataSource),dataSource=" + dataSource);
	try {
		JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils.getDataSource());
		DatabaseMetaData dm = DBUtils.getDataSource().getConnection().getMetaData();
		String databaseType = dm.getDatabaseProductName();
		String databaseVersion = dm.getDatabaseProductVersion();
		LOG.info("the database type is " + databaseType + ",version is " + databaseVersion);
		// 定义sql返回结果集
		SqlRowSet rs = null;
		boolean isOracle = false;
		if (MySQL_TYPE.equalsIgnoreCase(databaseType)) {
			// 获取此 当前数据源连接 对象的当前目录名称。
			String catalog = jdbcTemplate.getDataSource().getConnection().getCatalog();
			LOG.info("the sql is " + TABLE_INFOR);
			rs = jdbcTemplate.queryForRowSet(TABLE_INFOR, new Object[]{catalog});
		} else if (ORACLE_TYPE.equalsIgnoreCase(databaseType)) {
			isOracle = true;
			StringBuffer sql = new StringBuffer("select distinct t_col.DATA_TYPE,t_col.TABLE_NAME,t_col.COLUMN_NAME,t_des.comments as TABLE_COMMENT,c_des.comments as COLUMN_COMMENT from user_tab_columns t_col,user_col_comments c_des,user_tab_comments t_des ").append("where t_col.table_name = c_des.table_name and t_col.table_name = t_des.table_name order by t_col.table_name");
			rs = jdbcTemplate.queryForRowSet(sql.toString());
		} else if("mssql".equalsIgnoreCase(databaseType)){
			
		}
		
		
		List<BizDataObject> bizDataObjects = new ArrayList<BizDataObject>();
		BizDataObject bizDataObject = null;
		DataVariableDefinition dataVariableDefine = null;
		String tableName = null;
		StringBuffer sbExpression = new StringBuffer();
		if(rs != null){
		// 获取表信息
		while (rs.next()) {
			// 处理首次和区分不同表
			if (!rs.getString(TABLE_NAME).equals(tableName)) {
				bizDataObject = new BizDataObject();
				bizDataObject.setId(rs.getString(TABLE_NAME));
				if (isOracle) {
					bizDataObject.setName(rs.getString(TABLE_COMMENT));
				}
				bizDataObject.setDataSource(dataSource);
				// 添加业务数据对象
				bizDataObjects.add(bizDataObject);
			}
			dataVariableDefine = new DataVariableDefinition();
			dataVariableDefine.setId(rs.getString(COLUMN_NAME));
			dataVariableDefine.setFieldName(rs.getString(COLUMN_NAME));
			dataVariableDefine.setDataType(rs.getString(DATA_TYPE));
			// 生成表达式
			sbExpression.append("import org.foxbpm.engine.impl.util.DataVarUtil;\n");
			sbExpression.append("DataVarUtil.getInstance().getDataValue(");
			sbExpression.append("\"" + dataSource + "\"").append(',').append("processInfo.getProcessInstance().getBizKey(),");
			sbExpression.append("\"" + dataVariableDefine.getId() + "\"");
			sbExpression.append(",processInfo);");
			dataVariableDefine.setExpression(sbExpression.toString());
			
			dataVariableDefine.setDocumentation(rs.getString(COLUMN_COMMENT));
			dataVariableDefine.setBizType(Constant.DB_BIZTYPE);
			// 添加数据变量定义
			bizDataObject.getDataVariableDefinitions().add(dataVariableDefine);
			tableName = rs.getString(TABLE_NAME);
			// 清空sbExpression缓存
			sbExpression.delete(0, sbExpression.length());
		}}
		LOG.debug("end getDataObjects(String dataSource)");
		return bizDataObjects;
	} catch (SQLException e) {
		throw ExceptionUtil.getException("获取数据对象失败",e);
	}
}
 
Example 18
Source File: HibernateDocumentDAO.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Avoid file name duplications in the same folder
 */
private void setUniqueFilename(Document doc) {
	if (!RunLevel.current().aspectEnabled("uniquenessFilename"))
		return;

	String baseName = doc.getFileName();
	String ext = "";
	if (doc.getFileName().indexOf(".") != -1) {
		baseName = FilenameUtils.getBaseName(doc.getFileName());
		ext = "." + FilenameUtils.getExtension(doc.getFileName());
	}

	/*
	 * These sets will contain the found collisions in the given folder
	 */
	final Set<String> fileNames = new HashSet<String>();

	StringBuffer query = new StringBuffer(
			"select lower(ld_filename) from ld_document where ld_deleted=0 and ld_folderid=");
	query.append(Long.toString(doc.getFolder().getId()));
	query.append(" and lower(ld_filename) like '");
	query.append(SqlUtil.doubleQuotes(baseName.toLowerCase()));
	query.append("%' and not ld_id=");
	query.append(Long.toString(doc.getId()));

	// Execute the query to populate the sets
	try {
		SqlRowSet rs = queryForRowSet(query.toString(), null, null);
		if (rs != null)
			while (rs.next()) {
				String file = rs.getString(1);
				if (!fileNames.contains(file))
					fileNames.add(file);
			}
	} catch (PersistenceException e) {
		log.error(e.getMessage(), e);
	}

	int counter = 1;
	while (fileNames.contains(doc.getFileName().toLowerCase()))
		doc.setFileName(baseName + "(" + (counter++) + ")" + ext);
}