public void addArrayEntries(ConnectionWrapper cw, Long arrayId,
			Object array, DelayedInsertionBuffer delayBuffer)
			throws SQLException
	{
		ProtectionManager protectionManager = adapter.getPersist()
				.getProtectionManager();
		Class<?> compType = array.getClass().getComponentType();
		// the table name for the relation entries
		String tableName = NameGenerator.getArrayMemberTableName(compType,
				adapter);
		// create the statement
		StringBuilder builder = new StringBuilder("INSERT INTO ");
		builder.append(tableName);
		builder.append("(");
		builder.append(Defaults.ARRAY_MEMBER_ID);
		builder.append(",");
		builder.append(Defaults.ARRAY_POSITION);
		builder.append(",");
		builder.append(Defaults.VALUE_COL);
		builder.append(",");
		builder.append(Defaults.COMPONENT_CLASS_COL);
		builder.append(")values(?,?,?,?)");
		String statement = builder.toString();
		int length = Array.getLength(array);
		// iterate over all the elements
		for (int x = 0; x < length; x++)
		{
			PreparedStatement ps = cw.prepareStatement(statement);
			ps.setLong(1, arrayId);
			ps.setInt(2, x);
			Object value = Array.get(array, x);
			if (ObjectTools.isDatabasePrimitive(compType))
			{
				// The array entry is a primitive type, add it directly
				Tools.setParameter(ps, compType, 3, value);
				Integer compTypeNameId = adapter.getPersist().getClassNameNumberMap().getNumber(cw, compType);
				ps.setInt(4, compTypeNameId);
				Tools.logFine(ps);
				ps.execute();
				ps.close();
				// get the new id of the __ARRAY_MEMBER entry
				Long memberId = adapter.getPersist().getLastId(cw, tableName);
				// add a protection entry for the __ARRAY table
				protectionManager.protectObjectInternal(
						NameGenerator.getArrayTablename(adapter), arrayId,null, NameGenerator
								.getArrayMemberTableName(compType, adapter),
						memberId, NameGenerator.getSystemicName(Array.get(array,
								x).getClass()), cw);

			}
			else
			{
				// this is another type of object, insert a reference
				ps.setInt(4, adapter.getPersist().getClassNameNumberMap().getNumber(cw,value.getClass()));
				Long valueId = adapter.getPersist().saveObjectUnprotected(cw,
						value, delayBuffer);
				Long memberId = null;
				if (valueId == null)
				{
					// This means the object exists, either independently
					// or as part of another array.
					ps.setNull(3, java.sql.Types.BIGINT);
					Tools.logFine(ps);
					// save the object
					ps.execute();
					ps.close();
					// get the new id of the __ARRAY_MEMBER entry
					memberId = adapter.getPersist().getLastId(cw, tableName);
					// this is a circularly referenced object
					// mark it for later insertion
					delayBuffer.add(tableName, Defaults.VALUE_COL, memberId,
							value, compType,System.identityHashCode(array));
				}
				else
				{
					ps.setLong(3, valueId);
					Tools.logFine(ps);
					ps.execute();
					ps.close();
					// get the new id of the __ARRAY_MEMBER entry
					memberId = adapter.getPersist().getLastId(cw, tableName);
				}

				String valueClassName = null;
				String propertyName = NameGenerator.getArrayTablename(adapter);
				// add a protection entry for the __ARRAY table
				if (!compType.isArray())
				{
					valueClassName = NameGenerator.getSystemicName(value
							.getClass());
					propertyName = NameGenerator
							.getTableName(compType, adapter);
				}
				if (valueId != null)
				{
					// protect the object with array-member table as owner
					protectionManager
							.protectObjectInternal(tableName, memberId,null,
									propertyName, valueId, valueClassName, cw);
				}
				// protect the array-member with array as owner
				protectionManager.protectObjectInternal(
						NameGenerator.getArrayTablename(adapter), arrayId, null,tableName,
						memberId, valueClassName, cw);

			}
		}
	}