Search in sources :

Example 16 with SerialInfo

use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.

the class AbsExportDataHandler method exportSchemaToOBSFile.

/**
	 * Export the schema and index DDL to file
	 *
	 * @param databaseInfo DatabaseInfo
	 * @param exportDataEventHandler IExportDataEventHandler
	 * @param tableNameList Set<String>
	 * @param schemaFile String
	 * @param indexFile String
	 * @param fileCharset String
	 * @param exportStartValue whether keep start value
	 * @throws SQLException The SQL exception
	 * @throws IOException The IO exception
	 */
public static void exportSchemaToOBSFile(DatabaseInfo databaseInfo, IExportDataEventHandler exportDataEventHandler, Set<String> tableNameList, String schemaFile, String indexFile, String fileCharset, boolean exportStartValue) throws SQLException, IOException {
    // FIXME move this logic to core module
    if (schemaFile == null && indexFile == null) {
        return;
    }
    Connection conn = null;
    BufferedWriter schemaWriter = null;
    BufferedWriter indexWriter = null;
    LinkedList<SchemaInfo> schemaInfoList = null;
    boolean hasDataInIndexFile = false;
    try {
        if (schemaFile != null) {
            schemaWriter = getBufferedWriter(schemaFile, fileCharset);
        }
        if (indexFile != null) {
            indexWriter = getBufferedWriter(indexFile, fileCharset);
            schemaInfoList = new LinkedList<SchemaInfo>();
        }
        SchemaDDL schemaDDL = new SchemaDDL(new SchemaChangeManager(databaseInfo, true), databaseInfo);
        conn = JDBCConnectionManager.getConnection(databaseInfo, false);
        for (String tableName : tableNameList) {
            SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(conn, tableName);
            if (schemaInfo == null) {
                continue;
            }
            //write the create DDL
            if (schemaWriter == null) {
                continue;
            }
            String ddl = schemaDDL.getSchemaDDL(schemaInfo, false);
            if (ddl != null && ddl.trim().length() > 0) {
                schemaWriter.write(ddl);
                schemaWriter.write(StringUtil.NEWLINE);
            }
            schemaWriter.flush();
            if (exportStartValue) {
                List<SerialInfo> autoIncrementList = schemaDDL.getAutoIncrementList(schemaInfo);
                if (autoIncrementList.size() > 0) {
                    for (SerialInfo serialInfo : autoIncrementList) {
                        String serialName = getSerailName(tableName, serialInfo.getAttName());
                        String currentValue = getCurrentValueFromSystemTable(serialName, databaseInfo, conn);
                        String alterStartValueDDL = schemaDDL.getAlterSerialStartValueDDL(serialName, currentValue);
                        schemaWriter.write(alterStartValueDDL);
                        schemaWriter.write(StringUtil.NEWLINE);
                    }
                }
            }
            if (indexWriter == null) {
                continue;
            }
            schemaInfoList.add(schemaInfo);
        }
        // write PKs, indexes to a file
        if (schemaInfoList != null) {
            String ddl = null;
            // write pk
            for (SchemaInfo schemaInfo : schemaInfoList) {
                ddl = schemaDDL.getPKsDDL(schemaInfo);
                if (ddl != null && ddl.trim().length() > 0) {
                    indexWriter.write(ddl.trim());
                    indexWriter.newLine();
                    hasDataInIndexFile = true;
                }
            }
            if (hasDataInIndexFile) {
                indexWriter.newLine();
            }
            // write index
            for (SchemaInfo schemaInfo : schemaInfoList) {
                ddl = schemaDDL.getIndexsDDL(schemaInfo);
                if (ddl != null && ddl.trim().length() > 0) {
                    indexWriter.write(ddl.trim());
                    indexWriter.newLine();
                    hasDataInIndexFile = true;
                }
            }
            if (hasDataInIndexFile) {
                indexWriter.newLine();
            }
            //write fk
            for (SchemaInfo schemaInfo : schemaInfoList) {
                ddl = schemaDDL.getFKsDDL(schemaInfo);
                if (ddl != null && ddl.trim().length() > 0) {
                    indexWriter.write(ddl.trim());
                    indexWriter.newLine();
                    hasDataInIndexFile = true;
                }
            }
            if (hasDataInIndexFile) {
                indexWriter.flush();
            }
        }
    } finally {
        QueryUtil.freeQuery(conn);
        FileUtil.close(schemaWriter);
        FileUtil.close(indexWriter);
        if (!hasDataInIndexFile) {
            FileUtil.delete(indexFile);
        }
    }
}
Also used : SchemaChangeManager(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeManager) Connection(java.sql.Connection) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) BufferedWriter(java.io.BufferedWriter) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 17 with SerialInfo

use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.

the class ColumnProposalDetailInfo method getColumnAdditionalInfo.

/**
	 * Get column proposal additional information
	 *
	 * @return String
	 */
public String getColumnAdditionalInfo() {
    StringBuilder additionalInfoBf = new StringBuilder();
    additionalInfoBf.append(Messages.quickColInfoColumnName).append(": ").append(attributeInfo.getName()).append(StringUtil.NEWLINE);
    additionalInfoBf.append(Messages.quickColInfoTableName).append(": ").append(schemaInfo.getClassname()).append(StringUtil.NEWLINE);
    //		boolean isClassAttr = attributeInfo.isClassAttribute();
    //		additionalInfoBf.append(
    //				com.cubrid.common.ui.cubrid.table.Messages.grpColumnType).append(
    //				": ").append(isClassAttr ? "CLASS" : "INSTANCE").append(
    //				StringUtil.NEWLINE);
    String dataType = attributeInfo.getType();
    additionalInfoBf.append(Messages.quickColInfoDataType).append(": ").append(dataType).append(StringUtil.NEWLINE);
    boolean isNotNull = attributeInfo.isNotNull();
    additionalInfoBf.append(Messages.quickColInfoNotNull).append(": ").append(isNotNull ? "Y" : "N").append(StringUtil.NEWLINE);
    boolean isUnique = attributeInfo.isUnique();
    additionalInfoBf.append(Messages.quickColInfoUnique).append(": ").append(isUnique ? "Y" : "N").append(StringUtil.NEWLINE);
    String defaultValue = attributeInfo.getDefault();
    if (defaultValue != null && defaultValue.length() > 0) {
        additionalInfoBf.append(Messages.quickColInfoDefaultValue).append(": ").append(defaultValue).append(StringUtil.NEWLINE);
    }
    SerialInfo autoInc = attributeInfo.getAutoIncrement();
    if (autoInc != null) {
        String currValue = autoInc.getCurrentValue();
        String increValue = autoInc.getIncrementValue();
        additionalInfoBf.append(Messages.quickColInfoAutoIncr).append(": (").append(currValue).append(",").append(increValue).append(")").append(StringUtil.NEWLINE);
    }
    List<Constraint> constraintList = schemaInfo.getConstraints();
    boolean isPrimaryKey = false;
    String foreignTable = null;
    String indexType = null;
    for (Constraint constraint : constraintList) {
        if (constraint.getAttributes().contains(attributeInfo.getName()) || constraint.getClassAttributes().contains(attributeInfo.getName())) {
            String type = constraint.getType();
            if (Constraint.ConstraintType.PRIMARYKEY.getText().equals(type)) {
                isPrimaryKey = true;
            } else if (Constraint.ConstraintType.FOREIGNKEY.getText().equals(type)) {
                foreignTable = constraint.getReferencedTable();
            } else if (Constraint.ConstraintType.INDEX.getText().equals(type) || Constraint.ConstraintType.UNIQUE.getText().equals(type) || Constraint.ConstraintType.REVERSEINDEX.getText().equals(type) || Constraint.ConstraintType.REVERSEUNIQUE.getText().equals(type)) {
                indexType = type;
            }
            break;
        }
    }
    additionalInfoBf.append(Messages.quickColInfoPk).append(": ").append(isPrimaryKey ? "Y" : "N").append(StringUtil.NEWLINE);
    if (foreignTable != null && foreignTable.trim().length() > 0) {
        additionalInfoBf.append(Messages.lblFK).append(" REFERENCES ").append(foreignTable).append(StringUtil.NEWLINE);
    }
    if (indexType != null) {
        additionalInfoBf.append(Messages.quickColInfoIndex).append(": ").append(indexType).append(StringUtil.NEWLINE);
    }
    return additionalInfoBf.toString();
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 18 with SerialInfo

use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.

the class CubridSerialFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            database.getDatabaseInfo().setSerialInfoList(null);
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetSerialInfoListTask task = new GetSerialInfoListTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        parent.removeAllChild();
        List<SerialInfo> serialInfoList = task.getSerialInfoList();
        List<SerialInfo> authSerialInfoList = new ArrayList<SerialInfo>();
        if (serialInfoList != null && !serialInfoList.isEmpty()) {
            for (SerialInfo serialInfo : serialInfoList) {
                authSerialInfoList.add(serialInfo);
                String id = parent.getId() + NODE_SEPARATOR + serialInfo.getName();
                ICubridNode serialNode = createSerialNode(id, serialInfo);
                parent.addChild(serialNode);
            }
        }
        databaseInfo.setSerialInfoList(authSerialInfoList);
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : GetSerialInfoListTask(com.cubrid.cubridmanager.core.cubrid.serial.task.GetSerialInfoListTask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 19 with SerialInfo

use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.

the class CreateSerialAction method run.

/**
	 * run create serial
	 * @param database
	 */
public void run(CubridDatabase database) {
    CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), true);
    dialog.setDatabase(database);
    ISelectionProvider provider = getSelectionProvider();
    if (dialog.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        TreeViewer treeViewer = (TreeViewer) provider;
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSerialFolderLoader.SERIAL_FOLDER_ID);
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        // FIXME move this logic to core module
        String serialName = dialog.getSerialName().toLowerCase(Locale.getDefault());
        DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + serialName;
        SerialInfo serialInfo = new SerialInfo();
        serialInfo.setName(serialName);
        serialInfo.setOwner(userInfo.getName());
        ICubridNode newNode = CubridSerialFolderLoader.createSerialNode(id, serialInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
    }
}
Also used : CreateOrEditSerialDialog(com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 20 with SerialInfo

use of com.cubrid.common.core.common.model.SerialInfo in project cubrid-manager by CUBRID.

the class CreateOrEditSerialDialog method initialize.

/**
	 * Initial data
	 */
private void initialize() {
    if (editedNode == null) {
        startValText.setText("0");
        incrementValText.setText("1");
        minValText.setText("");
        minValText.setEnabled(false);
        noMinValueBtn.setSelection(true);
        maxValText.setText("");
        maxValText.setEnabled(false);
        noMaxValueBtn.setSelection(true);
        cycleButton.setSelection(false);
        if (isSupportCache) {
            cacheCountText.setEnabled(false);
            noCacheBtn.setSelection(true);
        }
        serialNameText.setFocus();
    } else {
        SerialInfo serialInfo = (SerialInfo) editedNode.getAdapter(SerialInfo.class);
        if (serialInfo != null) {
            serialNameText.setEditable(false);
            serialNameText.setText(serialInfo.getName());
            startValText.setText(String.valueOf(serialInfo.getCurrentValue()));
            String incrValue = serialInfo.getIncrementValue();
            incrementValText.setText(incrValue);
            String minValue = serialInfo.getMinValue();
            if (incrValue.indexOf("-") >= 0 && SERIAL_MIN.equals(minValue)) {
                noMinValueBtn.setSelection(true);
                minValText.setEnabled(false);
            } else {
                minValText.setText(minValue);
            }
            String maxValue = serialInfo.getMaxValue();
            if (incrValue.indexOf("-") < 0 && SERIAL_MAX.equals(maxValue)) {
                noMaxValueBtn.setSelection(true);
                maxValText.setEnabled(false);
            } else {
                maxValText.setText(maxValue);
            }
            if (isSupportCache) {
                String cacheCount = serialInfo.getCacheCount();
                if (cacheCount == null || (cacheCount.trim().matches("\\d+") && Integer.parseInt(cacheCount.trim()) <= 0)) {
                    noCacheBtn.setSelection(true);
                    cacheCountText.setEnabled(false);
                } else {
                    cacheCountText.setText(cacheCount);
                }
            }
            cycleButton.setSelection(serialInfo.isCyclic());
        }
    }
    serialNameText.addModifyListener(this);
    startValText.addModifyListener(this);
    incrementValText.addModifyListener(this);
    minValText.addModifyListener(this);
    maxValText.addModifyListener(this);
    if (isSupportCache) {
        cacheCountText.addModifyListener(this);
    }
    if (!isEditAble) {
        serialNameText.setEditable(false);
        startValText.setEditable(false);
        incrementValText.setEditable(false);
        maxValText.setEditable(false);
        minValText.setEditable(false);
        cycleButton.setEnabled(false);
        noMinValueBtn.setEnabled(false);
        noMaxValueBtn.setEnabled(false);
        noCacheBtn.setEnabled(false);
    }
}
Also used : SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Aggregations

SerialInfo (com.cubrid.common.core.common.model.SerialInfo)34 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)14 Constraint (com.cubrid.common.core.common.model.Constraint)12 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)9 ArrayList (java.util.ArrayList)8 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 TableItem (org.eclipse.swt.widgets.TableItem)4 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)3 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 CreateOrEditSerialDialog (com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog)2 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 GetSerialInfoListTask (com.cubrid.cubridmanager.core.cubrid.serial.task.GetSerialInfoListTask)2 BufferedWriter (java.io.BufferedWriter)2 Connection (java.sql.Connection)2 List (java.util.List)2 Table (org.eclipse.swt.widgets.Table)2 DBResolution (com.cubrid.common.core.common.model.DBResolution)1