List of usage examples for java.sql PreparedStatement setByte
void setByte(int parameterIndex, byte x) throws SQLException;
byte
value. From source file:com.jagornet.dhcp.db.JdbcIaAddressDAO.java
public void update(final IaAddress iaAddr) { String updateQuery = "update iaaddress" + " set ipaddress=?," + " starttime=?," + " preferredendtime=?," + " validendtime=?," + " state=?," + " identityassoc_id=?" + " where id=?"; getJdbcTemplate().update(updateQuery, new PreparedStatementSetter() { @Override/*from ww w . j a v a 2 s . c om*/ public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, iaAddr.getIpAddress().getAddress()); Date start = iaAddr.getStartTime(); if (start != null) { java.sql.Timestamp sts = new java.sql.Timestamp(start.getTime()); ps.setTimestamp(2, sts, Util.GMT_CALENDAR); } else { ps.setNull(2, java.sql.Types.TIMESTAMP); } Date preferred = iaAddr.getPreferredEndTime(); if (preferred != null) { java.sql.Timestamp pts = new java.sql.Timestamp(preferred.getTime()); ps.setTimestamp(3, pts, Util.GMT_CALENDAR); } else { ps.setNull(3, java.sql.Types.TIMESTAMP); } Date valid = iaAddr.getValidEndTime(); if (valid != null) { java.sql.Timestamp vts = new java.sql.Timestamp(valid.getTime()); ps.setTimestamp(4, vts, Util.GMT_CALENDAR); } else { ps.setNull(4, java.sql.Types.TIMESTAMP); } ps.setByte(5, iaAddr.getState()); ps.setLong(6, iaAddr.getIdentityAssocId()); ps.setLong(7, iaAddr.getId()); } }); }
From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java
private PreparedStatement createPreapredStatementUsingSetXXX(String sql) throws SQLException { PreparedStatement ps = con.prepareStatement(sql); ps.setBoolean(1, true); //setBoolean ps.setBoolean(2, true); //setBoolean ps.setShort(3, Short.valueOf("1")); //setShort ps.setInt(4, 2); //setInt ps.setFloat(5, 3f); //setFloat ps.setDouble(6, Double.valueOf(4)); //setDouble ps.setString(7, "test'string\""); //setString ps.setLong(8, 5L); //setLong ps.setByte(9, (byte) 1); //setByte ps.setByte(10, (byte) 1); //setByte ps.setString(11, "2012-01-01"); //setString ps.setMaxRows(2);/* w w w.j a v a2s . c o m*/ return ps; }
From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java
public void update(final IaPrefix iaPrefix) { String updateQuery = "update iaprefix" + " set prefixaddress=?," + " prefixlength=?," + " starttime=?," + " preferredendtime=?," + " validendtime=?," + " state=?," + " identityassoc_id=?" + " where id=?"; getJdbcTemplate().update(updateQuery, new PreparedStatementSetter() { @Override//from www. ja v a2 s .c o m public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, iaPrefix.getIpAddress().getAddress()); ps.setInt(2, iaPrefix.getPrefixLength()); Date start = iaPrefix.getStartTime(); if (start != null) { java.sql.Timestamp sts = new java.sql.Timestamp(start.getTime()); ps.setTimestamp(3, sts, Util.GMT_CALENDAR); } else { ps.setNull(3, java.sql.Types.TIMESTAMP); } Date preferred = iaPrefix.getPreferredEndTime(); if (preferred != null) { java.sql.Timestamp pts = new java.sql.Timestamp(preferred.getTime()); ps.setTimestamp(4, pts, Util.GMT_CALENDAR); } else { ps.setNull(4, java.sql.Types.TIMESTAMP); } Date valid = iaPrefix.getValidEndTime(); if (valid != null) { java.sql.Timestamp vts = new java.sql.Timestamp(valid.getTime()); ps.setTimestamp(5, vts, Util.GMT_CALENDAR); } else { ps.setNull(5, java.sql.Types.TIMESTAMP); } ps.setByte(6, iaPrefix.getState()); ps.setLong(7, iaPrefix.getIdentityAssocId()); ps.setLong(8, iaPrefix.getId()); } }); }
From source file:org.latticesoft.util.resource.dao.Param.java
private void setValueToStatement(Object o, PreparedStatement pstmt) throws SQLException { if (log.isDebugEnabled()) { log.debug(this.sqlIndex + "=" + o); }/* w w w.j a v a 2s .c om*/ switch (this.sqlType) { case Types.VARCHAR: case Types.CHAR: String s = (String) o; pstmt.setString(this.sqlIndex, s); break; case Types.BOOLEAN: if (o != null && o instanceof Boolean) { boolean b = ((Boolean) o).booleanValue(); pstmt.setBoolean(this.sqlIndex, b); } break; case Types.INTEGER: if (o != null && o instanceof Integer) { int i = ((Integer) o).intValue(); pstmt.setInt(this.sqlIndex, i); } break; case Types.SMALLINT: if (o != null && o instanceof Short) { short ss = ((Short) o).shortValue(); pstmt.setShort(this.sqlIndex, ss); } break; case Types.TINYINT: if (o != null && o instanceof Byte) { byte bb = ((Byte) o).byteValue(); pstmt.setByte(this.sqlIndex, bb); } break; case Types.BIGINT: if (o != null && o instanceof Long) { long l = ((Long) o).longValue(); pstmt.setLong(this.sqlIndex, l); } break; case Types.DOUBLE: if (o != null && o instanceof Double) { double dd = ((Double) o).doubleValue(); pstmt.setDouble(this.sqlIndex, dd); } break; case Types.FLOAT: if (o != null && o instanceof Float) { float f = ((Float) o).floatValue(); pstmt.setFloat(this.sqlIndex, f); } break; case Types.NUMERIC: if (o != null && o instanceof BigDecimal) { BigDecimal bd = (BigDecimal) o; pstmt.setBigDecimal(this.sqlIndex, bd); } break; case Types.TIMESTAMP: if (o != null && o instanceof Timestamp) { Timestamp ts = (Timestamp) o; pstmt.setTimestamp(this.sqlIndex, ts); } break; case Types.NULL: if (log.isDebugEnabled()) { log.debug(this.sqlIndex + " IS NULL"); } pstmt.setNull(this.sqlIndex, Types.NULL); break; default: if (o != null) { pstmt.setObject(this.sqlIndex, o); } } }
From source file:com.draagon.meta.manager.db.ObjectManagerDB.java
protected PreparedStatement getPreparedStatement(Connection c, String query, Collection<?> args) throws MetaException, SQLException { String sql = query; // (String) mOQLCache.get( query ); // If it's not in the cache, then parse it and put it there //if ( sql == null ) //{//from w w w .j a v a2s . c o m //Map<String,MetaClass> m = getMetaClassMap( query ); //if ( m.size() > 0 ) { // sql = convertToSQL( query, m ); //} //else sql = query; //mOQLCache.put( query, sql ); //} PreparedStatement s = c.prepareStatement(sql); if (args != null) { int i = 1; for (Object o : args) { if (o instanceof Boolean) { s.setBoolean(i, (Boolean) o); } else if (o instanceof Byte) { s.setByte(i, (Byte) o); } else if (o instanceof Short) { s.setShort(i, (Short) o); } else if (o instanceof Integer) { s.setInt(i, (Integer) o); } else if (o instanceof Long) { s.setLong(i, (Long) o); } else if (o instanceof Float) { s.setFloat(i, (Float) o); } else if (o instanceof Double) { s.setDouble(i, (Double) o); } else if (o instanceof Date) { s.setTimestamp(i, new Timestamp(((Date) o).getTime())); } else if (o == null) { s.setString(i, null); } else { s.setString(i, o.toString()); } // Increment the i i++; } } return s; }
From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.java
private void setArgument(PreparedStatement pstmt, String argument, int targetSqlType, int index) throws SQLException { switch (targetSqlType) { case Types.INTEGER: pstmt.setInt(index, Integer.parseInt(argument)); break;/*from w ww.jav a2s. c o m*/ case Types.DECIMAL: case Types.NUMERIC: pstmt.setBigDecimal(index, new BigDecimal(argument)); break; case Types.DOUBLE: case Types.FLOAT: pstmt.setDouble(index, Double.parseDouble(argument)); break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: pstmt.setString(index, argument); break; case Types.BIT: case Types.BOOLEAN: pstmt.setBoolean(index, Boolean.parseBoolean(argument)); break; case Types.BIGINT: pstmt.setLong(index, Long.parseLong(argument)); break; case Types.DATE: pstmt.setDate(index, Date.valueOf(argument)); break; case Types.REAL: pstmt.setFloat(index, Float.parseFloat(argument)); break; case Types.TINYINT: pstmt.setByte(index, Byte.parseByte(argument)); break; case Types.SMALLINT: pstmt.setShort(index, Short.parseShort(argument)); break; case Types.TIMESTAMP: pstmt.setTimestamp(index, Timestamp.valueOf(argument)); break; case Types.TIME: pstmt.setTime(index, Time.valueOf(argument)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: pstmt.setBytes(index, argument.getBytes()); break; case Types.NULL: pstmt.setNull(index, targetSqlType); break; default: pstmt.setObject(index, argument, targetSqlType); } }
From source file:org.apache.phoenix.query.BaseTest.java
protected static void initATableValues(String tenantId, byte[][] splits, Date date, Long ts, String url) throws Exception { if (ts == null) { ensureTableCreated(url, ATABLE_NAME, splits); } else {/*from w w w . j a v a 2 s . c o m*/ ensureTableCreated(url, ATABLE_NAME, splits, ts - 5); } Properties props = new Properties(); if (ts != null) { props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts - 3)); } Connection conn = DriverManager.getConnection(url, props); try { // Insert all rows at ts PreparedStatement stmt = conn.prepareStatement("upsert into " + "ATABLE(" + " ORGANIZATION_ID, " + " ENTITY_ID, " + " A_STRING, " + " B_STRING, " + " A_INTEGER, " + " A_DATE, " + " X_DECIMAL, " + " X_LONG, " + " X_INTEGER," + " Y_INTEGER," + " A_BYTE," + " A_SHORT," + " A_FLOAT," + " A_DOUBLE," + " A_UNSIGNED_FLOAT," + " A_UNSIGNED_DOUBLE)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, tenantId); stmt.setString(2, ROW1); stmt.setString(3, A_VALUE); stmt.setString(4, B_VALUE); stmt.setInt(5, 1); stmt.setDate(6, date); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 1); stmt.setShort(12, (short) 128); stmt.setFloat(13, 0.01f); stmt.setDouble(14, 0.0001); stmt.setFloat(15, 0.01f); stmt.setDouble(16, 0.0001); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW2); stmt.setString(3, A_VALUE); stmt.setString(4, C_VALUE); stmt.setInt(5, 2); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 2); stmt.setShort(12, (short) 129); stmt.setFloat(13, 0.02f); stmt.setDouble(14, 0.0002); stmt.setFloat(15, 0.02f); stmt.setDouble(16, 0.0002); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW3); stmt.setString(3, A_VALUE); stmt.setString(4, E_VALUE); stmt.setInt(5, 3); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 3); stmt.setShort(12, (short) 130); stmt.setFloat(13, 0.03f); stmt.setDouble(14, 0.0003); stmt.setFloat(15, 0.03f); stmt.setDouble(16, 0.0003); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW4); stmt.setString(3, A_VALUE); stmt.setString(4, B_VALUE); stmt.setInt(5, 4); stmt.setDate(6, date == null ? null : date); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 4); stmt.setShort(12, (short) 131); stmt.setFloat(13, 0.04f); stmt.setDouble(14, 0.0004); stmt.setFloat(15, 0.04f); stmt.setDouble(16, 0.0004); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW5); stmt.setString(3, B_VALUE); stmt.setString(4, C_VALUE); stmt.setInt(5, 5); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 5); stmt.setShort(12, (short) 132); stmt.setFloat(13, 0.05f); stmt.setDouble(14, 0.0005); stmt.setFloat(15, 0.05f); stmt.setDouble(16, 0.0005); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW6); stmt.setString(3, B_VALUE); stmt.setString(4, E_VALUE); stmt.setInt(5, 6); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2)); stmt.setBigDecimal(7, null); stmt.setNull(8, Types.BIGINT); stmt.setNull(9, Types.INTEGER); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 6); stmt.setShort(12, (short) 133); stmt.setFloat(13, 0.06f); stmt.setDouble(14, 0.0006); stmt.setFloat(15, 0.06f); stmt.setDouble(16, 0.0006); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW7); stmt.setString(3, B_VALUE); stmt.setString(4, B_VALUE); stmt.setInt(5, 7); stmt.setDate(6, date == null ? null : date); stmt.setBigDecimal(7, BigDecimal.valueOf(0.1)); stmt.setLong(8, 5L); stmt.setInt(9, 5); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 7); stmt.setShort(12, (short) 134); stmt.setFloat(13, 0.07f); stmt.setDouble(14, 0.0007); stmt.setFloat(15, 0.07f); stmt.setDouble(16, 0.0007); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW8); stmt.setString(3, B_VALUE); stmt.setString(4, C_VALUE); stmt.setInt(5, 8); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1)); stmt.setBigDecimal(7, BigDecimal.valueOf(3.9)); long l = Integer.MIN_VALUE - 1L; assert (l < Integer.MIN_VALUE); stmt.setLong(8, l); stmt.setInt(9, 4); stmt.setNull(10, Types.INTEGER); stmt.setByte(11, (byte) 8); stmt.setShort(12, (short) 135); stmt.setFloat(13, 0.08f); stmt.setDouble(14, 0.0008); stmt.setFloat(15, 0.08f); stmt.setDouble(16, 0.0008); stmt.execute(); stmt.setString(1, tenantId); stmt.setString(2, ROW9); stmt.setString(3, C_VALUE); stmt.setString(4, E_VALUE); stmt.setInt(5, 9); stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2)); stmt.setBigDecimal(7, BigDecimal.valueOf(3.3)); l = Integer.MAX_VALUE + 1L; assert (l > Integer.MAX_VALUE); stmt.setLong(8, l); stmt.setInt(9, 3); stmt.setInt(10, 300); stmt.setByte(11, (byte) 9); stmt.setShort(12, (short) 0); stmt.setFloat(13, 0.09f); stmt.setDouble(14, 0.0009); stmt.setFloat(15, 0.09f); stmt.setDouble(16, 0.0009); stmt.execute(); conn.commit(); } finally { conn.close(); } }
From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java
/** * This method bind values to prepared statement. * * @param type data Type/*from www . j av a 2 s . c o m*/ * @param value String value * @param ordinalPosition Ordinal Position * @param sqlStatement Statement * @throws SQLException * @throws ParseException * @throws ODataServiceFault */ private void bindValuesToPreparedStatement(int type, String value, int ordinalPosition, PreparedStatement sqlStatement) throws SQLException, ParseException, ODataServiceFault { byte[] data; try { switch (type) { case Types.INTEGER: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setInt(ordinalPosition, ConverterUtil.convertToInt(value)); } break; case Types.TINYINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setByte(ordinalPosition, ConverterUtil.convertToByte(value)); } break; case Types.SMALLINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setShort(ordinalPosition, ConverterUtil.convertToShort(value)); } break; case Types.DOUBLE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDouble(ordinalPosition, ConverterUtil.convertToDouble(value)); } break; case Types.VARCHAR: /* fall through */ case Types.CHAR: /* fall through */ case Types.LONGVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; case Types.CLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BOOLEAN: /* fall through */ case Types.BIT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBoolean(ordinalPosition, ConverterUtil.convertToBoolean(value)); } break; case Types.BLOB: /* fall through */ case Types.LONGVARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBlob(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.BINARY: /* fall through */ case Types.VARBINARY: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { data = this.getBytesFromBase64String(value); sqlStatement.setBinaryStream(ordinalPosition, new ByteArrayInputStream(data), data.length); } break; case Types.DATE: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setDate(ordinalPosition, DBUtils.getDate(value)); } break; case Types.DECIMAL: /* fall through */ case Types.NUMERIC: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setBigDecimal(ordinalPosition, ConverterUtil.convertToBigDecimal(value)); } break; case Types.FLOAT: /* fall through */ case Types.REAL: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setFloat(ordinalPosition, ConverterUtil.convertToFloat(value)); } break; case Types.TIME: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTime(ordinalPosition, DBUtils.getTime(value)); } break; case Types.LONGNVARCHAR: /* fall through */ case Types.NCHAR: /* fall through */ case Types.NVARCHAR: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNString(ordinalPosition, value); } break; case Types.NCLOB: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setNClob(ordinalPosition, new BufferedReader(new StringReader(value)), value.length()); } break; case Types.BIGINT: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setLong(ordinalPosition, ConverterUtil.convertToLong(value)); } break; case Types.TIMESTAMP: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setTimestamp(ordinalPosition, DBUtils.getTimestamp(value)); } break; default: if (value == null) { sqlStatement.setNull(ordinalPosition, type); } else { sqlStatement.setString(ordinalPosition, value); } break; } } catch (DataServiceFault e) { throw new ODataServiceFault(e, "Error occurred while binding values. :" + e.getMessage()); } }
From source file:com.kylinolap.rest.service.QueryService.java
/** * @param preparedState// w w w . j a va2 s . c om * @param param * @throws SQLException */ private void setParam(PreparedStatement preparedState, int index, StateParam param) throws SQLException { boolean isNull = (null == param.getValue()); Class<?> clazz = Object.class; try { clazz = Class.forName(param.getClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } Rep rep = Rep.of(clazz); switch (rep) { case PRIMITIVE_CHAR: case CHARACTER: case STRING: preparedState.setString(index, isNull ? null : String.valueOf(param.getValue())); break; case PRIMITIVE_INT: case INTEGER: preparedState.setInt(index, isNull ? null : Integer.valueOf(param.getValue())); break; case PRIMITIVE_SHORT: case SHORT: preparedState.setShort(index, isNull ? null : Short.valueOf(param.getValue())); break; case PRIMITIVE_LONG: case LONG: preparedState.setLong(index, isNull ? null : Long.valueOf(param.getValue())); break; case PRIMITIVE_FLOAT: case FLOAT: preparedState.setFloat(index, isNull ? null : Float.valueOf(param.getValue())); break; case PRIMITIVE_DOUBLE: case DOUBLE: preparedState.setDouble(index, isNull ? null : Double.valueOf(param.getValue())); break; case PRIMITIVE_BOOLEAN: case BOOLEAN: preparedState.setBoolean(index, isNull ? null : Boolean.parseBoolean(param.getValue())); break; case PRIMITIVE_BYTE: case BYTE: preparedState.setByte(index, isNull ? null : Byte.valueOf(param.getValue())); break; case JAVA_UTIL_DATE: case JAVA_SQL_DATE: preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue())); break; case JAVA_SQL_TIME: preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue())); break; case JAVA_SQL_TIMESTAMP: preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue())); break; default: preparedState.setObject(index, isNull ? null : param.getValue()); } }
From source file:com.flexive.ejb.beans.structure.TypeEngineBean.java
/** * Create a new type/*from ww w. j av a 2 s . c om*/ * * @param type the type to create * @return id of the new type * @throws FxApplicationException on errors */ private long create(FxTypeEdit type) throws FxApplicationException { final UserTicket ticket = FxContext.getUserTicket(); FxPermissionUtils.checkRole(ticket, Role.StructureManagement); final FxEnvironment environment = CacheAdmin.getEnvironment(); if (StringUtils.isEmpty(type.getName())) throw new FxInvalidParameterException("NAME", "ex.structure.create.nameMissing"); if (!type.getStorageMode().isSupported()) throw new FxInvalidParameterException("STORAGEMODE", "ex.structure.typeStorageMode.notSupported", type.getStorageMode().getLabel().getBestTranslation(ticket)); if (type.getACL().getCategory() != ACLCategory.STRUCTURE) throw new FxInvalidParameterException("aclId", "ex.acl.category.invalid", type.getACL().getCategory().name(), ACLCategory.STRUCTURE.name()); if (type.hasDefaultInstanceACL() && type.getDefaultInstanceACL().getCategory() != ACLCategory.INSTANCE) throw new FxInvalidParameterException("DEFACL", "ex.acl.category.invalid", type.getDefaultInstanceACL().getCategory(), ACLCategory.INSTANCE); Connection con = null; PreparedStatement ps = null; long newId = seq.getId(FxSystemSequencer.TYPEDEF); final long NOW = System.currentTimeMillis(); try { con = Database.getDbConnection(); ps = con.prepareStatement(TYPE_CREATE); ps.setLong(1, newId); ps.setString(2, type.getName()); if (type.getParent() != null) ps.setLong(3, type.getParent().getId()); else ps.setNull(3, java.sql.Types.INTEGER); ps.setInt(4, type.getStorageMode().getId()); ps.setInt(5, type.getCategory().getId()); ps.setInt(6, type.getMode().getId()); ps.setInt(7, type.getLanguage().getId()); ps.setInt(8, type.getState().getId()); ps.setByte(9, type.getBitCodedPermissions()); ps.setBoolean(10, type.isTrackHistory()); ps.setLong(11, type.getHistoryAge()); ps.setLong(12, type.getMaxVersions()); ps.setInt(13, type.getMaxRelSource()); ps.setInt(14, type.getMaxRelDestination()); ps.setLong(15, ticket.getUserId()); ps.setLong(16, NOW); ps.setLong(17, ticket.getUserId()); ps.setLong(18, NOW); ps.setLong(19, type.getACL().getId()); ps.setLong(20, type.getWorkflow().getId()); if (type.getIcon().isEmpty()) ps.setNull(21, java.sql.Types.INTEGER); else ps.setLong(21, type.getIcon().getDefaultTranslation().getId()); ps.setBoolean(22, type.isUseInstancePermissions() && type.isMultipleContentACLs()); ps.setBoolean(23, type.isIncludedInSupertypeQueries()); if (type.hasDefaultInstanceACL()) ps.setLong(24, type.getDefaultInstanceACL().getId()); else ps.setNull(24, java.sql.Types.INTEGER); ps.setBoolean(25, type.isAutoVersion()); ps.executeUpdate(); Database.storeFxString(type.getLabel(), con, TBL_STRUCT_TYPES, "DESCRIPTION", "ID", newId); StructureLoader.reload(con); FxType thisType = CacheAdmin.getEnvironment().getType(newId); htracker.track(thisType, "history.type.create", type.getName(), newId); //store relations ps.close(); if (type.getAddedRelations().size() > 0) { ps = con.prepareStatement("INSERT INTO " + TBL_STRUCT_TYPERELATIONS + " (TYPEDEF,TYPESRC,TYPEDST,MAXSRC,MAXDST)VALUES(?,?,?,?,?)"); ps.setLong(1, thisType.getId()); for (FxTypeRelation rel : type.getAddedRelations()) { if (rel.getSource().isRelation()) throw new FxInvalidParameterException("ex.structure.type.relation.wrongTarget", type.getName(), rel.getSource().getName()); if (rel.getDestination().isRelation()) throw new FxInvalidParameterException("ex.structure.type.relation.wrongTarget", type.getName(), rel.getDestination().getName()); ps.setLong(2, rel.getSource().getId()); ps.setLong(3, rel.getDestination().getId()); ps.setLong(4, rel.getMaxSource()); ps.setLong(5, rel.getMaxDestination()); ps.addBatch(); htracker.track(thisType, "history.type.create.relation.add", type.getName(), rel.getSource().getName(), rel.getMaxSource(), rel.getDestination().getName(), rel.getMaxDestination()); } ps.executeBatch(); } if (type.getParent() == null) { for (FxPropertyAssignment spa : environment.getSystemInternalRootPropertyAssignments()) { final FxPropertyAssignmentEdit derived = FxPropertyAssignmentEdit.createNew(spa, thisType, spa.getAlias(), "/"); assignmentEngine.save( updateAclAssignmentMultiplicity(type, derived).setEnabled(true)._setSystemInternal(), false); } } else { //create parent assignments List<FxAssignment> parentAssignments = type.getParent().getConnectedAssignments("/"); for (FxAssignment as : parentAssignments) { if (as instanceof FxPropertyAssignment) { FxPropertyAssignmentEdit pae = FxPropertyAssignmentEdit.createNew((FxPropertyAssignment) as, thisType, as.getAlias(), "/"); pae.setEnabled(type.isEnableParentAssignments()); assignmentEngine.save(updateAclAssignmentMultiplicity(type, pae), false); } else if (as instanceof FxGroupAssignment) { FxGroupAssignmentEdit pge = FxGroupAssignmentEdit.createNew((FxGroupAssignment) as, thisType, as.getAlias(), "/"); pge.setEnabled(type.isEnableParentAssignments()); assignmentEngine.save(pge, true); } } } // store structure options storeTypeOptions(con, TBL_STRUCT_TYPES_OPTIONS, "ID", newId, type.getOptions(), false); StructureLoader.reload(con); } catch (SQLException e) { if (StorageManager.isUniqueConstraintViolation(e)) { EJBUtils.rollback(ctx); throw new FxCreateException("ex.structure.type.exists", type.getName()); } EJBUtils.rollback(ctx); throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage()); } catch (FxCacheException e) { EJBUtils.rollback(ctx); throw new FxCreateException(LOG, e, "ex.cache", e.getMessage()); } catch (FxLoadException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } catch (FxNotFoundException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } catch (FxEntryExistsException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } catch (FxUpdateException e) { EJBUtils.rollback(ctx); throw new FxCreateException(e); } finally { Database.closeObjects(TypeEngineBean.class, con, ps); } return newId; }