public static void loadIdentitySpecifier( Connection connection, IdentitySpecifier identitySpecifier, Column column) throws SQLException { final Table table = column.getTable(); final Schema schema = table.getSchema(); final Database database = ModelHelper.getDatabase(schema); final DatabaseDefinition databaseDefinition = RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(database); final DataModelElementFactory factory = databaseDefinition.getDataModelElementFactory(); String query = "Select INCREMENT,START,MAXVALUE,MINVALUE,CYCLE, CACHE " + //$NON-NLS-1$ " FROM SYSCAT.COLIDENTATTRIBUTES" + //$NON-NLS-1$ " WHERE TABSCHEMA='" + LUWUtil.getIdentifier(schema.getName()) + "'" + //$NON-NLS-1$ //$NON-NLS-2$ " AND TABNAME= '" + LUWUtil.getIdentifier(table.getName()) + "'" + //$NON-NLS-1$ //$NON-NLS-2$ " AND COLNAME ='" + LUWUtil.getIdentifier(column.getName()) + "'"; //$NON-NLS-1$ //$NON-NLS-2$ Statement s = connection.createStatement(); ResultSet r = s.executeQuery(query); try { while (r.next()) { DB2IdentitySpecifier identity = (DB2IdentitySpecifier) identitySpecifier; identity.setIncrement(r.getBigDecimal("INCREMENT").toBigInteger()); // $NON-NLS-1$ identity.setStartValue(r.getBigDecimal("START").toBigInteger()); // $NON-NLS-1$ identity.setMinimum(r.getBigDecimal("MINVALUE").toBigInteger()); // $NON-NLS-1$ identity.setMaximum(r.getBigDecimal("MAXVALUE").toBigInteger()); // $NON-NLS-1$ identity.setCache(r.getInt("CACHE")); // $NON-NLS-1$ if (r.getString("CYCLE").trim().equals("Y")) { // $NON-NLS-1$ //$NON-NLS-2$ identitySpecifier.setCycleOption(true); } else { identitySpecifier.setCycleOption(false); } } } catch (Exception e) { e.printStackTrace(); } r.close(); s.close(); }
public synchronized void loadGenerateExrepression() { if (this.generateExpressionLoaded) return; this.generateExpressionLoaded = true; if (!this.isGenerated) return; boolean deliver = this.eDeliver(); this.eSetDeliver(false); try { final Table table = this.getTable(); final Schema schema = table.getSchema(); final Database database = ModelHelper.getDatabase(schema); final DatabaseDefinition databaseDefinition = RDBCorePlugin.getDefault().getDatabaseDefinitionRegistry().getDefinition(database); final DataModelElementFactory factory = databaseDefinition.getDataModelElementFactory(); Statement s = this.getConnection().createStatement(); ResultSet r = s.executeQuery( "SELECT TEXT FROM SYSCAT.COLUMNS" //$NON-NLS-1$ + " WHERE TABSCHEMA='" + LUWUtil.getIdentifier(schema.getName()) // $NON-NLS-1$ + "' AND TABNAME='" + LUWUtil.getIdentifier(table.getName()) // $NON-NLS-1$ + "' AND COLNAME='" + LUWUtil.getIdentifier(this.getName()) + "'"); //$NON-NLS-1$ //$NON-NLS-2$ while (r.next()) { String exprValue = r.getString("TEXT"); // $NON-NLS-1$ if (exprValue != null && exprValue.length() > 0) { ValueExpression expr = (ValueExpression) factory.create(SQLExpressionsPackage.eINSTANCE.getValueExpressionDefault()); this.setGenerateExpression(expr); int pos = exprValue.indexOf("AS"); // $NON-NLS-1$ if (pos >= 0) { exprValue = exprValue.substring(pos + 2).trim(); } expr.setSQL(exprValue); } } r.close(); s.close(); } catch (Exception e) { e.printStackTrace(); } this.eSetDeliver(deliver); }