📄 viewobjectsdaoimpl.java
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.config.utils.db;import com.queplix.core.error.GenericSystemException;import com.queplix.core.integrator.security.AccessLevel;import com.queplix.core.integrator.security.PermissionObjectType;import com.queplix.core.modules.config.jxb.Button;import com.queplix.core.modules.config.jxb.Col;import com.queplix.core.modules.config.jxb.ExternalField;import com.queplix.core.modules.config.jxb.ExternalForm;import com.queplix.core.modules.config.jxb.ExternalSet;import com.queplix.core.modules.config.jxb.Focus;import com.queplix.core.modules.config.jxb.Form;import com.queplix.core.modules.config.jxb.Header;import com.queplix.core.modules.config.jxb.HiddenControl;import com.queplix.core.modules.config.jxb.Htmlelement;import com.queplix.core.modules.config.jxb.Htmlelements;import com.queplix.core.modules.config.jxb.InternalField;import com.queplix.core.modules.config.jxb.Link;import com.queplix.core.modules.config.jxb.LinkedDataset;import com.queplix.core.modules.config.jxb.Row;import com.queplix.core.modules.config.jxb.SubFocus;import com.queplix.core.modules.config.jxb.Tab;import com.queplix.core.modules.config.jxb.types.FormLabelsOrientationType;import com.queplix.core.modules.config.jxb.types.PermissionsType;import com.queplix.core.modules.config.utils.EntityHelper;import com.queplix.core.modules.config.utils.ViewObject;import com.queplix.core.modules.config.utils.ViewObjectsDAO;import com.queplix.core.modules.config.utils.ViewObjectsStructure;import com.queplix.core.utils.dao.AbstractDAO;import com.queplix.core.utils.sql.SqlWrapper;import com.queplix.core.utils.sql.SqlWrapperFactory;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;/** * Project-specific implementation of the FocusConfigDAO * * @author [ALB] Baranov Andrey * @author Kozmin Sergey * @version $Revision: 1.1.1.1 $ $Date: 2005/09/12 15:30:18 $ */public class ViewObjectsDAOImpl extends AbstractDAO implements ViewObjectsDAO { private static final int FOCUS_TYPE = Integer.parseInt(DBRealmManager.getProperty("focus_type_id")); private static final int SUBFOCUS_TYPE = Integer.parseInt(DBRealmManager.getProperty("subfocus_type_id")); private static final int TAB_TYPE = Integer.parseInt(DBRealmManager.getProperty("tab_type_id")); private static final int FORM_TYPE = Integer.parseInt(DBRealmManager.getProperty("form_type_id")); private static final int FIELD_TYPE = Integer.parseInt(DBRealmManager.getProperty("field_type_id")); private static final String VIEW_OBJECTS_TABLE_NAME = "QX_VIEW_OBJECTS"; protected SqlWrapper sqlWrapper = SqlWrapperFactory.getSqlWrapper(); /** * @see com.queplix.core.modules.config.utils.ViewObjectsDAO#deleteObjects(com.queplix.core.modules.config.utils.ViewObjectsStructure) */ public void deleteObjects(ViewObjectsStructure toBeDeleted) { Collection<ViewObject> objects = toBeDeleted.getFullObjects().values(); int idsSize = objects.size(); StringBuffer sqlObjectsSet = new StringBuffer("("); for(Iterator<ViewObject> iterator = objects.iterator(); iterator.hasNext();) { ViewObject viewObject = iterator.next(); sqlObjectsSet.append(viewObject.getId()); if(iterator.hasNext()) { sqlObjectsSet.append(","); } } sqlObjectsSet.append(")"); String s = sqlObjectsSet.toString();// INFO("Objects to be deleted :" + s); Connection con = null; Statement stat = null; try { con = sqlWrapper.doConnection(); stat = sqlWrapper.doStatement(con); if(idsSize > 0) { sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_form_settings_in_set") + s); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_permission_in_set") + s); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("updateall_role_in_set") + s); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_view_object_in_set") + s); } sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_linked_datasource")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_external_field")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_external_form")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_external_set")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_header")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_row")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_col")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_button")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_html_element")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_hiddencontrol")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_link")); sqlWrapper.executeUpdate(stat, DBRealmManager.getSql("delall_helplink")); } catch (SQLException ex) { throw new GenericSystemException("SQL exception: " + ex.getMessage(), ex); } finally { sqlWrapper.closeConnection(con, stat); } } public void updateExternalTabValues(List<Tab> tabs) { Connection con = sqlWrapper.doConnection(); PreparedStatement deleteStatement = sqlWrapper.doPreparedStatement(con, DBRealmManager.getSql("delete_helplink")); PreparedStatement insertStatement = sqlWrapper.doPreparedStatement(con, DBRealmManager.getSql("insert_helplink")); try { for (Tab tab:tabs) { sqlWrapper.getStringParser().setValue(deleteStatement, 1, tab.getName()); sqlWrapper.executeUpdate(deleteStatement); if (tab.getHelplink() != null) { sqlWrapper.getStringParser().setValue(insertStatement, 1, tab.getName()); sqlWrapper.getStringParser().setValue(insertStatement, 2, tab.getHelplink()); sqlWrapper.executeUpdate(insertStatement); } } deleteStatement.close(); insertStatement.close(); } catch(SQLException ex) { throw new GenericSystemException("SQL exception: " + ex.getMessage(), ex); } finally { sqlWrapper.closeConnection(con); } } public void updateObjects(ViewObjectsStructure toUpdate) { Connection con = null; Map<String, ViewObject> focuses = toUpdate.getFocuses(); //update focuses try { con = sqlWrapper.doConnection(); for(ViewObject viewObject : focuses.values()) { if(viewObject.getStatus() == ViewObject.ObjectStatus.EXISTING) { updateViewObject(viewObject, con); } else if(viewObject.getStatus() == ViewObject.ObjectStatus.TO_BE_INSERTED) { insertFocus(viewObject, con); } } updateSubFocuses(toUpdate, con); } catch (SQLException e) { throw new GenericSystemException("SQL exception: " + e.getMessage(), e); } finally { sqlWrapper.closeConnection(con); } } private void updateSubFocuses(ViewObjectsStructure toUpdate, Connection con) throws SQLException { Map<String, ViewObject> subFocuses = toUpdate.getSubFocuses(); for(ViewObject viewObject : subFocuses.values()) { if(viewObject.getStatus() == ViewObject.ObjectStatus.EXISTING) { updateViewObject(viewObject, con); } else if(viewObject.getStatus() == ViewObject.ObjectStatus.TO_BE_INSERTED) { insertSubFocus(viewObject, con); } } updateTabs(toUpdate, con); } private void updateTabs(ViewObjectsStructure toUpdate, Connection con) throws SQLException { Map<String, ViewObject> tabs = toUpdate.getTabs(); for(ViewObject viewObject : tabs.values()) { if(viewObject.getStatus() == ViewObject.ObjectStatus.EXISTING) { updateViewObject(viewObject, con); } else if(viewObject.getStatus() == ViewObject.ObjectStatus.TO_BE_INSERTED) { insertTab(viewObject, con); } } updateForms(toUpdate, con); } private void updateForms(ViewObjectsStructure toUpdate, Connection con) throws SQLException { Map<String, ViewObject> forms = toUpdate.getForms(); for(ViewObject viewObject : forms.values()) { if(viewObject.getStatus() == ViewObject.ObjectStatus.EXISTING) { updateViewObject(viewObject, con); } else if(viewObject.getStatus() == ViewObject.ObjectStatus.TO_BE_INSERTED) { insertForm(viewObject, con); }// updateFields } } private void insertFocus(ViewObject viewObject, Connection con) throws SQLException { insertViewObject("insert_focus", viewObject, con); } private void insertSubFocus(ViewObject viewObject, Connection con) throws SQLException { insertViewObject("insert_subfocus", viewObject, con); } private void insertTab(ViewObject viewObject, Connection con) throws SQLException { insertViewObject("insert_tab", viewObject, con); } private void insertForm(ViewObject viewObject, Connection con) throws SQLException { insertViewObject("insert_form", viewObject, con); } private void insertViewObject(String sqlStatementName, ViewObject viewObject, Connection con) throws SQLException { PreparedStatement insertStatement = sqlWrapper.doPreparedStatement(con, DBRealmManager.getSql(sqlStatementName)); try { long id = sqlWrapper.getNextKey(con, VIEW_OBJECTS_TABLE_NAME); sqlWrapper.getLongParser().setValue(insertStatement, 1, id); sqlWrapper.getStringParser().setValue(insertStatement, 2, viewObject.getName()); Long parentId = viewObject.getParent(); if(parentId == null) { ViewObject obj = viewObject.getParentObject(); if(obj != null) { parentId = obj.getId(); } } sqlWrapper.getLongParser().setValue(insertStatement, 3, parentId); sqlWrapper.getIntParser().setValue(insertStatement, 4, viewObject.getOrderInGroup()); sqlWrapper.getStringParser().setValue(insertStatement, 5, viewObject.getIcon()); sqlWrapper.getIntParser().setValue(insertStatement, 6, viewObject.getInFrameLinks() ? 1 : 0); sqlWrapper.getIntParser().setValue(insertStatement, 7, viewObject.getGrid() ? 1 : 0); sqlWrapper.executeUpdate(insertStatement); viewObject.setId(id); } finally { insertStatement.close(); } } private void updateViewObject(ViewObject viewObject, Connection con) throws SQLException { PreparedStatement updateObject = sqlWrapper.doPreparedStatement(con, DBRealmManager.getSql("update_object")); try { sqlWrapper.getIntParser().setValue(updateObject, 1, viewObject.getOrderInGroup()); sqlWrapper.getStringParser().setValue(updateObject, 2, viewObject.getIcon()); sqlWrapper.getIntParser().setValue(updateObject, 3, viewObject.getInFrameLinks() ? 1 : 0); sqlWrapper.getIntParser().setValue(updateObject, 4, viewObject.getGrid() ? 1 : 0); sqlWrapper.getLongParser().setValue(updateObject, 5, viewObject.getId()); sqlWrapper.executeUpdate(updateObject); } finally { updateObject.close(); } } /** * @see com.queplix.core.modules.config.utils.ViewObjectsDAO#loadViewObjects() */ public ViewObjectsStructure loadViewObjects() { ViewObjectsStructure ret = new ViewObjectsStructure(); Connection con = sqlWrapper.doConnection(); Statement stat = sqlWrapper.doStatement(con); try { ResultSet set = sqlWrapper.executeQuery(stat, DBRealmManager.getSql("select_view_objects")); while(set.next()) { Long id = sqlWrapper.getLongParser().getValue(set, 1); String name = sqlWrapper.getStringParser().getValue(set, 2); Long parentId = sqlWrapper.getLongParser().getValue(set, 3); int type = sqlWrapper.getIntParser().getValue(set, 4); String icon = sqlWrapper.getStringParser().getValue(set, 5); int order = sqlWrapper.getIntParser().getValue(set, 6); boolean inFrameLinks = sqlWrapper.getIntParser().getValue(set, 7) != 0; boolean grid = sqlWrapper.getIntParser().getValue(set, 8) != 0; ret.add(new ViewObject(id, name, parentId, order, getPermission(type), ViewObject.ObjectStatus.EXISTING, null, icon, inFrameLinks, grid)); } } catch (SQLException ex) { throw new GenericSystemException("SQL exception: " + ex.getMessage(), ex); } finally { sqlWrapper.closeConnection(con, stat); } return ret; } public void updateExternalFormValues(Map<ViewObject, Form> updatingStructure) { Connection con = sqlWrapper.doConnection(); Set<ViewObject> objects = updatingStructure.keySet(); try { for(ViewObject viewObject : objects) { Form form = updatingStructure.get(viewObject); if(viewObject.getStatus() == ViewObject.ObjectStatus.EXISTING) { updateFormSettings(form, viewObject, con); } else if(viewObject.getStatus() == ViewObject.ObjectStatus.TO_BE_INSERTED) { insertFormSettings(viewObject, form, con); } insertExternalSets(form, con); insertExternalForms(form, con); insertExternalFields(form, con); insertLinkedDatasets(form, con); //don't insert internal fields. saveLinks(con, form); saveButtons(con, form); saveHtmlElements(con, form); saveLayout(con, form); } } catch (SQLException e) { throw new GenericSystemException("SQL exception: " + e.getMessage(), e); } finally { sqlWrapper.closeConnection(con); } } private void insertFormSettings(ViewObject viewObject, Form form, Connection con) throws SQLException { PreparedStatement insertFormSettings = sqlWrapper.doPreparedStatement(con,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -