/** * Overrides the parent implementation to provide a more efficient mechanism for generating * primary keys, while generating the primary key support on the fly. * * @param count the batch size * @param entity the entity requesting primary keys * @param channel open JDBCChannel * @return NSArray of NSDictionary where each dictionary corresponds to a unique primary key value */ public NSArray newPrimaryKeys(int count, EOEntity entity, JDBCChannel channel) { if (isPrimaryKeyGenerationNotSupported(entity)) { return null; } EOAttribute attribute = (EOAttribute) entity.primaryKeyAttributes().lastObject(); String attrName = attribute.name(); boolean isIntType = "i".equals(attribute.valueType()); NSMutableArray results = new NSMutableArray(count); String sequenceName = sequenceNameForEntity(entity); DB2Expression expression = new DB2Expression(entity); boolean succeeded = false; for (int tries = 0; !succeeded && tries < 2; tries++) { while (results.count() < count) { try { StringBuffer sql = new StringBuffer(); sql.append("SELECT "); sql.append("next value for " + sequenceName + " AS KEY"); sql.append(" from sysibm.sysdummy1"); expression.setStatement(sql.toString()); channel.evaluateExpression(expression); try { NSDictionary row; while ((row = channel.fetchRow()) != null) { Enumeration pksEnum = row.allValues().objectEnumerator(); while (pksEnum.hasMoreElements()) { Number pkObj = (Number) pksEnum.nextElement(); Number pk; if (isIntType) { pk = Integer.valueOf(pkObj.intValue()); } else { pk = Long.valueOf(pkObj.longValue()); } results.addObject(new NSDictionary(pk, attrName)); } } } finally { channel.cancelFetch(); } succeeded = true; } catch (JDBCAdaptorException ex) { throw ex; } } } if (results.count() != count) { throw new IllegalStateException( "Unable to generate primary keys from the sequence for " + entity + "."); } return results; }
@MarshalsPointer public static long toNative(List<CVPixelFormatType> l, long flags) { if (l == null) { return 0L; } NSMutableArray<NSNumber> array = new NSMutableArray<>(); for (CVPixelFormatType i : l) { array.add(NSNumber.valueOf(i.value())); } return NSObject.Marshaler.toNative(array, flags); }
@MarshalsPointer public static long toNative(List<CMVideoCodecType> l, long flags) { if (l == null) { return 0L; } NSMutableArray<NSString> array = new NSMutableArray<>(); for (CMVideoCodecType i : l) { array.add(new NSString(i.asFourCharCode())); } return NSObject.Marshaler.toNative(array, flags); }
@MarshalsPointer public static long toNative(List<SCNMatrix4> l, long flags) { if (l == null) { return 0L; } NSMutableArray<NSValue> array = new NSMutableArray<>(); for (SCNMatrix4 i : l) { array.add(NSValue.valueOf(i)); } return NSObject.Marshaler.toNative(array, flags); }